简体   繁体   中英

How to change AWS EBS volume filesystem type

EBS volume was attached as ext4 on /opt/apps . There are currently no data on it. How to change filesystem type to xfs and assign a new mount point to /data ?

[centos@ip-10-24-xx-xxx ~]$ df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/xvda1     xfs       8.0G  1.4G  6.7G  17% /
devtmpfs       devtmpfs  7.3G     0  7.3G   0% /dev
tmpfs          tmpfs     7.2G     0  7.2G   0% /dev/shm
tmpfs          tmpfs     7.2G   17M  7.2G   1% /run
tmpfs          tmpfs     7.2G     0  7.2G   0% /sys/fs/cgroup
/dev/xvdb      ext4       99G   61M   94G   1% /opt/apps
tmpfs          tmpfs     1.5G     0  1.5G   0% /run/user/1000

This is not specific to AWS EBS. Amazon gives you a "disk" called EBS, attached to /dev/xvdb. Then, feel free to mount it anywhere (/opt/apps, or /data) and format it with the filesystem you want.

This page can help you http://ask.xmodulo.com/create-mount-xfs-file-system-linux.html

See you have two options to achieve your use case.

You can either convert your root volume to XFS or create a second volume. Personally, I would favour the latter as it offers more flexibility.

Option 1: Convert Root Volume to XFS

  1. Stop your instance (not terminate) (let's call it instance A)
  2. Start a new instance (let's call it instance B)
  3. Detach the root volume from instance A and attach it to instance B
  4. Create a second EBS volume, attach it to instance B
  5. Format the new EBS volume as XFS (install xfsprogs if not already done)
  6. Copy all the data from the first volume to the new one (eg using rsync -aHAXxSP /source /target )
  7. Detach the new volume from instance B and attach it as the root volume of instance A
  8. Start instance A
  9. Terminate instance B (the original root volume should persist, keep it around until things work to your liking).

The reason for attaching the root volume to another instance is to attain consistency, which would be difficult with the volume in use.

Option 2: Move data to a second EBS volume

  1. Create a second EBS volume and attach it to your instance; format it as XFS and mount it
  2. Identify which directories you wish to move to the new volume (some to consider include: /var/log, /var/lib/mysql, /var/www, /var/spool/mail, /var/vmail)
  3. Stop as many services as possible to remove write locks
  4. Use lsof | grep /path/to/dir lsof | grep /path/to/dir to check for remaining write locks
  5. Move the directory to the new EBS volume
  6. Mount bind the new directory to its old location (ie mount -o bind /mnt/path/to/dir /orig/path/to/dir )
  7. Repeat for each directory
  8. Start your services to ensure all is working
  9. Edit your /etc/fstab file to make the mount points permanent; eg: /mnt/path/to/dir /orig/path/to/dir bind defaults,noatime,bind 0 0

Restart to ensure everything persists and functions as it should. You may also want to consider shrinking your root volume down a bit since, hopefully, it shouldn't be growing (or changing) much with all the data removed from it.

(As a point of mention, it may be possible to freeze an ext4 file system using fsfreeze , which is included in util-linux-ng ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM