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

tux big   New Computer, Old OS: How To Migrate Linux Between MachinesTechnology 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

ubuntu packages list   New Computer, Old OS: How To Migrate Linux Between Machines
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

ubuntu gparted copy partition   New Computer, Old OS: How To Migrate Linux Between Machines
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!

Check out more about:

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

33 Comments -

michel

All that command line garbage is what keeps me (and I bet lots of others) from bothering to try linux. I don’t care how easy geeks think it is. The whole point of a gui was to move away from DOS-type nonsense. It seems every time there’s a “how-to” article for linux, it involves terminal commands.

I would welcome more articles about linux but only if there’s a moratorium on the command line.

Lee

I think the command line is one of the better reasons to use Linux. If you really want a nice GUI and never want to touch the command line, I’d definitely stick to Windows, but you can do so much with the command line because of scripts. Plus, it makes it easier to install software (just type sudo apt-get install on a Debian based distro) and run things with admin privileges.

I do get your point though, some things are definitely easier with a GUI (like copying and pasting, or managing files). It’s so much easier to just drag a file from one window to another, or be able to see multiple windows of files at the same time.

Márcio Guerra

I’m a Linux noobie but I think the command line is very helpful. Well, I also miss MS-DOS, aahaha. Do you know that you still have one command, at least that I remember, in DOS that Windows cannot replicate? Renaming things… In Windows it is awful… Back in the days some * or ? would allow you to change a specific name or an entire folder… I also remember, back in the Win95 days to go to pc sellers ask for pcs without Windows, ahahaha! Well, those were the days indeed.
Now, back to this, I have Peppermint, we have a great GUI and also a command line. Win-win situation. In fact, and I’m a graphic designer, the only set back is that one… No Adobe software «native» for Linux, like Photoshop, Illustrator, InDesign, etc., and I really need those… If you’re a «plain» MS user, some LibreOffice (previously OpenOffice) is more than enough and you also have great apps to other stuff that LO doesn’t handle!

Cheers!

Danny Stieben

I understand your concerns. When I first started with Linux, I was pretty afraid of messing my system up with commands off of the Internet, especially since I didn’t really know what they did until after I had used them over 100 times.

For this specific use, it seems like commands are the way to go. I can’t tell you of any GUI which can do the same things for you. On other articles, however, I do have to say that people add commands because that’s what they’re used to, although there’s a perfectly good GUI way of completing the task. Linux has been getting better and better at that, but commands will never go away. Not entirely, at least.

Budiarno

Simple solution is “don’t use Linux if you don’t know how to, just stick on to what you know”.

Richard Steven Hack

I actually recommend the fresh install method. I keep a list of the applications I really want installed on the new system – on paper. I just go down the list in the package manager and reinstall them. It’s almost trivial – no command line needed.

Of course, with this method you have to go through and re-do all your tweaks to the desktop and the like and THAT can be a bit of a pain. especially if you forget some and get bitten by them later.

But if you really are simply moving the current OS to a new machine, it’s also trivial to just copy the various config files from the old machine over to the new machine, either directly if the old hard drive is in the new system or via an external USB or flash drive. No command line needed there either – just drag and drop the relevant directories. That should copy all the various tweaks as well.

That said, try doing any of this with Windows! You can’t even legally move your system (if it’s an OEM system) because it’s tied to the old motherboard! :-) Not that it stops anyone from doing it (illegally). :-)

Danny Stieben

I absolutely agree with the part concerning Windows. Being able to freely move the operating system without coming into some sort of trouble is an amazing feeling.

Lee

Isn’t it better to do a clean install if installing on a new machine? I’m not too familiar with how Linux handles things like hardware, but in Windows you would have a lot of crap to deal with because of all the old drivers and activation issues (which, obviously, you don’t need to worry about with Linux because it’s typically free).

dragonmouth

“in Windows you would have a lot of crap to deal with because of all the old drivers and activation issues ”

Just shows how primitive Windows is. Linux is so resilient that it will recognize all the new hardware and automatically update the config files. If it should happen to miss one or two, it is a trivial matter to update them manually.

Danny Stieben

Excluding specific packages that you install (such as those pertaining to proprietary graphics drivers), Linux is extremely robust. It won’t have any activation issues because all versions of Linux are free (well, I’m not sure how Red Hat does it, but it’s still not as complex as it is with Windows).

Hardware also isn’t an issue. All drivers can be found in the kernel or other system-level areas, and it detects which drivers it needs to load during boot time. It’s the reason why everything works out of the box in a LiveCD environment.

Moez bouhlel

realy useful

Lee

Linux handles most of the drivers and other stuff very easily. And as for the command line, it’s not like you’re typing in a large batch file. If you like computers, then the command line is not that big of a deal (and most things can be done through a GUI anyway). If you don’t really care for computers but see them as a necessary tool, Linux is still better: it [almost] never crashes, all the software is FREE, you don’t have to worry about viruses, and, as I said, most things can be done through a GUI. Someone like that wouldn’t be doing the things on the command line anyway, for the most part.

