Tools
1 | # Partition |
Insert sdcard to usb slot
Use sudo disk -l
or sudo lsblk
to checkout disk name, for example /dev/sda
.
/dev/sda1
is the boot partition, which is fat32. /dev/sda2
is the root partition, which is ext4.
Prepare directories
1 | mkdir backupimg/ |
Mount source disk
1 | sudo mount -t vfat -o uid=pi,gid=pi /dev/sda1 ./src_boot # Mount boot partition |
Then use sudo df -h
to check it.
pi.img: Create empty file
Use df -h
to checkout size of /dev/sda1
and /dev/sda2
, caculate FILESIZE=/dev/sda1
.Size+/dev/sda2
.Used. It’s a good idea to add more size to FILESIZE, e.g. 1G.
Then create an empty file(example with FILESIZE=5G):
1 | # bs*count = FILESIZE = 5G |
pi.img: Make partitions
Use sudo fdisk -l /dev/sda1
to checkout start and end sector of /dev/sda1
and /dev/sda2
.
1 | sudo parted pi.img --script mklabel msdos |
After parted, use sudo parted pi.img --script print free
to double check.
pi.img: Create loop device
1 | sudo losetup -f --show pi.img # Create loop device with pi.img |
Check /dev/mapper/loop0p1
and /dev/mapper/loop0p2
, or use sudo lsblk
.
pi.img: Mount filesystem
1 | sudo mount -t vfat -o uid=pi,gid=pi /dev/mapper/loop0p1 ./dst_boot/ # Mount boot partition |
Clone
1 | sudo cp -rfvp ./src_boot/* ./dst_boot/ # Copy boot files |
On success DUMP IS DONE
will be printed out. If there is Broken pipe
error, use df -h
to check if Avail of /dev/mapper/loo0p2
greater than Used of /dev/sda2
.
Modify boot/fstab
Use sudo blkid
to check PARTUUID
of boot partition and root partition, print info as below:
1 | /dev/mapper/loop0p1: SRC_TYPE="msdos" LABEL="boot" UUID="755C-729C" TYPE="vfat" PARTUUID=="af2f8761-01" |
Modify ./dst_boot/cmdline.txt
as below:
1 | ## Set root=PARTUUID=af2f8761-02 |
Modify ./dst_root/etc/fstab
, as below:
1 | ## Mount boot partition to '/boot' |
Cleanup
1 | sudo umount /dev/mapper/loop0p1 /dev/mapper/loop0p2 /dev/sda1 /dev/sda2 |