55

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

robsoft
  • 207

12 Answers12

33

Clonezilla sounds like it fits your needs

  • 1
    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. – popey Aug 20 '10 at 14:39
  • 7
    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. – Evan Oct 10 '10 at 19:21
  • 1
    It sucks. Failed to clone after two days work. Hangs on alculating bitmap... Use Windows and Acronis Trueimage – Olcay Ertaş Sep 12 '11 at 05:10
  • Will DD not make the bootable backup CD? Is that the reason use CloneZilla? –  Nov 16 '11 at 16:17
  • @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. – MestreLion Apr 09 '13 at 03:09
  • 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. – SDsolar Jul 03 '17 at 02:34
18

dd

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/sda is the source and /dev/sdb is 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)

Derek
  • 249
  • 3
    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? – Derek Aug 20 '10 at 14:28
  • 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. –  Nov 16 '11 at 16:15
  • 2
    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)? – jos Aug 24 '12 at 18:58
  • What do you mean by run "something like this? I am positive of sda and sdb but don't understand why you picked that bs. – SDsolar Jul 03 '17 at 02:35
5

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.

4

Create an image using Remastersys, transfer it to a pen drive using the Startup Disk Creator utility and install on other system.

Owais Lone
  • 7,382
2

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" root@<ImageComputerIP>:/ /path/to/new/partition/

Use the blkid command to find the UUID of the filesystem you just created. Edit the /path/to/new/partition/etc/fstab to 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):

grub-install /dev/sdX

Recreate the GRUB 2 menu file (grub.cfg)

update-grub

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.

Azendale
  • 11,891
  • Thanks for this - I've got another one coming up shortly, I'll give this a try. Cheers – robsoft Mar 07 '11 at 12:30
  • 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 Jan 30 '16 at 15:31
  • @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. – Azendale Jan 30 '16 at 22:29
2

Partimage

Another great cloning utility which I've used, as well. Features a terminal gui.

Derek
  • 249
2

I use ddrescue for exactly this task. It works flawlessly. Super simple.

See this thread on technibble for details

Zanna
  • 70,465
  • 1
    Link rot is why this answer should at least include some of the details. Like, how to install it and start it running, at the very least. – SDsolar Jul 03 '17 at 02:36
1

G4L

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.

hhlp
  • 42,002
  • OMG. This is precisely what I have wanted for ages. Even for Windows. TNX for the post. I'll check it out right away. – SDsolar Jul 03 '17 at 02:38
1

Fsarchiver

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/sda1 you use a command like this

fsarchiver -A -j 2 -z 1 savefs /media/anwar/USB_Drive/myrootpartition /dev/sda1

The -A option allows you to copy partition even if it is used! Great feature!

-j 2 says to use 2 CPU core for compression. Useful for multi-cored CPU and if you use compression

-z 1 sets the compression level.

To restore the file system you used

fsarchiver restfs /data/myrootpartition.fsa id=0,dest=/dev/sda2

The id=0 says 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/sda2 sets the destination of the restoring.

Anwar
  • 76,649
0

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 /mnt/etc/fstab).

Shut down the swap:

sudo swapoff -a

Create a new swap using the original UUID, copyied from /mnt/etc/fstab:

sudo mkswap /dev/sda2 -U original-UUID

(I supose your swap is in /dev/sda2)

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/hostname and /etc/hosts to change the hostname for each machine in order to avoid network conflicts.

muru
  • 197,895
  • 55
  • 485
  • 740
-1

Having never done been in this predicament (I don't have hundreds of servers - I've always just used base images), I can only give you my gut instinct.

That aside, I would say netboot is probably your best bet. Create a master server, get it doing what you want and then have all your other machines boot and install from it. Scripting things to happen automatically (ala run-once) shouldn't be too hard. You do all the secondary things through kickstart.

More (although it's a little old): https://help.ubuntu.com/community/PXEInstallServer

Edit: There's an application called system-config-kickstart that should help make generating the kickstart file quite a bit easier. YMMV.

alt text

Oli
  • 293,335
-1

Another option for mass-installs is the Ubuntu Landscape/private cloud approach where you (basically) provision servers dynamically based on a pool of hardware. Clever stuff.

Oli
  • 293,335