1

I am having an EBS volume of 50 GB and I want to decrease it to 20 GB. The OS is centos 7 and has XFS file system. I have followed this link but it is more specific to ext4 and Ubuntu, can someone tell me how to proceed for XFS file system type

  • I wonder if doing it in two steps would work: 1) reduce the file system size 2) Reduce the EBS volume size. You can create a copy of your current volume and try that out before you do it on a production volume. – Tim Jan 23 '18 at 08:09

2 Answers2

1

You may be able to change the XFS file system size, but you cannot decrease the size of an EBS volume.

You will need to create a new EBS volume, attach it to your instance, create a file system on the new EBS volume and then copy (migrate) the files from the old EBS volume to the new EBS volume.

John Hanley
  • 4,754
  • 1
  • 11
  • 21
  • 1
    I already did that and I used `rsync` to copy files from source to destination. But when I attach the volume as new volume and reboot it the instance is not starting – Venkata S S Krishna Manikeswar Jan 23 '18 at 10:14
  • There are many steps involved in creating a bootable file system. Rsync does not support this type of file system copy. You will need to use a tool that supports migrating operating systems. – John Hanley Feb 04 '18 at 14:33
0

Here are (not really basic) but instructions on how to do this:

  1. Spin up an ec2 instance that will be your "Dupe" Server. a mX.large should be sufficient. Once you can connect to it, shut it down as you will need to mount some volumes.
  2. Create an EBS volume that will be the "New" volume. I suggest labeling both new and old volumes in the AWS console.
  3. Shut down the EC2 instance "TooBig" that you want to shrink. Hopefully you can do without it for 5-10 minutes. Depending on your volume size, it shouldn't take longer than that.
  4. Detach volume "Old" from "TooBig".
  5. Attach volume "Old" to "Dupe"
  6. Attach volume "New" to "Dupe".
  7. Start "Dupe". You will need to check that the volumes are mounted in this order. If not you'll have to modify the attached script.

-> /dev/nvme0n1p1 (this is your "Dupe" boot partition)

-> /dev/nvme1n1p1 (this should be your "Old" EBS)

-> /dev/nvme2n1p1 (this should be your "New" EBS)

Run blkid to get all your block IDs. You will need to add them to below script.

"blkidold" is the block id of your "Old" EBS.

#!/bin/bash

fdisk /dev/nvme2n1
sleep 1
mkfs.xfs /dev/nvme2n1p1
mount -o ro /dev/nvme1n1p1 /mnt/nvme1n1p1
mount /dev/nvme2n1p1 /mnt/nvme2n1p1
xfsdump -l0 -J - /mnt/nvme1n1p1 | xfsrestore -J - /mnt/nvme2n1p1
umount /mnt/*
xfs_admin -U blkidold /dev/nvme1n1p1
xfs_admin -U blkidold /dev/nvme2n1p1
chroot / grub2-install /dev/nvme2n1
  1. Stop Dupe. Detach "Old" and "New"
  2. Attach "New" to "TooBig"

You should be good to go.

Jacob S
  • 1
  • 1