The following examples treat the case of a traditionnal partitionning. If you use Logical Volume Manager (LVM) it will be as easy than this but I’ll describe it in an another post.
First, extend your block storage
In OCI dashboard, go to the instance where the volume block is attached (different from mounted !)
click Modify the volume block and increase the size in GB
validate
oracle gives the commands to be executed for a new scan of peripherics on Oracle Linux:
sudo dd iflag=direct if=/dev/oracleoci/oraclevd<paste device suffix here> of=/dev/null count=1
echo "1" | sudo tee /sys/class/block/`readlink /dev/oracleoci/oraclevd<paste device suffix here> | cut -d'/' -f 2`/device/rescan
But if you have another distro you can use traditionnal Linux command:
for i in $(ls /sys/class/scsi_host/ | awk -F 'host' '{print $2}'); do echo "- - -" > /sys/class/scsi_host/host$i/scan ; done
# This command force scan to verify the add of new peripherics
These commands (for Oracle Linux, or traditionnal Linux scan) allow you to see the new free space.
[root@instance-nicotest2 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 46.6G 0 disk
├─sda1 8:1 0 100M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 45.5G 0 part
├─ocivolume-root 252:0 0 35.5G 0 lvm /
└─ocivolume-oled 252:1 0 10G 0 lvm /var/oled
sdb 8:16 0 52G 0 disk
└─sdb1 8:17 0 50G 0 part /volumetest
we can see that after the scan, the block volume sdb is seen as a 52GB volume, but our partition /volumetest is still 50GB
Then we will modify the partition of the volume. Note here you can read a reminder about the identification of disks and partition (Peripherics naming). In our case the volume is identified by /dev/sdb
parted <volume_id>
[root@instance-nicotest2 ~]# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print all
Model: ORACLE BlockVolume (scsi)
Disk /dev/sdb: 55.8GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 53.7GB 53.7GB primary ext4
We can verify that there is free space unused:
(parted) print free
Model: ORACLE BlockVolume (scsi)
Disk /dev/sdb: 55.8GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1024B 1049kB 1048kB Free Space
1 1049kB 53.7GB 53.7GB primary ext4
53.7GB 55.8GB 2147MB Free Space
We see the start of the partition is not 0 but 1049kB, it’s normal this space is an offset made for the partition aligment. This offset was determined with the parameter ‘optimal’ passed to parted during the partition creation. It is the optimal offset to have better I/O performance (better I/O performance means partition alignment).
You can check the aligment:
(parted) align-check optimal 1
1 aligned
align-check: Determine whether the starting sector of partition n meets the disk’s selected alignment criteria. align-type must be ‘minimal’, ‘optimal’ or an abbreviation.
Our partition has a number that identified it (here number 1), and after the partition we see the free space that is not occupied by our partition.
Now it very important to change unit in order to precisely see the start of the partition (note the start, here it’s 2048s):
(parted) unit s
(parted) print
Model: ORACLE BlockVolume (scsi)
Disk /dev/sdb: 838860800s
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 2048s 54525951s 54523904s primary ext4
Now as we want resize our primary partition, to do this we remove the partition with parted:
(parted) rm 1
Error: Partition /dev/sdb1 is being used. You must unmount it before you modify it with parted.
(parted) quit
As you can see you can’t remove the primary partition because it’s mounted, it means it is used by our system.
[root@instance-nicotest2 ~]# umount /volumetest
Now we can do the job on the partition:
[root@instance-nicotest2 ~]# parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print all
Model: ORACLE BlockVolume (scsi)
Disk /dev/sdb: 55.8GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 53.7GB 53.7GB primary ext4
(parted) rm 1
(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? ext4
Start? 2048s
End? 100%
(parted) quit
Information: You may need to update /etc/fstab.
We remove our primary extension and then recreate it using the whole volume space (end=100%).
now we can mount again the file system:
[root@instance-nicotest2 ~]# mount /dev/sdb1 /volumetest
[root@instance-nicotest2 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 46.6G 0 disk
├─sda1 8:1 0 100M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 45.5G 0 part
├─ocivolume-root 252:0 0 35.5G 0 lvm /
└─ocivolume-oled 252:1 0 10G 0 lvm /var/oled
sdb 8:16 0 52G 0 disk
└─sdb1 8:17 0 50G 0 part /volumetest
As we can see earlier we have created a primary extension. The extended partition is /dev/sdb1.
The extended partition /dev/sdb1 still doesn’t use the whole space.
Before extending /dev/sdb1, we check/repair eventually filesystem errors on the extended partition.
For filesystem xfs:
[root@instance-nicotest2 ~]# xfs_repair /dev/sdb1
in our case, ext4:
[root@instance-nicotest2 ~]# e2fsck -f /dev/sdb1
e2fsck 1.45.6 (20-Mar-2020)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/sdb1: 13/3276800 files (0.0% non-contiguous), 284559/13106944 blocks
now we can mount again the file system:
[root@instance-nicotest2 ~]# mount /dev/sdb1 /volumetest
Then we can extend the filesystem.
For xfs:
[root@instance-nicotest2 ~]# xfs_growfs -d <directory_name>
in our case, for ext4 (and also for all ext* file system):
[root@instance-nicotest2 ~]# resize2fs /dev/sdb1
resize2fs 1.45.6 (20-Mar-2020)
Filesystem at /dev/sdb1 is mounted on /volumetest; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 7
The filesystem on /dev/sdb1 is now 13631232 (4k) blocks long.
[root@instance-nicotest2 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 46.6G 0 disk
├─sda1 8:1 0 100M 0 part /boot/efi
├─sda2 8:2 0 1G 0 part /boot
└─sda3 8:3 0 45.5G 0 part
├─ocivolume-root 252:0 0 35.5G 0 lvm /
└─ocivolume-oled 252:1 0 10G 0 lvm /var/oled
sdb 8:16 0 52G 0 disk
└─sdb1 8:17 0 52G 0 part /volumetest
[root@instance-nicotest2 ~]# df -lh
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.7G 0 4.7G 0% /dev
tmpfs 4.8G 0 4.8G 0% /dev/shm
tmpfs 4.8G 17M 4.8G 1% /run
tmpfs 4.8G 0 4.8G 0% /sys/fs/cgroup
/dev/mapper/ocivolume-root 36G 8.4G 28G 24% /
/dev/mapper/ocivolume-oled 10G 116M 9.9G 2% /var/oled
/dev/sda2 1014M 314M 701M 31% /boot
/dev/sda1 100M 5.1M 95M 6% /boot/efi
tmpfs 967M 0 967M 0% /run/user/0
tmpfs 967M 0 967M 0% /run/user/987
tmpfs 967M 0 967M 0% /run/user/1000
/dev/sdb1 51G 53M 49G 1% /volumetest
of course we don’t have lost any files.
We can check that there is no more free space available after the disk offset.
(parted) select /dev/sdb
Using /dev/sdb
(parted) print free
Model: ORACLE BlockVolume (scsi)
Disk /dev/sdb: 55.8GB
Sector size (logical/physical): 512B/4096B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1024B 1049kB 1048kB Free Space
1 1049kB 55.8GB 55.8GB primary ext4
(parted) quit
Leave a Reply