Đọc Virtualization section của tôi -> focus mostly VMware/VirtualBox, chút cloud/image remastering. Time to branch out. Bắt đầu era tutorials mới với KVM. Sau sẽ có Xen và weird beasts, nhưng now: KVM.
Guide này: học KVM (Kernel-based Virtual Machine), developed by RedHat, free open-source alternative commercial solutions. Học download, install, setup KVM, tools manage VMs, options, CLI usage/scripting, advanced networking/storage, more. Let's begin.

KVM - Glossary
Brief overview KVM works. Tiny intro basic terminology. Simple soon.
KVM dùng CPU virtualization extensions trên Intel/AMD modern: Intel-VT, AMD-V. Kernel module loaded vào memory, KVM dùng processor, via user-mode driver based on modified QEMU, emulate hardware layer tạo/chạy VMs. KVM chạy không CPU extensions -> pure emulation mode QEMU, significant performance penalty.
KVM manage: GUI tool (giống VMware/VirtualBox) hoặc command line several methods.
Popular GUI: Virtual Machine Manager (VMM), RedHat develop. Package name virt-manager. Supporting tools: virt-install, virt-clone, virt-image, virt-viewer (provision, clone, install, view VMs). VMM cũng support Xen machines.
Generic KVM CLI: virsh. Supporting tools như virt-install tạo VM. Ubuntu: ubuntu-vm-builder tool provisioning Ubuntu builds, Canonical develop.
Multitude names confusing, take it easy. Thêm confusing: KVM own syntax giống QEMU. Not recommended manage VMs.
More info: Kernel Virtual Machine - Community Ubuntu Documentation, KVM tutorials howtoforge.com, KVM/Virsh - Community Ubuntu Documentation. Step 1 done.
KVM - Pros and Cons
Dùng KVM? Depends what you want.
Casual home user, hobbyist, intermediate geek: KVM difficult start. Primarily CLI tool, không intuitive/friendly như VMware/VirtualBox. KVM feels years behind competition GUI management, nhưng powerful delivering. Designed CLI -> better productivity/control long run. Business environment most sense.
CPU không support virtualization -> KVM big waste time, extreme slow/inefficient emulation mode. KVM known conflict VirtualBox (separate tutorial).
Vì vậy KVM cho người keen interest virtualization, likely admins/professionals. Not cuddliest home toy, might not be years. But willing to dig in -> master new language, force multiplier other techs. VMware/VirtualBox prefer GUI tools, KVM oriented raw efficiency CLI scripting.
Tóm lại: KVM good nếu: free modern virtualization, unlimited usage, no licensing fees/feature tiering, powerful CLI, không sợ dirty hands. KVM not good nếu: CPU no virtualization extensions, sợ viết script, no desire dabble code, prefer simpler solutions (VMware Server, ESXi, VirtualBox).
All right, let's go.
Test Platform
KVM dùng được pretty much any Linux distro. General: RedHat flavors favor KVM. RHEL ships KVM enabled OS -> tìm trong CentOS, Scientific Linux, Fedora.
Tôi chạy mostly Ubuntu at home -> test Ubuntu trên HP laptop mới, i5 revvy support virtualization. Năm nay plan deploy CentOS/Scientific Linux mới trên multi-boot Linux machine -> additional tutorials cho distros đó. Xen cũng sẽ có.
Tutorial này: setup KVM trên 64-bit Ubuntu Lucid LTS. Sequels cover nhiều topics: dùng alongside other virtualization techs, resolve conflicts, advanced management, scripting, more.
Finally, begin in earnest.
Prerequisites
CPU support virtualization. Check:
egrep -c '(vmx|svm)' /proc/cpuinfo
Non-zero -> good. NHƯNG... cần check virtualization enabled trong BIOS. Enable feature -> cold power-cycle machine cho effect.
Boot OS, get KVM installed.
Check kvm-ok:

Download & Install KVM
Packages (apt commands):
apt-get install qemu-kvm libvirt-bin
Optionally, most recommended:
apt-get install bridge-utils virt-manager python-virtinst
P.S. Package names vary distros. VD: virt-install có thể python-virt-install, python-virtinst, virt-install. Dependencies virt-clone, virt-image, virt-viewer auto-resolved.
Contrary most tutorials: KHÔNG cần bridge utilities. Chỉ cần nếu bridge virtual adapters với physical cards. Demo detailed VirtualBox networking tutorial. Principle same.
Most tutorials mention Wireless interfaces không support bridging. Có thể, nhưng all my testing: successfully bridge Wireless adapters. Keep hopes high.
VMM (virt-manager) highly recommended. Helper tools: virt-viewer, virt-install, virt-image, virt-clone.
Có thể ubuntu-vm-builder:
apt-get install ubuntu-vm-builder
Dependencies auto-resolved, downloads takes a while. RedHat: yum install. SUSE: zypper install.
Conflict với VirtualBox
Again contrary tutorials: CÓ THỂ both KVM và VirtualBox installed same host. Có thể không chạy both same time. Một hoặc other kernel module unload từ memory. No reason rush. Try, see if works, not then corrective actions.
In-vivo, không reboot drastic. Separate tutorial handle case. Thực tế both installed running test host.
Sử Dụng KVM
Fun part. Bắt đầu VMM (GUI tool, most people start). Practical purposes: similar tools như VMware console hoặc VirtualBox.
Virtual Machine Manager (VMM)
Tour. Lần đầu launch: 2 categories, both not connected. Localhost KVM modules, still not in use. Right-click > connect.
Add new connections: File > Add Connection. Window specify Hypervisor type, connection type. VMM local/remote, QEMU/KVM, Xen. Auth methods all kinds.
Autoconnect: next time fire VMM, connections ready. Giống VMware Server ask start program. Reference:
Kernel vs Usermode
Difference normal/default vs Usermode? Usermode: run without admin privileges, network capability limited. Move on.
VMM Overview Continued
Network functionality review/change Host Details. Separate tutorial KVM network. Setup bridge utilities.
Storage settings change. Dedicated guide promised.
Change preferences
VMM options tweak look/behave smarter: system tray icon, statistics polling interval, enable polling disk/network metrics (deselected default), console keyboard grabbing, console scaling, audio options, confirmation windows machine activities.


