How many times have you reinstalled your machine? I know I long ago lost count. It isn’t that it is unreliable but, in my case, I often upgrade to new versions or reinstall to test things out. How nice would it be if you could clone your current installation and fairly easily reinstall to just about the same stage you were before you changed? This post will tell you how!
The first thing to remember is that 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 a future 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}' > package_list
update: (see comments) – the blog reformats the single-quotes around the parameters for grep & awk. Note that both should be the character on the quote key. Also, the “–get-selections” is a double-dash, although it doesn’t appear as such.
At this point you should end up with a file called “package_list” 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):
sudo aptitude update
cat package_list | xargs sudo aptitude install
Note: this should only be used between the same distribution and the same release version. Example, only use this to clone a 6.06.1 to 6.06.1 machine. You will run into problems in trying to clone from 6.06.1 to 6.10 or similar.
Awesome tip!
However, copy-pasting you code doesn’t work for two reasons:
1) get-selections should have 2 leading dashes, not one.
2) The params for grep and awk should be enclosed in single quotes.
I guess your text editor automatically put open quote and close quote – two different symbols.
Stefan,
Thanks for the notice. I do see that the blog reformats the single quote. I’ll update the post to make notice of that.
Howdy! Thank you for sharing this tip. On my blog, I was trying to show how to backup an entire hard drive, partitions and all. Unfortunately, the process didn’t work for me…I ran out of disk space at around 311 megs even though dealing with a 120gig hard drive.
Any suggestions for using dd to backup an entire hard drive? Or a better solution?
Thanks,
I in fact do have some other tips on backups 🙂
Check out the ‘sbackup’ package which stands for Simple Backup. The backup config has some really good default settings & the backup restore is really easy to use!
here is the nice sbackup tutorial with nice screenshots http://www.debianadmin.com/backup-and-restore-your-ubuntu-system-using-sbackup.html
why don’t you use aptoncd for this it will be very simple one to clone all your packages
this tip is copied from ubuntu hacks book
many of these tutorials are based on other resources–I don’t claim to have invented them. I just aim to create a central place to find easy to follow tutorials.
dpkg –get-selections | grep ‘[[:space:]]install’ | awk ‘{print $1}’ > package_list2
"dpkg --get-selections | grep '[[:space:]]install' | awk '{print $1}' > package_list2"
Roger-
And what’s your point? Making information available to millions, strengthening the community and providing resources to others that may not otherwise have them available.
I’ve asked this before, and I’ll ask it again: what are YOU doing to help the Ubuntu community?
It is a Very useful command. Thanks for your tutorial.
I have doubt,
” sudo dpkg –get-selections | awk ‘{print $1}’ ” and ” sudo dpkg –get-selections | grep ‘[[:space:]]install$’| awk ‘{print $1}’ ” does the same. then Why to use grep ?
Thank you
OK. This copies off the packages, but what about the customized configuration files? Do we just try to clone /etc, and hope that gets everything, or is there a more sophisticated way to do it?
Pingback: brian baggett dot com »
hello,i am the new user of ubuntu linux i have installed this but yet it is not being started.bcoz it ask for commands and i dont know about these commands. i installed the breezy
Hi UT,
Great tutorial, thanks–but I can’t get it to run. I ran:
sudo dpkg –get-selections | grep ‘[[:space:]]install$=’ \| awk ‘{print $1}’ > package_list grep: |:
with the correct dashes & quotation marks as noted, but the output was:
No such file or directory
grep: awk: No such file or directory
grep: {print $1}: No such file or directory
Am I missing something?
Also, since Sbackup is mentioned in the comments, I’ve been trying it. It behaves exactly as the tutorial describes except that it doesn’t back up–does nothing in fact.
I’m running Ubuntu 6.06.2, kernel 2.6.15-51-686 on a 2.80GHz Pentium 4 CPU.
Thanks in advance for any suggestions.
awesome article… but i use different method
$ sudo dpkg –get-selections | grep ‘install$=’ | awk ‘{print $1}’ > package_list
I find a simpler method
sudo dpkg –get-seleccions > ubuntuSel.txt
In te nuw system:
sudo dpkg –get-selections < ubuntuSel.txt
sudo aptitude install
Will this work going between 64bit 9.04 and 32bit 9.04?