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?

DavWEB
  • 101
  • 1
  • 2

1 Answers1

1

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?

Ingo
  • 42,961
  • 20
  • 87
  • 207