Friday, January 20, 2012

Just add disk to Volume Group (linux)

Last night, I tested to run OPatch Automation for Grid Home (virtualbox) and it failed. I investigated it needs more free space i have. I didn't know what I was supposed to do. ...and I figured it out. Oh! I had used Linux Logical Volume. So, I justed added new disk for virtualbox and added to Volume Group.
After I added new disk for virtualbox:
[root@myhost01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
17G 13G 3.4G 79% /
/dev/sda1 99M 43M 52M 45% /boot
tmpfs 943M 0 943M 0% /dev/shm
[root@myhost01 ~]#
[root@myhost01 ~]#
[root@myhost01 ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdd: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1305, default 1305):
Using default value 1305

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@myhost01 ~]# pvscan
PV /dev/sda2 VG VolGroup00 lvm2 [19.88 GB / 0 free]
Total: 1 [19.88 GB] / in use: 1 [19.88 GB] / in no VG: 0 [0 ]

[root@myhost01 ~]# pvcreate /dev/sdd1
Physical volume "/dev/sdd1" successfully created

[root@myhost01 ~]# pvscan
PV /dev/sda2 VG VolGroup00 lvm2 [19.88 GB / 0 free]
PV /dev/sdd1 lvm2 [10.00 GB]
Total: 2 [29.87 GB] / in use: 1 [19.88 GB] / in no VG: 1 [10.00 GB]

[root@myhost01 ~]# vgextend VolGroup00 /dev/sdd1
Volume group "VolGroup00" successfully extended

[root@myhost01 ~]# lvresize -L 25G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 25.00 GB
Logical volume LogVol00 successfully resized

[root@myhost01 ~]# pvscan
PV /dev/sda2 VG VolGroup00 lvm2 [19.88 GB / 0 free]
PV /dev/sdd1 VG VolGroup00 lvm2 [9.97 GB / 1.94 GB free]
Total: 2 [29.84 GB] / in use: 2 [29.84 GB] / in no VG: 0 [0 ]

[root@myhost01 ~]# resize2fs -p /dev/VolGroup00/LogVol00 25G
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 6553600 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 6553600 blocks long.

[root@myhost01 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
25G 13G 11G 54% /
/dev/sda1 99M 43M 52M 45% /boot
tmpfs 943M 0 943M 0% /dev/shm

wow! it worked for me (I could test to run OPatch Automation for Grid Home). I felt like with the Linux Logical Volume Manager.
*** Nothing more for technical in this, just fun and improve my writing in the same time ***
Note:
Added PV to VG by using vgextend command.
Resized the LV by using lvresize command.
Resized (ext3) filesystem by using resize2fs command.

2 comments:

Anonymous said...

I am brand new to VirtualBox and created a VM the other day to play around with Oracle when it soon became apparent I did not allocate enough space to my disk and needed to expand it. I have been banging my head against the wall for like two days straight now trying to figure out how to expand the LVM! I tried Gparted but it didn't work on the LVM (locked) and I also tried Plop to boot from a USB with the Gparted iso but that just resulted in a black screen. Eventually I found your post...I added a new .vdi to the VM and then used your instructions to expand the LVM. Worked exactly as you posted! THANK YOU!

Surachart Opun said...

After Step -
[root@myhost01 ~]# vgextend VolGroup00 /dev/sdd1

We might use:
- Extende LV
# lvextend /dev/VolGroup00/LogVol00 /dev/sdd1
- Resize the FS
# resize2fs /dev/VolGroup00/LogVol00