Networking

Unix and Linux network configuration. Multiple network interfaces. Bridged NICs. High-availability network configurations.

Applications

Reviews of latest Unix and Linux software. Helpful tips for application support admins. Automating application support.

Data

Disk partitioning, filesystems, directories, and files. Volume management, logical volumes, HA filesystems. Backups and disaster recovery.

Monitoring

Distributed server monitoring. Server performance and capacity planning. Monitoring applications, network status and user activity.

Commands & Shells

Cool Unix shell commands and options. Command-line tools and application. Things every Unix sysadmin needs to know.

Home » Computer Components, Hardware

Clone Raspberry Pi SD to Larger Card

Submitted by on October 28, 2021 – 11:56 am

This is more of a note to myself: every time I need to clone the RPi card, I end up googling things for an hour. The process is two-fold: clone the SD and resize the filesystem.

Before you proceed, check out my earlier post about backup options for RPi. Cloning the SD is one of the options I reviewed. You will need two things: a) a Micro SD-to-USB adapter (preferably USB3); and b) SSH or console access to your RPis.

Insert the new SD into the USB3 adapter and attach it to the running Pi. SSH into the box or use the console to run the commands below. The dd process is likely to be crawling along at around 10-12MB/s, so expect cloning a 32-GB card to take roughly an hour.

Raspberry Pi OSLibreELEC

Since your Raspberry Pi is active when the dd process is running, the resulting image will be somewhat inconsistent – fuzzy, as they say. Running touch /boot/forcefsck will force filesystem integrity check should you ever boot from the backup SD card.

touch /boot/forcefsck
umount <whatever is mounted on /dev/sba*>
dd if=/dev/mmcblk0 of=/dev/sda bs=1M status=progress
/bin/rm -f /boot/forcefsck

Instead of mucking about with dd, I would recommend using the rpi-clone script. Here’s how I installed it:
sudo su -
cd ~
git clone https://github.com/billw2/rpi-clone
cd rpi-clone/
/bin/cp rpi-clone rpi-clone-setup /usr/local/sbin

And here’s how I run it:
sudo su -
t=sda
umount -f $(egrep "^/dev/${t}([0-9]{1,})?" /etc/mtab | awk '{print $2}') 2>/dev/null
cd ~ && nohup rpi-clone -u ${t} &

umount <whatever is mounted on /dev/sba*>
dd if=/dev/mmcblk0 of=/dev/sda bs=1M & pid=$!
# To see dd status:
watch -n10 "kill -USR1 $pid"

If your source RPi uses a static IP, you will need to disconnect it from the network temporarily to configure the correct IP on the clone.

The final step is to resize the filesystem to utilize the full capacity of your new SD card:

Raspberry Pi OSLibreELEC

raspi-config

It’s not possible to resize the LibreElEC partition while you’re booted from the SD: you will not be able to unmount the /storage filesystem even after killing every process that lsof shows as using this filesystem.

You have a couple of options here: a) boot your PC or VM from a gparted Live CD, pop in the SD card, and the resizing process is very much straight forward from there; b) create a backup of your LibreELEC and Kodi via the GUI (see details here), then download the LibreELEC USB-SD-Creator, let it partition and prep the new SD, and then restore the backup you created in the previous step.

In terms of time, method b) might be faster as the backup/restore takes less time than dd and you also don’t need to deal with gparted. And the USB-SD-Creator piece is very quick: it just installs the base OS and Kodi.

Print Friendly, PDF & Email

Leave a Reply