Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I'm trying to use partition labels (or UUIDs, that does not matter) to select root partition without use of an initrd/initramfs.

With initramfs, this is fairly easy: root=LABEL=... or root=/dev/disk/by-label/... in the kernel arguments does the job. However, without initramfs the above is not possible: the LABEL= notation is decoded by initramfs script, and /dev/disk/by-label/... symlinks are created by udev running from the initramfs. Only the root=/dev/sdXY notation is understood by the kernel itself.

However, GRUB supports shell-like scripting, and I think that it is somehow possible to write a GRUB 2 scriptlet that will generate root=/dev/sdXY string from a device label or UUID.

Especially, the command search --label <label> --set ROOTDEV will set variable ROOTDEV with a string like hd0,gpt5 which points to the partition with given label. If I understand correctly (please correct me if I'm wrong) the order of devices in GRUB and kernel is the same, so hd0 is /dev/sda, hd1 is /dev/sdb and so on.

So here is a question: is there a way, from inside the GRUB 2 script, to convert hd0,gpt5 into /dev/sda5? Exactly the hd0 into sda part - the rest is easy with regexes.

share|improve this question
    
No, the device in GRUB and kernel has no reason to be the same. –  Stéphane Chazelas Jan 11 '14 at 21:07
1  
You cannot make a purely textual translation: GRUB has to follow BIOS device numbering, and the kernel doesn't, so there is no intrinsic connection between the a in Linux's sda and the 0 in Grub's hd0. You can't do the conversion inside Grub as far as I know, but you can do it from /boot/grub/device.map when generating the Grub configuration file. –  Gilles Jan 11 '14 at 21:49
    
@Gilles: dammit. So is initrd unavoidable in this case?.. –  intelfx Jan 12 '14 at 13:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.