0

I'm running Raspian on RPi3 from a 16GB SD card. Now I try to use a SSD connected by USB to hold the root / partition and copy the /boot partition to a smaller SD card that is 512MB. I can't get it working somehow.

I don't want to touch the OTP memory to boot directly to USB, so I need the SD card for boot.

I started off with guides like this: https://www.raspberrypi.org/forums/viewtopic.php?t=44177

Drives:

  • sda is the 16GB SDcard from the Raspi running Raspian
  • sdb is the new 512MB SDcard
  • sdc is the SSD

I did the following steps on my PC booting into a live Linux (PartedMagic):

  1. sudo dd if=/dev/sda of=/dev/sdb
  2. sudo gdisk /dev/sdc
  3. create /dev/sdc1 partition covering the whole SSD
  4. run clonezilla and copy partition /dev/sda2 -> /dev/sdc1
  5. blkid
  6. take note of PARTUUID of /dev/sdb1 and /dev/sdc1
  7. sudo mkdir /mnt/sdb1
  8. sudo mount /dev/sdb1 /mnt/sdb1
  9. sudo nano /mnt/sdb1/cmdline.txt

    dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=[PARTUUID-of-sdc1] rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

  10. sudo mkdir /mnt/sdc1

  11. sudo mount /dev/sdc1 /mnt/sdc1
  12. sudo nano /mnt/sdc1/etc/fstab

    proc /proc proc defaults 0 0

    PARTUUID=[PARTUUID-of-sdb1] /boot vfat defaults 0 2

    PARTUUID=[PARTUUID-of-sdc1] / ext4 defaults,noatime 0 1

Upon boot, I can see the linux booting up, rootfs seems to work, but then there is a problem with boot partition not found and the whole thing halts.

EDIT:

My goal is to move rootfs to USB SSD disk and boot using SD Card. But I don't want to use the current 16GB card for booting, as a 512MB card is more than enough to hold the /boot partition. The above instructions are just to illustrate what I tried, if there are better ways to accomplish my goal I'm more than happy to proceed as suggested.

EDIT 2:

I did set the OTP usb boot flag in the mean time, meaning the smaller SD card is no longer necessary. This makes the whole process much easier. What I try now is the following:

First copy the whole SD card to the SSD drive:

sudo dd if=/dev/sda of=/dev/sdc

If I attach the resulting SSD to the RasPi it boots just fine and everything works. But if I try to grow the /dev/sdc2 partition (rootfs) using GParted, it won't boot successfully anymore. Here is a screenshot showing the problem(s):

Boot Error Messages

How can I resize rootfs without causing this problem?

  • I don't want to touch the OTP memory to boot directly to USB - Just out of curiosity: why? – Dirk Sep 23 '18 at 21:09
  • 1
    If you want help post actual file content - AND actual error messages. Your first step sudo dd if=/dev/sda of=/dev/sdb will produce an invalid disk. This could be done far more simply on the Pi itself using the SD Copy utility. – Milliways Sep 24 '18 at 0:20
  • @Dirk because it says ONE TIME and I'm not sure of it's implications and I fear if there are any downsides to it, I cannot revert this. – DavWEB Sep 24 '18 at 14:49
  • @Milliways: I'll get the file contents and more important, the error messages. I'm aware this produces an invalid sdcard, specifically the second partition overlaps the disk size. However, the second partition is unused anyway. Every attempt to fix the disc partitions (using gdisk) resulted in missing bootmanager after saving the corrected partition table (sudo gdisk /dev/sdb -> delete partition 2, verify & write partition table) – DavWEB Sep 24 '18 at 14:52
  • @Milliways: My rationale not running it on the raspi was to get the system at rest, not having files in the rootfs changing while copying. Do you have any reference on how to use the mentioned SD Copy utility, especially if it's possible to move to smaller SD cards not capable holding the rootfs? – DavWEB Sep 24 '18 at 14:54
0

As already discussed in the comments there is an issue with the boot-, root-partitions and with the master boot record (MBR). You can do it all by hand from a tar archive. So you have clean hand made partitions and even a hand made MBR. I have just tested it. I only use one USB slot /dev/sdb? on my laptop and I used a USB stick for the root partition. Here are the commands I have used to get it to work. For reference I used Raspbian Stretch Lite 2018-06-27, full upgraded with sudo apt update && sudo apt full-upgrade && reboot.

First archive the old SD Card into a tar archive:

pc ~$ sudo -Es
pc ~# mkdir /mnt/sdb2
pc ~# mount /dev/sdb2 /mnt/sdb2
pc ~# mount /dev/sdb1 /mnt/sdb2/boot
pc ~# tar -czf raspi-old.tar.gz -V "old installation from SD Card" -C /mnt/sdb2/ ./ # dot+slash IMPORTANT for correct restore
# optional testing the archive
pc ~# tar -tvf raspi-old.tar.gz
pc ~# umount /dev/sdb1
pc ~# umount /dev/sdb2

Attach new small SD Card and prepare master boot record. Be aware that this will destroy all data on the SD Card without asking: "Are you sure?" and once again "You really really want to destroy all data on your storage?".

pc ~# dd if=/dev/zero of=/dev/sdb bs=512 count=1
pc ~# /bin/echo -ne '\x28\xe4\x3e\x4d' | dd of=/dev/sdb bs=1 seek=440
pc ~# /bin/echo -ne '\x55\xaa' | dd of=/dev/sdb bs=1 seek=510

Make boot partition, format it and restore data:

pc ~# parted /dev/sdb mkpart primary fat32 8192s 100%
pc ~# mkfs.vfat -F 32 -n BOOT /dev/sdb1
pc ~# mkdir /mnt/sdb1
pc ~# mount /dev/sdb1 /mnt/sdb1
pc ~# tar -xf raspi-old.tar.gz --strip-components=2 -C /mnt/sdb1 ./boot/

Change root entry in cmdline.txt to root=/dev/sda1

pc ~# umount /dev/sdb1

Change to USB stick, partition, format it and restore data:

pc ~# parted /dev/sdb mktable msdos
pc ~# parted /dev/sdb mkpart primary ext4 8192s 100%
pc ~# mkfs.ext4 -L rootfs /dev/sdb1
pc ~# mount /dev/sdb1 /mnt/sdb1
pc ~# tar -xf raspi-old.tar.gz --exclude=./boot/* -C /mnt/sdb1

Change partitions in fstab to

/dev/mmcblk0p1  /boot   vfat    defaults          0       2
/dev/sda1       /       ext4    defaults,noatime  0       1

pc ~# umount /dev/sdb1
pc ~# exit
pc ~$

Attach the SD Card and the root drive to the RasPi and boot.


references:
[1] Howto prepare a SD card from a tar archive
[2] Is it possible to use partition UUID for root-parameter in cmdline.txt?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.