原文链接: https://blog.51cto.com/duron/2125821
转换磁盘镜像格式之后导入KVM系统无法启动,但是可以进入恢复模式,可能是virtio的内核模块没有加载,把磁盘改为IDE模式后正常。
但是IDE模式效率没有virtio高,这时可以手动加载virtio模块,方法参考腾讯云帮助文档: https://cloud.tencent.com/document/product/213/9929
grep -i virtio /boot/config-$(uname -r)
首选用上面这条命令检查内核模块是否包含virtio
CONFIG_VIRTIO_BLK=m
CONFIG_VIRTIO_NET=m
有这两项, 说明有了这个模块, 如果后面的 m 是 y, 那么说明这个不是作为模块加载的, 而是编译到内核中了, 编译到内核中的理论上不应该启动不了, 所以可能是其他问题, 请略过此文, 找别的解决方法, 如果是 m, 请继续
lsinitrd /boot/initramfs-$(uname -r).img | grep virtio
用上面这条命令检查initramfs是否包含virtio驱动
[root@localhost ~]# lsinitrd /boot/initramfs-$(uname -r).img | grep virtio
Arguments: -f --add-drivers ' virtio_blk virtio_pci'
-rw-r--r-- 1 root root 7916 Oct 20 2020 usr/lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/block/virtio_blk.ko.xz
-rw-r--r-- 1 root root 12964 Oct 20 2020 usr/lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/char/virtio_console.ko.xz
-rw-r--r-- 1 root root 14348 Oct 20 2020 usr/lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/net/virtio_net.ko.xz
-rw-r--r-- 1 root root 8220 Oct 20 2020 usr/lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/scsi/virtio_scsi.ko.xz
drwxr-xr-x 2 root root 0 Dec 2 18:31 usr/lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/virtio
-rw-r--r-- 1 root root 4552 Oct 20 2020 usr/lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/virtio/virtio.ko.xz
-rw-r--r-- 1 root root 9940 Oct 20 2020 usr/lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/virtio/virtio_pci.ko.xz
-rw-r--r-- 1 root root 8556 Oct 20 2020 usr/lib/modules/3.10.0-1160.el7.x86_64/kernel/drivers/virtio/virtio_ring.ko.xz
如果类似上面的结果,说明不是驱动问题,请略过此文,另外寻找原因,如果没有结果,说明是内核模块没有加载,请执行以下命令
cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak #备份原有的initramfs
mkinitrd -f --with=virtio_blk --with=virtio_pci /boot/initramfs-$(uname -r).img $(uname -r) #制作新的initramfs
完成之后使用上面的lsinitrd命令查询,应该正常了,关闭guestos,调整磁盘模式为virtio,启动guestos,问题解决
以上方法适用于CentOS或者RedHat RHEL 7 以上版本
抄完原作者的办法,我的VM是能启动了,这里要感谢原作者!
现在fdisk -l
可以看到磁盘由sda变成了vda, 同时blkid内容也发生了变化
[root@localhost ~]# fdisk -l
Disk /dev/vda: 107.4 GB, 107374182400 bytes, 209715200 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 label type: dos
Disk identifier: 0x00098115
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 2099199 1048576 83 Linux
/dev/vda2 2099200 209715199 103808000 8e Linux LVM
Disk /dev/mapper/centos-root: 97.7 GB, 97706311680 bytes, 190832640 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/centos-swap: 8589 MB, 8589934592 bytes, 16777216 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
root@localhost ~]# blkid
/dev/vda1: UUID="c1213919-376a-428a-b80b-29045d265e7a" TYPE="xfs"
/dev/vda2: UUID="gjGTm7-5xbM-ss4k-Lhn3-pkxS-QcoO-j2COSN" TYPE="LVM2_member"
/dev/mapper/centos-root: UUID="16c38563-fbaa-4f33-9932-90d058cf4164" TYPE="xfs"
/dev/mapper/centos-swap: UUID="46385553-a48c-40f5-8093-eee61af57dae" TYPE="swap"
标签:workstation,virtio,--,磁盘格式,虚拟机,bytes,dev,512,root
From: https://www.cnblogs.com/zhaojli/p/16945374.html