# GRUB2: determine device from which it boots



## varda (Nov 13, 2015)

Hello Gentlemen.

I have several HDD/USB drives with GRUB2 boot manager. Sometimes I'm attach them together at once, move between ports. Accordingly, the devices names/numbering changes. How to avoid (hd0,1) and etc hardcoded device selection in config file, i. e. where/how GRUB2 saves (which variable or other way) the device from which it boots?

Thanks.


----------



## Carpetsmoker (Nov 15, 2015)

This is why using a filesystem UUID is useful. For example from my Ubuntu box:


```
search --no-floppy --fs-uuid --set=root 1abbe84a-ae35-4e95-825f-9a5b055654b9
linux /boot/vmlinuz-3.19.0-33-generic.efi.signed root=UUID=1abbe84a-ae35-4e95-825f-9a5b055654b9 ro  quiet splash $vt_handoff
initrd  /boot/initrd.img-3.19.0-25-generic
```

The first line tries to find a filesystem with the UUID "1abbe84a-ae35-4e95-825f-9a5b055654b9", and sets the root variable to whatever that is; it's the same as set root=(hd0,gpt1).

I've never booted FreeBSD with this, but this should point you in the right direction ;-)


----------



## tobik@ (Nov 15, 2015)

On FreeBSD use e.g. `gpart list ada0` to find the UUID of your root partition.

GRUB's search command also has support for labels: `search --label yourlabel`


----------



## varda (Nov 19, 2015)

Thanks for your attention and advices, Gentlemen.

I know and use all those methods of partitions differentiation and detection (labels or UUIDs) myself too. Bot frequently I'm just cloning disk and forget to pay attention for labeling or spending extra time to find out UUIDs. Sometimes hurry or distracted from which disk booted and modify erroneously not that I wanted.

In general, to think less, make once common configuration, and just stupidly copy it or even place and forget forever. Sure it is possible automate with script but I wanted to simplify process completely.

That is why I've asked. Although the question is not very important but still relevant.

Thank You.


----------

