In case if you want to ask kernel to "reread partition table", or update the size of specific partition to its actual size on Oracle Linux 6, these instructions could be helpful.
Let's say you have a machine with Oracle Linux 6, relatively new kernel 4.1.12-124.28.3.el6uek.x86_64, you just changed the size of your virtual disk, and now you're in situation that your /dev/sdc is 2.1 TiB but its own only MOUNTED partition sdc1 is 2 TiB, and you want to resize it to 2.1 TiB without unmounting it or rebooting. lsblk
will show you something like that:
sdc 8:32 0 2.1T 0 disk
`-sdc1 8:33 0 2T 0 part
What I've found is that there is no ready-to-use application that you can install from package repository to help you with the issue: all programs in repository are too old and in the best case they will rewrite your partition table to disk (it's still required), but will use BLKRRPART to notify kernel about changes that won't work with mounted/"busy" partitions.
What you can do instead is to build your own simple C program that will run newer BLKPG ioctl to do the trick. Fortunately, you don't need to write it from scratch: just download this C file, modify it, build and run:
wget https://raw.githubusercontent.com/gportay/blkpg-part/master/blkpg-part.c
sed -i 's/BLKPG_RESIZE_PARTITION/3/' blkpg-part.c
make blkpg-part
Why you need to replace BLKPG_RESIZE_PARTITION with hardcoded value 3? It's because Oracle Linux 6 ships with the old conservative UAPI that is not synchronized with actual Linux kernel API, and therefore BLKPG_RESIZE_PARTITION
constant from include/uapi/linux/blkkg.h is not available, even though the feature is present in kernel (you can check it by grepping the Linux kernel source code with BLKPG_RESIZE_PARTITION
).
Okay, so you have your blkpg-part
built, now you can check that it's working. Let's start with running it "dry-run": just ask it to resize the partition /dev/sdc1 with its own current size (reminder: the size of partition from kernel's point of view is still the "old" one, therefore /sys/class/block/sdc1/size will return the "old" size, not the one that is written in the new partition table):
./blkpg-part resize /dev/sdc 1 $(( $(cat /sys/class/block/sdc1/start) * 512 )) $(( $(cat /sys/class/block/sdc1/size) * 512 ))
If it runs without errors, it means that this userspace application succeeded with running BLKPG_RESIZE_PARTITION
and interacting with kernel; so, we are close to actually ask kernel to change the size of the partition.
Now you need to run blkpg-part with the new partition size in bytes that is written in the new partition table. parted /dev/sdc unit B print
can be used to identify the actual size of the partition, you'll get something like that:
Number Start End Size File system Name Flags
1 20480B 2254857813503B 2254857793024B primary lvm
So, the new size of partition is 2254857793024, and you can finally run this command below:
./blkpkg-part3 resize /dev/sdc 1 $(( $(cat /sys/class/block/sdc1/start) * 512 )) 2254857793024
Immediately after that kernel will update the state of the partition, and in lsblk you'll see:
sdc 8:32 0 2.1T 0 disk
`-sdc1 8:33 0 2.1T 0 part
Useful links:
man sfdisk
says:Since version 2.26 sfdisk no longer provides the -R or --re-read option to force the kernel to reread the partition table. Use blockdev --rereadpt instead.
mdadm --stop /dev/mdXX
is needed first?