We have some clients' business grow fast, thus they need to upgrade the server storage. Since they primarily have one single hard drive and built the system with LVM, then want a 2nd hard drive to be inserted and extend the LVM logical volume.
Let's set an example here and see how to get through:
We assume the current system storage structure looks like below:
root ~:# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 18G 4.0G 13G 24% / /dev/sda1 99M 40M 55M 42% /boot tmpfs 502M 0 502M 0% /dev/shm root ~:#
Now, we will use
fdisk to create a partition on the newly added device (in this case /dev/sdb).
root ~:# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in the memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-261, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-261, default 261): Using default value 261 Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e Changed system type of partition 1 to 8e (Linux LVM) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. SCSI device sdb: 4194303 512-byte hdwr sectors (2147 MB) sdb: Write Protect is off SCSI device sdb: drive cache: write back SCSI device sdb: 4194303 512-byte hdwr sectors (2147 MB) sdb: Write Protect is off SCSI device sdb: drive cache: write back Syncing disks. root ~:#
We then use the next utility to notify the operating system of the partition table changes on the new device.
root ~:# partprobe /dev/sdb
And then we will create the physical volume for the new hard disk.
root ~:# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created
Now we can extend the (logical) volume group that we want to have more space.
root ~:# vgentend VolGroup00 /dev/sdb1 Volume group "VolGroup00" successfully extended
Remember, when extending the logical volume always leaving some space for LVM meta-data. So:
root ~:# lvextend -L +1.8G /dev/VolGroup00/LogVol00 Rounding up size to full physical extend 1.81 GB Extending logical volume LogVol00 to 19.72 GB Logical volume LogVol00 successfully resized
At last, we have to resize the extended logical volume to allocate the additional disk space.
root ~:# resize2fs /dev/VolGroup00/LogVol00 resize2fs 1.39 (29-May-2006) Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required Performing an on-line resize of /dev/VolGroup00/LogVol00 to 5169152 (4k) blocks. The filesystem on /dev/VolGroup00/LogVol00 is now 5169152 blocks long.
And obviously, the size was increased:
root ~:# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LogVol00 20G 4.0G 15G 22% / /dev/sda1 99M 40M 55M 42% /boot tmpfs 502M 0 502M 0% /dev/shm