whatdoido
Posts: 9
Joined: Tue Jan 31, 2017 11:11 pm

SD boot with USB root - kernel boot does not see USB device

Wed Dec 11, 2019 11:07 am

I wanted to use the Buster lite (Sept 2019) image for a RPi 1B and have root on a mains powered USB 2.5” 250GB hdd in a USB3 enclosure BUT boot via SD card. The USB3 enclosure is fine used on my RPi3 with no issues regarding firmware/chipset.

I believe my setup is correct (cmdline.txt updated root=… and rootfs imaged to hdd). However when booting, the kernel complains that it can’t find root= and lists available devices that only includes ram0 .. ram16 devices. I tried root=/dev/sda2 (only usb msd plugged in at boot) as well as root=PARTUUID=… and both fail with the same error. For whatever reason it looks like it can’t see the USB hdd even though its already powered up, spinning already (its got its own power) when I apply power to the RPI.

Is there anything obvious to check?

The only thing to note is the hard disk already has 200G worth of data on it (/dev/sda1) and a empty 2nd partition that is 16GB at the end of the disk. I ONLY image the rootfs onto /dev/sda2 of the hdd and it appears fine to avoid having to move the original /dev/sda1 data.

On my desktop:

Code: Select all

# usb hdd on /dev/sdb, sd card on /dev/sdc

# image buster rootfs to hdd
losetup /dev/loop0 ./rpi-buster.img
partprobe /dev/loop0
dd if=/dev/loop0p2 of=/dev/sdb2 bs=1M
losetup -D
# image to SD
dd if=./rpi-buster.img of=/dev/sdc bs=1M

# remount /dev/sdb2 and edit etc/fstab so / mount based on PARTUUID
I boot with the SD card and fails - cmdline.txt has tried with root=/dev/sda2 but also I also tried root=PARTUUID=… with same VFS errors. Specifying rootwait=10 makes no difference

dustnbone
Posts: 160
Joined: Tue Nov 05, 2019 2:49 am

Re: SD boot with USB root - kernel boot does not see USB device

Wed Dec 11, 2019 12:35 pm

How did you write the image to the disk? The Buster image is a disk image, not a partition image, so it contains a partition table and 2 partitions.

When written to a raw disk it creates a partition table that refers to the 2 partitions (boot and rootfs), but when written to just a partition it would make, well, a mess I think. The first sectors of that partition would contain something other than what the bootloader is expecting to find in a rootfs partition.

If you've written the whole image out to the SD card, including the rootfs partition, you could dd that partition to the appropriate one on the USB drive and that should work as expected.

whatdoido
Posts: 9
Joined: Tue Jan 31, 2017 11:11 pm

Re: SD boot with USB root - kernel boot does not see USB device

Wed Dec 11, 2019 1:52 pm

The *partition image* was written to the hdd with the buster image made available on the /dev/loop0 device and the corresponding [b/dev/loop0p1 (boot)[/b] and /dev/loop0p2 (rootfs). I the dd buster’s rootfs onto the hdd’s /dev/sda2 (which is 16GB) so the buster rootfs filesystem fits. As you say, its just a partition image (and the rootfs) now but its going onto the hdd’s /dev/sda2 existing partition which is what I want - after all, a filesystem is just a bunch of bytes that are supposed to live between a bunch of sectors on a device. The partition table on the hdd hasn’t changed at this point.

Code: Select all

# image buster rootfs to hdd
losetup /dev/loop0 ./rpi-buster.img
partprobe /dev/loop0
dd if=/dev/loop0p2 of=/dev/sdb2 bs=1M
The image on the SD card is written as I’ve always done it via dd

Code: Select all

dd if=./rpi-buster.img of=/dev/sdc bs=1M
The *cmdline.txt* root=… param is where its telling the kernel to find the root partition; in my case trying root=/dev/sda2 as well as root=PARTUUID=… as pulled from blkid /dev/sda2. The fact that at kernel boot it doesn’t see the sda2 partition is the odd thing suggesting either it hasn’t scanned the usb bus for the hdd or the /dev/sda device is not available at this point even though the hdd is already spinning and I’ve got rootwait=10 on the kernel params too.

From a hdd partition perspective its fine – I can mount /dev/sda2 on all other machines and it is fine.

Do I need a special initrd to make this work?

swampdog
Posts: 301
Joined: Fri Dec 04, 2015 11:22 am

Re: SD boot with USB root - kernel boot does not see USB device

Wed Dec 11, 2019 6:20 pm

No, you do not need an initrd unless you do something exotic like use LVM.

There might be a tool to do what you want. I can't remember because I haven't used it. Someone else will post to verify, I'm sure.

I installed to an sdcard then with the system running, created the partition on the usb disk, formatted to ext4, mounted it then 'rsync'd most of the sdcard across. Something like this..

Code: Select all

# rsync --progress -auxv --exclude='/boot/*'  / /mnt/tmp/
..edit /mnt/tmp/etc/fstab and /boot/cmdline.txt

Code: Select all

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mapper/pi18-root rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
^^^from an rpi4 using LVM, just change "root=" to the correct device (PARTUUID preferable).

I think that's about it. Unmount /mnt/tmp & reboot.

You don't seem to have mentioned editing "fstab" (the one on the usb, not the sdcard). Also, I've never tried booting a pi off anything but the first usb partition. Again, someone else will know if this is a problem.

whatdoido
Posts: 9
Joined: Tue Jan 31, 2017 11:11 pm

Re: SD boot with USB root - kernel boot does not see USB device

Wed Dec 11, 2019 10:23 pm

I managed to get this to work but the steps I used were the same.

The only diff was I took the image on SD and booted this, ran atp update/upgrade and dd the SD to a file again, reimaged the rootfs onto hdd via loop0p2

This time the kernel could see the usb hdd and start to boot...

whatdoido
Posts: 9
Joined: Tue Jan 31, 2017 11:11 pm

Re: SD boot with USB root - kernel boot does not see USB device

Sun Dec 15, 2019 10:13 am

Just to close off this thread.

The Buster SD (boot) + powered usb HDD (root) worked fine on my RPi 3 and RPI 4. However using the same SD card (its a micro in a full SD adptor) and usb HDD on RPi 1 and RPi Zero did not work with these starting to boot and getting through to starting services but then reporting ext4_find_entry reading directory lblock 0 errors.

Return to “Troubleshooting”