0

I need to clone a bootable disk to multiple disks (of different sizes) on different computers and it needs to be scriptable, but I can't find a way to do it.

I'm using Ubuntu 16.04 on everything.

First I tried dd, I ran (with the disk unmounted):

$ dd if=/dev/sda bs=1K count=10000000 status=progress | gzip -c > os.img

That's about 10GB, the compressed file is about 3.8GB, the source disk is 120GB, the destination disk I'm testing on is 16GB, so I'm sure that it's going to work on all sizes, I wrote to disk with:

$ gunzip -c os.img | dd bs=1K of=/dev/sda status=progress

But it doesn't boot, I get:

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown block(0,0)

no idea what that means, so I googled it but I didn't find a solution. Then I tried to mount the disk on a live OS to see if at least that worked, but I get:

$ sudo mount /dev/sda1 /mnt
EXT4-fs (sda1): bad geometry: block count 29306624 exceeds size of device (14653670 blocks)

which doesn't make sense to me. Anyone know if I can fix this or if there's a better method to do it? I see people recommending clonezilla but I can't find a scriptable version, it looks like I can only use it with "terminal GUI".

  • can you instead use help.ubuntu.com/lts/installation-guide/i386/ch04s06.html and install to the different sized disks? – thrig Jul 3 '18 at 13:47
  • 1
    You want to use a tool like clonezilla - specifically the server option that can broadcast an image out to multiple machines at once - clonezilla.org/clonezilla-SE – ivanivan Jul 3 '18 at 14:22
  • What do fdisk -l /dev/sda or parted /dev/sda print on your original disk say? – ctrl-d Jul 3 '18 at 15:17
  • Thanks for your comments, I considered using an automatic installation but I also need various drivers and scripts, it would be much easier to do the way I'm doing it, if it works. I already addressed clonezilla in my post. fdisk prints this – Fyde Jul 4 '18 at 11:48
0

The problem is that the size of the source disk is larger than (some of the) destination disk(s). Which means the partition table doesn't work, because it's made for a disk of different size.

In your place, I'd write a script that uses fdisk etc. to first delete all partitions on the disk, then makes a partition of fixed size (which should be identical to the size of the partition where your image comes from; you may have to create such a partition), and then makes it bootable. This will ensure the partition table is correct for a disk of that size. Finally you copy the partition (e.g. /dev/sda1) instead of the whole disk.

BTW, using both gzip/gunzip and dd doesn't make sense (unless you like the progress display) - all dd does is to make sure the writes are of some particular size. You could just use

gzip -c /dev/sda1 > os.img
gunzip -c os.img > /dev/sdb1

etc. And if you want to display progress, there's also pv.

  • Thanks for your answer! I did like you said, I resized the partition to 6000MB with gparted, copied it and created one just as big with this command: sudo echo ',6000M;' | sudo sfdisk /dev/sda and I made it bootable, but when I write the file I get Not enough space on device (?), I tried with a bigger partition and it works but it doesn't boot, I get a blinking cursor. What am I doing wrong? – Fyde Jul 4 '18 at 10:55
  • Nevermind, the size is actually 8000MB, the write works, but I still only get a blinking cursor when I try to boot. – Fyde Jul 4 '18 at 11:17
  • What's the bootloader? grub? Did you refresh the boot image when you resized the partition? Do you boot on the same computer where you made the bootloader, or on a different one? If devices numbering is different from the computer where you made the image, possibly one has to configure grub etc. properly. – dirkt Jul 5 '18 at 5:41
  • I don't know what you mean with refresh. Yes, it's a different one, I'm going to have to use this image on many different computers. So basically I have to reconfigure (or reinstall) GRUB on that disk after I write the image to it? Can I use grub-install? – Fyde Jul 5 '18 at 6:58
  • I used grub-install and it works, thank you so much! – Fyde Jul 5 '18 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.