3

I want to resize EC2 EBS root volume, I tried to install e2fsprogs but it's still "not found". I'm using debian 8.

How do I install this application?

  • 3
    Are you running the command as root? It's under /sbin/resize2fs, so not in the user's path. – Faheem Mitha Apr 10 '17 at 5:17
  • Yes, I running as root. /sbin is not in PATH envinroment, so I can not run it. – Nguyen Tien Huy Apr 10 '17 at 8:52
  • I don't understand your problem. Please give more details about happens when you try to install e2fsprogs. Include the command you are using in your question, as well as the output of that command. – Faheem Mitha Apr 11 '17 at 4:02
  • The usual problem is su'ing without getting the right PATH. sudo usually does the expected thing. – Thomas Dickey Feb 24 '18 at 22:41
  • There's a fundamental misconception here, "/sbin is not in PATH envinroment, so I can not run it". Just use /sbin/resize2fs or add /sbin to your PATH with PATH="/sbin:$PATH". The PATH is a convenience not a restriction. – roaima Sep 10 '18 at 10:21
3

As mentioned in the comments, resize2fs may be located in sbin (that was also the case in my EC2 instance). You can either change your PATH, or cd /sbin then resize2fs. You can then resize your EC2 EBS root volume with resize2fs.

1

Paraphrasing from Matt Berther's "How to Resize AWS EC2 EBS Volumes"

Shrinking an EBS Volume

When you wish to shrink an EBS root volume, you will need to start a new, small EC2 instance that you can attach the volume you wish to resize. A t2.micro instance should be more than sufficient for this task. Once you have this instance created, proceed with the following steps.

  1. Always Prefer to take backup, stop your EC2 instance and take a snapshot.

  2. Create a new EBS volume that is the size you wish to shrink to

  3. Detach the volume you wish to resize from the current EC2 instance and attach both volumes to the new, small EC2 instance you created
    • Mount the old volume as /dev/sdf (this becomes /dev/xvdf)
    • Mount the new volume as /dev/sdg (this becomes /dev/xvdg)
  4. Power on the new, small instance and wait for it to come online
  5. SSH into the instance and run the following commands
  6. To ensure that the file system is in order, run sudo e2fsck -f /dev/xvdf1. If you're resizing a different partition on the drive, change the number 1 to the partition number you wish to resize.

  7. If the e2fsck command ran without errors, now run sudo resize2fs -M -p /dev/xvdf1. Again, change the 1 to the partition number you wish to resize if you're not resizing the first one.

  8. The last line from the resize2fs command should tell you how many 4k blocks the filesystem now is. To calculate the number of 16MB blocks you need, use the following formula: blockcount * 4 / (16 * 1024). Round this number up to give yourself a little buffer.

  9. If you dont yet have a partition on your new volume (/dev/xvdg1), use fdisk to create one.
  10. Execute the following command, using the number you came up with in the previous step.

    sudo dd bs=16M if=/dev/xvdf1 of=/dev/xvdg1 count=numberfrompreviousstep
    

    Depending on how large your volume is this may take several minutes to run -- let it finish.

  11. After the copy finishes, resize and check and make sure that everything is in order with the new filesystem by running

    sudo resize2fs -p /dev/xvdg1 && sudo e2fsck -f /dev/xvdg1
    
  12. After this step is complete, detach both volumes from the new instance you created. Attach the shrunken volume to the old EC2 instance as /dev/sda1 (your boot device) and restart your old instance. Save the previous, larger volume until you've validated that everything is working properly. When you've verified things are working well, feel free to delete the new EC2 instance you created, plus the larger volume and snapshot.

Expanding an EBS Volume

Expanding the size of an EBS volume is a bit easier, since we dont have to execute a disk-disk copy. To expand the size of the volume, execute the following steps:

  1. Please take EC2 instance and take a snapshot.

  2. Create a new EBS volume from the snapshot specifying the new, larger size

  3. Attach the new EBS volume to your existing EC2 instance, as /dev/sda1 if this is the root volume
  4. Power on your existing instance and wait for it to come online
  5. SSH into the instance and run the following commands
  6. To ensure that the file system is in order and run sudo e2fsck -f /dev/xvda1. If you're resizing a different partition on the drive, change the number 1 to the partition number you wish to resize.
  7. If the e2fsck command ran without errors, now run sudo resize2fs -p /dev/xvda1. Again, change the 1 to the partition number you wish to resize if you're not resizing the first one.
  8. Save the previous, smaller volume and the snapshot until you've validated that everything is working properly. When you've verified things are working well, feel free to delete the original volume and snapshot.

I hope these instructions were able to help you.

If you still just want to install e2fsprogs.. try below method its easy..

sudo apt-get install e2fsprogs

if you are not able to install from apt then try this link

  • Actually you don't need a second EC2 instance. I use lightsail which does not support attaching to other instances, so I had to write a little initramfs script to run resize2fs on the root before it was mounted, then reboot the instance. – psusi Mar 28 '18 at 16:48
  • sudo resize2fs would have been enough to fix the OP's PATH problem -- you didn't need to paste in the whole essay and slightly reword it. See How to reference material written by others. – JigglyNaga Oct 26 '18 at 7:29

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.