Linux磁盘设备名变了
/dev/sde/dev/sdb/dev/sdc/dev/sdd/dev/sdf/dev/sdg/dev/sdh/dev/sdi/dev/sdj/dev/sdk/dev/sdl
·
好奇怪, 今天发现一台服务器上以前配置为数据盘的/dev/sda, 变成了系统盘; 而以前的系统盘/dev/sde现在却空闲着.
# cat conf/disks
/dev/sda
/dev/sdb
/dev/sdc
/dev/sdd
/dev/sdf
/dev/sdg
/dev/sdh
/dev/sdi
/dev/sdj
/dev/sdk
/dev/sdl
# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 950079572 111872396 789945852 13% /
tmpfs 16428628 0 16428628 0% /dev/shm
/dev/sda1 1032088 61292 918368 7% /boot
Google了一下, 实际上操作系统是没法保证设备名与物理磁盘的关系的. 为什么用了那么久的PC, 一直没有遇到这样的问题呢? 因为PC通常只有一个硬盘, 哈哈.
解决办法有好几个, 我这里因为是直接使用整个硬盘而且有重新格式化硬盘的需要, by-uuid和label都不如by-id简单, 简单到把/dev/sdx替换成对应的disk id就可以了:
# ls -l /dev/disk/by-id/
total 0
lrwxrwxrwx. 1 root root 9 Apr 17 20:42 ata-Hitachi_HUA722010CLA330_JPW9K0N12DHDXL -> ../../sda
lrwxrwxrwx. 1 root root 10 Apr 17 20:42 ata-Hitachi_HUA722010CLA330_JPW9K0N12DHDXL-part1 -> ../../sda1
lrwxrwxrwx. 1 root root 10 Apr 17 20:42 ata-Hitachi_HUA722010CLA330_JPW9K0N12DHDXL-part2 -> ../../sda2
lrwxrwxrwx. 1 root root 10 Apr 17 20:42 ata-Hitachi_HUA722010CLA330_JPW9K0N12DHDXL-part3 -> ../../sda3
lrwxrwxrwx. 1 root root 9 Apr 18 10:05 ata-Hitachi_HUA722010CLA330_JPW9K0N12DMP3L -> ../../sdd
lrwxrwxrwx. 1 root root 9 Apr 18 10:04 ata-Hitachi_HUA722010CLA330_JPW9K0N12DP61L -> ../../sdj
lrwxrwxrwx. 1 root root 9 Apr 18 10:04 ata-Hitachi_HUA722010CLA330_JPW9K0N12DV3HL -> ../../sdh
lrwxrwxrwx. 1 root root 9 Apr 18 10:06 ata-Hitachi_HUA722010CLA330_JPW9K0N12E020L -> ../../sdk
lrwxrwxrwx. 1 root root 9 Apr 18 10:06 ata-Hitachi_HUA722010CLA330_JPW9K0N12E3VYL -> ../../sdl
lrwxrwxrwx. 1 root root 9 Apr 18 10:05 ata-Hitachi_HUA722010CLA330_JPW9K0N12E3YWL -> ../../sdi
lrwxrwxrwx. 1 root root 9 Apr 18 10:04 ata-Hitachi_HUA722010CLA330_JPW9K0N12E43DL -> ../../sdb
lrwxrwxrwx. 1 root root 9 Apr 18 10:21 ata-Hitachi_HUA722010CLA330_JPW9K0N12E59XL -> ../../sde
lrwxrwxrwx. 1 root root 9 Apr 18 10:04 ata-Hitachi_HUA722010CLA330_JPW9K0N12EBXWL -> ../../sdg
lrwxrwxrwx. 1 root root 9 Apr 18 10:04 ata-Hitachi_HUA722010CLA330_JPW9K0N12ED39L -> ../../sdc
lrwxrwxrwx. 1 root root 9 Apr 18 10:04 ata-Hitachi_HUA722010CLA330_JPW9K0N12ED3PL -> ../../sdf
写了一段脚本:
show_disk_id()
{
while read dev_name
do
for dev_id in /dev/disk/by-id/*
do
if test $dev_id -ef $dev_name; then
echo $dev_id
break
fi
done
done
}
执行之, 最后的配置文件变成这样:
# cat conf/disks | show_disk_id
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12E59XL
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12E43DL
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12ED39L
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12DMP3L
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12ED3PL
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12EBXWL
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12DV3HL
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12E3YWL
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12DP61L
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12E020L
/dev/disk/by-id/ata-Hitachi_HUA722010CLA330_JPW9K0N12E3VYL
更多推荐
已为社区贡献2条内容
所有评论(0)