One of my CentOS Test VMs is a standard install with / living on a LVM. Re-assigning the VMs hard disk a larger size in virtualbox is easy (on the cli ofc).

michi@imagine ~ $ VBoxManage list hdds
michi@imagine ~ $ VBoxManage modifyhd /media/stuff/vms/centos6.vdi --resize 15000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Though, the magic boot-resize2fs-done does not apply here 😉

First, use fdisk to recreate the partition using all cylinders.

  • p … list all partitions (note: 1912 cylinders)
  • d – 2 … delete secondary partition
  • n – p – 2 … create new primary partition
  • 64 – 1912 … old start, new end (noted from above, and auto-selected)
  • t – 8e … set type to Linux LVM
  • p … verify new partition layout
  • w … write changes to disk

Then reboot the vm.

[root@localhost coding]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Befehl (m für Hilfe): p

Platte /dev/sda: 15.7 GByte, 15728640000 Byte
255 Köpfe, 63 Sektoren/Spur, 1912 Zylinder
Einheiten = Zylinder von 16065 × 512 = 8225280 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000051ef

   Gerät  boot.     Anfang        Ende     Blöcke   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 endet nicht an einer Zylindergrenze.
/dev/sda2              64        1045     7875584   8e  Linux LVM

Befehl (m für Hilfe): d
Partitionsnummer (1-4): 2

Befehl (m für Hilfe): n
Befehl  Aktion
   e      Erweiterte
   p      Primäre Partition (1-4)
p
Partitionsnummer (1-4): 2
Erster Zylinder (64-1912, Vorgabe: 64): 64
Last Zylinder, +Zylinder or +size{K,M,G} (64-1912, Vorgabe: 1912): 1912

Befehl (m für Hilfe): t
Partitionsnummer (1-4): 2
Hex code (L um eine Liste anzuzeigen): L

Hex code (L um eine Liste anzuzeigen): 8e
Der Dateisystemtyp der Partition 2 ist nun 8e (Linux LVM)

Befehl (m für Hilfe): p

Platte /dev/sda: 15.7 GByte, 15728640000 Byte
255 Köpfe, 63 Sektoren/Spur, 1912 Zylinder
Einheiten = Zylinder von 16065 × 512 = 8225280 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000051ef

   Gerät  boot.     Anfang        Ende     Blöcke   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 endet nicht an einer Zylindergrenze.
/dev/sda2              64        1912    14845116   8e  Linux LVM

Befehl (m für Hilfe): w
Die Partitionstabelle wurde verändert!

Rufe ioctl() um Partitionstabelle neu einzulesen.

WARNING: Re-reading the partition table failed with error 16: Das Gerät oder die Ressource ist belegt.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Synchronisiere Platten.
[root@localhost coding]# reboot

Having the partition layout modified, we can now extend the phyiscal volume to the new size.

[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup
  PV Size               7,51 GiB / not usable 3,00 MiB
  Allocatable           yes (but full)
  PE Size               4,00 MiB
  Total PE              1922
  Free PE               0
  Allocated PE          1922
  PV UUID               JAWtzB-1vwT-t0w3-KjD1-tVFV-TVI7-51pInW

[root@localhost ~]# pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

[root@localhost ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               VolGroup
  PV Size               14,16 GiB / not usable 836,00 KiB
  Allocatable           yes
  PE Size               4,00 MiB
  Total PE              3624
  Free PE               1702
  Allocated PE          1922
  PV UUID               JAWtzB-1vwT-t0w3-KjD1-tVFV-TVI7-51pInW

Now check the volume groups and the available cylinders (Note the Free PE 1702)

[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  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               14,16 GiB
  PE Size               4,00 MiB
  Total PE              3624
  Alloc PE / Size       1922 / 7,51 GiB
  Free  PE / Size       1702 / 6,65 GiB
  VG UUID               5eot8g-GTdh-C1pD-V1SQ-VDHt-hV4M-ved3yq

Check the logical volumes and resize the root volume with the additional free PE 1702.

[root@localhost ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/VolGroup/lv_root
  LV Name                lv_root
  VG Name                VolGroup
  LV UUID                8K1Uvp-G5nN-DU08-7f3r-ql1T-iPSp-qNLTcv
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2013-02-14 20:40:06 +0100
  LV Status              available
  # open                 1
  LV Size                6,54 GiB
  Current LE             1674
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

[root@localhost ~]# lvextend -l +1702 /dev/VolGroup/lv_root
  Extending logical volume lv_root to 13,19 GiB
  Logical volume lv_root successfully resized

Once done, resize the root filesystem online (another reboot does not hurt afterwards).

[root@localhost ~]# resize2fs /dev/VolGroup/lv_root
resize2fs 1.41.12 (17-May-2010)
Das Dateisystem auf /dev/VolGroup/lv_root ist auf / eingehängt; Online-Grössenveränderung nötig
old desc_blocks = 1, new_desc_blocks = 1
Führe eine Online-Grössenänderung von /dev/VolGroup/lv_root auf 3457024 (4k) Blöcke durch.
Das Dateisystem auf /dev/VolGroup/lv_root ist nun 3457024 Blöcke groß.

Verify the new size, and have fun!

[root@localhost ~]# df -h
Dateisystem           Size  Used Avail Use% Eingehängt auf
/dev/mapper/VolGroup-lv_root
                       13G  3,2G  9,3G  26% /
%d bloggers like this: