billw2 / rpi-clone

A shell script to clone a booted disk.
BSD 3-Clause "New" or "Revised" License
2.56k stars 333 forks source link

Can't clone anymore: rsync: mkstemp "/mnt/clone/boot/overlays/.<filename>" failed: Read-only file system (30) #59

Closed develoxir closed 6 years ago

develoxir commented 6 years ago

Hi,

I've been happily using rpi-clone for some time by now, but since a few months ago I can't anymore. I used it every few months to backup my current SD since they will eventually fail (all of them). Probably due to some error in the current SD card (but an error not shown in any fsck), now every time I try I get this:

raspberrypi:~# rpi-clone sda
Error: Can't have a partition outside the disk!
Error: Can't have a partition outside the disk!

Source disk     : mmcblk0
Destination disk: sda
   Partition tables do not match, sda must be initialized.
sda current partitions are:
Disk /dev/sda: 32027MB
Partition Table: msdos

Number  Start   End      Size     Type     File system  Flags
 1      4.19MB  67.1MB   62.9MB   primary  fat16        lba
 2      67.1MB  32018MB  31951MB  primary  ext4

*** All data on destination disk sda will be overwritten! ***

Do you want to initialize the destination disk /dev/sda? (yes/no): yes
Error: Can't have a partition outside the disk!

Imaging the partition structure, copying 8 megabytes...
8+0 records in
8+0 records out
8388608 bytes (8.4 MB, 8.0 MiB) copied, 2.35888 s, 3.6 MB/s
Running fsck on /dev/sda1...
Sizing partition 2 (root partition) to use all SD card space...
Error: Can't have a partition outside the disk!
mke2fs 1.43.4 (31-Jan-2017)
/dev/sda2 contains a ext4 file system
    last mounted on /mnt/clone on Mon Jun 11 18:26:04 2018
Creating filesystem with 7800576 4k blocks and 1950240 inodes
Filesystem UUID: c719903b-2659-47a7-8b5d-d63c1567de2c
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

/dev/sda is initialized and resized.  Its partitions are:
Disk /dev/sda: 32027MB
Partition Table: msdos

Number  Start   End      Size     Type     File system  Flags
 1      4.19MB  67.1MB   62.9MB   primary  fat16        lba
 2      67.1MB  32018MB  31951MB  primary  ext4

Your booted /dev/mmcblk0p2 rootfs existing label:
You may enter a label for the destination rootfs /dev/sda2:

