# Force Grub to select eMMC when Flash Drive plugged in

**URL:** <https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725>\
**Category:** General Discussions\
**Created:** [June 18, 2019, 9:40am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725 "2019-06-18T09:40:17Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![rreignier](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rreignier](https://hub.mender.io/u/rreignier)\
**Post date:** [June 18, 2019, 9:40am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/1 "2019-06-18T09:40:17Z")

</div>

I am using an Upboard so a x86 system with Grub as bootloader.

When booting, the eMMC is referred as `hd0` by Grub so the script `grub.cfg` handle the partitions properly.

But for my system I need an external flash drive to be plugged at boot some time.  
But in that case, Grub refers the USB flash drive as `hd0` and the eMMC as `hd1` so the Grub script do not work and ends with the Grub command line.

Is there a mean to force grub to always use `hd0` for the eMMC?

---

<div class="post-metadata">

**Author:** ![rreignier](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rreignier](https://hub.mender.io/u/rreignier)\
**Post date:** [June 18, 2019, 9:41am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/2 "2019-06-18T09:41:22Z")

</div>

Actually, I have found that the grub command `search` allows to find partition by label or UUID but the default `grub.cfg` would need a lot of changes.

Does anyone managed to handle this?

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [June 18, 2019, 9:42am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/3 "2019-06-18T09:42:28Z")

</div>

Are you using Yocto and in that case which version?

---

<div class="post-metadata">

**Author:** ![rreignier](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rreignier](https://hub.mender.io/u/rreignier)\
**Post date:** [June 18, 2019, 9:46am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/4 "2019-06-18T09:46:58Z")

</div>

@mirzak Yes, I am using Yocto with the **sumo** version.

Thanks

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [June 18, 2019, 9:49am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/5 "2019-06-18T09:49:07Z")

</div>

Ah, unfortunately we do not support booting using UUID on **sumo** , but on **thud** you can active this feature.

> <https://github.com/mendersoftware/meta-mender/blob/thud/meta-mender-core/classes/mender-setup.bbclass#L224-L225>

It is unclear to me what the workaround would be on sumo, and I wonder if the “bios” boot priority can affect what gets assigned to `hd0`.

---

<div class="post-metadata">

**Author:** ![rreignier](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rreignier](https://hub.mender.io/u/rreignier)\
**Post date:** [June 18, 2019, 9:51am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/6 "2019-06-18T09:51:52Z")

</div>

Ah, interesting.  
I am stucked on sumo because of `meta-upboard` for now but I may try to port it to thud.

---

<div class="post-metadata">

**Author:** ![rreignier](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rreignier](https://hub.mender.io/u/rreignier)\
**Post date:** [June 18, 2019, 9:54am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/7 "2019-06-18T09:54:01Z")

</div>

In my case, the bios boot priority does not seem to affect grub naming.

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [June 18, 2019, 9:56am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/8 "2019-06-18T09:56:27Z")

</div>

One quick way to move to **thud** is to utilize `meta-intel` and `intel-corei7-64` machine which also works on Up boards.

But this depends on if you rely on functionality that is available in meta-up-board.

---

<div class="post-metadata">

**Author:** ![rreignier](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rreignier](https://hub.mender.io/u/rreignier)\
**Post date:** [June 18, 2019, 9:58am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/9 "2019-06-18T09:58:10Z")

</div>

Ah yes, I should go that way because I do not use specific UpBoard features like GPIO.

And anyway, I can apply upboard kernel patches manually on top of meta-intel.

---

<div class="post-metadata">

**Author:** ![rreignier](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rreignier](https://hub.mender.io/u/rreignier)\
**Post date:** [September 2, 2019, 1:24pm UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/10 "2019-09-02T13:24:47Z")

</div>

@mirzak I have moved my system to the `thud` branch but the `partuuid` feature does not fix my issue because it is the whole disk the issue.

With no USB drive inserted, the internal eMMC of the Upboard appears has `hd0` in Grub but with the USB drive inserted, the eMMC appears has `hd1`.

Changing boot order does not change anything.

Did you think of any solution?

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [September 9, 2019, 6:53am UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/11 "2019-09-09T06:53:44Z")

</div>

Makes sense now, that `partuuid` only applies to the `mender_root` variable and not to the `mender_grub_storage_device`.

I can not think of an easy way to get around this, because GRUB is not able to scan/probe for a partuuid.

But I know of one user who has solved a similar problem using the GRUB [search](https://www.gnu.org/software/grub/manual/grub/grub.html#search) command, which supports looking up filesystem image by label or fs-uuid. But this would require changes to the grub.cfg file + making sure that the partitions are labeled accordingly on each update.

---

<div class="post-metadata">

**Author:** ![mdavis777](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mdavis777/32/65_2.png) [@mdavis777](https://hub.mender.io/u/mdavis777)\
**Post date:** [September 16, 2019, 2:25pm UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/12 "2019-09-16T14:25:49Z")

</div>

Copy and paste my response from [992](https://hub.mender.io/t/adding-mender-partuuid-causes-an-error-dev-sda1-does-not-contain-a-valid-partuuid-path/992) so people can find it in either place.

I somewhat solved this issue back when I implemented partuuid.  
A small secret about the grub disk order is that it is derived from the BIOS boot priority order (in most cases). So if the disk you have grub on is highest in boot priority there is a good chance it will always be hd0 regardless of new media being added.

Not a perfect solution but it should cover most embedded cases where someone isn’t expecting to boot from a different device.

---

<div class="post-metadata">

**Author:** ![rreignier](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rreignier](https://hub.mender.io/u/rreignier)\
**Post date:** [September 16, 2019, 2:42pm UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/13 "2019-09-16T14:42:58Z")

</div>

@mdavis777 Oh great. You seem lucky. I could not managed to do the same on the UpBoard, even after updating the BIOS.

---

<div class="post-metadata">

**Author:** ![mdavis777](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mdavis777/32/65_2.png) [@mdavis777](https://hub.mender.io/u/mdavis777)\
**Post date:** [September 16, 2019, 3:17pm UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/14 "2019-09-16T15:17:43Z")

</div>

@rreignier

Unfortunately that is why I had to add the caveat of in most cases. It is supposed to be 100%, but not every BIOS does the magic grub is expecting.  
You may want to contact UP and see if they have something in the BIOS that is forcing USB to always be higher in boot priority.  
Also make sure to check the setting with the USB drive inserted. Sometimes they only show the devices connected in the priority list.

---

<div class="post-metadata">

**Author:** ![mirzak](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/mirzak/32/2056_2.png) [@mirzak](https://hub.mender.io/u/mirzak)\
**Post date:** [March 28, 2020, 3:21pm UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/15 "2020-03-28T15:21:49Z")

</div>

FYI, there are changed up for merge that will resolve this, meaning that `mender_grub_storage_device` is dynamically determined at run-time.

> <https://github.com/mendersoftware/meta-mender/pull/951>

---

<div class="post-metadata">

**Author:** ![rreignier](https://avatars.discourse-cdn.com/v4/letter/r/ec9cab/32.png) [@rreignier](https://hub.mender.io/u/rreignier)\
**Post date:** [March 30, 2020, 12:01pm UTC](https://hub.mender.io/t/force-grub-to-select-emmc-when-flash-drive-plugged-in/725/16 "2020-03-30T12:01:29Z")

</div>

Thanks a lot for the update @mirzak I really appreciate it!
