Clone Your Ubuntu installation
Posted by Admin on January 3rd, 2007
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
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