Press "Enter" to skip to content

Tag: kvm

Fix ‘libguestfs launch fail’

在小破本Thinkpad X200s升级为X201s之后,我将其重新安装了Ubuntu 16.04.3 LTS版本并将其升级到最新版本。在兴冲冲搭建完成KVM虚拟化环境之后,并成功完成Centos7和Ubuntu虚拟机的样本之后,我打算对其副本进行sysprep操作的时候,提示'export LIBGUESTFS_TRACE=1 LIBGUESTFS_DEBUG=1',无法进行操作。
进行了libguest-test-tool进行了检查操作之后,系统提示‘libguestfs launch fail’错误。在排除了网上列出的库文件错误、版本bug和supermin配置文件错误之后,我把怀疑方向转向了内核,原因是有内核风暴的错误出现。
首先,安装了linux-generic-hwe-16.04-edge这个服务器内核,然后问题依旧。
然后,把hwe内核和最后升级得来的4.13版本内核卸载并重启之后,问题解决。

$ sudo virt-sysprep -d centos7
[   0.0] Examining the guest ...
[   6.9] Performing "abrt-data" ...
[   6.9] Performing "bash-history" ...
[   7.0] Performing "blkid-tab" ...
[   7.0] Performing "crash-data" ...
[   7.0] Performing "cron-spool" ...
[   7.0] Performing "dhcp-client-state" ...
[   7.0] Performing "dhcp-server-state" ...
[   7.0] Performing "dovecot-data" ...
[   7.0] Performing "logfiles" ...
[   7.1] Performing "machine-id" ...
[   7.1] Performing "mail-spool" ...
[   7.1] Performing "net-hostname" ...
[   7.1] Performing "net-hwaddr" ...
[   7.1] Performing "pacct-log" ...
[   7.1] Performing "package-manager-cache" ...
[   7.1] Performing "pam-data" ...
[   7.1] Performing "puppet-data-log" ...
[   7.1] Performing "rh-subscription-manager" ...
[   7.1] Performing "rhn-systemid" ...
[   7.1] Performing "rpm-db" ...
[   7.1] Performing "samba-db-log" ...
[   7.1] Performing "script" ...
[   7.1] Performing "smolt-uuid" ...
[   7.1] Performing "ssh-hostkeys" ...
[   7.1] Performing "ssh-userdir" ...
[   7.1] Performing "sssd-db-log" ...
[   7.1] Performing "tmp-files" ...
[   7.1] Performing "udev-persistent-net" ...
[   7.1] Performing "utmp" ...
[   7.1] Performing "yum-uuid" ...
[   7.1] Performing "customize" ...
[   7.1] Setting a random seed
[   7.2] Performing "lvm-uuids" ...

虚拟机的mac地址也得到更新,避免了删除网卡再新重建网卡的麻烦。
macdiff
最后,使用apt-mark来保留旧内核以解决使用apt upgrade会升级内核的问题。

$ sudo apt-mark hold linux-image-4.10.0-28-generic
linux-image-4.10.0-28-generic 设置为保留。
$ sudo apt-mark hold linux-image-extra-4.10.0-28-generic
linux-image-extra-4.10.0-28-generic 设置为保留。

virsh管理virt-manager创建的虚机

virsh是kvm虚拟化套件libvirtd提供的字符模式虚拟机管理工具。virt-manager是redhat开发的一套图形界面的kvm虚拟机管理工具。虽然virt-manager和virsh同时是libvirtd这套管理程序的不同类型的管理实现方式,但具体使用起来还是有些许不兼容的地方。
默认使用Desktop版ubuntu安装virt-manager所创建的虚拟机,使用virsh list是看不到的,必须使用virsh list --all命令才能看到。同样,virsh start Beijing也是无法启动虚拟机,会出现“域无法找到”的类似错误。
解决的方法是使用virsh define /etc/libvirt/qemu/Beijing.xml命令,将虚拟机的配置文件在virsh中重新注册一下就可以使用其他的virsh管理命令了。

[root@tc8304 ~]# virsh list --all
 Id    名称                         状态
----------------------------------------------------
 1     Beijing                        running
 2     Shanghai                       running
 -     CentOS                         关闭

tips:
Ubuntu中默认的虚拟机磁盘存放位置是在
/var/lib/libvirt/images
而kvm的配置文件存储位置在
/etc/libvirt/qemu/

CentOS虚拟化实验环境搭建

为了准备RHCE考试,我把一台i7-2600k、16G内存、120Gssd的闲置主机刷成了CentOS7.下面是具体环境搭建的细节。


首先是系统的准备工作

su

yum update -y
yum install -y epel-release
yum makecache

yum install -y bash-completion network-tool sysfsutils 
yum install -y htop vim ctags curl wget mlocate lftp
curl https://raw.githubusercontent.com/wklken/vim-for-server/master/vimrc > ~/.vimrc

配置虚拟化环境

#安装kvm
yum -y install qemu-kvm libvirt virt-install bridge-utils
yum -y install libguestfs-tools virt-top

#启动虚拟化管理服务
systemctl start libvirtd
systemctl enable libvirtd

#开启kvm嵌套
echo "options kvm-intel nested=1" >> /etc/modprobe.d/kvm-intel.conf

#重新加载kvm模块
modprobe -r kvm_intel
modprobe kvm_intel

#关闭防火墙
systemctl stop firewalld
systemctl disable firewalld

#关闭selinux
vi /etc/selinux/config 
>SELINUX=disabled

reboot