我正在尝试将几个卷安装到我的实例上,它们都是 NVME。我读到 NVME 卷不会保持它们的映射相同,每次随机给它们序列号。关键是我需要保持映射一致,它用于一个 db 和 1 个卷假设保留数据。现在,如果我重新启动实例,卷就会混淆,因此具有数据的卷可能会挂载到不同的目录,因此 db 服务启动并且找不到任何数据。
当然,它也会在创建图像之后发生,所以我无法配置 1 个实例并使用图像进行更多操作。
如何强制映射保持一致?还是停止使用 NVME?(我读到这个随机序列化只发生在 NVME 上)
我正在尝试将几个卷安装到我的实例上,它们都是 NVME。我读到 NVME 卷不会保持它们的映射相同,每次随机给它们序列号。关键是我需要保持映射一致,它用于一个 db 和 1 个卷假设保留数据。现在,如果我重新启动实例,卷就会混淆,因此具有数据的卷可能会挂载到不同的目录,因此 db 服务启动并且找不到任何数据。
当然,它也会在创建图像之后发生,所以我无法配置 1 个实例并使用图像进行更多操作。
如何强制映射保持一致?还是停止使用 NVME?(我读到这个随机序列化只发生在 NVME 上)
You need to use device UUID
. See my example below.
I have 3 disks, 8 GB, 10 GB and 12 GB.
They show as device nvme0n1
(8 GB), nvme1n1
(10 GB) and 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
.
Also a file on disk of size 12 GB called /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.
$ 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.
$ 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).
Now: nvme0n1
(8 GB), nvme1n1
(12 GB) and 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
. Also any time you generate an AMI or snapshot, the UUID
is the same, as it belongs to filesystem, not to EBS volume.