Tuesday, 3 November 2009

Adding diskspace to root VG on Linux guest VM

....Im increasing my root VG from 4GB to 7GB....
(aim: to increase root filesystel /, from 3.3GB to about 6GB)

Summary:
-make the vmdk bigger,
-use fdisk to increase the partition,
-use pvcreate/pvresize to increase the PV,
-use lvextend/lvresize to increase the LV then finally,
-use resize2fs to expand the filessytem

Make vmdk bigger
Make vmdk bigger using any vm client (vitualcenter etc) e.g.
If you have ESX 3.5 or newer:
1. Open VMware Infrastructure Client and connect to VirtualCenter or the ESX host.
2. Right-click the virtual machine.
3. Click Edit Settings.
4. Select Virtual Disk.
5. Increase the size of the disk.

using fdisk
##check current usage
[root@guestvm ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-root
3.3G 2.6G 506M 84% /
/dev/sda1 251M 29M 210M 12% /boot
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/mapper/myapp-lvol0
188G 7.5G 171G 5% /opt/myapp

##check current space available
[root@guestvm ~]# fdisk -l
Disk /dev/sda: 4096 MB, 4294967296 bytes
255 heads, 33 sectors/track, 512 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 33 265041 83 Linux
/dev/sda2 34 522 3927892+ 8e Linux LVM

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

##Reboot VM...

##check if there if disk has now free space
[root@guestvm ~]# fdisk -l

Disk /dev/sda: 7516 MB, 7516192768 bytes
255 heads, 63 sectors/track, 913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 33 265041 83 Linux
/dev/sda2 34 522 3927892+ 8e Linux LVM

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

##configure free space with fdisk
[root@guestvm ~]# fdisk /dev/sda

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4): 3
First cylinder (523-913, default 523):
Using default value 523
Last cylinder or +size or +sizeM or +sizeK (523-913, default 913):
Using default value 913

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@guestvm ~]#

##check if your now have a new partion carrying the free space
[root@guestvm ~]# fdisk -l
Disk /dev/sda: 7516 MB, 7516192768 bytes
255 heads, 63 sectors/track, 913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 33 265041 83 Linux
/dev/sda2 34 522 3927892+ 8e Linux LVM
/dev/sda3 523 913 3140707+ 8e Linux LVM

Disk /dev/sdb: 214.7 GB, 214748364800 bytes
255 heads, 63 sectors/track, 26108 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

LV Management
[root@guestvm ~]#pvcreate /dev/sda3 ##create a physical volume

[root@guestvm ~]#vgdisplay ##current volume group setting
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 3.72 GB
PE Size 32.00 MB
Total PE 119
Alloc PE / Size 119 / 3.72 GB
Free PE / Size 0 / 0
VG UUID n20DW3-UjK4-tY7q-tYmR-G4nQ-5LH3-AXivlS

[root@guestvm ~]#vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended

[root@guestvm ~]# pvscan
PV /dev/sdb VG myapp lvm2 [200.00 GB / 10.00 GB free]
PV /dev/sda2 VG VolGroup00 lvm2 [3.72 GB / 0 free]
PV /dev/sda3 VG VolGroup00 lvm2 [2.97 GB / 2.97 GB free]
Total: 3 [206.68 GB] / in use: 3 [206.68 GB] / in no VG: 0 [0 ]

[root@guestvm ~]# vgdisplay VolGroup00 | grep "Free"
Free PE / Size 95 / 2.97 GB

[root@guestvm ~]# lvextend -L+2.96GB /dev/VolGroup00/root
Rounding up size to full physical extent 2.97 GB
Extending logical volume root to 6.28 GB
Logical volume root successfully resized

[root@guestvm ~]# resize2fs /dev/VolGroup00/root
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/root is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/root to 1646592 (4k) blocks.
The filesystem on /dev/VolGroup00/root is now 1646592 blocks long.

[root@guestvm ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-root
6.1G 2.6G 3.3G 45% /
/dev/sda1 251M 29M 210M 12% /boot
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/mapper/myapp-lvol0
188G 7.6G 170G 5% /opt/myapp

No comments:

Post a comment