Copy Your Linux Install to a Different Partition or Drive
If you need to move your Linux installation to a different hard drive or partition (and keep it working) and your distro uses grub this tech tip is what you need.
To start, get a live CD and boot into it. I prefer Ubuntu for things like this. It has Gparted. Now follow the steps outlined below.
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.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- New Products
- RSS Feeds
- Tech Tip: Really Simple HTTP Server with Python
- Epistle
41 min 7 sec ago - Automatically updating Guest Additions
1 hour 49 min ago - I like your topic on android
2 hours 36 min ago - Reply to comment | Linux Journal
2 hours 57 min ago - This is the easiest tutorial
9 hours 11 min ago - Ahh, the Koolaid.
14 hours 50 min ago - git-annex assistant
20 hours 49 min ago - direct cable connection
21 hours 12 min ago - Agreed on AirDroid. With my
21 hours 22 min ago - I just learned this
21 hours 26 min ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.
In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.



Comments
Would it be possible to backup the system for later restore?
Instead of copying the system to another hard drive, would it be possible to compress it and keep for later restore?
single HD to raid?
Would this method also work for transfering a single HD to a raid setup?
I've been wanting to go back to a RAID 0 setup, but don't want to reinstall...
Thanks,
Dan
Correction to grub drive identification syntax
grub uses the form (hd0,0) rather than hd(0,0) to identify a disk partition, and (hd0), not hd(0) to identify a disk.
It did work with WIndows......
Actually, I did manage to do a Windows copy and was pleasantly surprised that it worked.
I typically do Linux FS copies all the time, which is where the idea came from - my Live distro of choice is Knoppix. I was doing a clone of a Windows hard drive (20GB to a new 300+GB) using disk cloning tools, but could not get the newly cloned drive to boot - it seemed that the boot sector or MBR was getting hosed in the copy. This happened with different drives, and on different machines used for the copy so it was not a hardware issue.
I tried a CD install of Windows, which worked and the system booted fine. I then did a disk copy of the old (20GB) windows drive over the new install (which was deleted first) all within the Live session, and lo & behold, the copy booted fine and worked with no issues.
Note though, I was not changing hardware, nor partitions. However, I think if changing partitions, then a simple boot.ini edit may fix it.
Note: when using Knoppix as a Live distro and creating/formatting the partitions, ensure a reboot between formatting (mk*fs) and copying to it, to ensure the new file systems are properly initialized (and synced) before use.
Also, I prefer to use the "tar/cd/tar" combination to ensure that all my permissions come across intact. I think I once read somewhere that it was also more efficient.
After mounting the entire filesystem tree on, say, /mnt/Source (/boot / /home /var /whatever) and the destination on /mnt/Dest (with the new filesystem structure, if needed and possibly additional volumes), I then do the following:
cd /mnt/Source
tar --preserve --sparse --totals -cf - | (cd /mnt/Dest; tar --preserve --totals -xvf -)
Explanation: create a tar archive, preserving permissions, dates times to standard output; pipe it to a tar extraction from standard output, also preserving the permissions, times and dates, but first changing directories to the destination target.
The use of --totals will print a final for both the source copy (tar -cf) and the destination extraction (tar -xvf) for easy comparison that all of the data was copied.
Note the brackets around the entire group of commands after the pipe
Why?
Why not just use dd to copy and then resize the partition using gparted? Works on windows partitions too.
defragmentation
Hi, Think this implies getting a very good defrag of partition at the same time. Right??
you are assuming
All the files are in / directory. You need to ask also if say /home or /usr or /var is mounted separately
Parted Magic
We've really enjoyed Parted Magic and thought it should be mentioned here.
http://www.partedmagic.com/
Sincerely,
John and Dagny Galt
.
Steps I use:
I clone Linux OS from partition to partition to have a sandbox to test risky software, like testing GRUB2. I was glad it was on a throw-away clone. I keep grub setup pointing to /dev/sda1 and chainlink to all but Slitaz.
Cloning Partitions:
1. Boot a neutal partition of same inode size (128 or 256, tune2fs to see)
2. Gparted --- unmount target partition, format as ext3, and remount (could shred target but I just use format)
3. sudo cp -a /source/* /target/
4. sudo gedit /target/etc/fstab --- 3 lines to change
edit /target/boot/grub/menu.lst - change partition of first stanza
edit sda1's /boot/grub/menu.lst --- copy in the new first stanza - add root (hdx,y)
5. boot into the target partition. no chainlinking yet $ df - to verify correct partition.
6. sudo grub-install /dev/target --- also change the background as a flag.
7. sudo gedit /UserHome/boot/grub/menu.lst --- set up chainlink to /mnt/target.
Thanks for the ls command - I saved a copy of that.
seriously?
Yes you CAN move a windows install to another drive. Just use ghost, partimage, clonezilla.. But I don't think you can copy it at the filesystem level like this, and you can't move it to a different machine unless they happen to be pretty close to identical without some serious repair work afterward.
Try that with Windows...
It's so easy. Yet it's probably not even possible to move a Windows installation to a new drive.