I am going to change my machine: from a laptop with Ubuntu to another laptop where I am going to install Ubuntu...

I am quite happy with the current system, what I am afraid of is having to rebuild everything from 0.

So what do people often do to clone an Ubuntu system? That may include the data, packages, shortcut settings, etc...

link|improve this question

71% accept rate
1  
Can't you simply extract the HDD from your old laptop and install it on your new laptop? I changed MB, MicroProcessor, RAM and HDD's, just conserving the boot HDD and expected a major issue after the boot, which didn't happen. This may not be really fancy but it works like a charm. – Geppettvs D'Constanzo Sep 20 '11 at 22:53
Or just create a clone of your system with remastersys, UCK, Customizer... – Uri Herrera Sep 20 '11 at 22:59
5  
I did this several times: Plug in the old laptop drive into the new laptop with an USB-to-SATA converter, boot the new laptop from Ubuntu live CD, wipe the new drive with gparted, copy the entire disk from old to new, resize partition, boot, have some biscuit, reconfigure X11. Won't possibly ever happen that easy with Windows! – aquaherd Sep 20 '11 at 23:11
feedback

2 Answers

up vote 3 down vote accepted

There are a few ways to copy your config and set up. It depends on how big the changes you have made. And if you are upgrading to a new version. Some of the methods are useful when upgrading between versions but be careful as they can stop some software form working correctly.

method 1: Fresh install

The most robust and stable way is a fresh install and then copy the config and re-install all your packages. This also work from an old version to a new version. There are ways to make this happen quite quickly, and automate most of the process. The slowest part would be having to download all the packages not included in your install media. I had the 8 dvd disk images that allowed me to install much faster then downloading.

I would recommend this option as setting up and install grub, can render your system unusable. You need to have a solid grasp of grub to use method 2.

Before you do your new install (new laptop) you need to copy some information off your old install (old laptop).

Your setup or configuration

All the files that save your customization are stored in two places. The first and most import is your /home/[username] directory. There can be hundreds of .[package-config-dir] files and directories. I am going to list the most important but you can have more and add more if you want. This process can cause problems with packages not working correctly. So be careful when you do this. Make a back up of you fresh install before you paste your new directories.

These directories and files are not very large, and will probably only take a few hundred megabytes. This method is also useful between upgrades. You can quite quickly copy all the configuration changes you made between Ubuntu versions.

By default most programs create the .[package-config-dir] when they run the first time. If it does not exist it is recreated. You should not rely on this behavior as not all programs will work like this.

Using Nautilus

Navigate to your home directory /home/[username]
View > Show Hidden Files # ctrl+h

You should now see all the hidden .* directories. You might need to do this as root. simply start nautilus as root from a command line.

Select the following directories and copy them to a separate directory. /home/aaron/.config
/home/aaron/.gconf
/home/aaron/.gnome2
/home/aaron/.gnome2_private
/home/aaron/.local
/home/aaron/.mozilla

I have made changes to these files. So I copy them as well.

/home/aaron/.bash_aliases /home/aaron/.bashrc /home/aaron/.vimrc

There may be many other packages that you use that don't store the configuration in these directories. Copy them as well, but be warned if the programs don't work as expected. You might need to restore the .* file or directory. You could do this buy simply deleting the file or directory, but you should have made a back up before copying over the directories.

Depending on how you use your system. You might have made changes to some of the files in the /etc directory. If you have you should copy them as well. I create a custom smb.conf file for work and I have many Apache virtual hosts I use for development so I copy them as well. You could copy your whole /etc directory but this can create problems if you machine does not have exactly the same set up in terms of hardware. Which it wont going form one machine to an other.

/etc/samba/smb.conf /etc/hosts /etc/apache2 # the whole directory.

Copy your config files before or after you install new software. Don't do this while an software package install is currently running. You could break the installation.

Your installed packages

Using synaptic you can export all your installed packages quite easily using the export markings menu option.

