Clone Your Ubuntu installation
Posted by Admin on January 3rd, 2007
Ubuntu uses the APT package management system which handles installed packages and their dependencies. If we can get a list of currently installed packages you can very easily duplicate exactly what you have installed now on your new machine. Below is a command you can use to export a list of your installed packages.
sudo dpkg --get-selections | grep '[[:space:]]install$='| awk '{print $1}' > installedpackages
Now you should end up with a file called “installedpackages” which consists of a long list of every package your currently have installed.
The next step would be to tell the clone machine to install each of those packages. You’ll have to copy that file to the clone machine (via network, usb drive, email, etc) and also make sure to duplicate the /etc/apt/sources.list file. Without the same access to repositories it may not be able to find the packages.
To tell your system to use the previously exported package list use the following command (after making sure to also clone your /etc/apt/sources.list file)
Update the source list using the following command
sudo aptitude update
Import the package list using the following command
cat installedpackages | xargs sudo aptitude install

January 4th, 2007 at 9:09 am
Not an expert with regular expressions but found that grep ‘[[:space:]]install$=’ worked when the ‘=’ was removed.
Very useful article though
Thanks
January 5th, 2007 at 10:11 am
What about using a more simple approach?
sudo dpkg –get-selections > packages.txt
Copy packages.txt to the remote machine and do:
sudo dpkg –set-selections
January 9th, 2007 at 10:28 pm
(QUOTE)
What about using a more simple approach?
sudo dpkg –get-selections > packages.txt
Copy packages.txt to the remote machine and do:
sudo dpkg –set-selections
(/QUOTE)
It took me a while to find the answer to this but the last step of this process is:
sudo apt-get dselect-upgrade
-GZ
February 5th, 2007 at 8:05 am
I don’t know why but this, from above, did not work for me:
sudo dpkg –get-selections | grep ‘[[:space:]]install$=’| awk ‘{print $1}’ > installedpackages
However, this worked great:
sudo dpkg –get-selections | perl -e ‘@lines = ;foreach(@lines){ $_ =~ m/(^[a-z,A-Z,0-9,-_]+)\s+.*/;print “$1\n”;}’ > installedpackages
April 3rd, 2007 at 2:45 pm
Sound easy to me. Thx you fpr sharing this. I’ll give it a try.
polarizers 2 cents
May 12th, 2007 at 9:14 pm
I use the scripts and have some troubles, but the idea is great to clonning ubuntu instalations. So, i use this scripts as root user and work fine:
Extract the packages:
dpkg –get-selections | grep install | awk -F” ” ‘{print $1}’ > pkg_files
To install:
cat pkg_files | xargs apt-get install -y
regards,
May 14th, 2007 at 2:31 pm
Hi,
that sounds good, I was looking for something like that, but as a real basic user, I’d have two questions :
1 – what if we have uninstalled something from the vanilla ubuntu installation ? Will it get uninstalled as well with these scripts ? Or just ignored by the script and therefore left on the target system ?
2 – I see several scripts here above, in the article and the comments, all Chinese to me. I’m good only at copy-pasting, is there one that you gurus agree is better than the others ? (as in, more robust ?)
many thanks in advance, cheers
May 25th, 2008 at 3:41 pm
sudo dpkg –get-selections > packages.txt
sudo dpkg –set-selections < packages.txt ## The less-than sign got eaten before, along with everything after it.
sudo apt-get dselect-upgrade
That system works well and is easy to use. No regexp required.
June 28th, 2009 at 11:05 am
I get errors running any of the:
dpkg –get-selections | grep install | awk -F” ” ‘{print $1}’ > pkg_fil
Ubuntu Intrepid 8.10, trying to store system before upgrade to 9.10
January 16th, 2010 at 10:17 pm
I disagree with all of these solutions.
If you do a fresh install, you need to do a fresh install of all your packages as well. Sorry, but in theory it sounds great, but in practice does not work. The list is so long that you don’t know what your installing, and the config files will all be new as well. Sorry, but in my opinion, there is no easy way to re-install all the software from an old system to a fresh new install. You would spend much less time just doing it all over again. Keep a simple text list of programs that you really need and go from there. Even then, things will change. Change is the only thing you can count on…
June 17th, 2010 at 10:58 pm
@RickBragg.
I think the dpkg method is effectively a fresh install over the new system of a list of (presumably kept up to date) packages. The list is only a list of each package to install, not the code.
However on the config side, you are correct I think. Without some way of collecting (from no well defined place) all the config files anyone using this will be lost.
@ALL
BUT… for ubuntu there is ‘remastersys’ you can create a snapshot of a working install onto a live DVD. I think (though I’ve not tried it) it also allows you to select install to disk, effectively cloning your system.
http://www.geekconnection.org/remastersys/