[CentOS] Upgrading to larger HD with LVM

Thu Dec 21 15:17:26 UTC 2006
Aleksandar Milivojevic <alex at milivojevic.org>

Quoting Paul <unix at bikesn4x4s.com>:

> I could dd it back and start from scratch.  I see that fdisk must be run
> to resize the partition, then run pvresize.  I was under the impression
> that changing the partition with fdisk will lose any data on it?

As long as the start of partition does not change (or in other words,  
partition only gets resized, but not moved), you will not loose any  
data.  The steps are:

1. Expanding file system
    - expand partition using fdisk
    - expand physical volume
    - expand logical volume
    - expand file system

2. Shrinking file system
    - shrink file system
    - shrink logical volume
    - shrink physical volume (currently not always possible)
    - shrink partition

> Here's what I have.  Yes, I am running LVM2, latest updates on Centos4.4:
> # fdisk -l
> Disk /dev/hda: 41.1 GB, 41174138880 bytes
> 255 heads, 63 sectors/track, 5005 cylinders
> Units = cylinders of 16065 * 512 = 8225280 bytes
>    Device Boot      Start         End      Blocks   Id  System
> /dev/hda1   *           1          13      104391   83  Linux
> /dev/hda2              14        2501    19984860   8e  Linux LVM

So you'd just recreate hda2 to start at the cylinder 14 and end the  
end of the disk.  Also make sure the ID stays 8e (Linux LVM).

> # fdisk /dev/hda2

Well, you can't fdisk /dev/hda2.  It's partition.  Hopefully you  
haven't exited from fdisk using "w" command (it could really screw up  
whatever was on hda2).  You probably wanted to "fdisk /dev/hda".