User avatar
jens.maus
Posts: 20
Joined: Sun Jan 01, 2017 10:53 am
Location: Dresden, Germany
Contact: Website

Booting rootfs via "root=LABEL=" or "root=UUID=" (buildroot)

Fri Jun 02, 2017 9:22 am

Hi,

I am currently fighting with getting my buildroot-generated project running in a way that it actually boots the root filesystem using "LABEL=" or "UUID=" specified on the kernel command-line. The reason for thisis, of course, that I want to deliver my image in a way that the cmdline.txt doesn't have to be manually modified by users depending on the way they have installed the *.img on either a microSD card to directly on a USB thumb drive or had disk having it connected to a RaspberryPi3 for directly booting from the USB disk. As said, I am using "buildroot" (version 2017.05) for generating the *.img and the whole rootfs environment and I have already tuned the rootfs in a way that it perfectly uses "LABEL=rootfs" statements in /etc/fstab for mounting all necessary partitions device name independent. The only thing missing is to get the kernel command line accept either "root=LABEL=rootfs" or a "root=UUID=..." entry for letting the kernel know where to mount the root filesystem from. Unfortunately, I have tried many things without success and haven't found a definite answer or howto. That's why I want to ask here for some help.

Has anyone a similar setup running with their Pis? and perhaps even by using build root? Please also note that I don't have a initrd running and I don't want to put the whole rootfs into a initramfs because it is way to large to be put completely in RAM. Also, I didn't find a way in build root to generate a initrd file just for helping the kernel to identify the LABEL= and/or UUID= specifiers and then mount the rootfs accordingly.

However, any help would be of course highly appreciated.

Regards,
Jens

arglebargle
Posts: 9
Joined: Tue May 23, 2017 1:43 am
Location: California

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Sun Jun 04, 2017 9:51 pm

I don't think `root=LABEL=` is actually implemented but I can tell you a little bit about PARTUUID and UUID.

Both root=UUID= and root=PARTUUID= work without issue with the current bootloader and kernel (4.9.24-v7+) as long as you aren't loading an initrd image
. Using an initrd.img causes root=PARTUUID= to fail but root=UUID= functions. I'm not sure what's going on there, but I hope that helps.[/s]

edit: Using an initramfs will boot with UUID and LABEL out of the box, but not with PARTUUID or PARTLABEL. Without using an initramfs booting by PARTUUID is possible but the others won't work. See below.
Last edited by arglebargle on Thu Jun 08, 2017 2:09 am, edited 2 times in total.

vintozver
Posts: 40
Joined: Thu Jun 01, 2017 2:16 am
Location: Bellevue, WA, USA

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Mon Jun 05, 2017 2:10 am

UUID= is NOT implemented in the kernel.
It IS possible to boot with UUID by adding initramfs.

1. # mkinitramfs -o /boot/initrd.img-kernel
2. add to the config.txt file: initramfs initrd.img-kernel followkernel

reboot, enjoy.
Don't forget to rebuild your initrd after every kernel update or module installation.
This will also bring up the ability to boot from LVM root or dmraid, as well as from the network root (provided that kernel/initrd are already loaded).

User avatar
jens.maus
Posts: 20
Joined: Sun Jan 01, 2017 10:53 am
Location: Dresden, Germany
Contact: Website

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Wed Jun 07, 2017 2:36 pm

Thanks for the replies and the comments about PARTUUID and UUID. The reason why I want to have LABEL= working is that in my build environment I just generate partitions with labels so that my distribution is independent on the UUID/PARTUUID changing with regenerating the filesystem. In the end the user should be able to put my *.img generated with buildroot either on the USB stick or on the SD card and then just power up the raspberry pi. I already added LABEL= statements in /etc/fstab and the system is perfectly booting with the labels and either mounts from /dev/sdaX or /dev/mmcblkpX depending on where it finds the filesystem labels.

