Increase Disk Space and RAM of an Oracle VirtualBox VM Guest (RH, CentOS, Oracle Linux)

Increasing the Disk Space to 120GIB and RAM to 8GIB also involves the increment of swap space to 8GIB. The following steps were performed with CentOS 6.6 as VirtualBox host system and Oracle Linux 6.6 as guest system.


Steps 1+2 performed on host system in console window with root user:
  1. Increase Disk Space of Virtual Drive (e.g. resize Virtual Drive vm1disk1.vdi to 120GIB):

    $ VBoxManage modifyhd vm1disk1.vdi --resize 122880
  2. Increase RAM (e.g. resize Memory for VM vm1 to 8GIB):

    $ VBoxManage modifyvm vm1 --memory 8192
Steps 3-9 performed on guest system in console window with root user:
  1. Resize partition for lvm (e.g. adjust partition /dev/sda2 to new size).

    Delete old partiton and create new, larger partition:

    $ fdisk /dev/sda
    Command (m for help): d
    Partition number (1-4): 2
    Command (m for help): n
    
    Command action
    e   extended
    p   primary partition (1-4)
    p
    Partition number (1-4): 2
    First sector (155-2097151, default 155): 
    Using default value 155
    Last sector, +sectors or +size{K,M,G} (155-37786, default 37786): 
    Using default value 37786
    
    Command (m for help): w
Reboot the system
  1. Make enlarged partition available for LVM

    $ lvm
    lvm> pvdisplay
    --- Physical volume ---
    PV Name               /dev/sda2
    VG Name               vg_vm1
    PV Size               19,51 GiB / not usable 3,00 MiB
    ..
    lvm> pvresize /dev/sda2
    Physical volume "/dev/sda2" changed
    1 physical volume(s) resized / 0 physical volume(s) not resized
    lvm> pvdisplay
    --- Physical volume ---
    PV Name               /dev/sda2
    VG Name               vg_vm1
    PV Size               119,51 GiB / not usable 716,00 KiB
    ..
    lvm> vgdisplay
    --- Volume group ---
    VG Name               vg_vm1
    System ID             
    Format                lvm2
    .. 
    VG Size               119,51 GiB
    ..
  2. Increasing logical volume for swap by 6GIB (from 2 to 8GIB):

    $ lvm
    lvm> lvdisplay
    ..
    --- Logical volume ---
    LV Path                /dev/vg_vm1/lv_swap
    LV Name                lv_swap
    VG Name                vg_vm1
    ..
    LV Size                2,00 GiB
    ..
    lvm> lvresize /dev/vg_vm1/lv_swap -L +6144M
    Size of logical volume vg_vm1/lv_swap changed from 2,00 GiB (512 extents) to 8,00 GiB (2048 extents).
    Logical volume lv_swap successfully resized
  3. Increasing logical volume for root file system by adding the remaining space of partition:

    $ lvm
    lvm> lvdisplay
    --- Logical volume ---
    LV Path                /dev/vg_vm1/lv_root
    LV Name                lv_root
    VG Name                vg_vm1
    .. 
    LV Size                17,51 GiB
    ..
    lvm> lvresize /dev/vg_vm1/lv_root -l +100%FREE
    Size of logical volume vg_vm1/lv_root changed from 17,51 GiB (4482 extents) to 111,51 GiB (28546 extents).
    Logical volume lv_root successfully resized
    lvm> lvdisplay
    --- Logical volume ---
    LV Path                /dev/vg_vm1/lv_root
    LV Name                lv_root
    VG Name                vg_vm1
    .. 
    LV Size                111,51 GiB
    ..
    --- Logical volume ---
    LV Path                /dev/vg_vm1/lv_swap
    LV Name                lv_swap
    VG Name                vg_vm1
    ..
    LV Size                8,00 GiB
    ..
  4. Analyze Swapping:

    $ swapon -s
    Filename	Type		Size	Used	Priority
    /dev/dm-1	partition	2097148	0		-1
    $ ls -l /dev/mapper
    total 0
    crw-rw----. 1 root root 10, 236  7. Apr 16:13 control
    lrwxrwxrwx. 1 root root       7  7. Apr 16:13 vg_vm1-lv_root -> ../dm-0
    lrwxrwxrwx. 1 root root       7  7. Apr 16:13 vg_vm1-lv_swap -> ../dm-1
  5. End Swapping:

    $ swapoff -v /dev/vg_vm1/lv_swap
    swapoff für /dev/vg_vm1/lv_swap
  6. Create and show new Swap space:

    $ mkswap -f /dev/vg_vm1/lv_swap
    Setting up swapspace version 1, size = 8388604 KiB
    no Label, UUID=..
    $ swapon -va
    swapon für /dev/mapper/vg_vm1-lv_swap
    swapon: /dev/mapper/vg_vm1-lv_swap: found swap signature: version 1, page-size 4, same byte order
    swapon: /dev/mapper/vg_vm1-lv_swap: pagesize=4096, swapsize=8589934592, devsize=8589934592
    $ swapon -s
    Filename				Type		Size	Used	Priority
    /dev/dm-1               partition	8388604	0	-1
Shutdown Guest system and boot with Linux live system (e.g. CentOS).
Steps 10-12 performed with Linux live system
  1. Analyze file system structure:

    [centoslive@livedvd ~]$ su -
    [root@livedvd ~]# fdisk -l
    
    Disk /dev/sda: 128.8 GB, 128849018880 bytes
    ..
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *           1         155      512000   83  Linux 
    /dev/sda2             155       37786   125314356   83  Linux 
    ..
    Disk /dev/mapper/vg_vm1-lv_root: 119.7 GB, 119730601984 bytes
    ..
    Disk /dev/mapper/vg_vm1-lv_swap: 8589 MB, 8589934592 bytes
    ..
  2. File system check of LVM file system

    [root@livedvd ~]# e2fsck -f /dev/mapper/vg_vm1-lv_root
    e2fsck 1.41.12 (17-May-2010)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    /dev/mapper/vg_vm1-lv_root: 205089/1148304 files (0.1% non-contiguous), 2013043/4589568 blocks
  3. Adjust root file system to size of logical volume

    [root@livedvd ~]# resize2fs /dev/mapper/vg_vm1-lv_root
    resize2fs 1.41.12 (17-May-2010)
    Resizing the filesystem on /dev/mapper/vg_vm1-lv_root to 29231104 (4k) blocks.
    The filesystem on /dev/mapper/vg_vm1-lv_root is now 29231104 blocks long.