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):

  1. sudo aptitude update
  2. 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.

If this site has been useful, please consider participating in the Fundraiser.

Other Points of Interest

  • No Related Post

Comments

18 Responses to “How to clone an installation : Ubuntu (5.10 / 6.06.1 / 6.10)”

  1. Stefan on December 5th, 2006 11:21 am

    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.

  2. Ubuntu Tutorials on December 5th, 2006 11:31 am

    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.

  3. Miguel Guhlin on December 5th, 2006 8:32 pm

    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,

  4. Ubuntu Tutorials on December 5th, 2006 8:51 pm

    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!

  5. mark g on December 5th, 2006 11:58 pm

    here is the nice sbackup tutorial with nice screenshots http://www.debianadmin.com/backup-and-restore-your-ubuntu-system-using-sbackup.html

  6. mark on December 6th, 2006 12:00 am

    why don’t you use aptoncd for this it will be very simple one to clone all your packages

  7. roger on December 7th, 2006 11:06 am

    this tip is copied from ubuntu hacks book

  8. Ubuntu Tutorials on December 7th, 2006 11:14 am

    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.

  9. fast_rizwaan on December 9th, 2006 4:05 pm

    dpkg –get-selections | grep ‘[[:space:]]install’ | awk ‘{print $1}’ > package_list2

  10. fast_rizwaan on December 9th, 2006 4:06 pm

    "dpkg --get-selections | grep '[[:space:]]install’ | awk ‘{print $1}’ > package_list2″

  11. Aaron Toponce on December 20th, 2006 9:02 am

    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?

  12. Abhinay on January 6th, 2007 7:32 am

    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

  13. Ben_K on February 17th, 2007 2:31 pm

    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?

  14. brian baggett dot com » on March 13th, 2007 6:50 pm

    [...] How to clone your Ubuntu installation - Every Ubuntu (or other Debian derivative) user should use this. Good for rebuilding your PC from scratch if you stick to using packages from repositories. Also back up your sources.list. [...]

  15. atif on April 25th, 2007 12:13 am

    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

  16. Mike on April 6th, 2008 3:06 pm

    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.

  17. udienz on June 19th, 2008 8:48 am

    awesome article… but i use different method
    $ sudo dpkg –get-selections | grep ‘install$=’ | awk ‘{print $1}’ > package_list

  18. Luis Casamayou on July 4th, 2008 7:41 am

    I find a simpler method

    sudo dpkg –get-seleccions > ubuntuSel.txt

    In te nuw system:
    sudo dpkg –get-selections < ubuntuSel.txt
    sudo aptitude install

Leave a Comment




    Subscribe to the RSS feed!


    subscribe to the ubuntu tutorials RSS feed

    Ubuntu Tutorials Fundraiser


    Please Donate to
    Server Improvement

    Target amount: USD1,000.00
    Total Donations: USD255.00
    Amount Needed: USD745.00

    Thank you for your support!

    Click to Donate

    Polls



  • Blogroll

  • Ads by Google