2

I need to create backups of a Ubuntu system in a way that I can easily restore the data and system as it is exactly in a ready to go state. So, I decided to go with dd to create a whole HHD images.

I created the image as follows:

dd if=/dev/current_drive of=/dev/backup_drive/backup.img conv=sync status=progress

The image was done without errors. After that I decided to restore the image to a test new drive:

dd if=/backup_drive/backup.img of=/dev/new_drive conv=sync status=progress

So far, so good. The image restore went without errors. But when I tried to boot from the new hard which got the image restored on, I encountered initramfs errors: enter image description here

So after manual fsck the errors were cleaned and I was able to boot from the new HDD. But I tried couple of times the procedure of restoring the image to the drive and each time I got problems with booting. My original system drive and the new one are absolutely identical according to

sudo fdisk -l:

/dev/sda/ is the new hard drive.

/dev/sdb/ is the original one from which the image was created.

Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 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: 0xf11c2eb5

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sda1  *         2048 455024639 455022592  217G 83 Linux
/dev/sda2       455026686 488396799  33370114 15.9G  5 Extended
/dev/sda5       455026688 488396799  33370112 15.9G 82 Linux swap / Solaris


Disk /dev/sdb: 232.9 GiB, 250059350016 bytes, 488397168 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: 0xf11c2eb5

Device     Boot     Start       End   Sectors  Size Id Type
/dev/sdb1  *         2048 455024639 455022592  217G 83 Linux
/dev/sdb2       455026686 488396799  33370114 15.9G  5 Extended
/dev/sdb5       455026688 488396799  33370112 15.9G 82 Linux swap / Solaris

So, any ideas what I am doing wrong and why I get boot errors after image restore? I don't want in a real situation to have to fix the eventual new hard drive in case of failure of the original one.

Btw, the original drive is SSD, while the new one is HDD if this matters.

3
  • Well the UNEXPECTED INCONSISTENCY: Run fsck sure sticks out to me. Maybe you should run fsck. BTW, you didn't actually try doing the original dd on a live filesystem did you? This is the type of thing that really should be done from a livecd or something.
    – Zoredache
    Feb 8, 2018 at 21:15
  • @Zoredache unfortunately, I created the image on a running system. The disk which the images was being created from was the system one(booted from). You think this might cause the issue?
    – CuriousGuy
    Feb 8, 2018 at 21:19
  • Yes, that would absolutely cause problems. The only way you could do that kind of backup with dd on a live filesystem that wouldn't result in a failure is by stopping all services, remounting all the filesystems read-only.
    – Zoredache
    Feb 8, 2018 at 22:09

1 Answer 1

1

Yes dd cannot make a coherent image of a living system. The bytes copied at the beginning of your image are from a different moment in time than the ending bytes. In other words, it's not a snapshot. That's why fsck complains.

I see use-the-simplest-tool tactic here, which is good because you can better predict the outcome. I suggest to prepare identical filesystems and copy file-by-file with rsync -aHAXE --delete-during source destination

It's also not a snapshot, but at least the fsck won't complain.

To maintain bootability with rsync, you grub-install a new disk, enforcing a new root location. Roughly speaking it will link the new boot sector with the contents of new /boot/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .