Useful Operations on a Raspberry

20240722  jean@huens.be


Make a backup disk of a running Raspberry

There are at least two tools that can be used for this task

  1. billw/rpi-clone https://github.com/billw2/rpi-clone/

    rpi-clone makes a backup of the running system to another USB disk.
  2. seamusdemora/RonR-RPi-image-utils https://github.com/seamusdemora/RonR-RPi-image-utils

Both utilities are shell scripts.

They use rsync to copy part of the running system. (Rsync is NOT used to copy remotely.)

Image-backup needs intermediate space to store the image.

My problems:

  1. Raspberry does not automount USB disks unless hdmi screen is active.
  2. USB disks withn hsfs (macos) are mounted readonly
  3. Both scripts did incomplete copies.
    rpi-clone has a last step where you can verify yourself the copy operation.
    And repeating rpi-clone does update the previous step.
  4. I have the impression running the script and running the script over ssh makes a difference ?
  5. The use of the miniSD adapter seems to be more reliable for my USB-to-card adapter ?

Rpi-clone

This is done an raspberry-4

pi@pipd70:~ $ sudo rpi-clone sdc

  Destination disk partition /dev/sdc2 is mounted on /media/pi/PiDP11-24071914.
  The clone cannot proceed unless it is unmounted.
Do you want to unmount /media/pi/PiDP11-24071914?  (yes/no): yes

  Destination disk partition /dev/sdc1 is mounted on /media/pi/04E6-821A.
  The clone cannot proceed unless it is unmounted.
Do you want to unmount /media/pi/04E6-821A?  (yes/no): yes

Booted disk: mmcblk0 31.9GB                Destination disk: sdc 31.9GB
---------------------------------------------------------------------------
Part               Size    FS     Label           Part   Size    FS     Label           
1 /boot/firmware   512.0M  fat32  --              1      512.0M  fat32  --              
2 root              29.2G  ext4   rootfs          2       29.2G  ext4   PiDP11-24071914 
---------------------------------------------------------------------------
== SYNC mmcblk0 file systems to sdc ==
/boot/firmware        (74.5M used)   : SYNC to sdc1 (512.0M size)
/                     (16.8G used)   : SYNC to sdc2 (29.2G size)
---------------------------------------------------------------------------
Run setup script       : no.
Verbose mode           : no.
-----------------------:

Ok to proceed with the clone?  (yes/no): yes

Syncing file systems (can take a long time)
Syncing mounted partitions:
  Mounting /dev/sdc2 on /mnt/clone
mount: (hint) your fstab has been modified, but systemd still uses
       the old version; use 'systemctl daemon-reload' to reload.
  => rsync // /mnt/clone with-root-excludes ...

Editing /mnt/clone/etc/fstab PARTUUID to use eb4cfc80
===============================
Done with clone to /dev/sdc
   Start - 11:04:33    End - 11:05:18    Elapsed Time - 0:45

Cloned partitions are mounted on /mnt/clone for inspection or customizing.

Hit Enter when ready to unmount the /dev/sdc partitions ...ENTER
  unmounting /mnt/clone/boot/firmware
  unmounting /mnt/clone
===============================

Before you hit ENTER to unmount the sdc partition you can do a quick verify of partition sizes:

root@pipd70:/home/jean# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.6G     0  1.6G   0% /dev
tmpfs           380M  1.4M  378M   1% /run
/dev/mmcblk0p2   29G   17G   11G  62% /
tmpfs           1.9G  204K  1.9G   1% /dev/shm
tmpfs           5.0M   16K  5.0M   1% /run/lock
/dev/mmcblk0p1  510M   75M  436M  15% /boot/firmware
tmpfs           380M   40K  380M   1% /run/user/1000
/dev/sdc2        29G   19G  8.5G  69% /mnt/clone
/dev/sdc1       511M   76M  436M  15% /mnt/clone/boot/firmware

Rpi-clone did never succeed ! see Problems below.

Image-backup

This example uses a storage disk mounted on /media.
/media/ is always excluded from te backup.

pi@pipd70:~ $ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.6G     0  1.6G   0% /dev
tmpfs           380M  1.4M  378M   1% /run
/dev/mmcblk0p2   29G   17G   11G  62% /
tmpfs           1.9G  204K  1.9G   1% /dev/shm
tmpfs           5.0M   16K  5.0M   1% /run/lock
/dev/mmcblk0p1  510M   75M  436M  15% /boot/firmware
tmpfs           380M   40K  380M   1% /run/user/1000
/dev/sdb1       917G  774G   97G  89% /media/pi/BACKUP5
pi@pipd70:~ $ sudo image-backup

Image file to create? /media/pi/BACKUP5/backup/pidp11-70.img

Initial image file ROOT filesystem size (MB) [20681]? 

Added space for incremental updates after shrinking (MB) [0]? 

Create /media/pi/BACKUP5/backup/pidp11-70.img (y/n)? y

Starting full backup (for incremental backups, run: /usr/local/sbin/image-backup /media/pi/BACKUP5/backup/pidp11-70)
mount: (hint) your fstab has been modified, but systemd still uses
       the old version; use 'systemctl daemon-reload' to reload.
mount: (hint) your fstab has been modified, but systemd still uses
       the old version; use 'systemctl daemon-reload' to reload.


e2fsck 1.47.0 (5-Feb-2023)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
rootfs: 174184/1324512 files (0.1% non-contiguous), 2375063/5294080 blocks

resize2fs 1.47.0 (5-Feb-2023)
Resizing the filesystem on /dev/loop0p2 to 2656720 (4k) blocks.
The filesystem on /dev/loop0p2 is now 2656720 (4k) blocks long.

resize2fs 1.47.0 (5-Feb-2023)
Resizing the filesystem on /dev/loop0p2 to 2651451 (4k) blocks.
The filesystem on /dev/loop0p2 is now 2651451 (4k) blocks long.

resize2fs 1.47.0 (5-Feb-2023)
Resizing the filesystem on /dev/loop0p2 to 2651441 (4k) blocks.
The filesystem on /dev/loop0p2 is now 2651441 (4k) blocks long.

e2fsck 1.47.0 (5-Feb-2023)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
rootfs: 174184/662256 files (0.1% non-contiguous), 2331458/2651441 blocks
mount: (hint) your fstab has been modified, but systemd still uses
       the old version; use 'systemctl daemon-reload' to reload.
mount: (hint) your fstab has been modified, but systemd still uses
       the old version; use 'systemctl daemon-reload' to reload.

pi@pipd70:~ $ ls -lh /media/pi/BACKUP5/backup/pidp11-70.img
-rw-r--r-- 1 root root 11G Jul 22 16:43 /media/pi/BACKUP5/backup/pidp11-70.img
pi@pipd70:~ $ 

next start rpi-etcher and write
/media/pi/BACKUP5/backup/pidp11-70.img to /dev/sdc

I did not change anything of rapberry configuration ...

The USB disk boots without problems. I have the impression there are a few reboots involved...




Problems

When you boot in {initramfs/} prompt  this is related to rpi-clone

My guess for solutions

  1. edit /etc/fstab on the root filesystem and replace PARTUUID= by /dev/mmcblk0p1 and /dev/mmcblk0p1.
    This does not solve the problem. See next step.
  2. update-initramfs to adapt the initramfs.
    Beware this must be done changerooted .
    I did switch to Image-backup hoping that raspberry-etcher will take care of these problems.