openstack KVM 虚拟机 光盘救援 centos7

虚拟机磁盘故障,单用户已经无法修复根目录的损坏,需要从光盘引导进行修复,笔记一下。

所有操作需要在宿主机上进行


sudo virsh list --all  ###查看宿主机上所有虚拟机

sudo virsh destroy  instance-00000912 ###强制停止虚拟机

sudo cp  /etc/libvirt/qemu/instance-00000912.xml  ~  ###备份一份到家目录用来快速恢复配置
sudo virsh edit   instance-00000912 ###编辑配置文件


  <os>
    <type arch='x86_64' machine='pc-i440fx-rhel7.5.0'>hvm</type>
    <boot dev='cdrom'/>   ###这里引导hd改成cdrom
    <smbios mode='sysinfo'/>
  </os>

......

<devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='file' device='cdrom'> ###---此字段没有手动添加
      <driver name='qemu' type='raw' cache='none'/>
      <source file='/home/cmadmin/Linux-Server-x86_64-DVD-190114.iso'/>   ###添加iso引导文件绝对路径
      <target dev='hda' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk> ###到这---此字段没有手动添加
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none' io='native'/>
      <source dev='/dev/dm-5'/>
      <target dev='vda' bus='virtio'/>
      <serial>49f3ae29-ee05-445f-9cb9-3c255235825b</serial>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </disk>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none' io='native'/>
      <source dev='/dev/dm-4'/>
      <target dev='vdb' bus='virtio'/>
      <serial>4663b590-5781-4974-b416-b1ed21661234</serial>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
    <controller type='usb' index='0' model='piix3-uhci'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <controller type='virtio-serial' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </controller>
    <interface type='vhostuser'>
      <mac address='fa:16:3e:be:cb:cd'/>
      <source type='unix' path='/var/run/openvswitch/vhu3c437219-1e' mode='server'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <interface type='vhostuser'>
      <mac address='fa:16:3e:df:c1:2e'/>
      <source type='unix' path='/var/run/openvswitch/vhu8a426ea4-2a' mode='server'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </interface>
    <serial type='pty'>
      <log file='/var/lib/nova/instances/76235cda-332b-413e-ad0d-9cef309be0fd/console.log' append='off'/>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <log file='/var/lib/nova/instances/76235cda-332b-413e-ad0d-9cef309be0fd/console.log' append='off'/>
      <target type='serial' port='0'/>
    </console>
    <channel type='unix'>
      <source mode='bind' path='/var/lib/libvirt/qemu/org.qemu.guest_agent.0.instance-00000912.sock'/>
      <target type='virtio' name='org.qemu.guest_agent.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <input type='tablet' bus='usb'>
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0' keymap='en-us'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <video>
      <model type='cirrus' vram='16384' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <stats period='10'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </memballoon>
  </devices>




  sudo virsh domblklist  instance-00000912  ###验证添加成功

  Target     Source
------------------------------------------------
hda        /home/cmadmin/Linux-Server-x86_64-DVD-190114.iso
vda        /dev/dm-5
vdb        /dev/dm-4


sudo virsh start  instance-00000912  ###启动虚拟机

在novcn控制台 正常引导进入光盘,
进行根目录修复,
已知系统是EXT4文件系统
openstack KVM 虚拟机 光盘救援 centos7_第1张图片

参考

1

2

3

20230921 更新第二段
救援模式无法识别挂载本地硬盘内分区系统
openstack KVM 虚拟机 光盘救援 centos7_第2张图片
如上图,默认的挂载目录无 根 数据。

查看挂载的硬盘信息、文件系统格式、逻辑卷信息
openstack KVM 虚拟机 光盘救援 centos7_第3张图片

lvdisplay
发现 根目录所以逻辑卷未激活

openstack KVM 虚拟机 光盘救援 centos7_第4张图片

vgchange -ay bel 激活 根目录所在逻辑卷
openstack KVM 虚拟机 光盘救援 centos7_第5张图片

挂载根目录报错
structure needs cleaning

已知根目录 为xfs文件系统,xfs_repair -L /dev/mapper/bel-root 强制修复文件系统。
ext4文件系统, fsck.ext4 -y 路径
openstack KVM 虚拟机 光盘救援 centos7_第6张图片

openstack KVM 虚拟机 光盘救援 centos7_第7张图片
修复完成,恢复xml文件修改。

你可能感兴趣的:(openstack,linux,运维,kvm)