Scriptable way to clone source disk to multiple destination disks?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












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".







share|improve this question





















  • can you instead use help.ubuntu.com/lts/installation-guide/i386/ch04s06.html and install to the different sized disks?
    – thrig
    Jul 3 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 at 14:22










  • What do fdisk -l /dev/sda or parted /dev/sda print on your original disk say?
    – ctrl-d
    Jul 3 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 at 11:48















up vote
0
down vote

favorite












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".







share|improve this question





















  • can you instead use help.ubuntu.com/lts/installation-guide/i386/ch04s06.html and install to the different sized disks?
    – thrig
    Jul 3 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 at 14:22










  • What do fdisk -l /dev/sda or parted /dev/sda print on your original disk say?
    – ctrl-d
    Jul 3 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 at 11:48













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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".







share|improve this question













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".









share|improve this question












share|improve this question




share|improve this question








edited Jul 3 at 14:36









slm♦

233k65479651




233k65479651









asked Jul 3 at 12:24









Fyde

52




52











  • can you instead use help.ubuntu.com/lts/installation-guide/i386/ch04s06.html and install to the different sized disks?
    – thrig
    Jul 3 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 at 14:22










  • What do fdisk -l /dev/sda or parted /dev/sda print on your original disk say?
    – ctrl-d
    Jul 3 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 at 11:48

















  • can you instead use help.ubuntu.com/lts/installation-guide/i386/ch04s06.html and install to the different sized disks?
    – thrig
    Jul 3 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 at 14:22










  • What do fdisk -l /dev/sda or parted /dev/sda print on your original disk say?
    – ctrl-d
    Jul 3 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 at 11:48
















can you instead use help.ubuntu.com/lts/installation-guide/i386/ch04s06.html and install to the different sized disks?
– thrig
Jul 3 at 13:47




can you instead use help.ubuntu.com/lts/installation-guide/i386/ch04s06.html and install to the different sized disks?
– thrig
Jul 3 at 13:47




1




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 at 14:22




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 at 14:22












What do fdisk -l /dev/sda or parted /dev/sda print on your original disk say?
– ctrl-d
Jul 3 at 15:17




What do fdisk -l /dev/sda or parted /dev/sda print on your original disk say?
– ctrl-d
Jul 3 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 at 11:48





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 at 11:48











1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










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.






share|improve this answer





















  • 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 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 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 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 at 6:58










  • I used grub-install and it works, thank you so much!
    – Fyde
    Jul 5 at 11:03










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453213%2fscriptable-way-to-clone-source-disk-to-multiple-destination-disks%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










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.






share|improve this answer





















  • 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 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 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 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 at 6:58










  • I used grub-install and it works, thank you so much!
    – Fyde
    Jul 5 at 11:03














up vote
0
down vote



accepted










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.






share|improve this answer





















  • 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 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 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 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 at 6:58










  • I used grub-install and it works, thank you so much!
    – Fyde
    Jul 5 at 11:03












up vote
0
down vote



accepted







up vote
0
down vote



accepted






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.






share|improve this answer













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.







share|improve this answer













share|improve this answer



share|improve this answer











answered Jul 4 at 6:25









dirkt

13.9k2930




13.9k2930











  • 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 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 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 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 at 6:58










  • I used grub-install and it works, thank you so much!
    – Fyde
    Jul 5 at 11:03
















  • 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 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 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 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 at 6:58










  • I used grub-install and it works, thank you so much!
    – Fyde
    Jul 5 at 11:03















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 at 10:55




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 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 at 11:17




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 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 at 5:41




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 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 at 6:58




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 at 6:58












I used grub-install and it works, thank you so much!
– Fyde
Jul 5 at 11:03




I used grub-install and it works, thank you so much!
– Fyde
Jul 5 at 11:03












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453213%2fscriptable-way-to-clone-source-disk-to-multiple-destination-disks%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay