Expanding storage in VM

CentOS guest on VirtualBox

Arun Vasudevan
3 min readFeb 24, 2014

Logical Volume Manager in Linux

Relationship between various elements of the LVM

Add physical storage to VM

  • Launch Oracle VM VirtualBox Manager
  • Determine virtual disk file
    server.centos.arunov.fsl -> settings -> Storage -> Controller: SATA -> server.centos.arunov.fsl -> Location
  • Open terminal
$ VBoxManage modifyhd “copied-path-of-disk-file” —resize 33280
  • Size is in mega bytes
  • Note: If attempt to reduce size, error:
VBOX_E_NOT_SUPPORTED
VBoxManage: error: Resize hard disk operation for this format is not implemented yet!

Launch VM

  • Launch VM: server.centos.arunov.fsl (hostname: puffin)
  • Connect from host terminal
$ ssh root@130.245.126.203
  • Login
  • List of commands
$ lvm help
  • Scan disk
$ lvmdiskscan
:
/dev/sda2 [ 7.51 GiB] LVM physical volume
/dev/ram3 [ 16.00 MiB]
/dev/sda3 [ 7.99 GiB]
:
  • See physical disks that are used
$ pvscan
PV /dev/sda2 VG VolGroup lvm2 [7.51 GiB / 0 free]
Total: 1 [7.51 GiB] / in use: 1 [7.51 GiB] / in no VG: 0 [0 ]
  • /dev/sda3 is not used, create
$ pvcreate /dev/sda3
Physical volume “/dev/sda3" successfully created
  • Add to volume group — find volume group and then extend
$ vgscan
Reading all physical volumes. This may take a while…
Found volume group “VolGroup” using metadata type lvm2
$ vgextend VolGroup /dev/sda3
/etc/lvm/archive/.lvm_puffin_1449_1782662981: write error failed: No space left on device
Volume group “VolGroup” metadata archive failed.
Internal error: Attempt to unlock unlocked VG #orphans.
  • Turn off VM

Boot from Live CD

  • Download live CD CentOS image:
    http://isoredirect.centos.org/centos/6/isos/x86_64/
    For example: CentOS-6.5-x86_64-LiveCD.iso
  • Configure VM to have live CD
    server.centos.arunov.fsl -> Settings -> Storage -> Controller: IDE -> empty -> CD/DVD Drive -> Choose a virtual CD/DVD disk file
    Select: CentOS-6.5-x86_64-LiveCD.iso
  • Check ‘Live CD/DVD’
  • Launch VM
  • Boot (text mode)
  • Login as ‘root’
  • Continue from where we left
$ vgextend VolGroup /dev/sda3
Volume group “VolGroup” succesfully extended
  • We’re done with adding storage at volume group and physical volume levels. Next, add to logical volume.
$ lvscan
inactive ‘/dev/VolGroup/lv_root’ [5.54 GiB] inherit
inactive ‘/dev/VolGroup/lv_swap’ [1.97 GiB] inherit
$ lvextend /dev/VolGroup/lv_root /dev/sda3
Extending logical volume lv_root to 13.53 GiB
Logical volume lv_root successfully resized
  • Shutdown live CD
$ shutdown -F now

Extend File system

  • Remove CD/DVD attachment in VM
  • Start VM and login as ‘root’
  • Find out mapped device
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
5.4G 5.4G 0 100% /
  • Resize file system
$ resize2fs /dev/mapper/VolGroup-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/VolGroup-lv_root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 3547136 (4k) blocks.
The filesystem on /dev/mapper/VolGroup-lv_root is now 3547136 blocks long.
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
14G 5.4G 7.3G 43% /
  • Reboot to verify
$ shutdown -Fr now

Open questions

  • My disk storage size is 32.5 GB. Retrieved only around 16 GB.
  • What is device mapper?
  • Could expansion be done without live CD?

--

--

Arun Vasudevan

Research Assistant, File Systems and Storage Lab, Stony Brook University