First off, I'm an absolute newbie in Linux, but I've been tasked to automate the process of resizing a partition on RHEL 6.5. The server resides as a virtual machine in VMWare, and we are trying to orchestrate an activity whereby an existing VMDK file is expanded and the partitions on that VMDK resize automatically.
As a test case, the VMDK is seen on the system as /dev/sdb. The size of this is say 5GB. Now, I have 2 partitions on it, /dev/sdb1, /dev/sdb2, sdb1 taking up 1GB and sdb2 taking up 5GB
If someone now increases the size of the VMDK from 5GB to 10GB and specifies that the extra space should go to /dev/sdb1, how can I do that? So far I've managed to create a process whereby the last partition can be resized without a problem (i.e. /dev/sdb2) but any previous ones can't because of Starting and Ending block numbers.
My process is as follows:
1) Increase the VMDK size 2) Run echo "1" > /sys/class/scsi_device/0:0:0:0/device/rescan to pick up the resized drive 3) Using fdisk, delete the partition and recreate it
This works fine if the partition being modified is the last partition, but if its the first or second, then the partition just gets recreated the way it was. Is there some tool which can do this intelligently?
This is the fdisk output in my environment:
Disk /dev/sdb: 10.7 GB, 10737418240 bytes 67 heads, 62 sectors/track, 5048 cylinders Units = cylinders of 4154 * 512 = 2126848 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xf3405e93 Device Boot Start End Blocks Id System /dev/sdb1 1 510 1059239 83 Linux /dev/sdb2 511 2524 4183078 83 Linux
As you can see, sdb1 takes up 1GB and SDB2 takes up 4GB, but there is about 5GB "free" on the disk. Now, how do I change this so that sdb1 takes up that remaining space? If I delete sdb1 and recreate it, it makes the same partition. I can easily create a new partition to occupy that space, or even change sdb2 to take up the remainder space (just delete sdb2 and recreate it using fdisk), but the question is how do I modify sdb1 to take up that space?
Hope my question is clear, and thanks in advance