However, I still can't figure out how I can generate an initrd file within my buildroot build environment so that I can get the kernel to actually mount also via a filesystem LABEL rather than UUID or PARTUUID. I am using buildroot 2017.05 (http://buildroot.org/) here. Nevertheless, if I could find a way to actually generate/modify the PARTUUID in my build environment this could also help. But I couldn't find a way to do this as well.

Any help appreciated!

arglebargle
Posts: 9
Joined: Tue May 23, 2017 1:43 am
Location: California

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Wed Jun 07, 2017 6:24 pm

vintozver wrote:UUID= is NOT implemented in the kernel.
It IS possible to boot with UUID by adding initramfs.

1. # mkinitramfs -o /boot/initrd.img-kernel
2. add to the config.txt file: initramfs initrd.img-kernel followkernel

reboot, enjoy.
Don't forget to rebuild your initrd after every kernel update or module installation.
This will also bring up the ability to boot from LVM root or dmraid, as well as from the network root (provided that kernel/initrd are already loaded).
Ah, you're right, I didn't catch that in my testing.

Here's a fun one, using an initrd without switching from root=PARTUUID= to root=UUID= will cause boot to dump you into busybox.

vintozver
Posts: 40
Joined: Thu Jun 01, 2017 2:16 am
Location: Bellevue, WA, USA

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Wed Jun 07, 2017 7:02 pm

