简体   繁体   English

如何更改AWS EBS卷文件系统类型

[英]How to change AWS EBS volume filesystem type

EBS volume was attached as ext4 on /opt/apps . EBS卷作为ext4附加在/opt/apps There are currently no data on it. 当前没有任何数据。 How to change filesystem type to xfs and assign a new mount point to /data ? 如何将文件系统类型更改为xfs并为/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. 这并非特定于AWS EBS。 Amazon gives you a "disk" called EBS, attached to /dev/xvdb. Amazon为您提供了一个称为EBS的“磁盘”,该磁盘附加到/ dev / xvdb。 Then, feel free to mount it anywhere (/opt/apps, or /data) and format it with the filesystem you want. 然后,随时将其挂载到任何位置(/ opt / apps或/ data),并使用所需的文件系统对其进行格式化。

This page can help you http://ask.xmodulo.com/create-mount-xfs-file-system-linux.html 此页面可以帮助您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. 您可以将根卷转换为XFS或创建第二个卷。 Personally, I would favour the latter as it offers more flexibility. 就个人而言,我更喜欢后者,因为它提供了更大的灵活性。

Option 1: Convert Root Volume to XFS 选项1:将根卷转换为XFS

  1. Stop your instance (not terminate) (let's call it instance A) 停止实例(不终止)(我们称其为实例A)
  2. Start a new instance (let's call it instance B) 启动一个新实例(我们称其为实例B)
  3. Detach the root volume from instance A and attach it to instance B 从实例A分离根卷并将其附加到实例B
  4. Create a second EBS volume, attach it to instance B 创建第二个EBS卷,将其附加到实例B
  5. Format the new EBS volume as XFS (install xfsprogs if not already done) 将新的EBS卷格式化为XFS(如果尚未安装,请安装xfsprogs
  6. Copy all the data from the first volume to the new one (eg using rsync -aHAXxSP /source /target ) 将所有数据从第一个卷复制到新的卷(例如,使用rsync -aHAXxSP /source /target
  7. Detach the new volume from instance B and attach it as the root volume of instance A 从实例B分离新卷,并将其作为实例A的根卷附加
  8. Start instance A 启动实例A
  9. Terminate instance B (the original root volume should persist, keep it around until things work to your liking). 终止实例B(原始根卷应保持不变,一直保留直到您满意为止)。

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 选项2:将数据移至第二个EBS卷

  1. Create a second EBS volume and attach it to your instance; 创建第二个EBS卷并将其附加到您的实例; format it as XFS and mount it 将其格式化为XFS并挂载
  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) 确定要移至新卷的目录(要考虑的目录包括:/ 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 lsof | grep /path/to/dir to check for remaining write locks lsof | grep /path/to/dir检查剩余的写锁
  5. Move the directory to the new EBS volume 将目录移到新的EBS卷
  6. Mount bind the new directory to its old location (ie mount -o bind /mnt/path/to/dir /orig/path/to/dir ) 安装将新目录绑定到其旧位置(即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; 编辑/etc/fstab文件以使挂载点永久存在; eg: /mnt/path/to/dir /orig/path/to/dir bind defaults,noatime,bind 0 0 例如: /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 ). (需要指出的是,有可能使用util-linux-ng包含的fsfreeze冻结ext4文件系统)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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