简体   繁体   English

重启后 AWS NVME 挂载到不同的目录

[英]AWS NVME mounted to different directory after reboot

I'm trying to mount a few volumes to my instance and they are all NVME.我正在尝试将一些卷安装到我的实例中,它们都是 NVME。 I read that NVME volumes don't keeping their mapping the same, each time they are given serialized numbers randomly.我读到 NVME 卷不会保持它们的映射相同,每次它们都随机获得序列号。 The point is I need to keep the mapping consistent, it's for a db and 1 of the volumes suppose to keep the data.关键是我需要保持映射一致,它用于一个 db 和 1 个假设要保留数据的卷。 Now if I reboot the instance the volumes get mixed up, so it's possible that the volume that has the data will be mounted to a different directory and hence the db service starts and doesn't find any data.现在,如果我重新启动实例,卷会混淆,因此具有数据的卷可能会安装到不同的目录,因此数据库服务启动并且找不到任何数据。

Of course it happens also after creating an image, so I can't configure 1 instance and the spin up more using an image.当然,它也会在创建图像后发生,所以我不能使用图像配置 1 个实例和更多的旋转。

How can I force the mapping to be consistent?如何强制映射保持一致? or stop using NVME?还是停止使用 NVME? (I read this random serialization happens only with NVME) (我读到这个随机序列化只发生在 NVME 中)

You need to use device UUID .您需要使用设备UUID See my example below.请参阅下面的示例。

I have 3 disks, 8 GB, 10 GB and 12 GB.我有 3 个磁盘,8 GB、10 GB 和 12 GB。
They show as device nvme0n1 (8 GB), nvme1n1 (10 GB) and nvme2n1 (12 GB).它们显示为设备nvme0n1 (8 GB)、 nvme1n1 (10 GB) 和nvme2n1 (12 GB)。

$ lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1       259:0    0  10G  0 disk
└─nvme1n1p1   259:6    0  10G  0 part /mnt/disk10
nvme2n1       259:1    0  12G  0 disk
└─nvme2n1p1   259:7    0  12G  0 part /mnt/disk12
nvme0n1       259:2    0   8G  0 disk
├─nvme0n1p1   259:3    0   8G  0 part /
└─nvme0n1p128 259:4    0   1M  0 part

Look that I have a file on disk of size 10 GB called /mnt/disk10/file10.txt .看看我在磁盘上有一个大小为 10 GB 的文件,名为/mnt/disk10/file10.txt
Also a file on disk of size 12 GB called /mnt/disk12/file12.txt .还有一个大小为 12 GB 的磁盘文件,名为/mnt/disk12/file12.txt

$ ls -l /mnt/*
/mnt/disk10:
total 0
-rw-r--r-- 1 root root 0 May  9 00:37 file10.txt

/mnt/disk12:
total 0
-rw-r--r-- 1 root root 0 May  9 00:38 file12.txt

My fstab file use UUID to refer those disks, as you can see below.我的fstab文件使用UUID来引用这些磁盘,如下所示。

$ cat /etc/fstab
# Disk 8 GB
UUID=7b355c6b-f82b-4810-94b9-4f3af651f629     /           xfs    defaults,noatime  1   1
# Disk 10 GB
UUID=2b19004b-795f-4da3-b220-d531c7cde1dc     /mnt/disk10           xfs    defaults,noatime  0   0
# Disk 12 GB
UUID=1b18a2f2-f48f-4977-adf8-aa483e1fa91f     /mnt/disk12           xfs    defaults,noatime  0   0

If you want to know what is the UUID for each device, use blkid , as you can see below.如果您想知道每个设备的UUID是什么,请使用blkid ,如下所示。

$ blkid
/dev/nvme1n1: PTUUID="2e6aaa33" PTTYPE="dos"
/dev/nvme1n1p1: UUID="2b19004b-795f-4da3-b220-d531c7cde1dc" TYPE="xfs" PARTUUID="2e6aaa33-01"
/dev/nvme2n1: PTUUID="10565c83" PTTYPE="dos"
/dev/nvme2n1p1: UUID="1b18a2f2-f48f-4977-adf8-aa483e1fa91f" TYPE="xfs" PARTUUID="10565c83-01"
/dev/nvme0n1: PTUUID="1760802e-28df-44e2-b0e0-d1964f72a39e" PTTYPE="gpt"
/dev/nvme0n1p1: LABEL="/" UUID="7b355c6b-f82b-4810-94b9-4f3af651f629" TYPE="xfs" PARTLABEL="Linux" PARTUUID="a5dcc974-1013-4ea3-9942-1ac147266613"
/dev/nvme0n1p128: PARTLABEL="BIOS Boot Partition" PARTUUID="dc255fff-03c6-40e6-a8dc-054ec864a155"

Now I will stop my machine, force change device order and start it again.现在我将停止我的机器,强制更改设备顺序并重新启动它。
Look how the disk changes the device name, but they are still being mounted on the same path, with the same files on it.看看磁盘如何更改设备名称,但它们仍然安装在相同的路径上,上面有相同的文件。

Before: nvme0n1 (8 GB), nvme1n1 (10 GB) and nvme2n1 (12 GB).之前: nvme0n1 (8 GB)、 nvme1n1 (10 GB) 和nvme2n1 (12 GB)。
Now: nvme0n1 (8 GB), nvme1n1 (12 GB) and nvme2n1 (10 GB).现在: nvme0n1 (8 GB)、 nvme1n1 (12 GB) 和nvme2n1 (10 GB)。

$ lsblk
NAME          MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme1n1       259:0    0  12G  0 disk
└─nvme1n1p1   259:1    0  12G  0 part /mnt/disk12
nvme2n1       259:2    0  10G  0 disk
└─nvme2n1p1   259:3    0  10G  0 part /mnt/disk10
nvme0n1       259:4    0   8G  0 disk
├─nvme0n1p1   259:5    0   8G  0 part /
└─nvme0n1p128 259:6    0   1M  0 part

$ ls -l /mnt/*
/mnt/disk10:
total 0
-rw-r--r-- 1 root root 0 May  9 00:37 file10.txt

/mnt/disk12:
total 0
-rw-r--r-- 1 root root 0 May  9 00:38 file12.txt

UUID is an attribute from filesystem, so any time you create an filesystem it will generate an UUID . UUID是文件系统的一个属性,因此无论何时创建文件系统,它都会生成一个UUID Also any time you generate an AMI or snapshot, the UUID is the same, as it belongs to filesystem, not to EBS volume.此外,无论何时生成 AMI 或快照, UUID都是相同的,因为它属于文件系统,而不是 EBS 卷。

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

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