New Computer, Old OS: How To Migrate Linux Between Machines

Ads by Google

linux move between desktopsTechnology 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.

Ads by Google

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!

Ads by Google
Comments (33)
  • Bruce Barnes

    I think the simplest way to copy the contents from one hard drive to another is to use a standalone hard drive duplicator. I used one in my last job to upgrade users to Windows 7 from XP and I also used it to upgrade my netbook to a hybrid drive which really sped it up.

    A hard drive duplicator might cost less than you think, typically $45 to $65. The one I used was make by StarTech and it couldn’t have been simpler to use. Put both the old and new hard drive in it and set it for copy and push the start button. It took maybe 45 minutes to an hour and it copied everything including the factory restore partition. Works with Win, Mac, and Linux.

  • Prasanth Mathialagan

    Useful information!!!

  • Jacob

    What I like most about Linux is the transparency of the system. There is no attempt to make you buy anything.
    If you want to adjust the settings or even re-write the entire operating system from scratch and use the existing one as a template, there is nothing wrong with that.

    The distributions nowadays are getting more and more user-friendly so even people who have no experience with command lines can use them.

    I have had experience transferring files like this. I have used most of them methods described in this article (except for the command line parts). The debian command for the list of packages would have been helpful!

    But it’s a very nice article! Well done!

  • Paul Girardin

    Thanks for sharing these tricks, I plan to build a new tower later this year and was wondering how to transfer my Linux on it!

    Your article will help ease the process!

    Thank you again!

  • Anomaly

    I use two cloning programs for this very thing as well as making backups.

    Clonezilla and ReDo Backup will clone your HDD and restore it to another HDD. I also use these two programs to make clones of my drives that dual boot Linux and Windows. These are by far the best and easiest to use cloning programs. No command line work needed.

    • Danny Stieben

      Great tips! Thank you! There’s always an untold alternative way to complete a task. :)

    • dragonmouth

      One small problem with cloning is that the HDs have to be the same size.

    • Anomaly

      No they don’t. The new HDD just has to the same size or bigger so you will only run into problems if the new HDD is smaller than the older one. That won’t happen too often really, you usually upgrade to a bigger drive.

Load 10 more
Affiliate Disclamer

This review may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.
Affiliate Disclamer

This review may contain affiliate links, which pays us a small compensation if you do decide to make a purchase based on our recommendation. Our judgement is in no way biased, and our recommendations are always based on the merits of the items.

For more details, please read our disclosure.