Cannot restore openHAB onto identical card type (using openHABian option 54 Raw copy SD)

Hi All,

I have a raspberry pi 4 with openHAB installed via flashing the 32bit openhabian image onto a 8GB SD card.

I set everything up then used option 53 Setup SD mirroring in the openhabian GUI to be safe should my SD fail. This step ran perfectly on a 32GB SD (inserted via usb reader).

  1. I then shutdown the Pi,

  2. swapped out the original 8GB card for the 32GB version that I had just mirrored to

  3. inserted an identical (brand, size, type) empty 8GB card into the card reader.

  4. Powered on Pi and ran option 54 Raw copy SD

at which point I keep running into the same error:

$ dd if=/dev/mmcblk0p2 bs=1M of=/dev/sda2 status=progress 
569376768 bytes (569 MB, 543 MiB) copied, 13 s, 43.8 MB/s
dd: error writing '/dev/sda2': No space left on device
574+0 records in
573+0 records out
601124864 bytes (601 MB, 573 MiB) copied, 13.7571 s, 43.7 MB/s
FAILED (raw device copy of /dev/sda2)

full.log (4.0 KB)

Things i’ve tried

Different brands and sizes of cards:

  • 3 different Verbatim class 10 8GB (identical to original, purchased at the same time)
  • Kingston class 10 16GB
  • Sandisk ultra 32GB
  • Kingston Canvas v10 32GB

Over my head but added new superblock incase it was corrupt as the error said

I even formatted a 32GB card with 1 partition and ran

$ dd if=/dev/mmcblk0p1 bs=1M of=/dev/sda1 status=progress

Still the same error in the log.

I assume this error may not be related to openhabian but I’m unsure. Any ideas would be much appreciated thanks very much.

If that’s all you did to the new 8G SD you have not partitioned it so the dest partition might be smaller (by default) than the source, check with blockdev --getsize64 <partition>.
I guess you also made some mistake when creating that single 32GB partition else I cannot explain why to copy there doesn’t work.

Have you tried to mirror the original 8GB to the new 8 GB using option 54 ?

1 Like

Many thanks for your reply, sorry due to my limited understanding I did not realise that the partitions were not created automatically.

I’ve spent all day trying to understand how to partition my new card to match my old one before copying over.

8GB to 8GB using option 54

First I did what you said on the two 8GB cards to make sure they were in fact identical.

sudo blockdev --getsize64 /dev/sda        SD IN USB
8010072064

sudo blockdev --getsize64 /dev/mmcblk0    SOURCE 
8010072064

I then ran option 54 and it worked as expected.

Partitioning

I added the 32GB card and ran 53 Mirror and it worked as expected.

I put the 32GB into the internal SD slot and the 8GB into the back.

I tried my best to create a 2 partitions on the 8GB to match those on the 32GB (ignoring the 3rd which I assumed I did not need). For some reason I would not get them exact on the 8GB (could not use the same “start end” range) I’m possibly missing something here. I then decided to use a 16GB card as that would definitely have enough space to match the partitions.

Internal

Disk /dev/mmcblk0: 29.1 GiB, 31293702144 bytes, 61120512 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: 0x84bebabd

Device         Boot    Start      End  Sectors  Size Id Type
/dev/mmcblk0p1          8192   532479   524288  256M  c W95 FAT32 (LBA)
/dev/mmcblk0p2        532480 15644671 15112192  7.2G 83 Linux
/dev/mmcblk0p3      15644672 61120511 45475840 21.7G 83 Linux

External

Disk /dev/sda: 14.4 GiB, 15476981760 bytes, 30228480 sectors
Disk model: UHSII uSD Reader
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: 0x48100fc1

Device     Boot  Start      End  Sectors  Size Id Type
/dev/sda1         8192   532479   524288  256M  c W95 FAT32 (LBA)
/dev/sda2       532480 15644671 15112192  7.2G 83 Linux

Tried this

Internal

sudo blockdev --getsize64 /dev/mmcblk0p1
268435456

sudo blockdev --getsize64 /dev/mmcblk0p2
7737442304

External ??? (Googled all over and could not figure this out)

sudo blockdev --getsize64 /dev/sda1
blockdev: ioctl error on BLKGETSIZE64: Inappropriate ioctl for device

sudo blockdev --getsize64 /dev/sda2
blockdev: ioctl error on BLKGETSIZE64: Inappropriate ioctl for device

I tried to copy over and it did not work

sudo dd if=/dev/mmcblk0p1 bs=1M of=/dev/sda1 status=progress

152043520 bytes (152 MB, 145 MiB) copied, 1 s, 151 MB/s
256+0 records in
256+0 records out
268435456 bytes (268 MB, 256 MiB) copied, 1.72777 s, 155 MB/s

sudo dd if=/dev/mmcblk0p2 bs=1M of=/dev/sda2 status=progress

587202560 bytes (587 MB, 560 MiB) copied, 18 s, 32.6 MB/s
dd: error writing '/dev/sda2': No space left on device
574+0 records in
573+0 records out
601124864 bytes (601 MB, 573 MiB) copied, 18.6751 s, 32.2 MB/s

I’m now confused, hopefully what I have sent is useful? If anyone has any ideas on what is going wrong or what I’ve done wrong I would really appreciate it thanks.

sudo blockdev --getsize64 /dev/sda2
blockdev: ioctl error on BLKGETSIZE64: Inappropriate ioctl for device

I have never seen that error. Maybe your external card writer is bad ? Or the driver you use for it ?
Try with a different model.

1 Like

After much more testing it is now working!

I noticed that even though I had removed the partitions, fdisk and parted would both fail in some way while trying to add new ones and sudo blockdev --getsize64 /dev/sda2 would fail as above.

I tried 3 cards and 3 different card readers in my Pi and all 3 had the same issue. I was going a bit crazy but luckily I found another SD card which I tried and it worked perfectly. Although I thought it was unlikely it appears that all 3 SD cards were corrupt (possibly by me while learning how to partition them!!!)

Thanks @mstormi for pointing me in the right direction.

I can see that if the destination SD card is partitionless to begin with then option 54 creates them correctly and copies the data across OK so I don’t need to specifically match and create them myself.

Here is the process I used in case it is helpful to anyone else:

# Quick check of devices/partitions
lsblk

# Remove partitions from destination if necessary
sudo parted /dev/sda mktable msdos

# Take note of accurate source partition details
sudo parted /dev/mmcblk0 'unit s print'

# e.g
Model: SD  (sd/mmc)
Disk /dev/mmcblk0: 15644672s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start    End        Size       Type     File system  Flags
 1      8192s    532479s    524288s    primary  fat32        lba
 2      532480s  15644671s  15112192s  primary  ext4

# Create partitions
sudo parted /dev/sda --script -- mkpart primary fat32 8192s 532479s
sudo parted /dev/sda --script -- mkpart primary ext4 532480s 15644671s

# Make sure the sizes match
sudo blockdev --getsize64 /dev/mmcblk0p1
sudo blockdev --getsize64 /dev/sda1
sudo blockdev --getsize64 /dev/mmcblk0p2
sudo blockdev --getsize64 /dev/sda2
sudo blockdev --getsize64 /dev/sda3

# Check source and destination partitions match
sudo parted /dev/mmcblk0 'unit s print'
sudo parted /dev/sda 'unit s print'

# Copy partition 1
sudo dd if=/dev/mmcblk0p1 bs=1M of=/dev/sda1 status=progress

# Copy partition 2 
sudo dd if=/dev/mmcblk0p2 bs=1M of=/dev/sda2 status=progress

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.