openhab / openhabian

openHABian - empowering the smart home, for Raspberry Pi and Debian systems
https://community.openhab.org/t/13379
ISC License
818 stars 251 forks source link

Setup SD-Mirroring results in FAILED (set random UUID) error #1751

Closed vhbevan closed 1 year ago

vhbevan commented 1 year ago

Issue information:

When running openhabian-config and selecting Option 53 "Setup SD-Mirroring" and USB Device = sda 59.5G the command fails when writing to the second partition (sda3) created on the backup sdcard in a usb-attached card reader (details below) with the following message: FAILED (set random UUID).

I tried openhabian-config option 54 "Raw copy SD" and it fails with the same error. On using the card in a Windows 11 notebook it works fine. I also tried deleting all partitions on the card and repeated the process but same error appears.

Best regards,

Vincent Bevan

Debug information:

+ choice2='53 | Setup SD mirroring'
+ '[' 0 -eq 1 ']'
+ '[' 1 -eq 255 ']'
+ case "$choice2" in
+ setup_mirror_SD install
+ local src=/dev/mmcblk0
+ local srcSize
+ local dest
+ local destSize
+ local 'infoText1=DANGEROUS OPERATION, USE WITH PRECAUTION!\n\nThis will *copy* your system root from your SD card to a USB attached card writer device. Are you sure'
+ local 'infoText2=is an SD card writer device equipped with a dispensible SD card? Are you sure, this will destroy all data on that card and you want to proceed writing to this device?'
+ local minStorageSize=4000000000
+ local sdIncludesDir=/opt/openhabian/includes/SD
+ local serviceTargetDir=/etc/systemd/system
+ local 'sizeError=your destination SD card device does not have enough space'
+ local storageDir=/storage
+ local sDir=storage
+ local 'storageRemovalQuery=Do you also want to remove the storage mount for /storage?\nIf you do not but remove the physical device it is located on, you will have trouble every time you restart your system.\nRemember though it might also contain data you might want to keep such as your Amanda backup data. If /storage is not where your mount is, stop now and enter your mountpoint in /etc/openhabian.conf as the storagedir= parameter.'
+ local svcname
+ cond_redirect install -m 755 /opt/openhabian/includes/SD/set-partuuid /usr/local/sbin
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ install -m 755 /opt/openhabian/includes/SD/set-partuuid /usr/local/sbin \033[39;49;00m'

$ install -m 755 /opt/openhabian/includes/SD/set-partuuid /usr/local/sbin
+ install -m 755 /opt/openhabian/includes/SD/set-partuuid /usr/local/sbin
+ return 0
++ timestamp
++ printf '%(%F_%T_%Z)T\n' -1
+ echo -n '2023-01-16_20:44:55_CET [openHABian] Setting up automated SD mirroring and backup... '
2023-01-16_20:44:55_CET [openHABian] Setting up automated SD mirroring and backup... + [[ -n '' ]]
+ [[ install == \r\e\m\o\v\e ]]
+ [[ install != \i\n\s\t\a\l\l ]]
+ is_pi
+ is_pifour
+ [[ '' == \p\i\4 ]]
+ grep -q '^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]11[0-9a-fA-F]$' /proc/cpuinfo
+ return 1
+ is_cmfour
+ [[ '' == \c\m\4 ]]
+ grep -q '^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]14[0-9a-fA-F]$' /proc/cpuinfo
+ return 1
+ is_pi400
+ [[ '' == \p\i\4\0\0 ]]
+ grep -q '^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]13[0-9a-fA-F]$' /proc/cpuinfo
+ return 1
+ is_cmthreeplus
+ [[ '' == \c\m\3\+ ]]
+ grep -q '^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]10[0-9a-fA-F]$' /proc/cpuinfo
+ return 1
+ is_cmthree
+ [[ '' == \c\m\3 ]]
+ grep -q '^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[aA][0-9a-fA-F]$' /proc/cpuinfo
+ return 1
+ is_pithreeplus
+ [[ '' == \p\i\3\+ ]]
+ grep -q '^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[dDeE][0-9a-fA-F]$' /proc/cpuinfo
+ return 1
+ is_pithree
+ [[ '' == \p\i\3 ]]
+ grep -q '^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[8dDeE][0-9a-fA-F]$' /proc/cpuinfo
+ return 0
+ return 0
+ mkdir -p /storage
+ cond_redirect apt-get install --yes gdisk
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ apt-get install --yes gdisk \033[39;49;00m'

$ apt-get install --yes gdisk
+ apt-get install --yes gdisk
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
gdisk is already the newest version (1.0.6-1.1).
0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.
+ return 0
+ [[ -n 1 ]]
+ select_blkdev '^sd' 'Setup SD mirroring' 'Select USB device to copy the internal SD card data to'
+ [[ -z 1 ]]
+ array=()
+ declare -a array
+ read -r id foo foo size foo foo foo
++ lsblk -i
++ tr -d '`\\|'
++ grep -E '^sd'
++ tr -d '\\-'
+ array+=("$id" "$size")
+ read -r id foo foo size foo foo foo
+ [[ 2 -eq 0 ]]
+ (( count=2 + 8 ))
++ whiptail --title 'Setup SD mirroring' --cancel-button Cancel --ok-button Select --menu '\nSelect USB device to copy the internal SD card data to' 10 76 0 sda 59.5G
+ retval=sda
+ [[ -z sda ]]
+ dest=/dev/sda
++ blockdev --getsize64 /dev/sda
+ [[ -n 63864569856 ]]
+ mount
+ grep -Eq '$dest[12]'
+ infoText='DANGEROUS OPERATION, USE WITH PRECAUTION!\n\nThis will *copy* your system root from your SD card to a USB attached card writer device. Are you sure /dev/sda is an SD card writer device equipped with a dispensible SD card? Are you sure, this will destroy all data on that card and you want to proceed writing to this device?'
++ blockdev --getsize64 /dev/mmcblk0
+ srcSize=31914983424
+ minStorageSize=35914983424
++ blockdev --getsize64 /dev/sda
+ destSize=63864569856
+ [[ 63864569856 -lt 31914983424 ]]
+ [[ -n 1 ]]
+ whiptail --title 'Copy internal SD to /dev/sda' --yes-button Continue --no-button Back --yesno 'DANGEROUS OPERATION, USE WITH PRECAUTION!\n\nThis will *copy* your system root from your SD card to a USB attached card writer device. Are you sure /dev/sda is an SD card writer device equipped with a dispensible SD card? Are you sure, this will destroy all data on that card and you want to proceed writing to this device?' 12 116
++ basename /storage
+ mountUnit=storage.mount
+ systemctl stop storage.mount
+ sfdisk -d /dev/mmcblk0
+ grep -q '^/dev/mmcblk0p3'
+ [[ 63864569856 -ge 35914983424 ]]
++ fdisk -l /dev/mmcblk0
++ head -1
++ cut '-d ' -f5
+ start=31914983424
+ (( destSize-=start ))
+ (( start/=512 ))
+ destSizeSector=31949586432
+ (( destSizeSector/=512 ))
+ sfdisk -d /dev/mmcblk0
+ sfdisk --force /dev/sda
+ echo '/dev/mmcblk0p3 : start=62333952,size=62401536, type=83'
Checking that no-one is using this disk right now ... OK

Disk /dev/sda: 59.48 GiB, 63864569856 bytes, 124735488 sectors
Disk model: Multi-Card
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: 0x763de928

Old situation:

Device     Boot    Start       End  Sectors  Size Id Type
/dev/sda1           8192    532479   524288  256M  c W95 FAT32 (LBA)
/dev/sda2         532480  62333951 61801472 29.5G 83 Linux
/dev/sda3       62333952 124735487 62401536 29.8G 83 Linux

>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new DOS disklabel with disk identifier 0x076fcd66.
/dev/sda1: Created a new partition 1 of type 'W95 FAT32 (LBA)' and of size 256 MiB.
Partition #1 contains a vfat signature.
/dev/sda2: Created a new partition 2 of type 'Linux' and of size 29.5 GiB.
Partition #2 contains a ext4 signature.
/dev/sda3: Created a new partition 3 of type 'Linux' and of size 29.8 GiB.
Partition #3 contains a ext4 signature.
/dev/sda4: Done.

New situation:
Disklabel type: dos
Disk identifier: 0x076fcd66

Device     Boot    Start       End  Sectors  Size Id Type
/dev/sda1           8192    532479   524288  256M  c W95 FAT32 (LBA)
/dev/sda2         532480  62333951 61801472 29.5G 83 Linux
/dev/sda3       62333952 124735487 62401536 29.8G 83 Linux

The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
+ partprobe
+ cond_redirect mke2fs -F -t ext4 /dev/sda3
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ mke2fs -F -t ext4 /dev/sda3 \033[39;49;00m'

$ mke2fs -F -t ext4 /dev/sda3
+ mke2fs -F -t ext4 /dev/sda3
mke2fs 1.46.2 (28-Feb-2021)
/dev/sda3 contains a ext4 file system
        last mounted on Mon Jan 16 20:28:12 2023
Creating filesystem with 7800192 4k blocks and 1950240 inodes
Filesystem UUID: bb66419b-909a-4183-882e-08b22e5909cd
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

+ return 0
+ sed -e 's|%DEVICE|/dev/sda3|g' -e 's|%STORAGE|/storage|g' /opt/openhabian/includes/SD/storage.mount-template
+ cond_redirect chmod 644 /etc/systemd/system/storage.mount
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ chmod 644 /etc/systemd/system/storage.mount \033[39;49;00m'

$ chmod 644 /etc/systemd/system/storage.mount
+ chmod 644 /etc/systemd/system/storage.mount
+ return 0
+ cond_redirect systemctl -q daemon-reload
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ systemctl -q daemon-reload \033[39;49;00m'

$ systemctl -q daemon-reload
+ systemctl -q daemon-reload
+ return 0
+ cond_redirect systemctl enable --now storage.mount
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ systemctl enable --now storage.mount \033[39;49;00m'

$ systemctl enable --now storage.mount
+ systemctl enable --now storage.mount
+ return 0
+ mirror_SD raw /dev/sda
+ local src=/dev/mmcblk0
+ local dest=/dev/sda
+ local start
+ local destPartsLargeEnough=true
+ local storageDir=/storage
+ local syncMount=/storage/syncmount
+ local dirty=no
+ local repartitionText
+ local 'dumpInfoText=For your information as the operator of this openHABian system:\nA timed background job to run semiannually has just created a full raw device copy of your RPI'\''s internal SD card.\nOnly partitions to contain openHABian (/boot and / partitions 1 & 2) were copied.'
+ local partUUID
+ [[ 2 -eq 1 ]]
+ [[ /dev/mmcblk0 == \/\d\e\v\/\s\d\a ]]
++ blockdev --getsize64 /dev/sda
+ [[ -n 63864569856 ]]
+ mount
+ grep -Eq '$dest[12]'
+ [[ -d /storage/syncmount ]]
+ mkdir -p /storage/syncmount
+ [[ raw == \r\a\w ]]
+ for i in 1 2 3
+ sfdisk -d /dev/mmcblk0
+ grep -q '^/dev/mmcblk0p1'
++ blockdev --getsize64 /dev/mmcblk0p1
+ srcSize=268435456
++ blockdev --getsize64 /dev/sda1
+ destSize=268435456
+ [[ 268435456 -lt 268435456 ]]
+ for i in 1 2 3
+ sfdisk -d /dev/mmcblk0
+ grep -q '^/dev/mmcblk0p2'
++ blockdev --getsize64 /dev/mmcblk0p2
+ srcSize=31642353664
++ blockdev --getsize64 /dev/sda2
+ destSize=31642353664
+ [[ 31642353664 -lt 31642353664 ]]
+ for i in 1 2 3
+ sfdisk -d /dev/mmcblk0
+ grep -q '^/dev/mmcblk0p3'
+ continue
+ [[ true == \t\r\u\e ]]
+ echo 'Taking a raw partition copy, be prepared this may take long such as 20-30 minutes for a 16 GB SD card'
Taking a raw partition copy, be prepared this may take long such as 20-30 minutes for a 16 GB SD card
+ cond_redirect dd if=/dev/mmcblk0p1 bs=1M of=/dev/sda1 status=progress
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ dd if=/dev/mmcblk0p1 bs=1M of=/dev/sda1 status=progress \033[39;49;00m'

$ dd if=/dev/mmcblk0p1 bs=1M of=/dev/sda1 status=progress
+ dd if=/dev/mmcblk0p1 bs=1M of=/dev/sda1 status=progress
254803968 bytes (255 MB, 243 MiB) copied, 11 s, 23.1 MB/s
256+0 records in
256+0 records out
268435456 bytes (268 MB, 256 MiB) copied, 14.8905 s, 18.0 MB/s
+ return 0
+ cond_redirect dd if=/dev/mmcblk0p2 bs=1M of=/dev/sda2 status=progress
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ dd if=/dev/mmcblk0p2 bs=1M of=/dev/sda2 status=progress \033[39;49;00m'

$ dd if=/dev/mmcblk0p2 bs=1M of=/dev/sda2 status=progress
+ dd if=/dev/mmcblk0p2 bs=1M of=/dev/sda2 status=progress
31634489344 bytes (32 GB, 29 GiB) copied, 1396 s, 22.7 MB/s
30176+1 records in
30176+1 records out
31642353664 bytes (32 GB, 29 GiB) copied, 1400.39 s, 22.6 MB/s
+ return 0
+ sfdisk -d /dev/mmcblk0
+ grep -q '^/dev/mmcblk0p3'
++ blkid /dev/mmcblk0p2
++ sed -n 's|^.*PARTUUID="\(\S\+\)".*|\1|p'
++ sed -e s/-02//g
+ origPartUUID=076fcd66
++ yes
++ cond_redirect set-partuuid /dev/sda2 random
++ [[ -n '' ]]
++ echo -e '\n\033[90;01m$ set-partuuid /dev/sda2 random \033[39;49;00m'
++ set-partuuid /dev/sda2 random
++ awk '/^PARTUUID/ { print substr($7,1,length($7) - 3) }'
++ return 0
+ partUUID=9835d817
+ cond_redirect tune2fs /dev/sda2 -U random
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ tune2fs /dev/sda2 -U random \033[39;49;00m'

$ tune2fs /dev/sda2 -U random
+ tune2fs /dev/sda2 -U random
tune2fs 1.46.2 (28-Feb-2021)

This operation requires a freshly checked filesystem.

Please run e2fsck -f on the filesystem.

+ return 1
+ echo 'FAILED (set random UUID)'
FAILED (set random UUID)
+ dirty=yes
+ umount -q /dev/sda1
+ mount /dev/sda1 /storage/syncmount
+ sed -i 's|076fcd66|9835d817|g' /storage/syncmount/cmdline.txt
+ umount /storage/syncmount
+ umount -q /dev/sda2
+ mount /dev/sda2 /storage/syncmount
+ sed -i 's|076fcd66|9835d817|g' /storage/syncmount/etc/fstab
+ [[ -f /storage/syncmount/etc/systemd/system//storage.mount ]]
+ sed -i 's|^What=.*|What=/dev/mmcblk0p3|g' /storage/syncmount/etc/systemd/system//storage.mount
+ umount /storage/syncmount
+ cond_redirect fsck -y -t ext4 /dev/sda2
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ fsck -y -t ext4 /dev/sda2 \033[39;49;00m'

$ fsck -y -t ext4 /dev/sda2
+ fsck -y -t ext4 /dev/sda2
fsck from util-linux 2.36.1
e2fsck 1.46.2 (28-Feb-2021)
rootfs: clean, 71042/1925760 files, 1348526/7725184 blocks
+ return 0
+ [[ yes == \n\o ]]
+ [[ -n '' ]]
+ return 0
+ sed -e 's|%DEST|/dev/sda|g' /opt/openhabian/includes/SD/sdrawcopy.service-template
+ sed -e 's|%DEST|/dev/sda|g' /opt/openhabian/includes/SD/sdrsync.service-template
+ cond_redirect install -m 644 -t /etc/systemd/system /opt/openhabian/includes/SD/sdrawcopy.timer /opt/openhabian/includes/SD/sdrsync.timer
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ install -m 644 -t /etc/systemd/system /opt/openhabian/includes/SD/sdrawcopy.timer /opt/openhabian/includes/SD/sdrsync.timer \033[39;49;00m'

$ install -m 644 -t /etc/systemd/system /opt/openhabian/includes/SD/sdrawcopy.timer /opt/openhabian/includes/SD/sdrsync.timer
+ install -m 644 -t /etc/systemd/system /opt/openhabian/includes/SD/sdrawcopy.timer /opt/openhabian/includes/SD/sdrsync.timer
+ return 0
+ cond_redirect install -m 755 /opt/openhabian/includes/SD/mirror_SD /usr/local/sbin
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ install -m 755 /opt/openhabian/includes/SD/mirror_SD /usr/local/sbin \033[39;49;00m'

$ install -m 755 /opt/openhabian/includes/SD/mirror_SD /usr/local/sbin
+ install -m 755 /opt/openhabian/includes/SD/mirror_SD /usr/local/sbin
+ return 0
+ cond_redirect systemctl -q daemon-reload
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ systemctl -q daemon-reload \033[39;49;00m'

$ systemctl -q daemon-reload
+ systemctl -q daemon-reload
+ return 0
+ cond_redirect systemctl enable --now sdrawcopy.timer sdrsync.timer
+ [[ -n '' ]]
+ echo -e '\n\033[90;01m$ systemctl enable --now sdrawcopy.timer sdrsync.timer \033[39;49;00m'

$ systemctl enable --now sdrawcopy.timer sdrsync.timer
+ systemctl enable --now sdrawcopy.timer sdrsync.timer
+ return 0
+ echo OK
OK
+ [[ -z 1 ]]
+ '[' 0 -ne 0 ']'
+ true
+ show_main_menu

System information:

Please tell us what OS you are running (Raspberry Pi OS, Debian, Ubuntu), what HW you are running on (Raspberry Pi, amd64).

Raspberry Pi 3 Model B Rev 1.2
SANDISK High Endurance Micros SDHC 32GB (boot disk with openhabian image)
Hama Card Reader USB3.0
SANDISK High Endurance Micros SDHC 64GB (backup disk) 
Linux openhabian 5.15.76-v7+ #1597 SMP Fri Nov 4 12:13:17 GMT 2022 armv7l
openHAB 3.4.1 - Release Build

Also include the output of cat /etc/os-release

PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

and uname -m.

armv7l
mstormi commented 1 year ago

Your source SD probably needs an fsck that's why tunefs doesn't work. But I don't see anything wrong with what openHABian is doing.

And Github is not for user support. Please turn to the forum.