Skip to main content

VM - Resize a .vdi disk

I created a VM with 10G disk, after the Linux 7 installation, and the first upgrade, decided was better to increase the disk to 50GB.

This post , i'm sharing the steps and commands I ran to increase the disk size.

Software :
Host : Windows 10 Pro , Oracle VM 6.1.2
Guest : Red Hat Enterprise Linux Server release 7.1 (Maipo) / Oracle Linux Server release 7.1

Ok - the first step is to resize the *vdi disk on the host side.

Open a PowerShell console in the VM folder (Left Shift + Mouse Right Click on Windows)







Quick list and check on the files.


PS D:\VMs\OracleLinux7_MSSQL> ls
Directory: D:\VMs\OracleLinux7_MSSQL

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 09/02/2020 18:40 Logs
-a---- 09/02/2020 18:41 5689 OracleLinux7_MSSQL.vbox
-a---- 09/02/2020 18:41 5688 OracleLinux7_MSSQL.vbox-prev
-a---- 09/02/2020 18:40 9268363264 OracleLinux7_MSSQL.vdi

PS D:\VMs\OracleLinux7_MSSQL> VBoxManage.exe | Select-string show

showvminfo <uuid|vmname> [--details]
showvminfo <uuid|vmname> --log <idx>
showmediuminfo [disk|dvd|floppy] <uuid|filename>
VBoxManage snapshot <uuid|vmname> showvminfo <snapshot-name>
VBoxManage debugvm <uuid|vmname> show [--human-readable | --sh-export | --sh-eval | --cmd-set] [settings-item...]
VBoxManage cloudprofile <--provider=name> <--profile=name> show

PS D:\VMs\OracleLinux7_MSSQL> VBoxManage.exe showmediuminfo .\OracleLinux7_MSSQL.vdi
UUID: 817eacdb-0bf2-4c9b-87de-e7c449996e72
Parent UUID: base
State: locked write
Type: normal (base)
Location: D:\VMs\OracleLinux7_MSSQL\OracleLinux7_MSSQL.vdi
Storage format: VDI
Format variant: dynamic default
Capacity: 10240 MBytes
Size on disk: 8839 MBytes
Encryption: disabled
Property: AllocationBlockSize=1048576
In use by VMs: OracleLinux7_MSSQL (UUID: c247ec24-5f12-42be-9a68-21794947491b)




Ok - the *vdi disk, is done using : VBoxManage.exe modifymedium

With the VM down, ran the commands , make a copy then resize to about 52GB.


PS D:\VMs\OracleLinux7_MSSQL> copy OracleLinux7_MSSQL.vdi OracleLinux7_MSSQL.vdi.backup
PS D:\VMs\OracleLinux7_MSSQL> VBoxManage.exe | Select-string medium

closemedium [disk|dvd|floppy] <uuid|filename>
[--medium none|emptydrive|additions|
showmediuminfo [disk|dvd|floppy] <uuid|filename>
createmedium [disk|dvd|floppy] --filename <filename>
modifymedium [disk|dvd|floppy] <uuid|filename>
clonemedium [disk|dvd|floppy] <uuid|inputfile> <uuid|outputfile>
mediumproperty [disk|dvd|floppy] set <uuid|filename>
encryptmedium <uuid|filename>
checkmediumpwd <uuid|filename>
Medium content access:
VBoxManage mediumio <--disk=uuid|filename | --dvd=uuid|filename | --floppy=uuid|filename>
VBoxManage mediumio <--disk=uuid|filename | --dvd=uuid|filename | --floppy=uuid|filename>
VBoxManage mediumio <--disk=uuid|filename | --dvd=uuid|filename | --floppy=uuid|filename>

PS D:\VMs\OracleLinux7_MSSQL> VBoxManage.exe modifymedium .\OracleLinux7_MSSQL.vdi --resize 50000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

PS D:\VMs\OracleLinux7_MSSQL> VBoxManage.exe showmediuminfo .\OracleLinux7_MSSQL.vdi
UUID: 817eacdb-0bf2-4c9b-87de-e7c449996e72
Parent UUID: base
State: locked write
Type: normal (base)
Location: D:\VMs\OracleLinux7_MSSQL\OracleLinux7_MSSQL.vdi
Storage format: VDI
Format variant: dynamic default
Capacity: 50000 MBytes
Size on disk: 8839 MBytes
Encryption: disabled
Property: AllocationBlockSize=1048576
In use by VMs: OracleLinux7_MSSQL (UUID: c247ec24-5f12-42be-9a68-21794947491b)

After running the command we can see capacity is now about 50GB

Capacity: 50000 MBytes
Size on disk: 8839 MBytes


Now inside the VM guest, the file system stills with old size, the df anf fdisk shows as below


[root@localhost ~]# df -h 
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ol-root 8.5G 8.4G 87M 100% /
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 148K 1.4G 1% /dev/shm
tmpfs 1.4G 8.8M 1.4G 1% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/sda1 497M 149M 349M 30% /boot


[root@localhost ~]# fdisk -l

Disk /dev/sda: 52.4 GB, 52428800000 bytes, 102400000 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: 0x0002d820

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 20971519 9972736 8e Linux LVM

Disk /dev/mapper/ol-root: 9093 MB, 9093251072 bytes, 17760256 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 /dev/mapper/ol-swap: 1073 MB, 1073741824 bytes, 2097152 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

I followed the approach :


1- recreate the partition /dev/sda2.


[root@Unknown-08-00-27-5f-5c-3e ~]# fdisk /dev/sda
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): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition\'s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): p

