How to switch over from SD-card to USB-attached device (USB thumbstick, USB enclosed SSD or HDD, etc.) to have more durable storage option.
-
Connect USB device to your RPI
-
Make sure USB device visible by the system
sudo fdisk -l sudo lsblk
Usually
mmcblk0
is your SD-card, andsda
,sdb
,sdX
are attached USB devices, in my case it wassda
. Make sure there is no sensitive data stored on the target USB device. If it's new USB device there should be no partitions reported byfdisk
for it. You may want to clean target device usingsudo sfdisk --delete /dev/sda
(be very careful, it will delete everything on your target device) -
Install
rpi-clone
git clone https://github.com/billw2/rpi-clone.git cd rpi-clone sudo cp rpi-clone rpi-clone-setup /usr/local/sbin sudo rpi-clone-setup -t $(hostname -s) sudo rpi-clone -s
-
Clone SD-card to USB device
sudo rpi-clone sda # replace sda here with your device name
This may take some time depending on how much data you have, storage performance, running applications, clients connected, etc. During the process few questions will be asked, read carefully and answer. On the last step where it's asked to examine mounted clone run another connection to RPI, keep existing intact.
If you've accidentally skipped it just remount it manually:
sudo mount /dev/sda6 /mnt/clone/boot
.sudo mount /dev/sda7 /mnt/clone
-
Identify partitions
Target device will have the same partitions layout as in source device. We need to find out
boot
and last partition ids.sudo lsblk -o name,mountpoint,size,partuuid /dev/sda6 # clone of mmcblk0p6 mounted as /boot sudo lsblk -o name,mountpoint,size,partuuid /dev/sda7 # clone of mmcblk0p7 mounted as / or root
Write down
PARTUUID
column, in my case these were3b4344a4-06
forboot
and3b4344a4-07
for root partition respectively -
Change
cmdline.txt
To be able to boot from the target device we have to change
cmdline.txt
file:- change
root=/dev/mmcblk0p7
toroot=PARTUUID=3b4344a4-07
which is the root partition id - append at the end of the line
rootdelay=5
option to wait while attached device is initialized at boot time
Complete example:
console=serial0,115200 console=tty1 root=PARTUUID=3b4344a4-07 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait rootdelay=5
If you'll try to boot without this change you'll get endless
Waiting for root
message.Note: there is one interesting caveat, if you'd like to use LABEL or UUID instead of PARTUUID you must create initramfs/initrd file, hence additional step will be required. Do not use PARTUUID with initrd.
If you're going to use PARTUUID then you don't need this step (I repeat, skip it and follow the next step).
- make sure
root=
set to something likeroot=LABEL=USB-ROOT
cd /mnt/clone/boot/
- generate initrd file with
mkinitramfs -o initrd.sda
- append
initramfs initrd.sda followkernel
afterrootdelay=5
Complete example:
console=serial0,115200 console=tty1 root=LABEL=USB-ROOT rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait rootdelay=5 initramfs initrd.sda followkernel
- change
-
Change
fstab
After the boot process has been completed we would need to mount correct partitions.
Open
/mnt/clone/etc/fstab
and do the following:- change device
/dev/mmcblk0p6
toPARTUUID=3b4344a4-06
(remember to use your own id) - change device
/dev/mmcblk0p7
toPARTUUID=3b4344a4-07
(remember to use your own id)
Complete example:
proc /proc proc defaults 0 0 PARTUUID=3b4344a4-06 /boot vfat defaults 0 2 PARTUUID=3b4344a4-07 / ext4 defaults,noatime 0 1
- change device
-
Unmount
Now return back to the initial terminal where we've left
rpi-clone
process open and hit enter to unmount all partitions. Make sure you don't have the second terminal open somewhere at the mounted paths. -
Test
Shutdown RPI with
sudo shutdown -h now
, disconnect PSU, unplug SD card, plug PSU in, verify
Thank you for developing this - I was faithful I could clone my SD Card to a 2.5" drive and exactly followed the instructions. But I failed several times, even after using the abovementioned EEPROM Bootloader utility. The RPi4 never boots from USB, when I remove the SD Card.
Could these be two reasons for my problem:?
As for the editing of the cmdline.txt - I do it via this command:
sudo nano /mnt/clone/boot/cmdline.txt
The strange thing is that I do get an output, that seems, as if the 2.5" drive is active as the bootdrive, when the SD-Card is back in and the RPi boots:
xxxxxx:~ $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 4,6T 0 disk
├─sda1 8:1 0 2,4G 0 part
├─sda2 8:2 0 1K 0 part
├─sda5 8:5 0 32M 0 part
├─sda6 8:6 0 256M 0 part /boot
└─sda7 8:7 0 2T 0 part /
mmcblk0 179:0 0 29,7G 0 disk
├─mmcblk0p1 179:1 0 2,4G 0 part
├─mmcblk0p2 179:2 0 1K 0 part
├─mmcblk0p5 179:5 0 32M 0 part
├─mmcblk0p6 179:6 0 256M 0 part
└─mmcblk0p7 179:7 0 27,1G 0 part
xxxxxx:~ $ df -h
Dateisystem Größe Benutzt Verf. Verw% Eingehängt auf
/dev/root 2,0T 6,0G 1,9T 1% /
devtmpfs 775M 0 775M 0% /dev
tmpfs 936M 12K 936M 1% /dev/shm
tmpfs 936M 18M 919M 2% /run
tmpfs 5,0M 4,0K 5,0M 1% /run/lock
tmpfs 936M 0 936M 0% /sys/fs/cgroup
/dev/sda6 253M 50M 203M 20% /boot
tmpfs 188M 0 188M 0% /run/user/1000
When searching for the edited cmdline.txt (the one I altered in /mnt/clone/boot/cmdline.txt), I am able to find it with the appropriate PARTUUID in /boot/cmdline.txt. Strange, that the RPi does not boot... I even set rootdelay to 20 seconds, just in case...
Another hint may be, that software, that I did install on the SD Card prior to cloning (Samsung Smartcontol to monitor drive health), is not working , when booting with the SD Card put back in. So some stuff seemed to be cloned, other stuff not?
Would you be so kind and give me some hints on what to do?
Thanks