[quote="arglebargleAh, you're right, I didn't catch that in my testing.
Here's a fun one, using an initrd without switching from root=PARTUUID= to root=UUID= will cause boot to dump you into busybox.[/quote]
Correct. Having busybox is a good sign, that means you have kernel&initrd loaded successfully. I guess changing root= won't be a problem ;)

arglebargle
Posts: 9
Joined: Tue May 23, 2017 1:43 am
Location: California

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Wed Jun 07, 2017 8:09 pm

vintozver wrote:[quote="arglebargleAh, you're right, I didn't catch that in my testing.
Here's a fun one, using an initrd without switching from root=PARTUUID= to root=UUID= will cause boot to dump you into busybox.
Correct. Having busybox is a good sign, that means you have kernel&initrd loaded successfully. I guess changing root= won't be a problem ;)[/quote]

Any idea what would need to be done to boot using PARTUUID and an initrd?

vintozver
Posts: 40
Joined: Thu Jun 01, 2017 2:16 am
Location: Bellevue, WA, USA

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Wed Jun 07, 2017 9:07 pm

arglebargle wrote:Any idea what would need to be done to boot using PARTUUID and an initrd?
Generally, udev is built in into initrd, and is responsible for creating /dev/disk/... symlinks. Will need to play with it.
I suggest to do some digging by unpacking generated initrd and look at udev rules.

When booting w/o initrd, kernel must know what PARTUUID=XXX exactly is, so I suspect that /dev/disk/by-partid/... links are already present in the root partition. I might be wrong ...

When booting with initrd (say / is initrd image), initrd is responsible for mounting /proc, /sys, /dev, ... /fsroot as well as remounting /fsroot to / (that's where the magic comes ...).

Some reading here: https://stackoverflow.com/questions/106 ... -initramfs (to not be confused with initrd and initramfs, we actually have initramfs)

arglebargle
Posts: 9
Joined: Tue May 23, 2017 1:43 am
Location: California

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Wed Jun 07, 2017 10:19 pm

vintozver wrote:
arglebargle wrote:Any idea what would need to be done to boot using PARTUUID and an initrd?
Generally, udev is built in into initrd, and is responsible for creating /dev/disk/... symlinks. Will need to play with it.
I suggest to do some digging by unpacking generated initrd and look at udev rules.

When booting w/o initrd, kernel must know what PARTUUID=XXX exactly is, so I suspect that /dev/disk/by-partid/... links are already present in the root partition. I might be wrong ...

When booting with initrd (say / is initrd image), initrd is responsible for mounting /proc, /sys, /dev, ... /fsroot as well as remounting /fsroot to / (that's where the magic comes ...).

Some reading here: https://stackoverflow.com/questions/106 ... -initramfs (to not be confused with initrd and initramfs, we actually have initramfs)
I've done some cursory investigation there already. It looks like only by-uuid and by-label are created by initramfs-tools (this confirms what I've observed in busybox at boot.)

This is odd as new Raspbian images now ship by default using root=PARTUUID= to boot and means that any use of an initramfs will break boot unless cmdline.txt is updated to reference root by UUID or /dev/sd?|mmc* style name.

from /usr/share/initramfs-tools/scripts/functions:

Code: Select all

294 # Resolve device node from a name.  This expands any LABEL or UUID.
295 # $1=name
296 # Resolved name is echoed.
297 resolve_device() {
298         DEV="$1"
299
300         case $DEV in
301         LABEL=*)
302                 DEV="${DEV#LABEL=}"
303
304                 # support any / in LABEL= path (escape to \x2f)
305                 case "${DEV}" in
306                 */*)
307                 if command -v sed >/dev/null 2>&1; then
308                         DEV="$(echo ${DEV} | sed 's,/,\\x2f,g')"
309                 else
310                         if [ "${DEV}" != "${DEV#/}" ]; then
311                                 DEV="\x2f${DEV#/}"
312                         fi
313                         if [ "${DEV}" != "${DEV%/}" ]; then
314                                 DEV="${DEV%/}\x2f"
315                         fi
316                         IFS='/'
317                         newroot=
318                         for s in $DEV; do
319                                 newroot="${newroot:+${newroot}\\x2f}${s}"
320                         done
321                         unset IFS
322                         DEV="${newroot}"
323                 fi
324                 esac
325                 DEV="/dev/disk/by-label/${DEV}"
326                 ;;
327         UUID=*)
328                 DEV="/dev/disk/by-uuid/${DEV#UUID=}"
329                 ;;
330         esac
331         # Only canonicalise if a valid file, in case $DEV isn't a filename
332         [ -e "$DEV" ] && DEV=$(readlink -f "$DEV")
333         echo "$DEV"
334 }

edit: it looks like this is already fixed in later releases, https://bugs.debian.org/cgi-bin/bugrepo ... bug=801154 - I'll modify my initramfs-tools scripts and see what happens.

edit2: Confirmed, the patches in message #17 and message #18 get root=PARTUUID= booting again when using an initramfs.

edit3: Booting with root=LABEL= is also possible, but only with an initramfs after patching.

User avatar
jens.maus
Posts: 20
Joined: Sun Jan 01, 2017 10:53 am
Location: Dresden, Germany
Contact: Website

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Thu Jun 08, 2017 8:44 am

arglebargle wrote: edit3: Booting with root=LABEL= is also possible, but only with an initramfs after patching.
Thanks for all the hints. However, my initial question remains open: How can I generate an appropriate initrd file from within a buildroot environment or from my x86-based cross compilation linux system which is then suitable for being used with the RaspberryPi? Or do I have to boot a RaspberryPi with a linux development system and run mkinitramfs manually there once and then use that initrd file for the build root system I am using?

arglebargle
Posts: 9
Joined: Tue May 23, 2017 1:43 am
Location: California

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Thu Jun 08, 2017 7:57 pm

I don't have enough experience with buildroot to be specific, sorry. The documentation indicates that buildroot can build the initramfs but I don't know if it uses initramfs-tools from the target distribution or from the host.

If using the target distro's copy just patch the initramfs-tools/scripts/functions script before kicking off the initramfs build and LABEL booting should work. If using the host distro tools make sure initramfs-tools is a version >=1.21.

User avatar
jens.maus
Posts: 20
Joined: Sun Jan 01, 2017 10:53 am
Location: Dresden, Germany
Contact: Website

Re: Booting rootfs via "root=LABEL=" or "root=UUID=" (buildr

Mon Jun 12, 2017 9:28 pm

Just want to let everyone know that I found a solution for my problem. With the help of the buildroot community I was able to develop a solution where I could use a PARTUUID specifier to make sure my image is either booted from a SD card or from an external USB memory stick or hard disk. The solution is documented/explained here:

http://lists.busybox.net/pipermail/buil ... 94458.html

Return to “Advanced users”