I'm running an EC2 instance in AWS with 12 GB volume attached to it. The OS is Ubuntu. I want to create a partition of 2GB from this 12GB volume.

So, here is the output of sudo fdisk -l:

$ sudo fdisk -l 
Disk /dev/xvda: 12 GiB, 12884901888 bytes, 25165824 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x89cdb65f

Device       Boot   Start        End     Sectors    Size    Id    Type
/dev/xvda1   *       2048   25165790    25163743     12G    83    Linux

How to create a partition without deleting the OS? To be exact how to create a partition from xvda1 and how to decide first and last sector values?

  • Please don't post images of text, if you can just copy and paste the terminal output. – Hunter.S.Thompson Jan 31 '18 at 9:58
  • Run fdisk /dev/xvda and then select the option to create a new partition. – Raman Sailopal Jan 31 '18 at 10:01
  • Hi Raman, when i try to create a new partition using fdisk /dev/xvda i get "To create more partitions, first replace a primary with an extended partition." – Masud Shaik Jan 31 '18 at 10:28
  • How to decide first and last sector ? – Masud Shaik Jan 31 '18 at 10:36
  • The first sector of the new partition remains the same (so enter 2048 when prompted). fdisk allows you to specify the size in MB/GB/etc and automatically calculates the last sector based on the specified size. – mjturner Feb 2 '18 at 6:46

As the discussion has shown, there isn’t an easy way to shrink the root file system of a running system (resize2fs doesn’t support it). You have two options:

  1. If the VM can’t be restarted, you’ll need to do an online resize (see, for example, this answer).
  2. If the VM can be restarted and can have a period of downtime for the resize, the better approach is to take a snapshot of the EBS volume, mount it on another VM and use that VM to resize it. There is a good guide in this answer.

Regarding your question about the first and last sectors - the first sector of partition 1 remains 2048 (ie enter 2048 when prompted) and fdisk will calculate the last sector number based on the partition size you enter (eg, if you specify a partition size of 2GiB it will calculate the last sector automatically for you).

As others have suggested, having a single partition per EBS volume does make management easier, so you may want to take the opportunity to do that while you’re at it (ie, shrink the root EBS volume to 2GiB and add a second one of 10GiB instead of having a single partitioned volume).


All space available in your volume /dev/xvda is already used up by partition /dev/xvda1.

If a filesystem (and data) exists on the volume, but unused space is available at the end of the file system, first shrink the file system using resize2fs <device> <size>, e.g. resize2fs /dev/xvda 2G.

Then use fdisk to reduce end of partition /dev/xvda1 to match the new size of the file system placed on this partition (here: reduce by 2G).

Now you can create a new partition, e.g. /dev/xvda2, using the free space at the end of the volume.

Start of the second partition will be end of the first partition + 1.

End of the second partition depends on your needs, e.g. the number of available sectors (here: 25165824).

Note: In a virtualized environment, I recommend placing only one disk partition per disk device/volume. This makes later changes much easier, e.g. if file system/disk partition must get increased for any reason.

  • I tried to run "resize2fs /dev/xvda 2G" but got the error message " esize2fs 1.42.13 (17-May-2015) resize2fs: Device or resource busy while trying to open /dev/xvda Couldn't find valid filesystem superblock." – Masud Shaik Jan 31 '18 at 23:42
  • @MasudShaik As the filesytem is on the partition, you need to use /dev/xvda1 and not /dev/xvda when calling resize2fs. Can you try that and let us know the results. – mjturner Feb 1 '18 at 10:41
  • @mjturner I tried to resize the /dev/xvda1, Got the message "resize2fs 1.42.13 (17-May-2015) Filesystem at /dev/xvda1 is mounted on /; on-line resizing required resize2fs: On-line shrinking not supported " – Masud Shaik Feb 2 '18 at 1:55
  • Ah yes - I had forgotten that resize2fs doesn’t support online shrinking. There are ways to work around it but they are risky - see this answer. – mjturner Feb 2 '18 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.