Wednesday, 10 October 2012

How to move your installed Linux to another drive and keep it working.

When I was trialling Linux, I installed it onto a drive (partition) that became too small (as I was installing more and more things). I had my original and much larger Windows 7 drive gathering dust so I thought to get rid of that and move Linux there. Here's how I moved my Linux without having to re-install anything.
That's not an easy task under Windows and is fraught with danger, however it's easy under Linux. In fact I can keep both copies and be able to boot either, which is a great failsafe, should one not boot.

Copying 
  • Mount both your source and destination partitions. 
  • Run this command from a terminal: 
      $ sudo cp -afv /path/to/source/* /path/to/destination 
      Don’t forget the asterisk after the source path.
  • After the command finishes copying, shut down, remove the source drive, and boot the live CD again. 

Configuration 
  • Mount your destination drive (or partition). 
  • Run the command “gksu gedit” (or use nano or vi). 
  • Edit the file /etc/fstab. Change the UUID or device entry with the mount point / (the root partition) to your new drive. 
  • You can find your new drive’s (or partition’s) UUID with this command:
      $ ls -l /dev/disk/by-uuid/ 
  • Edit the file /boot/grub/menu.lst. Change the UUID of the appropriate entries at the bottom of the file to the new one. 

Install Grub 
  • Run sudo grub. 
  • At the Grub prompt, type: 
      find /boot/grub/menu.lst 
      This will tell you what your new drive and partition’s number is. 
      (Something like hd(0,0)) 
  • Type: 
      root hd(0,0) 

      but replace "hd(0,0)" with your partition’s number from above.
  • Type: setup hd(0) but replace "hd(0)" with your drive's number from above. (Omit the comma and the number after it). 

That’s it! You should now have a bootable working copy of your source drive on your destination drive! You can use this to move to a different drive, partition, or filesystem.

No comments:

Post a Comment