In vitualization world, sometime, when you create a VM, you assign certain amount of disk space and then you realize that you need more. Resizing a partition is not a easy task, especially is boot partition, you have to reboot the machine to take effect. This memories will take me through some basically step to help me resize linux partition online/offline (this step apply for both Centos and Ubuntu).
Before go through the guidance, let talk a bit to make clear my concept about Linux disk, there include 3 type of disk(or partition) will be mention in this document is physical disk, underlying partition and parttion. Physical disk is the this that we attach to the server (hard disk), underlying partition is just a partition that occupies a whole physical disk (ext: /dev/sda), and partition is a parted disk (/dev/sda1; /dev/sda2).
First, on hypervisor layer, try to extend the physical disk and check by fdisk -l, we should see the disk has ready to extend the partition.
Please NOTE,
1) We can not extend root disk on-line, this will not take effect after we reboot the server. So just extend the physical disk and reboot the server (on Centos, resize2fs is automatically run after boot, otherwise we have to run resize2fs manually with Ubuntu).
2) resize2fs or grow_xfs utilities, as their document, can extend partition without un-mount it, but after test, i realize it can be only done when we using underlying partition. Not effect to other partition.
For offline re-size: (resize partition such as /dev/sda1, /dev/sda2)
In this example, partition will be resized using ext4 format, first, umount the partition and check for error and disable journal as well.
The next step will be stress you up with delete partition steps, we have to delete the partition which we want to extend the capacity, don't worry, we are not going to lose the data, this step just make sure the partition table is updated with new size
Now, recheck the partition and resize it
We almost done here, re-enable something that we throw away from our first step
Now, the partition is ready to mount and use.
For online re-size: (resize underlying partition /dev/sda)
Just run command:
No comments:
Post a Comment