Disk /dev/sda: 52.4 GB, 52428800000 bytes, 102400000 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: 0x0002d820

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 20971519 9972736 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):
Using default response p
Partition number (2-4, default 2):
First sector (1026048-102399999, default 1026048):
Using default value 1026048
Last sector, +sectors or +size{K,M,G} (1026048-102399999, default 102399999):
Using default value 102399999
Partition 2 of type Linux and of size 48.3 GiB is set

Command (m for help): p

Disk /dev/sda: 52.4 GB, 52428800000 bytes, 102400000 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: 0x0002d820

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 102399999 50686976 83 Linux

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/sda: 52.4 GB, 52428800000 bytes, 102400000 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: 0x0002d820

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 102399999 50686976 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.

Reboot and ckeck again,
OK: /dev/sda2 1026048 102399999 50686976 8e Linux LVM

The filesystem remains with old size.
KO: /dev/mapper/ol-root 8.5G 8.4G 87M 100% /


[root@localhost ~]# disk -l 

Disk /dev/sda: 52.4 GB, 52428800000 bytes, 102400000 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: 0x0002d820

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 102399999 50686976 8e Linux LVM

Disk /dev/mapper/ol-root: 9093 MB, 9093251072 bytes, 17760256 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 /dev/mapper/ol-swap: 1073 MB, 1073741824 bytes, 2097152 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


