openhab / openhabian

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

Can’t setup SD mirroring #1631

Closed Markkuuss closed 2 years ago

Markkuuss commented 2 years ago

When I try to Setup SD Mirroring (option 53), I get the following output:

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048 62332927 62330880 29,7G  c W95 FAT32 (LBA)

>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new DOS disklabel with disk identifier 0x80735363.
/dev/sda1: Created a new partition 1 of type 'W95 FAT32 (LBA)' and of size 256 MiB.
/dev/sda2: Created a new partition 2 of type 'Linux' and of size 14,6 GiB.
Partition #2 contains a ext4 signature.
/dev/sda3: No free sectors available.
Failed to add #3 partition: Auf dem Gerät ist kein Speicherplatz mehr verfügbar
Leaving.

I’m booted from a 16GB SD card and trying to backup to a 32GB card in a usb card reader.

Info on both of SD cards:

Disk /dev/mmcblk0: 14,84 GiB, 15931539456 bytes, 31116288 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: 0x80735363

Device         Boot  Start      End  Sectors  Size Id Type
/dev/mmcblk0p1        8192   532479   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      532480 31116287 30583808 14,6G 83 Linux

Disk /dev/sda: 29,72 GiB, 31914983424 bytes, 62333952 sectors
Disk model: STORAGE DEVICE
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: 0xb8d3a6a1

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048 62332927 62330880 29,7G  c W95 FAT32 (LBA)

The full debug output is as follows:

+ 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
+ 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
++ date +%F_%T_%Z
+ echo -n '2021-12-05_21:34:32_CET [openHABian] Setting up automated SD mirroring and backup... '
2021-12-05_21:34:32_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 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
Paketlisten werden gelesen… Fertig
Abhängigkeitsbaum wird aufgebaut… Fertig
Statusinformationen werden eingelesen… Fertig
gdisk ist schon die neueste Version (1.0.6-1.1).
0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.
+ 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 29,7G
+ retval=sda
+ [[ -z sda ]]
+ dest=/dev/sda
++ blockdev --getsize64 /dev/sda
+ [[ -n 31914983424 ]]
+ 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=15931539456
+ minStorageSize=19931539456
++ blockdev --getsize64 /dev/sda
+ destSize=31914983424
+ [[ 31914983424 -lt 15931539456 ]]
+ [[ -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'
+ [[ 31914983424 -ge 19931539456 ]]
++ fdisk -l /dev/mmcblk0
++ head -1
++ cut '-d ' -f7
+ start=31116288
+ (( destSize-=start ))
+ sfdisk -d /dev/mmcblk0
+ sfdisk --force /dev/sda
+ echo '/dev/mmcblk0p3 : start=31116288,size=31883867136, type=83'
Checking that no-one is using this disk right now ... OK

Disk /dev/sda: 29,72 GiB, 31914983424 bytes, 62333952 sectors
Disk model: STORAGE DEVICE
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: 0xb8d3a6a1

Old situation:

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048 62332927 62330880 29,7G  c W95 FAT32 (LBA)

>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Script header accepted.
>>> Created a new DOS disklabel with disk identifier 0x80735363.
/dev/sda1: Created a new partition 1 of type 'W95 FAT32 (LBA)' and of size 256 MiB.
/dev/sda2: Created a new partition 2 of type 'Linux' and of size 14,6 GiB.
Partition #2 contains a ext4 signature.
/dev/sda3: No free sectors available.
Failed to add #3 partition: Auf dem Gerät ist kein Speicherplatz mehr verfügbar
Leaving.

+ 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)
The file /dev/sda3 does not exist and no size was specified.
+ return 1
+ 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
A dependency job for storage.mount failed. See 'journalctl -xe' for details.
+ return 1
+ echo 'FAILED (enable storage mount)'
FAILED (enable storage mount)
+ return 1
+ '[' 1 -ne 0 ']'
+ whiptail --msgbox 'There was an error or interruption during the execution of:\n  "50 | Backup/Restore"\n\nPlease try again. If the error persists, please read /opt/openhabian/docs/openhabian-DEBUG.md or https://github.com/openhab/openhabian/blob/main/docs/openhabian-DEBUG.md how to proceed.' 14 80

see also: https://community.openhab.org/t/can-t-setup-sd-mirroring/126503/6