===== Extend Centos VM disk =====
This procedure describes the commands required to extend the disk size of a NetYCE VM based on RHEL/CentOS 6 or RHEL/CentOS 7. Both procedures are similar but differ in the details.
==== RHEL/CentOS 7 ====
=== 1) Resize the virtual disk ===
First, halt and power down the VM. Using the hypervisor resize the virtual disk of the VM.
In the example sessions the size is increased from 8 GB to 40 GB.
VirtualBox cannot resize VMDK disks, you need to convert to VDI disk format first. After halting the VM, execute on the host cli while in the appropriate directory the command below. The example converts the “Genesis” disk from vmdk to vdi format
VBoxManage clonehd --format VDI Genesis.vmdk Genesis.vdi
If the disk-filename or extension was changed, detach it from the Genesis storage controller using virtual box gui (machine - settings - storage) and attach the new image to the controller (add hard disk - choose existing)
Then you can resize the disk to desired value.
Start the VM and login using 'root'
=== 2) Recreate the disk partition ===
Using ''**fdisk**'', delete the second partition and recreate it using the new size. Fist note the current partitions
root@genesis7 ~
# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ae8d2
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 16777215 7339008 8e Linux LVM
Delete the second (LVM) partition
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted
And recreate it. Use the default start and end blocks. Then set the partition type to LVM again (8e).
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (2099200-16777215, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-16777215, default 16777215):
Using default value 16777215
Partition 2 of type Linux and of size 7 GiB is set
Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Verify the results and when satisfied write it to disk. Abort if incorrect, nothing will change until the 'w' is done.
Command (m for help): p
Disk /dev/sda: 8589 MB, 8589934592 bytes, 16777216 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ae8d2
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 16777215 7339008 8e Linux LVM
Command (m for help): w
=== 3) Reboot the VM ===
# reboot
=== 4) Verify the disk partitions ===
Login as 'root' and verify the disk partitions using ''**fdisk**'' as above.
# fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 43.4 GB, 43411046400 bytes, 84787200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ae8d2
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 84787199 41344000 8e Linux LVM
Command (m for help): q
=== 5) Resize the physical volume ===
Using ''**pvresize**''
# pvresize /dev/sda2
Physical volume "/dev/sda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
=== 6) Resize the logical volume ===
Using ''**lvresize**''.
The name of the /dev/mapper device may differ, use the for filename completion to find the reference for 'centos' and' root'.
# lvresize /dev/mapper/centos_c7--2-root /dev/sda2
Size of logical volume centos_c7-2/root changed from <6.20 GiB (1586 extents) to 38.62 GiB (9888 extents).
Logical volume centos_c7-2/root successfully resized.
=== 7) Extend the xfs filesystem ===
Using ''**xfs_growfs**''
# xfs_growfs /dev/mapper/centos_c7--2-root
meta-data=/dev/mapper/centos_c7--2-root isize=512 agcount=4, agsize=406016 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1624064, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 1624064 to 10125312
=== 8) Verify the results ===
Using ''**df -h /**''
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos_c7--2-root 39G 4.9G 34G 13% /
=== 9) Check filesystem ===
# touch /forcefsck
# reboot
When the system returns the extended disk is ready for use.
==== RHEL/CentOS 6 ====
=== 1) Resize the virtual disk ===
First, halt and power down the VM. Using the hypervisor resize the virtual disk of the VM.
VirtualBox cannot resize VMDK disks, you need to convert to VDI disk format first. After halting the VM, execute on the host cli while in the appropriate directory the command below. The example converts the "Genesis" disk from vmdk to vdi format
VBoxManage clonehd --format VDI Genesis.vmdk Genesis.vdi
If the disk-filename or extension was changed, detach it from the Genesis storage controller using virtual box gui (machine - settings - storage) and attach the new image to the controller (add hard disk - choose existing)
Then you can resize the disk to desired value.
Start the VM and login using 'root'
=== 2) Recreate the disk partition ===
The session samples show how a system using two LVM partitions is extended, not by adding a third partition by by extending the third partition. Look at the last section of this article how to extend the disk size of a RedHat/CentOS 6 system with an extra partition.
Using ''**fdisk**'', delete the third partition and recreate it using the new size. First note the current partitions
# 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').
Command (m for help): c
DOS Compatibility flag is not set
Command (m for help): u
Changing display/entry units to sectors
Command (m for help): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00034ecd
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 8388607 3681280 8e Linux LVM
/dev/sda3 8388608 16777215 4194304 8e Linux LVM
Delete the second (LVM) partition
Command (m for help): d
Partition number (1-4): 3
And recreate it. Use the default start and end blocks. Then set the partition type to LVM again (8e).
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First sector (8388608-209715199, default 8388608):
Using default value 8388608
Last sector, +sectors or +size{K,M,G} (8388608-209715199, default 209715199):
Using default value 209715199
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): p
Disk /dev/sda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00034ecd
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 8388607 3681280 8e Linux LVM
/dev/sda3 8388608 209715199 100663296 8e Linux LVM
Verify the results and when satisfied write it to disk. Abort if incorrect, nothing will change until the 'w' is done.
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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
=== 3) Reboot the VM ===
# reboot
=== 4) Verify the disk partitions ===
Login as 'root' and verify the disk partitions using ''**fdisk**'' as above.
=== 5) Resize the physical volume ===
Using ''**pvresize**''
# pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
=== 6) Resize the logical volume ===
Using ''**lvresize**''.
The name of the /dev/mapper device may differ, use the for filename completion to find the reference for 'VolGroup' and' root'.
# lvresize /dev/mapper/
control VolGroup-lv_root VolGroup-lv_swap
# lvresize /dev/mapper/VolGroup-lv_root /dev/sda3
Size of logical volume VolGroup/lv_root changed from 7.11 GiB (1819 extents) to 99.11 GiB (25371 extents).
Logical volume lv_root successfully resized.
=== 7) Extend the ext4 filesystem ===
Using ''**resize2fs**''
# 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 = 7
Performing an on-line resize of /dev/mapper/VolGroup-lv_root to 25979904 (4k) blocks.
=== 8) Verify the results ===
Using ''**df -h /**''
# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
98G 3.3G 90G 4% /
=== 9) Check filesystem ===
# touch /forcefsck
# reboot
When the system returns the extended disk is ready for use.
==== Adding a partition to RHEL/CentOS 6 ====
locate filesystem to extend
# df -h
eg: /dev/mapper/VolGroup-lv_root \\
we need the volgroup ''**VolGroup**'' and logical volume ''**lv_root**'' later
halt vm
# halt
compact the VM disk using VirtualBox cli tool
cd VirtualBox-VMs/YceOne/
VBoxManage modifyhd yceone-disk1.vdi --compact
resize vm disk, eg to 8G
VBoxManage modifyhd yceone-disk1.vdi --resize 8192
boot vm normally, login as root \\
locate next free partition number on /dev/sda
# fdisk -l
create extra primary partition of desired size (the amount added)
# fdisk /dev/sda
fdisk> c
fdisk> u
fdisk> n (add partition)
fdisk> p (primary)
fdisk> 3 (partiton)
fdisk> (default start)
fdisk> (default end)
fdisk> t (type)
fdisk> 3 (partition)
fdisk> 8e (linux LVM)
fdisk> w
halt and reboot
# halt
add partition as new physical volume and extend the volume group with it
# lvm
lvm> pvcreate /dev/sda3
lvm> vgextend VolGroup /dev/sda3
lvm> lvextend -L+10000 /dev/VolGroup/lv_root
this reports the number of extends available. take that number, multiply by 4 and specify that instead
lvm> lvextend -L+4092 /dev/VolGroup/lv_root
to be sure no other extends are available try to extend by one more
lvm> lvextend -L+1 /dev/VolGroup/lv_root
lvm> quit (exit lvm)
resize the filesystem
# resize2fs -F /dev/VolGroup/lv_root
Done! check free size
# df -h
//