Sponsored Link
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
I kind of prefer this instead:
dpkg –get-selections > mypackages.txt
sudo dpkg –set-selections
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
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
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?
This just saves a list, so you’d need internet.
I am not sure but i think you could get the deb packages.
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 (\
A had to include a -y switch on the second command to get it to work:
cat installedpackages | xargs sudo aptitude install -y
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.
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.
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.
Thanks Nelson. worked like a charm.
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`
Rjack, your thought was incomplete…
dpkg --get-selections | awk '$2 ~ /^install$/ {print $1}'
#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.
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
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?
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
how to clone ubuntu from PC to laptop ??
” 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!
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
thanks guys, am trying this but get the following error
awk: 1: unexpected character 0xe2
what might I be doing wrong ???
Thanks
Jim
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.
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).
Sami’s suggestion above worked flawlessly for me.
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
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.
me too, I had to remove the equal sign.
It works and its helpful. Thanks for the information!