File > save markings as
check the "Save full state, not only changes"
choose a name and directory to save this file.

You can then reload all your installed packages by reversing the process

File > read markings
select the file you created in the first step.
# you probably will have to put this on a flash drive.

This will probably take the longest. If you are download alot of packages like 1Gb of packages, this will take a few hours.

method 2: Using disk images

I will past method 2 as a separate post. This is a more advanced option. It requires you understand partition, install grub, and using the command line.

How to copy an Ubuntu install from one laptop to another

link|improve this answer
feedback

There are a few ways to copy your config and set up. It depends on how big the changes you have made. And if you are upgrading to a new version. Some of the methods are useful when upgrading between versions but be careful as they can stop some software form working correctly.

method 1: Fresh install

Posted separately. How to copy an Ubuntu install from one laptop to another

This is the safest method, and does not require you to edit your grub and boot set up. Easy as most of it can be done using a gui tools.

method 2: Using disk images

This can be fastest way to move is to copy your hard drive partitions as disk images. If you don't want to re-install every piece of software. Though creating, re-sizing and moving the disk images can take quite a long time. I would only recommend this if you are not going to upgrade to a new version of Ubuntu. Make sure you understand disk partitions and grub. Most of what I am doing will use the command line. You need to make sure you understand what a command does before you run it. I am not responsible for data lost as a result of the instructions that follow.

Step one create a disk image of your installation.

Fist we need to get some information about the set up. using parted -l and mount