Sau allow view VM metrics detail/control. VD: Ubuntu guest CPU, Disk I/O, Network I/O.
System tray icon:
Finally, ready create new VM.
Tạo Virtual Machine
VMM hoặc command line. Bắt đầu GUI. Step 1 intuitive: name, install media location. Local storage (ISO/CD/DVD), HTTP/FTP, NFS, PXE.
Local install media. Chọn physical device hoặc image. Case: ISO. Chọn OS type, version. Không precise nhưng educated guess good -> additional VM optimization.
Allocate RAM, CPUs.
Step 4 interesting: storage. Create new image hoặc use existing. Set size, preallocate all space (good performance, reduce fragmentation).
Focus soon storage. Now: assume disk ready hoặc create default storage pool. Note: Usermode -> không write /var (default storage pool). Cần new storage pool accessible non-admin users (separate article).
Step 5: summary, advanced options. Change network type, fixed MAC, virtualization type, target architecture. Usermode -> network options limited. No bridge utilities -> không bridge interfaces. No CPU virtualization extensions -> Virt Type: QEMU không phải KVM. Example later emulation mode drawbacks. Typical Ubuntu VM setup:
Machine ready use. Power up soon.
Virtual Machine Options
VM console options: send signals guest, switch virtual consoles, force reboot/power off, clone, migrate, save, screenshots, more. Similar competition.
Screenshots teasers clone/migrate. Road ahead: detailed tutorials GUI/CLI.
Virtual Machines Running
Fun part. Screenshots...
Ubuntu 10.10 Maverick 32-bit boot menu:
Puppy Linux against lovely desktop:
Ubuntu running, NAT-ed. CPU utilization very low. Important: pay attention later emulation only mode. Nagging but bear ultra-turbo education.
Scale console window fit guest (viewer menu). Preferences autoscale consoles. Puppy và Ubuntu side by side:
System usage: minimal. Smart consumption -> generously overcommit, enjoy more VMs than physical hardware normally permit, single machine bound to core.
Delete machine + associated files:
Comfortable basic usage, do command line.
Command Line
Infamous command line. VD: virsh list all VMs.
virsh 'list --all'
Sequence commands create/run VM virt-install. Note: không phải KVM guru. Template code man pages, billion examples online.
Actual command:
virt-install --connect qemu://system -n puppy -r 512 -f puppy.img -c lupu-520.iso --vnc --noautoconsole --os-type linux --accelerate --network=network:default
So what do we have here?
- --connect qemu:///system: hypervisor type. system = bare metal kernel as root. session = non-root. Recall VMM Usermode. Works xen too.
- -n puppy: unique VM name. virsh rename/delete nếu unsatisfied.
- -r 512: RAM.
- -f: disk file. puppy.img created dd command. Conserve space: sparse file (cool Linux hacks article 2).
- -c: CD-ROM, physical device hoặc ISO.
- --vnc: setup guest console export VNC server. --noautoconnect: không auto open console khi power on.
- --os-type: guest OS.
- --accelerate: KVM dùng optimization functions accelerate guest performance nếu possible.
- --network: network type. Default connection.
Nhiều functions khác: cores, bind CPU core, fixed MAC NIC, no storage, keyboard map, more. Man pages listed. Not intuitive but easier with use. Learning curve not high despite initial impression. Hang of virt-install -> fiddle other commands, start/stop virsh, Bob's your uncle.
Other Things
Few more details.
Chạy Pure Emulation Mode (Don't)
Told completely inefficient. Proof. Host Details Overview. Performance graph: CPU usage max 100% available resources VM (1 core = 25% utilization). Gần như DOS. 4 VMs, dù tiny/hungry, cripple 4-core host.
Performance horrible. Ubuntu guest ~1 phút boot (image loaded internal 7200rpm disk, Intel-VT enabled) -> ~20 phút emulation mode. Downside QEMU/KVM vs other solutions (vẫn decent performance no CPU extensions).
More Good Reading
Recommend KVM series howtoforge.com (linked).
Read: Discover Linux Kernel Virtual Machine, KVM management tools.
Kết Luận
Sincerely hope liked tutorial. Fairly long/detailed dù chỉ first steps KVM. Insight: initial setup/prerequisites, CLI/GUI tools, management options, create/run multiple VMs, more.
Ton of sequels: advanced storage/networking (bridged networking), clone/migrate VMs, resolve conflicts other virtualization software, more. Not strictly related: Xen và ESXi articles.
KVM powerful, dù daunting new users. Management options less newb-friendly rivals, nhưng fear/confusion spirited away today.
That's all. Enjoy!
Cheers.