Technology is progressing forward at a pretty fast rate, so much so that it isn't uncommon for you to find yourself buying a new computer or computer part. For example, you may want to buy a brand new laptop or replace a dying hard drive that your system is currently using. In cases like these, it would be great if you can simply move your operating system over to the new hard drive or system with as little fuss as possible.

While this may be a challenge if you're using Windows, especially when it comes to the necessity of reactivating your copy, this is done a lot more easily if you're running Linux. In fact, you even have a choice of a number of different ways, but I'm only going to recommend the ones that I find to be the easiest.

Fresh Install

The most common way for you to move your Linux installation over to a new hard drive is to simply reinstall Linux on the new system and copy over all of your files. Although this is the most common way of moving your system and files, I'd actually only recommend this if you cannot connect the two hard drives together to the same machine, no matter if you're moving to a new hard drive or a new system. While backing up your files, you should look in the /home, /etc, /opt, /root, and /var folders for anything that you may want to keep. Desktop users may want to primarily look in the /home folder as that is where all your personal files are located, while server users should primarily check through /etc and /var for configuration files and hosted data.

Keep A List Of Installed Packages

linux move between desktops

Debian-based distributions have an easy way to list all installed packages on your system and write that list into a simple text file. This list can then be used on your new Linux installation to mark all packages that need to be installed again. To create the list, you'll need to run the command

        sudo dpkg --get-selections > /home/[your user name]/packagelist.txt
    

, while replacing [your user name] with the appropriate entry. To mark packages for reinstallation on the new system, copy the text file over to that system and run the command

        sudo dpkg --set-selections < /home/[your user name]/packagelist.txt
    

.

This will mark all packages that you want back, but it won't actually install them until you run the command

        sudo apt-get -u dselect-upgrade
    

. This should install all packages from the official repos which you had on your old system, so a lot of familiar Linux software should reappear after some time to download and install. Don't forget to also restore your backed up data to the appropriate folders, and ta-da! Your system should now be back to the way it was!

Copying Your Partitions

linux move between desktops

If you are able to connect the old and new hard drives (or the hard drive of the old system and the hard drive of the new system) to the same machine, you can easily copy the entire Linux partition(s) over to the new hard drive. This method will make it a lot easier to keep your Linux environment the way it is because you won't have to freshly install the distribution and all needed packages. Besides having the two hard drives connected to the same machine in some fashion in which the computer recognizes them both, you'll also need to have a DVD or USB drive which has the distribution live environment on it.

As an example, a burned or written copy of the Ubuntu ISO will do just fine -- just remember to keep it the same as what you already have installed, including whether it's 32-bit or 64-bit. Once you have the live environment from the DVD/USB running, you can open Gparted and simply copy the partition(s) you want to keep over to the new hard drive by "copying and pasting" it in the interface. When copying over to a larger drive, resizing after the move is possible, while when copying to a smaller drive, you must resize the partition before moving it. Once the partition(s) are copied over to the new hard drive to the point of satisfaction, you will need to run a few commands in order to install the correct bootloader onto the new hard drive. To get the GRUB bootloader in working order on the new hard drive, run:

        sudo mount /dev/sdX# /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo cp /etc/resolv.conf /mnt/etc/resolv.conf
sudo chroot /mnt
grub-install /dev/sdX

You'll need to replace all instances of "X" in those commands for the new hard drive, and replace all instances of "#" for the partition number of the root Linux partition. All of this information can found via the Disks application as found from the Dash. Now go ahead and move the new hard drive into the correct machine and boot from it to load your distribution. Once inside your running Linux instance, you'll need to run

        sudo update-grub
    

to make sure that the GRUB bootloader correctly identifies the partitions on your system, across all hard drives. This is an especially important step if you have another partition or hard drive with another operating system on it such as Windows.

Conclusion

Hopefully with these two methods, you can quickly, easily, and efficiently move over your Linux installation to a new hard drive or system. Provided you follow the instructions correctly, it should work without fail. Those with questions or those needing help can comment on this article and I'll try to assist them as best as I can.

Have you moved a Linux installation before? Do you find these instructions to be easy? Have you checked out our ultimate guide to Linux yet? Let us know in the comments!