[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ol-root 8.5G 8.4G 87M 100% /
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 92K 1.4G 1% /dev/shm
tmpfs 1.4G 8.8M 1.4G 1% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/sda1 497M 149M 349M 30% /boot

By default the guest OS is using LVM,
we will need to resize the physical volume, with pvresize

[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 ol lvm2 a-- 9.51g 40.00m

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

[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 ol lvm2 a-- 48.34g 38.87g

[root@localhost ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name ol
PV Size 48.34 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 12374
Free PE 9950
Allocated PE 2424
PV UUID 9ywHVe-AHYJ-QTQ0-sc10-DNPy-xuel-398B14

Then the Logical volume, with lvextend


[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/ol/swap
LV Name swap
VG Name ol
LV UUID jbeaWF-6sbs-YGzQ-cd02-GFS5-FY0r-1QsTzn
LV Write Access read/write
LV Creation host, time localhost, 2018-09-14 09:56:00 +0100
LV Status available
# open 2
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:1

--- Logical volume ---
LV Path /dev/ol/root
LV Name root
VG Name ol
LV UUID 5jSQc1-iJC4-EFAb-cdTr-vHAK-4fjn-2yGJ0q
LV Write Access read/write
LV Creation host, time localhost, 2018-09-14 09:56:02 +0100
LV Status available
# open 1
LV Size 8.47 GiB
Current LE 2168
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0

[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/ol-root
Size of logical volume ol/root changed from 8.47 GiB (2168 extents) to 47.34 GiB (12118 extents).
Logical volume root successfully resized

[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/ol/swap
LV Name swap
VG Name ol
LV UUID jbeaWF-6sbs-YGzQ-cd02-GFS5-FY0r-1QsTzn
LV Write Access read/write
LV Creation host, time localhost, 2018-09-14 09:56:00 +0100
LV Status available
# open 2
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:1

--- Logical volume ---
LV Path /dev/ol/root
LV Name root
VG Name ol
LV UUID 5jSQc1-iJC4-EFAb-cdTr-vHAK-4fjn-2yGJ0q
LV Write Access read/write
LV Creation host, time localhost, 2018-09-14 09:56:02 +0100
LV Status available
# open 1
LV Size 47.34 GiB
Current LE 12118
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:0

Then extend the filesystem with : xfs_growfs


[root@localhost ~]# xfs_growfs /dev/mapper/ol-root
meta-data=/dev/mapper/ol-root isize=256 agcount=4, agsize=555008 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=2220032, 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 2220032 to 12408832

[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/ol-root 48G 8.4G 39G 18% /
devtmpfs 1.4G 0 1.4G 0% /dev
tmpfs 1.4G 148K 1.4G 1% /dev/shm
tmpfs 1.4G 8.8M 1.4G 1% /run
tmpfs 1.4G 0 1.4G 0% /sys/fs/cgroup
/dev/sda1 497M 149M 349M 30% /boot




Just a quick check on the host , remained the same.

Capacity: 50000 MBytes
Size on disk: 8839 MBytes





PS D:\VMs\OracleLinux7_MSSQL>  VBoxManage.exe showmediuminfo .\OracleLinux7_MSSQL.vdi
UUID: 817eacdb-0bf2-4c9b-87de-e7c449996e72
Parent UUID: base
State: locked write
Type: normal (base)
Location: D:\VMs\OracleLinux7_MSSQL\OracleLinux7_MSSQL.vdi
Storage format: VDI
Format variant: dynamic default
Capacity: 50000 MBytes
Size on disk: 8839 MBytes
Encryption: disabled
Property: AllocationBlockSize=1048576
In use by VMs: OracleLinux7_MSSQL (UUID: c247ec24-5f12-42be-9a68-21794947491b)




More about this:
VBoxManage.exe
LVM ADMINISTRATION






Thank you for reading, hope this post was helpful.
Rogerio


Comments

Popular posts from this blog

DB - How to monitor Oracle datapump jobs

These days there is lot of work around database migrations not only but mainly to cloud providers. One of the ways to migrate Oracle databases is using data pump (expdp/impdp). In general works fine, it allows an easy way to bring the database even different OS. It is always good to monitor the progress, to know where we are and estimate how long we are from the end. In this post, I am sharing some queries to help with database monitoring progress. The queries can be easily tailed to various scenarios. Starting with a simple one - the track the number of objects loaded during an import operation. When there is a massive amount of errors during the import. Drop and run the import again. The bellow query can be useful also to monitor the number of objects if we are dropping the users. Here, I’m making the assumption there were no other database activity in progress on the last 24 hours. select owner, count(0) from dba_objects where owner in ( select username from dba_users where created...

VM - Partilhar Pastas Windows - Linux

Neste post escrevo como partilhar pastas entre Windows (Host) e uma VM Guest, neste caso Linux. Ha algumas formas de fazer isto, esta parece me a mais facil. Seleccionar a Pasta Windows Na consola Virtual Box > Devices > Shared Folder Seleccionar a pasta windows para partilhar no Linux   O   Montar a pasta Windows na VM Ha duas opcoes : 1) Reiniciar a VM (Auto-mount) 2) Linha de comando [root@host ~]# mkdir -p /u01/stage/win_ebs_sw [root@host ~]# chmod 777 /u01/stage/win_ebs_sw [root@host ~]# mount -t vboxsf Oracle_EBS /u01/stage/win_ebs_sw/ [root@host ~]# ls /u01/stage/win_ebs_sw ebs_weblogic_webtier [root@host ~]# df -h /u01/stage/win_ebs_sw Filesystem Size Used Avail Use% Mounted on Oracle_EBS 895G 494G 401G 56% /u01/stage/win_ebs_sw Guardar a Configuracao no /etc/fstab para tornar as alteracoes permanentes. [root@host ~]# echo "Oracle_EBS /u01/stage/win_ebs_sw vboxsf defaults 0 0" >> /etc/fstab [root@host ~]# cat /etc/fstab # /etc/...

DB – How to monitor Oracle database long ops ?

As DBAs, some questions we are often asked and to be fair we ask ourselfs when we are doing massive operations, are : Is the database doing something? How long the database takes to complete the task? There a data dictionary view, GV$SESSION_LONGOPS whom is really usefull for monitoring and to provide estimated time to get the task done. Starting with a first example, a query for general propose . set lines 240 col message form a100 col opname form a50 select * from ( select round(l.sofar/l.totalwork*100,2) as complete, --l.* l.sid, --l.opname, l.message, l.start_time, l.time_remaining/60 "minuts remaining", l.elapsed_seconds from gv$session_longops l where totalwork !=0 ) where complete < 100; The view is also usefull on specific operations such as Oracle Recovery Manager (RMAN) jobs monitoring, this query returns information about backup,restore and recovery. select sid, serial#,opname, context, sofar, totalwork, round(sofar/totalwork*100,2) "%_complet...