Preface
Quotation from OCI documentation:
"When you create a new virtual machine (VM) instance or bare metal instance based on an Oracle-provided image or custom image, you have the option of specifying a custom boot volume size. You can also expand the size of the boot volume for an existing instance; see Resizing a Volume for more information. In order to take advantage of the larger size, you need to extend the partition for the boot volume.“
Starting point
Why do I want to write it here? Because the most OCI users like any other cloud users are just the people that don’t want to poke around the special OS administrative tasks and prefer to use a virtual machine without tuning it. I also belong to this group of users. What I need is an article with clear and correct explanation how to solve my issue step by step. Here, I try to cover this goal.
I wanna to describe my experience with three general cases:
- OCI utility oci_growfs and disk with XFS filesystem;
- Utility resize2fs and disk with ext4 filesystem;
- disk using LVM and utility "xfs_growfs".
OCI instances uses XFS filesystem as the default. At least, I haven’t seen any other filesystems used for a boot volume if you don’t use a custom image as a boot volume. But the article named “Extending boot partition after export VM to OCI”. So why do I talk about XFS and the default filesystem used for a boot volume in OCI? Because it’s doesn’t matter. You can use any filesystems on your local VMs with any size but after export to OCI you will need to do the similar steps described in this article. And these three scenarios cover the most part of use cases in OCI:
- The example with the utility “oci_growfs” is the default approach which may be used for any standard OCI instances.
- The example with the utility “resize2fs” and disk with ext4 filesystem is the common use case because the ext4 filesystem is the default filesystem for the most Linux OSs.
- The example with disk using LVM is important due to the distinct structure of storage. The type of filesystem is less important here, but in the example the filesystem XFS is used. That's why the utility "xfs_growfs" is used here.
NB! I'm not going to dive into all the details related to LVM or XFS. I just show what I had in the beginning, what I did and what I got in the end.
Extending partition using utility oci-growfs
OCI documentation advises to use the utility oci-growfs to extend a boot partition - https://docs.oracle.com/en-us/iaas/Content/Compute/References/oci-growfs.htm#ocigrowfs
If your instance is a standard OCI instance it would be the easiest way. I did it and there were no problems with it. There was one obscure point regarding how the utility “fdisk” displayed partition information.
Initially, the instance had 150GB boot volume, but the “df -h” shown only 39GB, the SWAP partition wasn’t displayed but the SWAP size was 8GB. So, sum up, we have about 50GB used by the boot volume:
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7,6G 0 7,6G 0% /dev
tmpfs 7,6G 0 7,6G 0% /dev/shm
tmpfs 7,6G 41M 7,6G 1% /run
tmpfs 7,6G 0 7,6G 0% /sys/fs/cgroup
/dev/sda3 39G 3,2G 36G 9% /
/dev/sda1 200M 8,6M 192M 5% /boot/efi
tmpfs 1,6G 0 1,6G 0% /run/user/0
tmpfs 1,6G 0 1,6G 0% /run/user/994
tmpfs 1,6G 0 1,6G 0% /run/user/1000
What the “fdisk -l” shown:
$ sudo fdisk -l
Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk label type: dos
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sda1 1 97677311 48838655+ ee GPT
Partition 1 does not start on physical sector boundary.
The strange item here was that not all partitions were displayed and the sentence “Partition 1 does not start on physical sector boundary.” was in the output. I have no clear explanation for this. Ok, just try to continue, look what the filesystem type was on the /dev/sda3:
$ sudo file -L -s /dev/sda3
/dev/sda3: SGI XFS filesystem data (blksz 4096, inosz 256, v2 dirs)
It was the XFS filesystem which OCI uses for the standard instances.
Some initial information we have and now try to run the utility “oci-growfs”. This is the standard utility and it’s located in the folder “/usr/libexec”.
$ sudo /usr/libexec/oci-growfs
CHANGE: partition=3 start=17188864 old: size=80486400 end=97675264 new: size=297383902 end=314572766
Confirm? [y/n]y
CHANGED: partition=3 start=17188864 old: size=80486400 end=97675264 new: size=297383902 end=314572766
meta-data=/dev/sda3 isize=256 agcount=4, agsize=2515200 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=0 finobt=0, sparse=0, rmapbt=0
= reflink=0
data = bsize=4096 blocks=10060800, imaxpct=25
= sunit=0 swidth=0 blks
naming = version 2 bsize=4096 ascii-ci=0, ftype=1
log = internal log bsize=4096 blocks=4912, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime = none extsz=4096 blocks=0, rtextents=0
data blocks changed from 10060800 to 37172987
The result looked good. The size changed - “data blocks changed from 10060800 to 37172987”.
Let’s look what we have:
$ sudo fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disk label type: gpt
Disk identifier: B1BAD63A-5E10-47EF-93D1-57E1A5BC89CB
# Start End Size Type Name
1 2048 411647 200M EFI System EFI System Partition
2 411648 17188863 8G Linux swap
3 17188864 314572765 141,8G Microsoft basic
Firstly, you may notice that all partitions were displayed and there weren’t the sentence “Partition 1 does not start on physical sector boundary”. It means the utility fixed some minor error with the sectors boundary.
Secondly, the odd item that the partition 3 was shown as “Microsoft basic”. Some explanation can be found here – http://www.rodsbooks.com/linux-fs-code. Briefly, It’s not the real problem which user should bother.
Look what the “df -h” and “lsblk” show:
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7,6G 0 7,6G 0% /dev
tmpfs 7,6G 0 7,6G 0% /dev/shm
tmpfs 7,6G 41M 7,6G 1% /run
tmpfs 7,6G 0 7,6G 0% /sys/fs/cgroup
/dev/sda3 142G 3,2G 139G 3% /
/dev/sda1 200M 8,6M 192M 5% /boot/efi
tmpfs 1,6G 0 1,6G 0% /run/user/0
tmpfs 1,6G 0 1,6G 0% /run/user/994
tmpfs 1,6G 0 1,6G 0% /run/user/1000
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 150G 0 disk
├─sda2 8:2 0 8G 0 part [SWAP]
├─sda3 8:3 0 141,8G 0 part /
└─sda1 8:1 0 200M 0 part /boot/efi
Both utilities display the actual information about the root filesystem with the correct size.
NB! There is no need to unmount the extended partition or SWAP partition or reboot the instance. It’s important in some cases.
Extending partition using utility resize2fs
In this case there was a standard disk 50GB with ext4 filesystem which was needed to extend. SWAP partition existed too, but here it followed the root partition. And the chain of actions is different and little bit harder because it’s needed to turn off swap feature temporary and delete SWAP partition to combine free space with the partition containing the root filesystem.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
|-sda1 8:1 0 7G 0 part /<-7GB, but 50GB in reality
`-sda2 8:2 0 1G 0 part [SWAP]
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 15G 0 15G 0% /dev
tmpfs 15G 0 15G 0% /dev/shm
tmpfs 15G 8.5M 15G 1% /run
tmpfs 15G 0 15G 0% /sys/fs/cgroup
/dev/sda1 6.9G 6.8G 0 100% /<-7GB, but 50GB in reality
tmpfs 3.0G 0 3.0G 0% /run/user/1000
Initial information
Using utility Parted
Getting information about the partitions sizes and free space. Run Parted, convert displaying size from “bytes” to “sectors”
$ sudo parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit s
(parted) print free
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 104857600s
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
2s 2047s 2046s Free Space
1 2048s 14680063s 14678016s primary ext4 boot
2 14680064s 16777215s 2097152s primary linux-swap(v1)
16777216s 104857599s 88080384s Free Space
It’s seen that the Free Space occupies 88080384 sectors.
Using utility fdisk
$ sudo fdisk -l
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: dos
Disk identifier: 0xc352c342
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 14680063 14678016 7G 83 Linux
/dev/sda2 14680064 16777215 2097152 1G 82 Linux swap / Solaris
It’s seen that the whole size of disk /dev/sda is 50GB.
Turn off swap
To use the available free space we need to turn off the swap.
$ sudo swapoff -a
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
|-sda1 8:1 0 7G 0 part
`-sda2 8:2 0 1G 0 part
It’s seen that the “lsblk” doesn’t mark /dev/sda2 as SWAP partition.
Using fdisk
Display free space on the disk
$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): F
Unpartitioned space /dev/sda: 42 GiB, 45097156608 bytes, 88080384 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
Start End Sectors Size
16777216 104857599 88080384 42G
Display information about partitions
Information about /dev/sda2
Command (m for help): i
Partition number (1,2, default 2): 2
Device: /dev/sda2
Start: 14680064
End: 16777215
Sectors: 2097152
Cylinders: 4113
Size: 1G
Id: 82
Type: Linux swap / Solaris
Start-C/H/S: 1023/254/2
End-C/H/S: 1023/254/2
Information about /dev/sda1
Command (m for help): i
Partition number (1,2, default 2): 1
Device: /dev/sda1
Boot: *
Start: 2048
End: 14680063
Sectors: 14678016
Cylinders: 28781
Size: 7G
Id: 83
Type: Linux
Start-C/H/S: 4/4/1
End-C/H/S: 1023/254/2
Attrs: 80
Deletion partitions
Now we are ready to delete partitions.
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
We deleted both partitions, not only SWAP partition.
General information now:
Command (m for help): p
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
Disklabel type: dos
Disk identifier: 0xc352c342
There are no any partitions.
Now we are ready to create 2 new partitions – first primary partition (48GB) and second SWAP partition (2 GB).
Creation new primary partition with size 48GB
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048-104857599, default 104857599):
+48G
Created a new partition 1 of type 'Linux' and of size 48 GiB.
Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: n
It’s possible to set the size in GB not in sectors. Here “+48G” is the size of new primary partition.
Mark partition 1 as bootable
Command (m for help): a
Selected partition 1
The bootable flag on partition 1 is enabled now.
Creation partition 2 with size 2GB
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (100665344-104857599, default 100665344):
Last sector, +sectors or +size{K,M,G,T,P} (100665344-104857599, default 104857599):
Created a new partition 2 of type 'Linux' and of size 2 GiB.
Mark partition 2 as SWAP
Command (m for help): t
Partition number (1,2, default 2): 2
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'.
Save settings and exit
Command (m for help): w
The partition table has been altered.
Syncing disks.
Disk extension without unmounting and rebooting
After creation new partitions with 48GB and 2GB the system still hasn’t seen the changes. The standard approach is to reboot the system. But we’ll try to avoid this step because the Linux starting from 2.6 kernel supports on-line resize for filesystems mounted using ext3 and ext4.
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 15G 0 15G 0% /dev
tmpfs 15G 0 15G 0% /dev/shm
tmpfs 15G 8.5M 15G 1% /run
tmpfs 15G 0 15G 0% /sys/fs/cgroup
/dev/sda1 6.9G 6.8G 0 100% / <---still 7GB
tmpfs 3.0G 0 3.0G 0% /run/user/1000
The “df -h” still displays /dev/sda1 wit the size 7GB.
Run partprobe
From partprobe documentation:”partprobe is a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.”. This quote explains all about this utility. Nothing to add.
$ partprobe
The partprobe doesn’t issue any messages in the case of success.
Run resize2fs
Run the command “sudo resize2fs /dev/sda1”. Our root filesystem has still mounted on /dev/sda1. Our goal here is to expand the root filesystem on the whole partition /dev/sda1.
$ sudo resize2fs /dev/sda1
resize2fs 1.45.4 (23-Sep-2019)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 6
The filesystem on /dev/sda1 is now 12582912 (4k) blocks long.
All looks good – no warnings, cautions, errors.
Mount back swap
The partition /dev/sda2 is used as the swap partition again.
Run the command “sudo mkswap /dev/sda2”:
$ sudo mkswap /dev/sda2
Setting up swapspace version 1, size = 2 GiB (2146430976 bytes)
no label, UUID=7e3edc09-b016-4a72-a8d2-f5f374874ad6
Remembering the UUID of new partitions
Run the command “lsblk -o +uuid”:
$ lsblk -o +uuid,name
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT UUID
sda 8:0 0 50G 0 disk
|-sda1 8:1 0 48G 0 part /
e8c76f86-3ec5-4cf6-b3c2-d19d5cd53e21
`-sda2 8:2 0 2G 0 part [SWAP]
7e3edc09-b016-4a72-a8d2-f5f374874ad6
Updating UUIDs in /etc/fstab
To keep the changes after rebooting we are going to update the file /etc/fstab. Update the UUIDs for the appropriate mount points.
$ cat /etc/fstab
UUID=
e8c76f86-3ec5-4cf6-b3c2-d19d5cd53e21 / ext4 defaults 1 1
UUID=
7e3edc09-b016-4a72-a8d2-f5f374874ad6 swap swap defaults 0 0
Turn on swap
$ sudo swapon -a
The final results
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 15G 0 15G 0% /dev
tmpfs 15G 0 15G 0% /dev/shm
tmpfs 15G 8.5M 15G 1% /run
tmpfs 15G 0 15G 0% /sys/fs/cgroup
/dev/sda1 48G 6.9G 39G 16% / <------the correct size 48GB
tmpfs 3.0G 0 3.0G 0% /run/user/1000
The size of the partition /dev/sda1 is correct and occupies 48GB.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
|-sda1 8:1 0 48G 0 part /
`-sda2 8:2 0 2G 0 part
[SWAP]
The partition /dev/sda2 marked as SWAP.
Extending partition using LVM
Initially it was a boot disk with 100GB size. But the command “df -h” displayed only 30GB size:
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 145M 32G 1% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/ocivolume-root 30G 14G 16G 46% / <--30GB, but 100GB in reality
/dev/mapper/ocivolume-oled 10G 143M 9.9G 2% /var/oled
/dev/sda2 1014M 409M 606M 41% /boot
/dev/sda1 100M 5.7M 95M 6% /boot/efi
tmpfs 6.3G 0 6.3G 0% /run/user/988
/dev/sdb 1007G 5.7G 951G 1% /mnt/data
tmpfs 6.3G 0 6.3G 0% /run/user/1000
Which partitions are used by LVM? The command “lsblk” says us about it:
$ lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
|-sda1 vfat E347-11BF /boot/efi
|-sda2 xfs c4e0f271-8199-48e8-b520-dea2c4de655b /boot
`-sda3
LVM2_member lUcAyE-ZeQe-pZj5-0Zf8-LcSt-TEfV-msghca
|-ocivolume-root xfs a71d0599-3867-4163-9dff-d61a44b36407 /
`-ocivolume-oled xfs 626b14d7-fb2f-4678-8a16-64deca22d002 /var/oled
The formatting isn't ideal but it's seen that the partition sda3 is under LVM control. So we will work with the disk /dev/sda below.
Using the utility Parted
Run Parted
$ sudo parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Warning: Not all of the space available to /dev/sda appears to be used, you can fix the GPT to use all of the space (an extra 112037888 blocks) or continue with the current setting?
Fix/Ignore? f
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 106MB 105MB fat16 EFI System Partition boot, esp
2 106MB 1180MB 1074MB xfs
3 1180MB 43.1GB 41.9GB lvm
We see that /dev/sda has the size 107GB. Again if we sum the values from the column “Size” it’s clear that the half part of disk isn’t used (41.9GB + 1074MB + 105MB isn’t equal 107GB).
Converting the size from bytes to sectors
Using dimension “sectors” instead of “bytes” is more convenient for our task because much easy in calculation.
(parted) unit s
(parted) print
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 209715200s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 2048s 206847s 204800s fat16 EFI System Partition boot, esp
2 206848s 2303999s 2097152s xfs
3 2304000s 84223999s 81920000s lvm
Display the free space
(parted) print free
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 209715200s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 2048s 206847s 204800s fat16 EFI System Partition boot, esp
2 206848s 2303999s 2097152s xfs
3 2304000s 84223999s 81920000s lvm
84224000s 209715166s 125491167s Free Space
You notice that now we observe a new line in the end containing the words “Free space”. It’s exactly those unused space which we are going to join to the original partition 3.
Deletion LVM partition
To combine the partition 3 and free space it ‘s needed to delete the partition 3 at first. It's not the join in reality, we’ll create new partition that span all free space on the disk.
(parted) rm 3
Error: Partition(s) 3 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.
Print free space
(parted) print free
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 209715200s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 2048s 206847s 204800s fat16 EFI System Partition boot, esp
2 206848s 2303999s 2097152s xfs
2304000s 209715166s 207411167s Free Space
Now the Free Space has size 207411167 sectors.
Also you see the error message, but you can skip it for now. The error is correct but it’s mostly a caution than error for us. Later you’ll see that there is a way to avoid the step with rebooting.
Creation new partition
We are going to create new partition which spans all free space on the partition and filesystem is XFS because the original filesystem is also XFS. To achieve this we use the start position which we got from the Parted “print free” in the chapter above. As the end position we use 100% that informs Parted that all available free space should be used.
(parted) mkpart
Partition name? []?
File system type? [ext2]? xfs
Start? 2304000s
End? 100%
Look what we got:
(parted) print free
Model: ORACLE BlockVolume (scsi)
Disk /dev/sda: 209715200s
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 2048s 206847s 204800s fat16 EFI System Partition boot, esp
2 206848s 2303999s 2097152s xfs
3 2304000s 209713151s 207409152s xfs
209713152s 209715166s 2015s Free Space
We can see that the third partition was created and the size is 207409152 sectors. And Free Space occupies only 2015 sectors.
And that’s all what we do with the utility Parted. Next part is about some special aspects regarding unmounting filesystem and the utility xfs_repair.
Using xfs_repair and trying to unmount a root filesystem
Somewhere in Oracle documentation or in some Oracle blogs, I don’t remember exactly, there was a recommendation to use the utility “xfs_repair” to check a partition with XFS filesystem. My apologies, but I can’t find this article at moment. All I remember that it was the recommendation to use “xfs_repair” before “xfs_growfs”. When I executed this command I saw the following errors:
$ sudo xfs_repair /dev/mapper/ocivolume-root
xfs_repair: /dev/mapper/ocivolume-root contains a mounted filesystem
xfs_repair: /dev/mapper/ocivolume-root contains a mounted and writable filesystem
Of course, there is some logic in the message. Ok, why don't try to unmount? It was impossible to unmount the filesystem:
$ sudo umount -f /dev/mapper/ocivolume-root /
umount: /: target is busy.
This also does matter of course. The root filesystem is used for now and can't be unmounted.
Finally, the command "xfs_growfs -d /" did nothing:
$ sudo xfs_growfs -d /
meta-data=/dev/mapper/ocivolume-root isize=512 agcount=4, agsize=1904384 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=7617536, imaxpct=25
= sunit=0 swidth=0 blks
naming = version 2 bsize=4096 ascii-ci=0, ftype=1
log = internal log bsize=4096 blocks=3719, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime = none extsz=4096 blocks=0, rtextents=0
data size unchanged, skipping
"data size unchanged, skipping" - this happened because LVM in action and to extend the partitions the LVM utlilties “pvs”, “pvresize”, “lvextend” must be used.
Using the utilities pvresize и lvextend
Run the utility “pvs” to display information about physical volumes:
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ocivolume lvm2 a-- <39.06g 0
Extend physical volume
Our physical volume is /dev/sda3. Run the command “sudo pvresize /dev/sda3”:
$ sudo pvresize /dev/sda3
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
Look what has been changed:
$ sudo pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 ocivolume lvm2 a-- <98.90g <59.84g
It's seen that the physical size is 98.9GB and free size is 59.84GB now. After physical volume we are going to extend logical volume.
Extend logical volume
Run the command “sudo lvextend -l +100%FREE /dev/mapper/ocivolume-root”:
$ sudo lvextend -l +100%FREE /dev/mapper/ocivolume-root
Size of logical volume ocivolume/root changed from <29.06 GiB (7439 extents) to <88.90 GiB (22758 extents).
Logical volume ocivolume/root successfully resized.
the argument "+100%FREE" says that all free space should be occupied. The output says that the logical volume has been resized successfully and it's size has grown up to 88.9GB.
Look what has been changed:
$ df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 8.6M 32G 1% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/mapper/ocivolume-root 30G 6.7G 23G 23% / <-still 30GB
/dev/sda2 1014M 409M 606M 41% /boot
/dev/mapper/ocivolume-oled 10G 142M 9.9G 2% /var/oled
/dev/sda1 100M 5.7M 95M 6% /boot/efi
tmpfs 6.3G 0 6.3G 0% /run/user/988
tmpfs 6.3G 0 6.3G 0% /run/user/1000
But the “df -h” has still shown nothing changes. The partition /dev/mapper/ocivolume-root has the old size 30GB.
Using the utility xfs_growfs
And now after the operations with LVM utilities we are ready to execute the command “xfs_growfs” as the last step:
$ sudo xfs_growfs /
meta-data=/dev/mapper/ocivolume-root isize=512 agcount=4, agsize=1904384 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=7617536, imaxpct=25
= sunit=0 swidth=0 blks
naming = version 2 bsize=4096 ascii-ci=0, ftype=1
log = internal log bsize=4096 blocks=3719, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime = none extsz=4096 blocks=0, rtextents=0
data blocks changed from 7617536 to 23304192
All look good and correct.
Final results:
$ df -hT | grep mapper
/dev/mapper/ocivolume-root xfs 89G 7.1G 82G 8% / <---------- now 89GB
/dev/mapper/ocivolume-oled xfs 10G 142M 9.9G 2% /var/oled
NB! There is no need to mount/unmount the partitions or reboot the system to apply the changes in case of using XFS filesystem.
The LVM partition /dev/mapper/ocivolume-root has new size 89GB. It's what we expected.
Afterword
There is a lot of information in the internet regarding resizing a boot partition on the different types of filesystems. This post isn't the final point. Here i described the 3 most common scenarios (as i suppose) which user runs into in the life. Apart from that i shown the output for all commands which were used in the article. I guess it should help users to understand what to expect in case of successful command.
https://blogs.oracle.com/virtualization/extending-boot-partition-after-export-virtualbox-vm-to-oci