Best way to clone an installation (copying to identical hardware)
Kind-of like this question but slightly different (I think), in that I have 6 identical Acer Aspire Revo R3610 machines. One is (almost) configured to my requirements - when I'm done preparing it I'd like to make the other 5 machines absolutely the same. I'm very new to Ubuntu, what's the most straightforward (easiest) way of doing this?
The machines are going to live on different networks if that might otherwise be a problem (eg with Windows you can clone disks but you then have to make registry changes afterwards if they're going to run on the same network etc). The hardware in all 6 machines is, I stress, the same!
How can I efficiently clone one source image on to these identical machines?
Please restrict one software/solution per answer
Clonezilla sounds like it fits your needs
Totally the right tool for the job. My Mum runs 'Mumbuntu' and I take a snapshot of her Acer Revo periodically using clonezilla and take it home to restore on a Revo I own as a backup. Works a treat.
One benefit of using tools like partimage and ntfsclone (which is what Clonezilla uses to create the disk image) is that they understand the underlying filesystem on each partition, which allows them to copy only used blocks. As dd does not have this functionality, it must copy every byte of the partition, regardless of whether or not it is used.
It sucks. Failed to clone after two days work. Hangs on alculating bitmap... Use Windows and Acronis Trueimage
Will DD not make the bootable backup CD? Is that the reason use CloneZilla?
@YumYumYum: `dd` makes *copies* of a file/partition/drive. So if you clone a bootable CD (either `.iso` image or a `CDFS` partition) the result will be bootable as well. But `dd` will *not* "convert" a given set of folders/files to a bootable image.
Clonezilla makes an "almost" perfect copy. Most everything works except Chromium. It looks like it is launching then just silently gives up. So here is the solution: go into the software installer, remove it then add it back again and log it back into Google to get bookmarks and extensions.
A low level copy using dd would do the trick!
Watch out for conflicting IP addresses and hostnames.
Basically put the source drive and destination drive in the same machine, boot into a live cd. And run something like the following where
/dev/sdais the source and
/dev/sdbis the destination:
dd if=/dev/sda of=/dev/sdb bs=4096
I remember the operands by:
if-> input file
of-> output file
bs-> block size (how many bytes to read at a time)
Sure why not? =/ I've seen people do that and I've seen people not do it. Is there a style guide somewhere to answers?
if you have Dynamic IP enabled, temporary before making that Bootable/backup CD/USB. There should not be any issue i believe for conflicting IP. As long as it back up A to Z that really matters to me, because of lot of drivers i had.
How safe is this, considering any public/private keys used by for example OpenSSH would be identical? What would we need to change to keep the system safe (different where we wan't it to be different)?
The easiest way to do this is to run a bare bones Ubuntu installation on your hard drive, install VirtualBox and set up a virtual Ubuntu machine. Run your virtual machine and set up that installation just like you want it with all the bells and whistles you want. Do all of your working and playing on the virtual computer.
VirtualBox maintains the virtual machine as a large disk image file (.vdi) along with a few other much smaller configuration files. Whenever you want to backup your virtual machine, just shut it down and copy its directory to your backup location. I use a Passport external drive for this purpose.
Right now, there is both a Windows 7 and an Ubuntu 12 virtual machine on that external drive. All of the system updates, programs, personal files, pictures, whatever, get saved in those virtual machines. A backup of this type is very fast, as one big disk image file will transfer much quicker than a bunch of individual files would. Since VirtualBox maintains the files in that format all the time, the virtual machine is always configured to be backed up.
One advantage of that setup is that I can run those virtual machines off the external drive on any computer with VirtualBox installed, so now, instead of lugging my computer all around, I just bring my external drive with both Windows and Ubuntu, install VirtualBox on whatever computer I plan to use (I have all the VirtualBox installation files also on my external hd - they are available for all the main operating systems), and I am ready to go. I can either copy my virtual machine to the computer I am using, or just run it off of the external drive.
If your computer crashes and dies at some point, who cares, you just grab your Ubuntu installation disk, install it on your new or repaired computer, hook up your external drive, install VirtualBox, and copy your virtual machines back on to your computer - problem solved with minimal stress, loss of time, and loss of data. How much data you lose depends on when you last backed up. For myself, I do a new backup whenever I make a major change or add a hard to get program. Just make sure that your virtual machine is operating normally when you do it. You would not want to copy a corrupted machine over a good one.
And no, I don't work for VirtualBox.
I would get one computer all the way you want it, and install the openssh-server package. Generate a ssh key pair with
ssh-keygen -t rsa. Add the public key to /root/.ssh/authorized_keys2. Then I would boot the new computers with a live cd and plug in a usb stick with the ssh private key. Use gparted to create a new partition. Then mount the new partition and run something like
sudo rsync -avzx -e "ssh -i /media/disk/path/to/privatekey" --exclude=".gvfs" [email protected]<ImageComputerIP>:/ /path/to/new/partition/
blkidcommand to find the UUID of the filesystem you just created. Edit the
/path/to/new/partition/etc/fstabto reflect the new UUID (and filesystem type if you used a different filesystem.)
Then I would follow the instructions on https://help.ubuntu.com/community/Grub2/Installing#via_ChRoot about how to install from a chroot.
A simplified version of that page (which doesn't account for lvm, software raid, or bcache, or separate /boot like the wiki page does):
Mount the critical virtual filesystems. Run the following as a single command:
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
Chroot into your normal system device:
sudo chroot /mnt
Reinstall GRUB 2 (substitute the correct device with sda, sdb, etc. Do not specify a partition number):
Recreate the GRUB 2 menu file (grub.cfg)
Exit chroot: CTRL-D on keyboard
By the way, this works good for backup, too. Ubuntu, unlike Windows, doesn't seem to have problems being transplanted to different hardware. I've put hard disks from one computer in another and it did fine, and I've copied installs to different hardware and it did fine.
Thanks for this - I've got another one coming up shortly, I'll give this a try. Cheers
The referenced link currently doesn't mention chroot nor any methods. That's why it is a good idea to quote relevant parts of your sources.
@Henno The wiki page was moved. The problem with including the page is that the wiki keeps up to date with new things like bcache and just copying the contents of the page will miss those updates, but the downside to just linking that is stuff can move on you. Either way, link updated, and a stripped down version included.
Ghost for Linux
Ghost for Linux is a hard disk and partition imaging and cloning tool similar to Norton Ghost(c) and (tm) by Symantec. The created images are optionally compressed, and they can be stored on a local hard drive or transferred to an anonymous FTP server. A drive can be cloned using the Click'n'Clone function. g4l supports file splitting if the local filesystem does not support writing files >2GB. The included kernel supports ATA, serial-ATA, and SCSI drives. Common network cards are supported. It is packaged as a bootable CD image with an ncurses GUI for easy use.
I don't know why no one mentioned this. This is especially handy when you want to restore the partition's content on another file system type (for example, restoring ext4 content to ext2 or reiserfs) or you want to restore to an smaller partition.
I used it and it's very easy. For example, to clone a partition say
/dev/sda1you use a command like this
fsarchiver -A -j 2 -z 1 savefs /media/anwar/USB_Drive/myrootpartition /dev/sda1
-Aoption allows you to copy partition even if it is used! Great feature!
-j 2says to use 2 CPU core for compression. Useful for multi-cored CPU and if you use compression
-z 1sets the compression level.
To restore the file system you used
fsarchiver restfs /data/myrootpartition.fsa id=0,dest=/dev/sda2
id=0says you're restoring the first filesystem from the archive (Even if you don't saved multiple partitions on a single archive, you need to specify it). And
dest=/dev/sda2sets the destination of the restoring.
I do this a lot, using rsync.
First you can run rsync to load all the data to an external hard drive (your external hard drive should be in ext4 - I use this, so I know it works): I assume you have two partitions: /dev/sda1 (root) and /dev/sda2 (swap).
Run in your original computer:
sudo rsync -avuorpESHAX /* /your/hard/drive
After copying the data, boot your next computer with an usb stick, and format the internal hard drive as the original hard drive.
Mount your external drive to
/mnt, and copy the UUIDs of all partitions. Edit the UUIDs of the partitions of the new computer and put the same UUIDs you have copyied from the original data (it is in
Shut down the swap:
sudo swapoff -a
Create a new swap using the original UUID, copyied from
sudo mkswap /dev/sda2 -U original-UUID
(I supose your swap is in
Next, change the UUID of
/dev/sda1: (the partition should be unmounted in order to change UUIDs)
sudo umount /mnt sudo tune2fs /dev/sda1 -U old-UUID
Done this, mount the destination partition:
sudo mount /dev/sda1 /mnt
Reverse rsync to the destination:
sudo rsync -avuorpESHAX /media/your-backup /mnt
Reinstall the grub:
sudo grub-install --root-directory /mnt /dev/sda
This will work. Remember to edit
/etc/hoststo change the hostname for each machine in order to avoid network conflicts.