今天保险丝烧断,关闭了一个小型服务器。
这台服务器有一个 USB-HDD 连接到它,但自从我大约 3-4 个月前连接它以来,我从未完全关闭服务器(没有电),只是偶尔发出一个sudo reboot
.
这个 USB-HDD 列在下面/dev/sdc
,所以我有一个通过sudo mount /dev/sdc1 /media/hdd5-usb-1
.
在 处还有一个挂载的 SSD /dev/sdb
,所以正确的fdisk -l
样子如下
Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000ece66
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 500117503 499615746 238.2G 5 Extended
/dev/sda5 501760 500117503 499615744 238.2G 8e Linux LVM
Disk /dev/sdb: 477 GiB, 512110190592 bytes, 1000215216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: CD3F3DA1-2901-45A0-B6E9-2BEEA36F3E78
Device Start End Sectors Size Type
/dev/sdb1 2048 1000214527 1000212480 477G Linux filesystem
Disk /dev/mapper/n3150--vg-root: 222.4 GiB, 238769143808 bytes, 466345984 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/n3150--vg-swap_1: 15.9 GiB, 17028874240 bytes, 33259520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdc: 4.6 TiB, 5000981077504 bytes, 9767541167 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes
Disklabel type: gpt
Disk identifier: 0B9E1A83-476F-47AE-8234-2D29497F55CA
Device Start End Sectors Size Type
/dev/sdc1 2048 9767541133 9767539086 4.6T Linux filesystem
在断电和服务器自动启动后,条目如下所示:
Disk /dev/sda: 4.6 TiB, 5000981077504 bytes, 9767541167 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 33553920 bytes
Disklabel type: gpt
Disk identifier: 0B9E1A83-476F-47AE-8234-2D29497F55CA
Device Start End Sectors Size Type
/dev/sda1 2048 9767541133 9767539086 4.6T Linux filesystem
Disk /dev/sdb: 238.5 GiB, 256060514304 bytes, 500118192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x000ece66
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 499711 497664 243M 83 Linux
/dev/sdb2 501758 500117503 499615746 238.2G 5 Extended
/dev/sdb5 501760 500117503 499615744 238.2G 8e Linux LVM
Disk /dev/sdc: 477 GiB, 512110190592 bytes, 1000215216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: CD3F3DA1-2901-45A0-B6E9-2BEEA36F3E78
Device Start End Sectors Size Type
/dev/sdc1 2048 1000214527 1000212480 477G Linux filesystem
Disk /dev/mapper/n3150--vg-root: 222.4 GiB, 238769143808 bytes, 466345984 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/n3150--vg-swap_1: 15.9 GiB, 17028874240 bytes, 33259520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
显然,这有一些非常讨厌的问题,因为 SSD 上的数据库在预期/dev/sdb1
〜/media/ssd1
突然出现在引导分区,而被认为是 USB 硬盘的实际上是安装的 SSD。
我怎样才能防止这样的事情再次发生?如何将硬件“固定”到特定/dev/sd*
条目?
您根本不应该尝试获取固定
/dev/sdX
名称。您不应该直接使用这样的名称。您应该做的是通过在
/dev/disk/
. 在可用的选项中,/dev/disk/by-id/
有与磁盘设备的序列号相关的条目。因此,即使是两个相同的磁盘也可以毫无歧义地加以区分。请注意,/dev/disk/
树中的所有条目都只是实际/dev/sdX
条目的符号链接,但正如您所发现的,它们可以是动态的:系统上出现或检测的顺序对于 来说确实/dev/sdX
很重要,对于/dev/disk/
(或至少对于/dev/disk/by-id/
)。那里的一些条目具有等效的
/etc/fstab
语法。LABEL= UUID= PARTUUID= PARTLABEL=
匹配他们的等价物/dev/disk/by-{label,uuid,partlabel,partuuid}/
。这是fstab(5)
联机帮助页的内容:这是一个关于这些条目的有趣 Archlinux wiki 页面:
https://wiki.archlinux.org/index.php/Persistent_block_device_naming