michel

yes, but what linux evangelists don’t like to hear is, Windows has a larger selection of free software (including many or most of the favorites on Linux), almost never crashes, and you don’t have to worry about viruses.

Plus, it comes pre-installed, and if you happen to be a professional, you can buy professional tools to use on it.

Call me when there’s no command line, a Native MS Office and Dragon Naturally speaking.

Lee

What? Did you get your wording mixed up? Windows does NOT have a larger selection of free hardware. And “almost never crashes”? Are you serious? It DOES crash, and quite often. In addition, there are thousands of viruses made just for Windows, whereas Linux does not have problems with viruses. (I have been running Linux now for 5+ years on several machines and it has never crashed!)

Besides, you can do everything you want on Linux without ever using the command line; there are several ways of doing things on Linux (besides, in this world, you are going to have to learn how to go beyond a GUI eventually — even in Windows — if you want to get anywhere). Dragon runs just fine on Linux using Wine, and you can use Speech-to-Text on Ubuntu using HTML5 (as well as other programs). LibreOffice works just as well (some previous Office users say better) than Office … and is FREE!

Linux is also very secure — much secure than Windows — right out of the package, without having to install and/or configure all types of security apps.

Are you aware that most servers use Linux, and that most governments around the world, as well as many large (and very large) corporations are switching to Linux?

I am not sure where you got your info but it’s incorrect.

michel

you linux guys don’t care about reality, you’re just like those apple fanatics. I’m not sure where I’d want to get using a command line on WIndows, I never have to use it.

WIndows doesn’t crash all the time. Do you really think it would be used by millions of professionals, business, groups, etc, if it weren’t stable? Viruses are not a problem: install anti-virus, done. Libreoffice is not good enough for anyone who needs to collaborate professionally with Office users.

oh, forget it. Have a nice day.

Danny Stieben

Just my two cents:

Yes, there’s more command line usage in Linux than in Windows, because the command prompt in Windows has little power. Linux users can also do quite a bit with GUI, provided that the developer programs for the user and includes a GUI.

Linux and Windows crash equally for various reasons. Linux has a tendency to crash less during normal runtime — if there’s an issue, you’ll most likely see it right at boot time.

Windows has a virus problem. If it didn’t, there wouldn’t be a need for antivirus software. Linux doesn’t need it. At least Microsoft seems to be doing something to combat this, but it will always be a problem as long as it continues using the NT kernel.

dragonmouth

You Windows guys don’t care about reality, you’re just like those Apple fanatics. You need to get your facts straight.

“Do you really think it would be used by millions of professionals, business, groups, etc, if it weren’t stable?”
YES! Check your Windows history. For a long time Microsoft contract with computer manufacturers stipulated that MS be paid a licensing fee for each and every computer that left the factory, whether it had Windows installed on it or not. So the manufacturers figured that since they were paying as if Windows was installed on every computer, they might as well install it on every computer. It was called the Microsoft Tax.

“Viruses are not a problem: install anti-virus, done.”
I’m glad you think so. What happens when a new virus is released into the wild? Your AV will not know what to do about it.

“Libreoffice is not good enough for anyone who needs to collaborate professionally with Office users.”
Then why, as of September 2011 that there were 10 million users worldwide who had obtained LibreOffice via downloads or CDs? Over 90% of those are on Windows, with another 5% on Mac OS X.
Why did the cities of Limerick Ireland, Las Palmas Spain, Umbria Italy, Copenhagen Denmark, Largo Florida and the entire province of Ile de France(including the city of Paris), just to mention a few, replace whatever office suite they were using with Libre Office?

oh, forget it. Have a nice day.

Firewall

Ubuntu and Debian users can use Remastersys for cloning their systems as-is. And it can do even more.

Danny Stieben

Thanks for the great tip!

Firewall

Ubuntu and Debian users can use Remastersys for cloning their systems as-is. And it can do even more.

Mark B

Wouldn’t a new install be better than an upgrade. This way you start off with a clean computer. I know Linux is not like Windows but I still think a new install is the way to go.

Danny Stieben

New installations are always best no matter what operating system you’re talking about, but sometimes upgrades are simply more practical if your system is still running smoothly and you have a lot of data on it.

dragonmouth

The easiest way of migrating Linux that I found is to physically move the HD from one PC to the other. Linux is resilient enough to recognize all the new hardware and update the config files automatically, something you can’t ever dream of doing with Windows, even cracked or pirated versions.

Another way is to set up a separate / and /home partitions and just installing new distros into the / partition. OOPPS! Sorry, that is Old PC, New O/S.

Danny Stieben

Very true! Some of the methods that I mentioned above are great, however, if you’re switching hard drives as well, and not just machines.

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.

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.

Danny Stieben

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

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!

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!

Danny Stieben

I’m glad you found it useful, Jacob! :)

Prasanth Mathialagan

Useful information!!!

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.