This will allow you to extend your linux disk to grow its size. This is really helpful for Virtual Machines. You will have to reboot the VM at the end, but you don’t need a boot disk.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#fdisk /dev/sda Command (m for help): mCommand action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) |
Print out the partition table
1 2 3 4 5 6 7 |
Command (m for help): p Disk /dev/sda: 5218 MB, 5218304000 bytes 255 heads, 63 sectors/track, 634 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 634 5092573+ 83 Linux |
Delete the old partition /dev/sda and create a new one. MAKE SURE you use the SAME Start offset as the original!!! Otherwise, it will not boot.
1 2 3 4 5 6 7 8 9 10 11 12 |
Command (m for help): dSelected partition 1 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-634, default 1): Using default value 1 Last cylinder or +size or +sizeM or +sizeK (1-634, default 634): Using default value 634 |
Add the bootable flag if the partition you are resizing was bootable.
1 2 |
Command (m for help): a Partition number (1-4): 1 |
Write the partition table to disk.
1 2 3 4 5 6 7 8 |
Command (m for help): wThe partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. |
REBOOT NOW!
1 2 3 4 |
resize2fs /dev/xvda1 resize2fs 1.39 (29-May-2006) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required Performing an on-line resize of /dev/xvda1 to 1522150 (4k) blocks. The filesystem on /dev/xvda1 is now 1522150 blocks long. |