Debian Admin

Debian/Ubuntu Linux System Administration Tutorials,Howtos,Tips

  • RSS Subscribe

    subscribe to the Debian Admin RSS feed
  • Sponsors



  • Categories

  • Sponsors

  • Support DebianAdmin

    Amount $:
    Website(Optional):


  • Meta

  • Archives



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!

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

  • Share/Bookmark

9 Responses to “Clone Your Ubuntu installation”

  1. Sam Says:

    Not an expert with regular expressions but found that grep ‘[[:space:]]install$=’ worked when the ‘=’ was removed.

    Very useful article though

    Thanks

  2. Excds Says:

    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

  3. GermanyZulu Says:

    (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

  4. Chuck Tellechea Says:

    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

  5. polarizer Says:

    Sound easy to me. Thx you fpr sharing this. I’ll give it a try.

    polarizers 2 cents

  6. Luis Morales Says:

    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,

  7. Nimo Says:

    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

  8. Daeng Bo Says:

    sudo dpkg –get-selections > packages.txt
    sudo dpkg –set-selections &lt 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.

  9. Erik Vandamme Says:

    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

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>