How to resize root partition in a running Oracle Linux Instance in OCI
Partition |
OCI Linux instances boot volume (BV) comes installed with classic Partitions. There Cloud be scenarios where we need to extend the root partitions. We will discuus about this (extend root Parttition ) in this article.
In OCI linux instances root file system is on partition "sda3" by default. The boot volume size of OCI is 46.6 GB. The partition available to root ( / ) became ~39 GB post OS installation. So we need to extend this partition.
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 46.6G 0 disk
├─sda2 8:2 0 8G 0 part [SWAP]
├─sda3 8:3 0 38.4G 0 part / >>>>>>>>>>>>>
└─sda1 8:1 0 200M 0 part /boot/efi
Solution:
To resize the root partition on OCI linux Instances, we need to do the following:
1. On cloud UI, stop the instance. (Optional, I've done it in a running OL7 system)
2. Detach the boot volume. (Optional, I've done it in a Attched boot volume in OL7 system)
3. Edit the boot volume to a new size which needs to be bigger value than the current one.
4. Attach the boot volume back.
5. Start the instance.
If you are doing itk Online resize then you need rescan the device tree.
# echo "c t l" > /sys/class/scsi_host/host[n]/scan
Where,
n -- Host bus number.
Or run the commad as displayed on OCI console for rescan.
sudo dd iflag=direct if=/dev/oracleoci/oraclevda of=/dev/null count=1
echo "1" | sudo tee /sys/class/block/`readlink /dev/oracleoci/oraclevda | cut -d'/' -f 2`/device/rescan
OCI disk Rescan |
By default, cloud-utils-growpart package is enabled on Oracle Linux RPM. You can check it by:
-On Oracle Linux 7:
# rpm -qa |grep growpart
cloud-utils-growpart-0.29-2.el7.noarch
-On Oracle Linux 6:
# rpm -qa |grep grow
cloud-utils-growpart-0.27-9.el6.x86_64
If it hasn't been installed, you can install it via:
6. Grow the root volume size to the customized size.
For Oracle Linux 7, there are two ways:
a. Resize via below commands:
$ sudo su
# growpart /dev/sda 3
CHANGED: disk=/dev/sda partition=3: start=17188864 old: size=80486399,end=97675263 new: size=108640222,end=125829086
# For XFS file system
# xfs_growfs /
meta-data=/dev/sda3 isize=256 agcount=4, agsize=2515200 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=0 finobt=0 spinodes=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 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 13580027
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 60G 0 disk
├─sda2 8:2 0 8G 0 part [SWAP]
├─sda3 8:3 0 51.8G 0 part / >>>>>>>>>>>>>>>>>>>>> it is extended to a new size
└─sda1 8:1 0 200M 0 part /boot/efi
# For ext4 file system you can use following command to extentd the file system.
# resize2fs /dev/sda3
b. Alternatively for OL7, we can modify the cloud.cfg file. This method will take effect after another reboot.
# cat /etc/cloud/cloud.cfg |grep grow
===============
# The growpart module is disabled by default. To enable automatic boot volume resizing, uncomment
# the below entry for '- growpart' and reboot. All the dependent packages for the growpart
# module to work such as cloud-utils-growpart and gdisk are already included in the image.
#- growpart >>>>>>
===============
Un-comment growpart entry from /etc/cloud/cloud.cfg and change it to:
# cat /etc/cloud/cloud.cfg |grep grow
==============
# The growpart module is disabled by default. To enable automatic boot volume resizing, uncomment
# the below entry for '- growpart' and reboot. All the dependent packages for the growpart
# module to work such as cloud-utils-growpart and gdisk are already included in the image.
- growpart >>>>>>
Reboot the instance to have the cloud-init's growpart module automatically resize the boot volume. This will cost an extra reboot.
For Oracle Linux 6, there are also two ways and both require a reboot:
a. Use below commands:
# sudo growpart /dev/sda 3
# sudo reboot
# sudo resize2fs /dev/sda3
# sudo reboot
b. Or uncomment the '#- growpart' entry from /etc/cloud/cloud.cfg and reboot
If you choose umcomment '#- growpart entry method for OL7 or OL6 above, please consider to comment it out after you make the change.
No comments