How To Resize Your Root Partion On EC2 Instance

aws_ec2

Step 1 : Run fdisk command with your partion_name.

# fdisk /dev/xvde

Note-: “xvde” is the partion name which will vary from machine to machine. So check before firing up the command

Step 2 : Now type p to list the number of partions created on machine.

Command (m for help): p

Disk /dev/xvde: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7a40d1f3

Device Boot         Start         End       Blocks      Id     System
/dev/xvde1               1          1045     8393931   83    Linux
/dev/xvde2            1046       1111      530145   82    Linux swap / Solaris

Step 3 : Now use d option delete both the  partions.

Command (m for help): d
Partition number (1-4): 1
Command (m for help): d
Partition number (1-4): 2

Step 4 : Now again pressto check whether the partions are deleted or not.

Command (m for help): p

Disk /dev/xvde: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7a40d1f3

Device Boot             Start         End      Blocks   Id  System

Step 5 : Now press n to create a new root partion.

Command (m for help): n

Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1): *Press Enter*
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): * Specify The Size For Root Partion *
Using default value 1305

Step 6: To commit the changes use w & fire the partprobe command to update partion table.

Command (m for help): w
The 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 or after you run partprobe(8) or kpartx(8)
Syncing disks.

[[email protected] ~]# partprobe
Warning: WARNING: the kernel failed to re-read the partition table on /dev/xvde (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.

Step 7: Now reboot your machine

# reboot

Step 8: Fire the below command to resize your root partion.

# resize2fs /dev/xvde1 size

Note-: You can increase your root partion size upto the size limit which you have specified while creating new root partion.

Step 9: Now verify the changes you can check by hitting the below command.

# df -h