======== Clone Summary ========
Clone mode               :  rsync all files to sda root file system
Clone source disk        :  mmcblk0
Clone destination disk   :  sda
Clone destination rootfs :  /dev/sda2 (no label) on /mnt/clone
Clone destination bootfs :  /dev/sda1 on /mnt/clone/boot
Verbose mode             :  off
Cross filesystems        :  off
===============================
Final check, is it Ok to proceed with the clone (yes/no)?: yes
=> Mounting /dev/sda2 (no label) on /mnt/clone
=> Mounting /dev/sda1 on /mnt/clone/boot
===============================
Starting the /boot rsync to sda
rsync: readlink_stat("/mnt/clone/boot/.fseventsd") failed: Input/output error (5)
rsync: delete_file: unlink(FSCK0037.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0036.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0035.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0034.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0033.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0032.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0031.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0030.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0029.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0028.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0027.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0026.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0025.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0024.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0023.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0022.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0021.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0020.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0019.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0018.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0017.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0016.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0015.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0014.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0013.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0012.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0011.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0010.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0009.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0008.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0007.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0006.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0005.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0004.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0003.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0002.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0001.REC) failed: Read-only file system (30)
rsync: delete_file: unlink(FSCK0000.REC) failed: Read-only file system (30)
IO error encountered -- skipping file deletion
rsync: recv_generator: mkdir "/mnt/clone/boot/.fseventsd" failed: Input/output error (5)
*** Skipping any contents from this failed directory ***
rsync: mkstemp "/mnt/clone/boot/overlays/.allo-digione.dtbo.bxpBHp" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.applepi-dac.dtbo.mJU0jF" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.audioinjector-addons.dtbo.nCa4IU" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.dionaudio-loco-v2.dtbo.c32efa" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.dwc2.dtbo.X7YcJp" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.enc28j60-spi2.dtbo.uvWA1E" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.exc3000.dtbo.PkRKhU" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.fe-pi-audio.dtbo.0ICLE9" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.goodix.dtbo.PhVfZo" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.gpio-ir-tx.dtbo.QkM5iF" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.gpio-ir.dtbo.txWFAV" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.gpio-key.dtbo.kTfaZb" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.gpio-poweroff.dtbo.1JNqls" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.gpio-shutdown.dtbo.Gd4pwI" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.i2c-bcm2708.dtbo.lpTVEY" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.i2c-rtc-gpio.dtbo.cFx4Te" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.jedec-spi-nor.dtbo.Z4L86u" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.mbed-dac.dtbo.I8xt9K" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.mcp3202.dtbo.3jAh90" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.media-center.dtbo.kxwreh" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.midi-uart0.dtbo.lErMhx" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.midi-uart1.dtbo.w0Xl8M" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.mpu6050.dtbo.zaEa32" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.papirus.dtbo.ETXSAh" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.pibell.dtbo.rZvU6v" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.pwm-ir-tx.dtbo.K99JJK" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.rotary-encoder.dtbo.ZXRmkZ" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.rpi-cirrus-wm5102.dtbo.ID7mJd" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.rpi-tv.dtbo.BOSk6r" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.sc16is752-i2c.dtbo.CXUUzG" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.superaudioboard.dtbo.vEsh1U" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.sx150x.dtbo.2tYjh9" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.uart0.dtbo.3m6aAn" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.upstream-aux-interrupt.dtbo.wIdEIB" failed: Read-only file system (30)
rsync: mkstemp "/mnt/clone/boot/overlays/.upstream.dtbo.7lkHNP" failed: Read-only file system (30)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1196) [sender=3.1.2]
Starting the filesystem rsync to sda
(This may take several minutes)...^Crsync error: received SIGINT, SIGTERM, or SIGHUP (code 20) at rsync.c(644) [sender=3.1.2]

The "Error: Can't have a partition outside the disk!" has been always there ever since I can recall it. it's annoying but never been hindering the process. The new problem that seems to do it is the fact that when the script re-mounts the destination /mnt/clone/boot it does so read-only, or at least that's what I find after I stop the script:

/dev/sda1 on /mnt/clone/boot type vfat (ro,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)

And I have to stop the script, because every time I've let it go, I end up with a non-bootable SD card.

Just in case it can be of any help:

pi@raspberrypi:~ $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 9.4 (stretch)
Release:    9.4
Codename:   stretch
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.14.34-v7+ #1110 SMP Mon Apr 16 15:18:51 BST 2018 armv7l GNU/Linux

Any hint towards the real cause and solution would be greatly appreciated.

BR Peppe

develoxir commented 6 years ago

It turns out the partition extending beyond the limit was exactly the problem.

Anyone incurring in this might be able to solve it as I did: dump the partition table on a text file using the command

sfdisk -d /dev/devName > partdump.txt

correct the partition size of the culprit partition, making it end no farther than the number of sectors of the disk (not the partition) as shown in the output line of the command:

raspberrypi:~# fdisk -lu /dev/mmcblk0
Disk /dev/mmcblk0: 29.8 GiB, 32010928128 bytes, 62521344 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xa50df092

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   131071   122880   60M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      131072 62521343 62390272 29.8G 83 Linux
raspberrypi:~#

Then once corrected the text dump, re-import it as follows:

sudo sfdisk --force /dev/devName < partdump.txt

Thanks to this thread for the tips: https://ubuntuforums.org/showthread.php?t=1012825&page=2