Upgrading a hard drive of my Fedora laptop
October 16th, 2009 by Min ChenI bought a 500G SATA hard drive to replace the 160G one in my HP laptop. I then managed to clone all partitions from the old disk to the new one, and resized (increased) the file system. Here’s how I did it.
What I needed:
- A computer with two SATA interfaces. I have a Windows desktop that has 4 SATA ports and 2 cables. I then pulled out the data cables and power cables from the existing 3.5″ desktop hard drives in the Windows box in order to hook up the 2.5″ laptop hard drives
- A Fedora 11 installation DVD
- Screw drivers
First I unscrewed the 160G hard drive from my laptop, and then took both new and old hard drives to my Windows desktop. I then plugged the data cables and power cables to both 2.5″ drives, the new one was on SATA 1 and the 160G old one was on SATA 2.
Powered on the box and booted from Fedora installation DVD. By entering “rescue mode”, I was able to ls /dev and saw /dev/sda and /dev/sdb, /dev/sdb1, /dev/sdb2, /dev/sdb3. Obviously the new 500G hard drive was /dev/sda and the old one was /dev/sdb.
To check the partition table of the old drive, I run fdisk -l /dev/sdb.
The output was
Disk /dev/sdb: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0×95aa95aa
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 25 200781 83 Linux
/dev/sdb2 18197 19457 10128982+ 7 HPFS/NTFS
/dev/sdb3 26 18196 145958557+ 8e Linux LVM
/dev/sdb1 was the
grub/dev/sdb2 was the HP’s system recovery image
/dev/sdb3 was the most important, it had all my Linux system and data
Based on this partition table, I run fdisk /dev/sda to setup 2 primary partitions on the new drive. Use n to create partition, and t to change the Id for 2nd partition from the default 83 to 8e, w to save the partition table. I made the sizes of new partitions identical to the old ones. The partition table of new hard drive look like this
Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 18196 145958557+ 8e Linux LVM
The size of /dev/sda1 was identical to the size of /dev/sdb1, and /dev/sda2 was identical to /dev/sdb3.
Restarting the machine, booted from Fedora DVD, and entered into rescue mode, and I was ready to clone the partitions. Simply run the dd command
dd if=/dev/sdb1 of=/dev/sda1 bs=1M to clone the /boot and
dd if=/dev/sdb3 of=/dev/sda2 bs=1M to clone the Linux system
It took about 10 seconds to clone the 200M grub partition, and about 2 hours to clone 140G Linux partition.
I then shut down the machine, unplugged all cables from laptop hard drives, and screwed the new 500G hard drive into my HP laptop. I had to insert the Fedora DVD into laptop and entered into rescue mode to setup grub. I run these commands
grub
root (hd0,0)
setup (hd0)
After these, I removed the DVD and booted from hard drive. I was able to use the new hard drive now. Everything was saved, the laptop works exactly the same as if I’d never changed the hard drive.
My next task is to increase the file system size. As shown in the fdisk output, my Linux is using LVM, so I need to increase the size of LVM partition, and then increase the size of virtual group and logical volume. Before I did any changes, I run pvdisplay, vgdisplay, and lvdisplay, and saved the output to a file. I have two logical volumes, /dev/VolGroup00/LogVol00 for my Linux file system, and /dev/VolGroup00/LogVol01 for swap.
First step was to increase the partition size. It was easily done by fdisk, by using d to delete the partition, and then n to recreate the partition with bigger size, and w to save the changes. I had to reboot the laptop to apply the changes.
This is the output of my partition table (fdisk -l /dev/sda) after increasing the size:
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0×000ba110
Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 36392 292117927+ 8e Linux LVM
I doubled the size of /dev/sda2 from the original 146G to now 292G.
The rest would be dealing with LVM.
- run
pvresize /dev/sda2to update the physical volume size - run
lvresize -L +1G /dev/VolGroup00/LogVol01to add 1G bytes to my swap - run
lvresize -l +100%FREE /dev/VolGroup00/LogVol00to add all free space to my Linux system - run
resize2fs -p /dev/VolGroup00/LogVol00to resize the ext3 file system - run
swapoff -ato turn off swap - cat /etc/fstab to get the swap UUID, in my case it’s 52841e8a-2b3d-4a9d-92bc-1b5af50e4b8a
- run
mkswap -U 52841e8a-2b3d-4a9d-92bc-1b5af50e4b8a /dev/VolGroup00/LogVol01to rebuild swap - run
swapon -ato turn on swap - run e2fsck to check the file system if necessary
After these steps, dh -h shows that I have successfully increased the size of my file system.