How does the pi select the device to boot from?
Posted: Sat Oct 19, 2019 11:13 am
This post is a continuation of my search to find out why the upgrade of the raspberrypi-kernel and bootloader packages on one of my remotely running Pi's is failing regularly.
The search was initially started under a different topic: upgrade of kernel and/or bootloader going wrong (https://www.raspberrypi.org/forums/view ... 8&t=250039), but that path did not provide any clues.
With the next kernel & bootloader upgrade pending, I started looking for other reasons for the problem and I stumbled over something interesting.
Because the pi is at a remote location, what I did is, make a 'perfect' clone of the SD card of the running pi for (remote) recovery purposes.
In order to be able to make configuration adaptations to the clone, I used a mini USB SD-cardreader with the clone inserted and put it in one of the free USB ports, causing it to be automagically mounted.
However, because it is a 'perfect' clone, the UUID's of the clone's partitions are identical to those of the master's partitions:
and looking at /etc/fstab
reveals that the requested PARTUUID's are available on both /dev/mmcblk0 and /dev/sda
This means, that, during boot there is more than one device to choose from to get the data/code from.
Hence my question: How does the pi select the device to boot from?
I thought it was preset to boot from the SD card, which I believe is /dev/mmcblk0 (Note: I have not touched the usb_boot_mode bit)
If so, why is the boot partition taken from /dev/sda, while the root partition is taken from /dev/mmcblk0 ? (Note: I have not modified /etc/fstab)
If it would be the other way around, i.e. boot from /dev/mmcblk0, I could somehow understand that the root partition is taken from /dev/sda, in case the boot process searches for the requested PARTUUID and finds the first one on /dev/sda.
I could modify /etc/fstab to point to the /dev/mmcblk0 partitions to work around this, but I wonder whether /etc/fstab is consulted during the boot process?
Can somebody shed some light on this? I know (now) that it probably would be better to adapt the PARTUUID and fstab of the clone, but I am nevertheless trying to find an explanation of this issue.
The search was initially started under a different topic: upgrade of kernel and/or bootloader going wrong (https://www.raspberrypi.org/forums/view ... 8&t=250039), but that path did not provide any clues.
With the next kernel & bootloader upgrade pending, I started looking for other reasons for the problem and I stumbled over something interesting.
Because the pi is at a remote location, what I did is, make a 'perfect' clone of the SD card of the running pi for (remote) recovery purposes.
In order to be able to make configuration adaptations to the clone, I used a mini USB SD-cardreader with the clone inserted and put it in one of the free USB ports, causing it to be automagically mounted.
However, because it is a 'perfect' clone, the UUID's of the clone's partitions are identical to those of the master's partitions:
Code: Select all
lsblk -o name,mountpoint,size,ptuuid,partuuid
NAME MOUNTPOINT SIZE PTUUID PARTUUID
sda 14.9G bcb7c562
├─sda1 /boot 257M bcb7c562 bcb7c562-01
└─sda2 14.7G bcb7c562 bcb7c562-02
mmcblk0 14.9G bcb7c562
├─mmcblk0p1 257M bcb7c562 bcb7c562-01
└─mmcblk0p2 / 14.7G bcb7c562 bcb7c562-02
Code: Select all
proc /proc proc defaults 0 0
PARTUUID=bcb7c562-01 /boot vfat defaults 0 2
PARTUUID=bcb7c562-02 / ext4 defaults,noatime 0 1
This means, that, during boot there is more than one device to choose from to get the data/code from.
Hence my question: How does the pi select the device to boot from?
I thought it was preset to boot from the SD card, which I believe is /dev/mmcblk0 (Note: I have not touched the usb_boot_mode bit)
If so, why is the boot partition taken from /dev/sda, while the root partition is taken from /dev/mmcblk0 ? (Note: I have not modified /etc/fstab)
If it would be the other way around, i.e. boot from /dev/mmcblk0, I could somehow understand that the root partition is taken from /dev/sda, in case the boot process searches for the requested PARTUUID and finds the first one on /dev/sda.
I could modify /etc/fstab to point to the /dev/mmcblk0 partitions to work around this, but I wonder whether /etc/fstab is consulted during the boot process?
Can somebody shed some light on this? I know (now) that it probably would be better to adapt the PARTUUID and fstab of the clone, but I am nevertheless trying to find an explanation of this issue.