Menu

Resize root EBS Volume on AWS Linux Instance

I have created a new CentOS Linux instance. I had selected 50GB of root volume during creating of instance but when system comes online it was showing only 8GB of disk is usable. I tried to resize root disk using resize2fs, I get the following message

root@e2c [~]# resize2fs /dev/xvda1 

The filesystem is already 16556731 blocks long.  Nothing to do!
So, I have following below steps and able to successfully resize volume to its ful size selected during instance creation

Step 1. Take Backups

We strongly recommended to take full backup (AMI) of your instance before doing any changes. Also create a snapshot of root disk.

Step 2. Check Current Partitioning

Now check the disk partitioning using following command. You can see that /dev/xvda is 53GB in size but
root@e2c[~]# df -h 

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       8G  3.7G   4.2G  45% /
tmpfs           1.8G     0  1.8G   0% /dev/shm
/usr/tmpDSK     485M  111M  349M  25% /tmp
root@e2c [~]# fdisk -l
Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00098461

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        1045     8387584   83  Linux

Step 3. Increase Size of Volume

Now start with the disk re partitioning using set of following commands. Execute all the commands carefully.
root@e2c[~]# fdisk /dev/xvda 
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Now change the display units to sectors using u switch.
Command (m for help): u 
Changing display/entry units to sectors
Now print the partition table to check for disk details
Command (m for help): p 

Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00098461

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048    16777215     8387584   83  Linux
Now delete the first partition using following command.
Command (m for help): d
Selected partition 1
Now create a new partition using following commands. For the first sector enter 2048 (as shows in above command output) and for last second just press enter to select all partition.
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (63-104857599, default 63): 2048 
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): [PRESS ENTER]
Using default value 104857599
Print the partition table again. You will see that new partition has occupied all disk space.
Command (m for help): p 

Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00098461

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048   104857599    52427776   83 Linux
Now set the bootable flag on partition 1.
Command (m for help): a 
Partition number (1-4): 1
Write disk partition permanently and exit.
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.
Lets reboot your system after making all above changes.
root@e2c [~]# reboot
Lets resize file system using resize2fs command. Remember that you are resizing filesystem not formatting.
root@e2c [~]# resize2fs /dev/xvda1 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 4
Performing an on-line resize of /dev/xvda1 to 13106944 (4k) blocks.
The filesystem on /dev/xvda1 is now 13106944 blocks long.

Step 4. Verify Upgraded Disk

At this point your root volume has been resized successfully. Just verify your disk has been resizes properly
root@e2c[~]# df -h 
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       50G  6.7G   40G  15% /
tmpfs           1.8G     0  1.8G   0% /dev/shm
/usr/tmpDSK     485M  111M  349M  25% /tmp
HackTheSec
HackTheSecTwitter
www.hackthesec.co.in

About Author:


I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Next
Newer Post
Previous
Older Post

0 comments:

Post a Comment

 
Top