$ sudo parted -l
Model: ATA ST9320423AS (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system     Flags
 1      32.3kB  197MB   197MB   primary   ext4            boot
 2      197MB   10.2GB  10.0GB  primary   linux-swap(v1)
 3      10.2GB  50.2GB  40.0GB  primary   ext4
 4      50.2GB  299GB   249GB   extended
 5      50.2GB  54.4GB  4195MB  logical   ext4
 6      54.4GB  65.9GB  11.5GB  logical   ext4
 7      65.9GB  299GB   233GB   logical   ext4

$ mount
/dev/sda5 on / type ext4 (rw,errors=remount-ro)
/dev/sda7 on /home type ext4 (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda6 on /usr type ext4 (rw)
# I took out the entries that were not need for these instructions

$ cat /etc/fstab 
proc            /proc           proc    nodev,noexec,nosuid 0       0
UUID=ddc8c237-e8ac-4038-a0ed-f7c866d6603b /               ext4    errors=remount-ro 0    1
UUID=aa9881d1-5cc1-4e94-8cd7-8125e18ece2f /boot           ext4    defaults        0      2
UUID=31a6fde1-6b96-4cc3-acfd-88573f52be36 /home           ext4    defaults        0      2
UUID=073146a7-5668-4728-9a6f-1a599f358a8d /usr            ext4    defaults        0      2
UUID=540b96b6-b3c3-4092-b4ad-6b33bcbbe16d none            swap    sw              0      0

Your set up might look different. I have separate partition for /home, root (/), and /usr.

creating the disk images I use dd as it is simple and quick. Make sure you read and understand how it works. You will need an empty partition that is bigger then the entire partition size that you are copying. This can take quite some time. Creating resizing and copying the partitions can take a few hours depending on their size. You will need replace the exteranldrive with a part to the storage media you will use for this process.

$ dd if=/dev/sda5 of=/media/exteranldrive/sda5-root.img
$ dd if=/dev/sda7 of=/media/exteranldrive/sda7-home.img
$ dd if=/dev/sda6 of=/media/exteranldrive/sda6-usr.img

Here is an actuall example of out after running this on my set up.

$ dd if=/dev/sda5 of=/media/home0/sda5-root.img
8193087+0 records in
8193087+0 records out
4194860544 bytes (4.2 GB) copied, 55.3159 s, 75.8 MB/s

We can reduce the sise of this disk iamge, using the tools provided buy Linux.

$ resize2fs -P sda5-root.img
resize2fs 1.41.11 (14-Mar-2010)
Estimated minimum size of the filesystem: 605972
$ ls -sh ./sda5-root.img
4.0G ./sda5-root.img
$ resize2fs -M sda5-root.img
resize2fs 1.41.11 (14-Mar-2010)
Please run 'e2fsck -f sda5-root.img' first.
$ e2fsck -fy ./sda5-root.img # y makes sure run with out asking thousands of questions.

e2fsck will output lots of errors or fixes necessarily. This is because the information in the file system is not longer correct in terms of where the partition boundaries start and end are. This is correct because it is no longer in a partition.

$ resize2fs -M sda5-root.img
resize2fs 1.41.11 (14-Mar-2010)
Resizing the filesystem on sda5-root.img to 605505 (4k) blocks.
Resizing the filesystem on sda5-root.img to 605505 (4k) blocks.
The filesystem on sda5-root.img is now 605505 blocks long.
$ ls -sh ./sda5-root.img
2.4G ./sda5-root.img

That is a two big difference in size once re-sized. Much quicker to copy. It essentially removes all the free space in the partition. So for the larger partition this can be more the 50% of the disk size.

You will boot up your new laptop with a live disk and do what follows here. You can now copy these disk images into the partitions on the new computer. You should have set up these partitions all ready. Using the live disk and geparted is a quick and easy way to do this. Make sure you have every thing your system requires, like a swap partition if you want. You can make these partition larger then the ones you had on your previous system. When we copy the disk images into them We will resize the file system and it will take up all the free space in the partition.

Now step two copying the disk images on to the new drive and into the new partitions.

dd if=/media/exteranldrive/sda5-root.img of=/dev/sda3 # replace the [sda3] with your partition.

On my machine this is what the output looked like

dd if=./sda5-root.img of=/dev/sdb6 4844040+0 records in
4844040+0 records out
2480148480 bytes (2.5 GB) copied, 87.4921 s, 28.3 MB/s $ fsck.ext4 -fy /dev/sdb6
e2fsck 1.41.11 (14-Mar-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
root1: 50470/504000 files (1.4% non-contiguous), 616736/2060328 blocks

Now we need to edit the fstab file to point to the correct devices. If you have just copied the how disk partition on to your new disk. The fstab file is on that partition so you need to mount it in order to access the file. You will also need to have the root partition mounted in order to install grub if you don't have a separate boot partition.

$ sudo mkdir /mnt/tmp mount /dev/sdb6 /mnt/tmp $ blkid # to see what the disk uuid is /dev/sda5: LABEL="root1" UUID="ddc8c237-e8ac-4038-a0ed-f7c866d6603b" TYPE="ext4" /dev/sdb6: LABEL="root1" UUID="ddc8c237-e8ac-4038-a0ed-f7c866d6603b" TYPE="ext4" $ gedit /mnt/tmp/etc/fstab replace the UUID with the UUID of your partition UUID=ddc8c237-e8ac-4038-a0ed-f7c866d6603b / ext4 errors=remount-ro 0 1

Here you can see that the new disk image that I copied across to the other disk has the same UUID as the the original file system. So you could copy your fstab file form your old install across into your new install and have a working system. That will boot. On my set up I can't leave my computer like this it will boot to which ever device it finds first. But it won't be a problem if you hard drives are on different computers.

Edit fstab and make sure the uuid match the partitions that you have set up for root and home and what ever other partition set up you have.

Last step is to install grub on you new disk.

$ chroot /mnt/tmp # your root partition. $ grub-install /dev/XXX In my case $ grub-install /dev/sdb $ grub-update Please read these instructions before beginning. It is no use having all the data on your new laptop and not being able to boot it up.
https://help.ubuntu.com/community/Grub2
https://help.ubuntu.com/community/RecoveringUbuntuAfterInstallingWindows

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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