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...
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.
/home/[username]
)Select "View menu → Show Hidden Files" (or 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.
I have made changes to these files. So I copy them as well.
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 by 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 from one machine to another.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.
You can then reload all your installed packages by reversing the process:
This will probably take the longest. If you download a lot of packages (1Gb of packages), this will take a few hours.
Method 2: Using disk images
I will make method 2 as a separate post. This is a more advanced option. It requires you understand partitions, install grub, and use the command line.
How to copy an Ubuntu install from one laptop to another
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 from 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 GUI tools.
method 2: Using disk images
This can be the fastest way to move. As to copy your hard drive partitions as disk images are quite fast. If you don't want to re-install every piece of software. Though creating, resizing 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 loss 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 setup. Using
parted -l
andmount
Your set up might look different. I have a 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 than 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 to replace the external drive with a part to the storage media you will use for this process.Here is an actual example of out put after running this on my set up.
We can reduce the size of this disk image, using the tools provided by Linux.
e2fsck
will output lots of errors or fixes necessarily. This is because the information in the file system is no longer correct in terms of where the partition boundaries start and end. This is correct because it is no longer in the partition it was configured for.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. Much quicker to copy a smaller file
You now need to boot up your new laptop with a live disk and do what follows here. You need to use a live disk as you can not make changes to a running partition that is currently used by the installed operating system.
You can now copy these disk images into the partitions on the new computer. You should have set up these partitions already. Using the live disk and
gparted
is a quick and easy way to do this. Make sure you have all the partitions your system requires. You can make these partitions larger than 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 on the partition.Now step two: copying the disk images on to the new drive and into the new partitions.
On my machine, this is what the output looked like
Now we need to edit the fstab file to point to the correct devices. If you have just copied the new 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.
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 or it will boot to whichever device it finds first.
Edit fstab and make sure the uuid match the partitions that you have set up for root and home and whatever other partition you set up.
Last step is to install grub on you new disk.
In my case:
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
Try clonezilla. Clonezilla is a disk imaging/clonning tool. You can use this tool to clone your Ububtu to a new system.
Clonezilla clones your settings and also your entire partitions.
There are two versions of clonezilla available. Clonezilla live is suitable for a single time use.
For further information visit this link.