December 31, 2006 · Backup · Email This Post

Sponsored Link
If you want to create a system that is similar to a different system you have already set up, it can be difficult to remember each and every package you had installed.This method works best when you are exporting to and importing from the same distribution and, specifically, the same releasefor example, exporting from Ubuntu Dapper to Ubuntu Dapper or ubuntu edgy to ubuntu edgy.

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

Incoming search terms:

Related posts

27 Comments to “Clone Your Ubuntu installation”

  1. I kind of prefer this instead:

    dpkg –get-selections > mypackages.txt
    sudo dpkg –set-selections

    [Reply]

  2. The rest of that got left out.. Lets try it again:

    dpkg –get-selections > mypackages.txt
    sudo dpkg –set-selections < mypackages.txt
    sudo apt-get dselect-upgrade

    [Reply]

  3. Øyvind Lein says:

    Your little snippet didn’t work for me, unless I removed the “equals”-sign.

    ….install$
    =instead of this:=
    ….install$=

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

    [Reply]

  4. Robert Crowe says:

    Does this copy the packages or just makes a list for apt to go off of. I have a desktop with no way to access a network and a laptop with wireless and obvious mobility advantages. Is it possible to clone my installed packages off my laptop onto desktop with this method?

    [Reply]

  5. Andy says:

    This just saves a list, so you’d need internet.
    I am not sure but i think you could get the deb packages.

    [Reply]

  6. rjack says:

    A simpler command can be

    dpkg --get-selections | awk '/\

    Sudo is not needed when you generate the list, nor grep. Awk prints the first field of every line that contains the word "install" on its own (\

    [Reply]

  7. Trevor says:

    A had to include a -y switch on the second command to get it to work:
    cat installedpackages | xargs sudo aptitude install -y

    [Reply]

  8. JohnnyColonic says:

    If you replace the install command with this:

    xargs -a installedpackages sudo aptitude install

    you won’t have to jimmy it past the abort with the -y option.

    [Reply]

  9. braddcadd says:

    Can I do this and copy my home directory to the new computer? I am trying to get data, configurations, and everything. I can’t use partimage or anything else because I have a single broken package that has killed dpkg.

    [Reply]

  10. Nelson says:

    If you want to export your applications to a pc without access to the internet, Just make an apt on cd.

    In the first pc (the one with internet) type:
    sudo apt-get install aptoncd

    then run the program, burn a cd with the apt and remember to configure the other pc to read repositories from the cd instead of the net.

    [Reply]

  11. sid says:

    Thanks Nelson. worked like a charm.

    [Reply]

  12. El says:

    I saw these commands on another site.

    Remember:
    dpkg -l | grep ii | awk ‘print $2′ > remember_these_debs.txt

    Reinstall:
    sudo apt-get install `cat remember_these_debs.txt`

    [Reply]

  13. El says:

    Rjack, your thought was incomplete…

    dpkg --get-selections | awk '$2 ~ /^install$/ {print $1}'

    [Reply]

  14. szandor says:

    #mondoarchive -Oi -9 -p m1330-image -d /storage/mondo/ISO -S /storage/mondo -E “/storage” -s 4300m

    this saves your entire hard drive (lvm supported) to a dvd as a bootable iso image. just use k3b or whatever to burn it. just make sure you create /storage/mondo/ISO and that you grab the 2.2.6 version of mondo and mindi from mondo rescue, not the repos. now you have a bootable dvd. i do this for all my laptops when i want to get crazy so i can just reimage my laptop rather than undoing all my changes.

    [Reply]

  15. pete says:

    This is a handy first step in cloning a system.
    Don’t forget, you’ll still have to copy across users/passwords, hosts, users profiles, their home directories, email, log files, any and all config data your packages may need and probably a ton of other stuff I’ve forgotten.
    This is far from a one-line machine cloning solution

    [Reply]

  16. Jacob Lorensen says:

    Does this also work between 32bit and 64bit versions of the same system? I.e. get the list off of a 64bit ubuntu and install the same packages (in 32 bit versions) on a 32bit ubuntu or vice versa?

    [Reply]

  17. jb says:

    It works for me:

    to obtain the list:
    dpkg –get-selections | awk ‘$2 ~ /^install$/ {print $1}’ > installedpackages

    to reinstall:
    cat installedpackages | xargs sudo aptitude install -y

    cheers

    [Reply]

  18. mazhel says:

    how to clone ubuntu from PC to laptop ??

    [Reply]

  19. w0lv3n says:

    ” Nelson says:
    July 28, 2007 at 9:19 pm

    If you want to export your applications to a pc without access to the internet, Just make an apt on cd.

    In the first pc (the one with internet) type:
    sudo apt-get install aptoncd”

    Simply Genius!
    Just what I was looking for, Thankyou!

    [Reply]

  20. Allan says:

    Same here… Perfect solution!

    to obtain the list:
    dpkg –get-selections | awk ‘$2 ~ /^install$/ {print $1}’ > installedpackages

    to reinstall:
    cat installedpackages | xargs sudo aptitude install -y

    [Reply]

  21. Jim says:

    thanks guys, am trying this but get the following error
    awk: 1: unexpected character 0xe2

    what might I be doing wrong ???

    Thanks

    Jim

    [Reply]

  22. Jacob says:

    A suggestion… You probably get the quotes wrong? Allan’s example (as it has ended up on the web page) does not use the right quotes. After awk, it must be a single quote, and just before the > must be single quote.

    [Reply]

  23. Eddie says:

    Sami Haahtinen’s method worked for me, and is also the simplest in my opinion. (Saves and restores package names only, not data or actual packages).

    [Reply]

  24. Sami’s suggestion above worked flawlessly for me.

    [Reply]

  25. Yogendra says:

    Hello Sir/Madam,

    Can you please let me know, How to Install “CloneZilla Live” from Internet in “Ubuntu”

    and second question is please let me know, after installation, how to copy and recover data from Hard drive to Hard drive in Ubuntu

    please tell me everything step by step so i have installed clonezilla and back up and recover data my self

    Please

    [Reply]

  26. shekhar says:

    Hello Admin,
    I am running the command in Ubuntu 12.10

    dpkg –get-selections | awk ‘$2 ~ /^install$/ {print $1}’ > installedpackages

    following error comes ->

    awk: 1: unexpected character 0xe2

    and command does not work

    and when I run the command
    sudo dpkg –get-selections | grep ‘[[:space:]]install$=’| awk ‘{print $1}’ > installedpackages

    blank file named “installedpackages” is created.

    [Reply]

  27. Kalegs says:

    me too, I had to remove the equal sign.

    [Reply]

Leave a Reply