OSVDC Series: Virtual Disk Management on oVirt 4 and CentOS 7 - rharmonson/richtech GitHub Wiki
Scenario
A virtual machine from a template utilizes one virtual disk. The application administrator has requested an increased capacity from 20 GB to 50 GB. The Linux administrator has chosen to increase capacity of the existing virtual disk versus creating and growing or mounting a second virtual disk.
Use pvdisplay
, vgdisplay
, and lvdisplay
to review current storage configuration.
[root@sw ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 4994
Free PE 10
Allocated PE 4984
PV UUID E34TI0-jnr3-8vIF-4rET-GILo-haID-VzmLkC
[root@sw ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
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 19.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4984 / 19.47 GiB
Free PE / Size 10 / 40.00 MiB
VG UUID AXJ9w1-jQXX-02Rk-SrFV-eqcD-oirw-xIfHhY
[root@sw ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID 5pOoUm-LMP6-5xTo-tNEL-Eil5-QG1t-gq7u3S
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-11-10 20:44:13 -0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID pyHQFR-KUHQ-pC1R-JR06-yRpA-AzcJ-Yl9Tu5
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-11-10 20:44:13 -0800
LV Status available
# open 1
LV Size 17.47 GiB
Current LE 4472
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
Using the oVirt administrator portal, extend the virtual disk.
- Authenticate to oVirt (Open Virtualization Manager)
- Shutdown VM (optional?)
- Select "Virtual Machines" tab
- Select the VM to edit in main pane
- Select "Disks" tab in bottom pane
- Select "Edit" menu
- Enter "Extend size by(GB)" value
- Select "OK"
- Poweron VM
Using fdisk
recreate and increase capacity of the desired primary partition.
- Logon to VM
- Execute "fdisk /dev/vda"
- Enter "p" and note the "Linux LVM" device vda2
- Enter "d" and delete vda2
- Enter "n" and create 'primary' and accept the default sectors
- Enter "t" and specify "8e" to set the new partition as 'Linux VM'
- Enter "w" to save changes
- "reboot"
Results
[root@sw ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x00088d6e
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1026047 512000 83 Linux
/dev/vda2 1026048 41943039 20458496 8e Linux LVM
Command (m for help): d
Partition number (1,2, default 2):
Partition 2 is deleted
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):
First sector (1026048-104857599, default 1026048):
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-104857599, default 104857599):
Using default value 104857599
Partition 2 of type Linux and of size 49.5 GiB is set
Command (m for help): t
Partition number (1,2, default 2):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x00088d6e
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1026047 512000 83 Linux
/dev/vda2 1026048 104857599 51915776 8e Linux LVM
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.
[root@sw ~]# reboot
Use pvresize
to utilize the additional storage.
- Logon to the virtual machine
- Execute "pvresize /dev/vda2"
Results
[root@sw ~]# pvresize /dev/vda2
Physical volume "/dev/vda2" changed
1 physical volume(s) resized / 0 physical volume(s) not resized
[root@sw ~]# pvdisplay
--- Physical volume ---
PV Name /dev/vda2
VG Name centos
PV Size 49.51 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12674
Free PE 7690
Allocated PE 4984
PV UUID E34TI0-jnr3-8vIF-4rET-GILo-haID-VzmLkC
[root@sw ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- 49.51g 30.04g
Use lvextend
extend the logical volume extents and file system.
- Execute "vgs" and note "VFree" or available space
- Execute "lvextend --resizefs --extents +100%FREE /dev/centos/root"
- Review the results using "vgs"
- Execute "reboot"
Results
[root@sw ~]# lvextend --resizefs --extents +100%FREE /dev/centos/root
Size of logical volume centos/root changed from 17.47 GiB (4472 extents) to 47.51 GiB (12162 extents).
Logical volume centos/root successfully resized.
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=1144832 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=0
data = bsize=4096 blocks=4579328, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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 4579328 to 12453888
[root@sw ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID 5pOoUm-LMP6-5xTo-tNEL-Eil5-QG1t-gq7u3S
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-11-10 20:44:13 -0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID pyHQFR-KUHQ-pC1R-JR06-yRpA-AzcJ-Yl9Tu5
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2016-11-10 20:44:13 -0800
LV Status available
# open 1
LV Size 47.51 GiB
Current LE 12162
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
Also,
[root@sw ~]# df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 48G 1.3G 47G 3% /
Shutdown and backup or snap the virtual host.
- fdisk
- lsblk
- pvdisplay
- vgdisplay
- lvdisplay
- vgs
- df
- du;
du -x <dirname> | sort -nr |more