Hồi trước tôi có 2 bài Xen troubleshooting, bàn về common problems khi provision environment dùng Xen. Hôm nay làm tương tự với KVM.
Cá nhân tôi thấy KVM elegant hơn về Python vomit verbosity và overall complexity, nhưng vẫn gặp ugly errors làm khó dễ. Tutorial này dạy workaround, identify config/setup conflicts, và các trick khác. After me.
Tip 1: Bridge networking interface không hiện
Muốn dùng custom bridge device br0 tự tạo. Khi setup network để guest dùng interface cụ thể, nó không hiện trong dropdown menu Virtual Machine Manager. Hình dưới show opposite, nhưng tưởng tượng desired device không trong list. Có thể xảy ra, tôi thấy, tin tôi.

Giải pháp đơn giản: thủ công edit config file domain. Mặc định KVM lưu file ở /etc/kvm/vm hoặc /etc/libvirt/qemu, likely tìm XML ở đó. Mở file liên quan, thủ công thay đổi bridged adapter details dưới <source bridge>. Close file, start VM, enjoy.
<interface type='bridge'> <source bridge='br0'/> <mac address='52:54:00:0d:e6:4a'/> </interface>
Tip 2: Biosdevname & không có network
Biosdevname: utility gán tên BIOS cho device, preserve commonality, simplify hardware admin logic, nhất là network device. Nếu nhiều device với capability/function unique, khó identify bằng generic ethX, nhưng nếu gán unique string, dễ phân biệt 1Gbps và 10Gbps adapter. Hữu ích cho enterprise, home user hiếm khi gặp.
Side effect: nếu dùng biosdevname trong guest OS trong KVM VM, có thể mất network, vì virtualized device nhận physical name không match.
Several workaround. Một: vài version utility detect chạy trong virtual env và exit không change. Hai: pass kernel argument GRUB menu; biosdevname=0 disable utility. Ba: hack udev rules gán tên network card. Ví dụ rudimentary cho máy single network adapter, cần logic dynamic cho multiple card. Hoặc như comment: tạo line riêng cho mỗi rule.

Thay đổi thủ công để có classic assignment:
vi /etc/udev/rules.d/70-persistent-net.rules # Replace NAME string from "eth_biosname" to "ethX" or anything you need: # PCI device ... SUBSYSTEM=="net", ACTION=="add", ATTR(type)=="1", KERNEL=="eth*", NAME="eth_biosname" # PCI device ... SUBSYSTEM=="net", ACTION=="add", ATTR(type)=="1", KERNEL=="eth*", NAME="eth0"
Rules khác tùy virtual hardware (Realtek, e1000, virtio...). Chú ý match solution với environment cụ thể.
Tip 3: Domain already exists
Thử define domain mới mà đã tồn tại, trừ bạn khó tìm config file/declaration. virsh list không có, virt-manager không show.
virsh define machine.xml error: Failed to define domain from machine.xml error: operation failed: domain 'machine' already exists with uuid 883ab02f-1a67-7430-ef9a-2b59af52210e7
Phải tìm config file và xóa. Restart libvirtd service.
updatedb locate machine.xml rm <full path to machine.xml> /etc/init.d/libvirtd restart
Tip 4: Internal error Unable to find cgroup
Có thể manifest sau restart libvirtd (như ví dụ trên), hoặc unrelated. Full error:
virsh create machine.xml error: Failed to create domain from machine.xml error: internal error Unable to find cgroup for machine
Nguyên nhân có thể liên quan systemd (theo Bugzilla), nhưng cũng xảy ra trên máy pristine không dùng systemd. Thường là race condition giữa cgroups và libvirtd, do libvirtd start trước cgroups, một cgroups bị xóa hoặc không exist.
Fix: edit config libvirtd /etc/libvirt/qemu.conf. Edit directive cgroups_controllers thành empty list:
cgroups_controllers = [ ]
Restart libvirtd. Hoặc thủ công tạo cgroups cần thiết và assign libvirtd process vào subsystem.
Tip 5: VM biến mất từ VMM khi halt/reboot
Có thể issue đơn giản. Sau halt/reboot VM, console đóng. Config vẫn đó, nhưng major inconvenience, phải can thiệp management cycle.
Tìm clause on_reboot trong XML file VM, đảm bảo action = restart thay vì destroy. Xong.
<on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash>
Tip 6: No reboot action; function not supported
Liên quan tip trước. Nếu chỉ định reboot thay vì restart, học được đây invalid command KVM không execute. Thấy error prolific:
libvirtError: this function is not supported by the hypervisor: virDomainReboot
Dùng restart, all well.
Tip 7: Bootloader error sau cài đặt
Thỉnh thoảng thấy GRUB error, likely số 15, first reboot sau cài từ external media. Happen nếu để CD/DVD image attached và selected first boot device trong XML. Problem similar VirtualBox bug ảnh hưởng vài distro Linux. Ví dụ:
root (hd0,1) Filesystem type is ext2fs, partition type 0x83 kernel /boot/vmlinuz Error 15: File not found Press any key to continue...
Khắc phục: unmount ISO image và reboot guest. Lần này OK. Issue không manifest nếu set hard disk first bootable device, vì KVM auto skip sang second source (PXE/CD/DVD) nếu không tìm valid partition table trên disk (nên là case nếu mới cài).
Done for today.
Tài liệu tham khảo thêm
- KVM storage và network guides, plus bridged networking
- KVM + Virtualbox side-by-side usage howto
- KVM cloning guide
Kết luận
Nửa tá tip cho first troubleshooting guide, không tệ. Tutorial focus: bridged networking setup, workaround biosdevname, cgroups + libvirtd problems, unregister duplicate domains auto-created by virt-manager, resolve guest OS restart woes.
Phần lớn work bằng edit config file và restart service. Không rely GUI, vì action dịch sang command line có thể script cho automated management dễ dàng. Hy vọng bạn thích; có idea cho sequel, ping me.
Cheers.