简体   繁体   English

重新启动后 AWS EC2 实例存储消失

[英]AWS EC2 Instance store is disappeared after rebooting

I've launch EC2 instance (i3en.xlarge) from my other AMI, then mount 2 EBS volume with one of them is root device .我已经从我的另一个 AMI 启动了 EC2 实例 (i3en.xlarge),然后安装了 2 个 EBS 卷,其中一个是root device After accident reboot my EC2 instance, its Instance Store was DISAPPEARED .意外重启我的 EC2 实例后,它的Instance StoreDISAPPEARED I can't find it by lsblk or `df -Th.我无法通过lsblk或 `df -Th 找到它。

I understand that data in the instance store will lost when accidently reboot.我知道实例存储中的数据会在意外重启时丢失。 However, It was totally DISAPPEARED .然而,它完全消失了

ubuntu@ip-10-0-0-10:~$ lsblk -p
NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
/dev/loop0         7:0    0 28.1M  1 loop /snap/amazon-ssm-agent/2012
/dev/loop1         7:1    0   18M  1 loop /snap/amazon-ssm-agent/1566
/dev/loop2         7:2    0 97.1M  1 loop /snap/core/9993
/dev/loop3         7:3    0 96.6M  1 loop /snap/core/9804
/dev/nvme0n1     259:0    0  500G  0 disk /data-2
/dev/nvme1n1     259:1    0  500G  0 disk 
└─/dev/nvme1n1p1 259:2    0  500G  0 part /


ubuntu@ip-10-0-0-10:~$ df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs   16G     0   16G   0% /dev
tmpfs          tmpfs     3.1G  896K  3.1G   1% /run
/dev/nvme1n1p1 ext4      485G  358G  128G  74% /
tmpfs          tmpfs      16G   36K   16G   1% /dev/shm
tmpfs          tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs          tmpfs      16G     0   16G   0% /sys/fs/cgroup
/dev/loop0     squashfs   29M   29M     0 100% /snap/amazon-ssm-agent/2012
/dev/loop1     squashfs   18M   18M     0 100% /snap/amazon-ssm-agent/1566
/dev/loop2     squashfs   98M   98M     0 100% /snap/core/9993
/dev/loop3     squashfs   97M   97M     0 100% /snap/core/9804
/dev/nvme0n1   ext4      492G   62G  405G  14% /data-2
tmpfs          tmpfs     3.1G     0  3.1G   0% /run/user/111
tmpfs          tmpfs     3.1G     0  3.1G   0% /run/user/1001
tmpfs          tmpfs     3.1G     0  3.1G   0% /run/user/1000

I just tried to reproduce your situation with an i3en instance.我只是试图用 i3en 实例重现你的情况。

I mounted an instance store volume following directions from Add instance store volumes to your EC2 instance - Amazon Elastic Compute Cloud :我按照从将实例存储卷添加到您的 EC2 实例 - Amazon Elastic Compute Cloud 中的说明安装了一个实例存储卷:

sudo mkfs -t xfs /dev/nvme1n1
sudo mkdir /data
sudo mount /dev/nvme1n1 /data

I then put a file in the /data directory and rebooted.然后我将一个文件放在/data目录中并重新启动。

Guess what... it disappeared too!你猜怎么着……它也消失了!

But then I noticed that the volume was not mounted.但是后来我注意到该卷没有安装。

I ran this command again:我再次运行这个命令:

sudo mount /dev/nvme1n1 /data

and the volume reappeared.并且音量重新出现。

If you want a mounted volume to remain after a reboot, use fstab .如果您希望重新启动后保留已安装的卷,请使用fstab

See: Making an Amazon EBS volume available for use on Linux - Amazon Elastic Compute Cloud请参阅: 使 Amazon EBS 卷可用于 Linux - Amazon Elastic Compute Cloud

(Not enough reputation to comment) (没有足够的声誉发表评论)

Note that John's answer will work if you simply reboot (as in the actual question).请注意,如果您只是重新启动(如在实际问题中),John 的回答将起作用。 That is because the ephemeral disk will remain formatted but no longer be mounted.这是因为临时磁盘将保持格式化但不再安装。

However, if you stop and start the instance, then you will get new hardware and the ephemeral disk will no longer be formatted.但是,如果您停止并启动实例,那么您将获得新硬件并且将不再格式化临时磁盘。 You will need to add a start script to the User Data to format / mount the disk etc every start.您需要在用户数据中添加一个启动脚本,以在每次启动时格式化/挂载磁盘等。

See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html But you need to run on every start not just on Launch.请参阅https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html但是您需要在每次启动时运行,而不仅仅是在启动时运行。 So also see https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/所以也请参阅https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/

Altogether you want to add something like this as User Data:总而言之,您要添加这样的内容作为用户数据:

Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0

--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
cloud_final_modules:
- [scripts-user, always]

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"

#!/bin/bash
mkfs -t xfs /dev/nvme1n1
mount /dev/nvme1n1 /tmp
chmod 777 /tmp

--//--

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

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