故障现象
给虚拟机增加一个卷后,重启无法进入系统。
故障原因
/etc/fstab中填写的文件系统类型与分区实际文件系统不一致。
处理方法
将虚拟机系统卷挂载到其他虚拟机上,修改/etc/fstab为正确配置。
排查过程
同事给一台虚拟机添加一个卷,重启之后发现虚拟机起不来了,打开vnc consle发现虚拟机进入了修复界面:
而这台虚拟机在创建的时候似乎没有正常初始化,输入root密码不对,无法进入系统。于是想进入单用户模式修改root密码,在grub启动菜单按e键进入编辑界面,讲linux16那一行的ro修改为rw init=/sysroot/bin/sh,然后ctlr+x启动:
卡在这个界面,可以看到确实跟块设备挂载有关:
看来没办法进入系统了,于是想把虚拟机系统卷映射到宿主机上,然后修改它的/etc/fstab:
# rbd map vms/a3dc7178-6936-4a3e-a129-38de543b70c8_disk --id cinder rbd: sysfs write failed RBD image feature set mismatch. You can disable features unsupported by the kernel with "rbd feature disable". In some cases useful info is found in syslog - try "dmesg | tail" or so. rbd: map failed: (6) No such device or address
失败,报错大致是说rbd中带有系统kernel不支持的feature,需要先使用rbd feature disable取消image上的feature。这是线上的机器,当然不能这么干,保不齐出什么问题。
而系统也没有nbd模块,因此rbd-nbd也不可用,这条路也行不通。
那么只能将它挂到另一个虚拟机上。于是创建一个新的虚拟机vm-01,并在其所在宿主机上编辑blk.xml:
<disk type='network' device='disk'> <driver name='qemu' type='raw' cache='writeback'/> <auth username='cinder'> <secret type='ceph' uuid='6f29947a-ae9b-477a-a31c-d0942177b734'/> </auth> <source protocol='rbd' name='vms/a3dc7178-6936-4a3e-a129-de543b70c8_disk'> <host name='10.20.67.106' port='6789'/> <host name='10.20.67.107' port='6789'/> <host name='10.20.67.108' port='6789'/> </source> <target dev='vdb' bus='virtio'/> </disk>
其中source就是故障虚拟机的系统卷。然后attach到vm-01上:
# virsh attach-device instance-00002965 blk.xml Device attached successfully
进入vm-01,查看块设备:
[root@vm-01 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 520K 0 rom vda 253:0 0 60G 0 disk └─vda1 253:1 0 60G 0 part / vdb 253:16 0 60G 0 disk └─vdb1 253:17 0 60G 0 part
vdb就是刚刚attach的故障虚拟机的系统卷,将它挂载到/mnt目录:
[root@vm-01 ~]# mount /dev/vdb1 /mnt mount: wrong fs type, bad option, bad superblock on /dev/vdb1, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so.
发现错误,根据错误提示,查看dmesg:
[root@vm-01 ~]# dmesg | tail [ 3437.071352] pci 0000:00:06.0: reg 0x14: [mem 0x00000000-0x00000fff] [ 3437.071927] pci 0000:00:06.0: BAR 1: assigned [mem 0xc0000000-0xc0000fff] [ 3437.072845] pci 0000:00:06.0: BAR 0: assigned [io 0x1000-0x103f] [ 3437.074055] virtio-pci 0000:00:06.0: enabling device (0000 -> 0003) [ 3437.078750] ACPI: PCI Interrupt Link [LNKB] enabled at IRQ 11 [ 3437.079535] virtio-pci 0000:00:06.0: virtio_pci: leaving for legacy driver [ 3437.082683] virtio-pci 0000:00:06.0: irq 29 for MSI/MSI-X [ 3437.082705] virtio-pci 0000:00:06.0: irq 30 for MSI/MSI-X [ 3437.086378] vdb: vdb1 [ 3597.459912] XFS (vdb1): Filesystem has duplicate UUID fc1bfc5d-a5d1-4c3c-afda-167500654723 - can't mount
原来是因为vdb1和vda1的文件系统的uuid重复了,因为这两台虚拟机都是由同一个镜像克隆而来。
于是用另一个镜像创建vm-02,重复上面的步骤挂载,一切正常,查看/etc/fstab:
# cat /mnt/etc/fstab # # /etc/fstab # Created by anaconda on Thu Dec 17 17:11:31 2015 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=fc1bfc5d-a5d1-4c3c-afda-167500654723 / xfs defaults 0 0 #/dev/vdb none swap sw,comment=cloudconfig 0 0 /dev/vdb1 /data xfs defaults 0 0 /dev/vdc1 /data1 xfs defaults 0 0
跟同事确认,他将/dev/vdc1格式化为ext4文件系统,而/etc/fstab写的是xfs,这才导致挂载错误。于是修改/etc/fstab:
/dev/vdc1 /data1 ext4 defaults 0 0
然后卸载:
[root@vm-02 ~]# umount /dev/vdb1
在宿主机上detach设备:
# virsh detach-device instance-0000296e blk.xml
Device detached successfully
启动虚拟机networktool01,顺利进入系统,块设备也已正确挂载:
[root@networktool01 ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on /dev/vda1 xfs 60G 1.2G 59G 2% / /dev/vdb1 xfs 200G 33M 200G 1% /data /dev/vdc1 ext4 197G 61M 187G 1% /data1