今天保险丝烧断,导致一台小型服务器关闭。
该服务器连接了一个 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 HDD 的实际上是安装的 SSD。
我怎样才能防止类似的事情再次发生?如何将硬件“固定”到特定/dev/sd*
条目?
答案1
/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)
手册页告诉:
LABEL=<label>
或者UUID=<uuid>
可以代替设备名称。这是推荐的方法,因为设备名称通常与硬件检测顺序一致,并且在添加或删除其他磁盘时可能会更改。例如,LABEL=Boot
或UUID=3e6be9de-8139-11d1-9106-a43f08d823a6
。 (使用特定于文件系统的工具,如 e2label(8)、xfs_admin(8) 或 fatlabel(8) 在文件系统上设置标签)。
这里有一个关于这些条目的有趣的 Archlinux wiki 页面:
https://wiki.archlinux.org/index.php/Persistent_block_device_naming