Hmm.. I tried lkvm or Native Linux KVM tool in past and was watching the patches coming into this space for this period. Its improved a lot from the time I first noticed it.
Today I decided to try native linux KVM tool again and here is the story.
First of all, let me point to the project itself :
https://github.com/penberg/linux-kvm/tree/master/tools/kvm
For the people who doesn’t know what it is , I would suggest to watch this video and then follow the ‘github’:
The goal of this tool is to provide a clean, from-scratch, lightweight
KVM host tool implementation that can boot Linux guest images (just a
hobby, won’t be big and professional like QEMU) with no BIOS
dependencies and with only the minimal amount of legacy device
emulation.
The steps to give a try with the tool is same as mentioned in the above URL.. How-ever in short you need below prerequisites:
1) Native linux kvm binary (lkvm)
2) A kernel image (bzimage)
The ‘rootfs’ can be created by below way:
[root@humbles-lap kvm]# ./lkvm setup default
A new rootfs ‘default’ has been created in ‘/root/.lkvm/default’.
You can now start it by running the following command:
lkvm run -d default
[root@humbles-lap kvm]#
Now lets see whats inside this ‘default’ rootfs:
[root@humbles-lap kvm]# cd /root/.lkvm/default/
[root@humbles-lap default]# ls
bin dev etc home host lib lib64 proc root sbin sys tmp usr var virt
[root@humbles-lap default]# ll
total 40
lrwxrwxrwx. 1 root root 9 Jul 29 00:29 bin -> /host/bin
drwxr-xr-x. 2 root root 4096 Jul 29 00:29 dev
drwxr-xr-x. 2 root root 4096 Jul 29 00:31 etc
drwxr-xr-x. 2 root root 4096 Jul 29 00:29 home
drwxr-xr-x. 2 root root 4096 Jul 29 00:29 host
lrwxrwxrwx. 1 root root 9 Jul 29 00:29 lib -> /host/lib
lrwxrwxrwx. 1 root root 11 Jul 29 00:29 lib64 -> /host/lib64
drwxr-xr-x. 2 root root 4096 Jul 29 00:29 proc
drwxr-xr-x. 2 root root 4096 Jul 29 00:29 root
lrwxrwxrwx. 1 root root 10 Jul 29 00:29 sbin -> /host/sbin
drwxr-xr-x. 2 root root 4096 Jul 29 00:29 sys
drwxr-xr-x. 2 root root 4096 Jul 29 00:29 tmp
lrwxrwxrwx. 1 root root 9 Jul 29 00:29 usr -> /host/usr
drwxr-xr-x. 3 root root 4096 Jul 29 00:29 var
drwxr-xr-x. 3 root root 4096 Jul 29 00:30 virt
[root@humbles-lap default]# cd host/
[root@humbles-lap host]# ls
[root@humbles-lap host]# cd virt/
[root@humbles-lap virt]# ls
home init
[root@humbles-lap virt]# file init
init: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.32, BuildID[sha1]=0x40afb8695db3b7b79014efd55d12e13fa88b101e, not stripped
[root@humbles-lap virt]# ll home/
total 0
[root@humbles-lap virt]
Run a VM:
[root@humbles-lap kvm]# ./lkvm run -d default
# lkvm run -k ../../arch/x86/boot/bzImage -m 448 -c 4 –name default
PPrroobbiinngg EEDDDD ((eedddd==ooffff ttoo ddiissaabbllee))…… ookk
Decompressing Linux… Parsing ELF… done.
Booting the kernel.
[ 0.000000] Linux version 3.0.0-rc5-reacher-01079-g1cf7f48 (root@humbles-lap.humblec.com) (gcc version 4.6.2 20111027 (Red Hat 4.6.2-1) (GCC) ) #21 SMP PREEMPT Tue Jan 10 12:48:21 IST 2012
[ 0.000000] Command line: noapic noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 i8042.dumbkbd=1 i8042.nopnp=1 console=ttyS0 earlyprintk=serial i8042.noaux=1 root=/dev/root rw rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p init=/virt/init ip=dhcp
[ 0.000000] CPU: vendor_id ‘LKVMLKVMLKVM’ unknown, using generic init.
[ 0.000000] CPU: Your system may be unstable.
[ 0.000000] BIOS-provided physical RAM map:
[ 0.000000] BIOS-e820: 0000000000000000 – 000000000009fc00 (usable)
[ 0.000000] BIOS-e820: 000000000009fc00 – 00000000000a0000 (reserved)
[ 0.000000] BIOS-e820: 00000000000f0000 – 00000000000fffff (reserved)
[ 0.000000] BIOS-e820: 0000000000100000 – 000000001c000000 (usable)
[ 0.000000] bootconsole [earlyser0] enabled
[ 0.000000] NX (Execute Disable) protection: active
[ 0.000000] DMI not present or invalid.
[ 0.000000] No AGP bridge found
[ 0.000000] last_pfn = 0x1c000 max_arch_pfn = 0x400000000
[ 0.000000] x86 PAT enabled: cpu 0, old 0x70106, new 0x7010600070106
[ 0.000000] CPU MTRRs all blank – virtualized system.
[ 0.000000] found SMP MP-table at [ffff8800000f0370] f0370
[ 0.000000] init_memory_mapping: 0000000000000000-000000001c000000
[ 0.000000] ACPI Error: A valid RSDP was not found (20110413/tbxfroot-219)
[ 0.000000] kvm-clock: Using msrs 4b564d01 and 4b564d00
[ 0.000000] kvm-clock: cpu 0, msr 0:1c98a01, boot clock
[ 0.000000] Zone PFN ranges:
[ 0.000000] DMA 0x00000010 -> 0x00001000
[ 0.000000] DMA32 0x00001000 -> 0x00100000
[ 0.000000] Normal empty
[ 0.000000] Movable zone start PFN for each node
[ 0.000000] early_node_map[2] active PFN ranges
[ 0.000000] 0: 0x00000010 -> 0x0000009f
[ 0.000000] 0: 0x00000100 -> 0x0001c000
[ 0.000000] SFI: Simple Firmware Interface v0.81 http://simplefirmware.org
[ 0.000000] Intel MultiProcessor Specification v1.4
[ 0.000000] MPTABLE: OEM ID: KVMCPU00
[ 0.000000] MPTABLE: Product ID: 0.1
[ 0.000000] MPTABLE: APIC at: 0xFEE00000
[ 0.000000] Processor #0 (Bootup-CPU)
[ 0.000000] Processor #1
[ 0.000000] Processor #2
[ 0.000000] Processor #3
[ 0.000000] IOAPIC[0]: apic_id 5, version 17, address 0xfec00000, GSI 0-23
[ 0.000000] Processors: 4
[ 0.000000] SMP: Allowing 4 CPUs, 0 hotplug CPUs
[ 0.000000] PM: Registered nosave memory: 000000000009f000 – 00000000000a0000
[ 0.000000] PM: Registered nosave memory: 00000000000a0000 – 00000000000f0000
[ 0.000000] PM: Registered nosave memory: 00000000000f0000 – 00000000000ff000
[ 0.000000] PM: Registered nosave memory: 00000000000ff000 – 0000000000100000
[ 0.000000] Allocating PCI resources starting at 1c000000 (gap: 1c000000:e4000000)
[ 0.000000] Booting paravirtualized kernel on KVM
[ 0.000000] setup_percpu: NR_CPUS:512 nr_cpumask_bits:512 nr_cpu_ids:4 nr_node_ids:1
[ 0.000000] PERCPU: Embedded 23 pages/cpu @ffff88001bc00000 s71232 r0 d22976 u524288
[ 0.000000] kvm-clock: cpu 0, msr 0:1bc10a01, primary cpu clock
[ 0.000000] KVM setup async PF for cpu 0
[ 0.000000] Built 1 zonelists in Zone order, mobility grouping on. Total pages: 113002
[ 0.000000] Kernel command line: noapic noacpi pci=conf1 reboot=k panic=1 i8042.direct=1 i8042.dumbkbd=1 i8042.nopnp=1 console=ttyS0 earlyprintk=serial i8042.noaux=1 root=/dev/root rw rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p init=/virt/init ip=dhcp
[ 0.000000] PID hash table entries: 2048 (order: 2, 16384 bytes)
[ 0.000000] Dentry cache hash table entries: 65536 (order: 7, 524288 bytes)
[ 0.000000] Inode-cache hash table entries: 32768 (order: 6, 262144 bytes)
[ 0.000000] xsave/xrstor: enabled xstate_bv 0x7, cntxt size 0x340
[ 0.000000] Checking aperture…
[ 0.000000] No AGP bridge found
[ 0.000000] Memory: 434592k/458752k available (6271k kernel code, 452k absent, 23708k reserved, 6555k data, 512k init)
[ 0.000000] SLUB: Genslabs=15, HWalign=64, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[ 0.000000] Preemptible hierarchical RCU implementation.
[ 0.000000] NR_IRQS:33024 nr_irqs:712 16
[ 0.000000] Console: colour *CGA 80×25
[ 0.000000] console [ttyS0] enabled, bootconsole disabled
[ 0.000000] console [ttyS0] enabled, bootconsole disabled
[ 0.000000] Detected 2494.332 MHz processor.
[ 0.000000] Marking TSC unstable due to TSCs unsynchronized
[ 0.001999] Calibrating delay loop (skipped) preset value.. 4988.66 BogoMIPS (lpj=2494332)
[ 0.003007] pid_max: default: 32768 minimum: 301
[ 0.003703] Security Framework initialized
[ 0.004025] Mount-cache hash table entries: 256
[ 0.005172] mce: CPU supports 32 MCE banks
[ 0.006006] MCE: unknown CPU type – not enabling MCE support.
[ 0.008198] CPU0: LKVMLKVMLKVM 06/3a stepping 09
[ 0.111027] Performance Events:
[ 0.123027] Booting Node 0, Processors #1
[ 0.134930] kvm-clock: cpu 1, msr 0:1bc90a01, secondary cpu clock
[ 0.134946] KVM setup async PF for cpu 1
[ 0.138036] #2
[ 0.149610] kvm-clock: cpu 2, msr 0:1bd10a01, secondary cpu clock
[ 0.149627] KVM setup async PF for cpu 2
[ 0.153037] #3 Ok.
[ 0.164623] kvm-clock: cpu 3, msr 0:1bd90a01, secondary cpu clock
[ 0.164641] Brought up 4 CPUs
[ 0.164644] Total of 4 processors activated (19954.65 BogoMIPS).
[ 0.164639] KVM setup async PF for cpu 3
[ 0.171048] devtmpfs: initialized
[ 0.172395] Time: 19:00:25 Date: 07/28/13
[ 0.173052] NET: Registered protocol family 16
[ 0.174050] PCI: Using configuration type 1 for base access
[ 0.205118] bio: create slab
[ 0.206074] ACPI: Interpreter disabled.
[ 0.207199] vgaarb: loaded
[ 0.207983] SCSI subsystem initialized
[ 0.208512] usbcore: registered new interface driver usbfs
[ 0.209113] usbcore: registered new interface driver hub
[ 0.210066] usbcore: registered new device driver usb
[ 0.211990] Advanced Linux Sound Architecture Driver Version 1.0.24.
[ 0.212993] PCI: Probing PCI hardware
[ 0.215257] Bluetooth: Core ver 2.16
[ 0.216042] NET: Registered protocol family 31
[ 0.216491] Bluetooth: HCI device and connection manager initialized
[ 0.216980] Bluetooth: HCI socket layer initialized
[ 0.217979] Bluetooth: L2CAP socket layer initialized
[ 0.218584] Bluetooth: SCO socket layer initialized
[ 0.219056] cfg80211: Calling CRDA to update world regulatory domain
[ 0.220158] NetLabel: Initializing
[ 0.220547] NetLabel: domain hash size = 128
[ 0.220978] NetLabel: protocols = UNLABELED CIPSOv4
[ 0.221555] NetLabel: unlabeled traffic allowed by default
[ 0.221985] Switching to clocksource kvm-clock
[ 0.223055] FS-Cache: Loaded
[ 0.223759] Switched to NOHz mode on CPU #0
[ 0.223742] Switched to NOHz mode on CPU #1
[ 0.223698] Switched to NOHz mode on CPU #3
[ 0.226303] Switched to NOHz mode on CPU #2
[ 0.227522] pnp: PnP ACPI: disabled
[ 0.238514] NET: Registered protocol family 2
[ 0.239220] IP route cache hash table entries: 4096 (order: 3, 32768 bytes)
[ 0.240379] TCP established hash table entries: 16384 (order: 6, 262144 bytes)
[ 0.241424] TCP bind hash table entries: 16384 (order: 6, 262144 bytes)
[ 0.242325] TCP: Hash tables configured (established 16384 bind 16384)
[ 0.243120] TCP reno registered
[ 0.243496] UDP hash table entries: 256 (order: 1, 8192 bytes)
[ 0.244282] UDP-Lite hash table entries: 256 (order: 1, 8192 bytes)
[ 0.245086] NET: Registered protocol family 1
[ 0.245742] RPC: Registered named UNIX socket transport module.
[ 0.246468] RPC: Registered udp transport module.
[ 0.246989] RPC: Registered tcp transport module.
[ 0.247518] RPC: Registered tcp NFSv4.1 backchannel transport module.
[ 0.248878] platform rtc_cmos: registered platform RTC device (no PNP device found)
[ 0.249746] Machine check injector initialized
[ 0.251439] microcode: no support for this CPU vendor
[ 0.253471] HugeTLB registered 2 MB page size, pre-allocated 0 pages
[ 0.261882] VFS: Disk quotas dquot_6.5.2
[ 0.262522] Dquot-cache hash table entries: 512 (order 0, 4096 bytes)
[ 0.265200] FS-Cache: Netfs ‘cifs’ registered for caching
[ 0.266439] NTFS driver 2.1.30 [Flags: R/W].
[ 0.267709] fuse init (API version 7.16)
[ 0.268748] Installing v9fs 9p2000 file system support
[ 0.269499] msgmni has been set to 848
[ 0.270853] NET: Registered protocol family 38
[ 0.271792] Block layer SCSI generic (bsg) driver version 0.4 loaded (major 253)
[ 0.272789] io scheduler noop registered
[ 0.273322] io scheduler deadline registered
[ 0.274099] io scheduler cfq registered (default)
[ 0.274982] pci_hotplug: PCI Hot Plug PCI Core version: 0.5
[ 0.278429] virtio-pci 0000:00:00.0: enabling device (0000 -> 0003)
[ 0.279525] virtio-pci 0000:00:01.0: enabling device (0000 -> 0003)
[ 0.280521] virtio-pci 0000:00:02.0: enabling device (0000 -> 0003)
[ 0.282583] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
�[ 0.548387] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a U6_16550A
�[ 0.827424] serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a U6_16550A
�[ 1.106463] serial8250: ttyS2 at I/O 0x3e8 (irq = 4) is a U6_16550A
[ 1.143302] Non-volatile memory driver v1.3
[ 1.143904] Linux agpgart interface v0.103
[ 1.146179] [drm] Initialized drm 1.1.0 20060810
[ 1.146811] [drm] radeon defaulting to kernel modesetting.
[ 1.147731] [drm] radeon kernel modesetting enabled.
[ 1.153047] brd: module loaded
[ 1.156511] loop: module loaded
[ 1.156902] kgdb: Registered I/O driver kgdbts.
[ 1.157527] kgdbts:RUN plant and detach test
[ 1.162116] kgdbts:RUN sw breakpoint test
[ 1.175392] kgdbts:RUN bad memory access test
[ 1.178108] kgdbts:RUN singlestep test 1000 iterations
[ 1.188017] kgdbts:RUN singlestep [0/1000]
[ 1.329542] kgdbts:RUN singlestep [100/1000]
[ 1.382416] kgdbts:RUN singlestep [200/1000]
[ 1.514202] kgdbts:RUN singlestep [300/1000]
[ 1.601698] kgdbts:RUN singlestep [400/1000]
[ 1.737772] kgdbts:RUN singlestep [500/1000]
[ 1.786410] kgdbts:RUN singlestep [600/1000]
[ 2.036960] kgdbts:RUN singlestep [700/1000]
[ 2.463700] kgdbts:RUN singlestep [800/1000]
[ 2.521400] kgdbts:RUN singlestep [900/1000]
[ 2.609083] kgdbts:RUN hw breakpoint test
[ 2.609688] kgdbts:RUN hw write breakpoint test
[ 2.610333] kgdbts:RUN access write breakpoint test
[ 2.611074] kgdbts:RUN do_fork for 100 breakpoints
[ 2.642220] e1000: Intel(R) PRO/1000 Network Driver – version 7.3.21-k8-NAPI
[ 2.643600] e1000: Copyright (c) 1999-2006 Intel Corporation.
[ 2.647328] e1000e: Intel(R) PRO/1000 Network Driver – 1.3.10-k2
[ 2.648439] e1000e: Copyright(c) 1999 – 2011 Intel Corporation.
[ 2.651201] Intel(R) Gigabit Ethernet Network Driver – version 3.0.6-k2
[ 2.652403] Copyright (c) 2007-2011 Intel Corporation.
[ 2.656480] Intel(R) Virtual Function Network Driver – version 1.0.8-k0
[ 2.657713] Copyright (c) 2009 – 2010 Intel Corporation.
[ 2.660471] tun: Universal TUN/TAP device driver, 1.6
[ 2.661156] tun: (C) 1999-2004 Max Krasnyansky
[ 2.665072] iwlagn: Intel(R) Wireless WiFi Link AGN driver for Linux, in-tree:d
[ 2.666384] iwlagn: Copyright(c) 2003-2011 Intel Corporation
[ 2.667679] iwl4965: Intel(R) Wireless WiFi 4965 driver for Linux, in-tree:
[ 2.668908] iwl4965: Copyright(c) 2003-2011 Intel Corporation
[ 2.673283] iwl3945: Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux, in-tree:s
[ 2.674588] iwl3945: Copyright(c) 2003-2011 Intel Corporation
[ 2.719142] console [netcon0] enabled
[ 2.719614] netconsole: network logging started
[ 2.745753] ehci_hcd: USB 2.0 ‘Enhanced’ Host Controller (EHCI) Driver
[ 2.747231] ohci_hcd: USB 1.1 ‘Open’ Host Controller (OHCI) Driver
[ 2.748953] uhci_hcd: USB Universal Host Controller Interface driver
[ 2.750778] usbcore: registered new interface driver cdc_wdm
[ 2.751818] Initializing USB Mass Storage driver…
[ 2.752945] usbcore: registered new interface driver usb-storage
[ 2.754069] USB Mass Storage support registered.
[ 2.755163] usbcore: registered new interface driver libusual
[ 2.756199] i8042: PNP detection disabled
[ 2.759323] serio: i8042 KBD port at 0x60,0x64 irq 1
[ 2.760527] mousedev: PS/2 mouse device common for all mice
[ 2.769678] input: AT Raw Set 2 keyboard as /devices/platform/i8042/serio0/input/input0
[ 2.777165] rtc_cmos rtc_cmos: rtc core: registered rtc_cmos as rtc0
[ 2.778469] rtc_cmos rtc_cmos: only 24-hr supported
[ 2.813180] i2c /dev entries driver
[ 2.842135] Linux video capture interface: v2.00
[ 2.853055] Bluetooth: Virtual HCI driver ver 1.3
[ 2.859204] Bluetooth: HCI UART driver ver 2.2
[ 2.859806] Bluetooth: HCI H4 protocol initialized
[ 2.860570] Bluetooth: HCI BCSP protocol initialized
[ 2.861188] Bluetooth: HCILL protocol initialized
[ 2.861770] Bluetooth: HCIATH3K protocol initialized
[ 2.862405] Bluetooth: Generic Bluetooth USB driver ver 0.6
[ 2.870546] usbcore: registered new interface driver btusb
[ 2.871386] Bluetooth: Generic Bluetooth SDIO driver ver 0.1
[ 2.872390] Bluetooth: Atheros AR30xx firmware driver ver 1.0
[ 2.873352] usbcore: registered new interface driver ath3k
[ 2.874229] cpuidle: using governor ladder
[ 2.874741] cpuidle: using governor menu
[ 2.876131] sdhci: Secure Digital Host Controller Interface driver
[ 2.876989] sdhci: Copyright(c) Pierre Ossman
[ 2.878076] EFI Variables Facility v0.08 2004-May-17
[ 2.903498] usbcore: registered new interface driver usbhid
[ 2.904348] usbhid: USB HID core driver
[ 2.908019] ALSA device list:
[ 2.908380] No soundcards found.
[ 2.908810] Netfilter messages via NETLINK v0.30.
[ 2.909390] nf_conntrack version 0.5.0 (3395 buckets, 13580 max)
[ 2.910672] ctnetlink v0.93: registering with nfnetlink.
[ 2.911695] ip_tables: (C) 2000-2006 Netfilter Core Team
[ 2.912383] TCP cubic registered
[ 2.912786] Initializing XFRM netlink socket
[ 2.913298] NET: Registered protocol family 17
[ 2.913813] NET: Registered protocol family 15
[ 2.914390] Bridge firewalling registered
[ 2.915120] Bluetooth: RFCOMM TTY layer initialized
[ 2.915749] Bluetooth: RFCOMM socket layer initialized
[ 2.916377] Bluetooth: RFCOMM ver 1.11
[ 2.916809] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[ 2.917450] Bluetooth: BNEP filters: protocol multicast
[ 2.918082] Bluetooth: HIDP (Human Interface Emulation) ver 1.2
[ 2.929324] lib80211: common routines for IEEE802.11 drivers
[ 2.930077] Installing 9P2000 support
[ 2.962797] Registering the dns_resolver key type
[ 2.970658] Magic number: 5:89:42
[ 2.971267] bdi 7:7: hash matches
[ 2.971688] BIOS EDD facility v0.16 2004-Jun-25, 0 devices found
[ 2.972438] EDD information not available.
[ 2.984081] Sending DHCP requests ., OK
[ 2.997064] IP-Config: Got DHCP answer from 192.168.33.1, my address is 192.168.33.15
[ 2.998808] IP-Config: Complete:
[ 2.999437] device=eth0, addr=192.168.33.15, mask=255.255.255.0, gw=192.168.33.1,
[ 3.001260] host=192.168.33.15, domain=, nis-domain=(none),
[ 3.003600] bootserver=192.168.33.1, rootserver=0.0.0.0, rootpath=
[ 3.005075] VFS: Unable to mount root fs via NFS, trying floppy.
[ 3.018273] VFS: Mounted root (9p filesystem) on device 0:13.
[ 3.019516] devtmpfs: mounted
[ 3.020904] Freeing unused kernel memory: 512k freed
[ 3.021978] Write protecting the kernel read-only data: 12288k
[ 3.028874] Freeing unused kernel memory: 1900k freed
[ 3.033644] Freeing unused kernel memory: 1432k freed
Mounting…
Then you got a shell:
sh-4.2# dmesg |grep IP
[ 0.001999] Calibrating delay loop (skipped) preset value.. 4988.66 BogoMIPS (lpj=2494332)
[ 0.164644] Total of 4 processors activated (19954.65 BogoMIPS).
[ 0.220978] NetLabel: protocols = UNLABELED CIPSOv4
[ 0.239220] IP route cache hash table entries: 4096 (order: 3, 32768 bytes)
[ 2.997064] IP-Config: Got DHCP answer from 192.168.33.1, my address is 192.168.33.15
[ 2.998808] IP-Config: Complete:
sh-4.2#
sh-4.2# pwd
/
sh-4.2#
sh-4.2# ls
bin etc host lib64 root sys usr virt
dev home lib proc sbin tmp var
sh-4.2#
In HOST system you can below process :
root 19127 2.3 0.7 1113212 44180 pts/12 Sl+ Jul29 102:17 ./lkvm run -d default
Wow, I like the process string : pretty light weight when compared to ‘qemu-kvm’ process output!!!
Let me explore some more on booted VM:
The running/created VM has a filesystem called “/host” inside it, its basically the fileystem of your host system mounted as READONLY volume using ‘virtfs-9p’ as shown below:
mount(“hostfs”, “/host”, “9p”, MS_RDONLY, “trans=virtio,version=9p2000.L”);
If you dont know whats virtfs-9p please refer:
Share host filsystem to guest using virtfs 9p filesystem passthrough
You can see it from guest :
sh-4.2# cd /host/
sh-4.2# ls
bin dev export lib lost+found mnt proc root sbin sys usr
boot etc home lib64 media opt rhev run srv tmp var
sh-4.2#
Along with above , other ‘pseudo’ filesystem are also mouned:
mount(“”, “/sys”, “sysfs”, 0, NULL);
mount(“proc”, “/proc”, “proc”, 0, NULL);
mount(“devtmpfs”, “/dev”, “devtmpfs”, 0, NULL);
mkdir(“/dev/pts”, 0755);
mount(“devpts”, “/dev/pts”, “devpts”, 0, NULL);
To exit the VM:
sh-4.2# exit
exit
[260641.370260] Unregister pv shared memory for cpu 0
[260641.370268] Unregister pv shared memory for cpu 3
[260641.370272] Unregister pv shared memory for cpu 2
[260641.374433] Unregister pv shared memory for cpu 1
[260641.390303] kvm: exiting hardware virtualization
[260641.426874] Restarting system.
[260641.427784] machine restart
# KVM session ended normally.
[root@humbles-lap kvm]#
Now let me run a VM as sandbox and execute ‘cat /etc/resolv.conf’
Here you go:
#./lkvm sandbox -k ../../arch/x86/boot/bzImage — cat /etc/resolv.conf
[ 2.011673] Write protecting the kernel read-only data: 12288k
[ 2.017508] Freeing unused kernel memory: 1900k freed
[ 2.021831] Freeing unused kernel memory: 1432k freed
Mounting…
# Generated by NetworkManager
nameserver 192.168.1.1
[ 2.240628] Unregister pv shared memory for cpu 1
[ 2.240635] Unregister pv shared memory for cpu 2
[ 2.240641] Unregister pv shared memory for cpu 3
[ 2.247055] Unregister pv shared memory for cpu 0
[ 2.248623] kvm: exiting hardware virtualization
[ 2.253141] Restarting system.
[ 2.254054] machine restart
# KVM session ended normally.
[root@humbles-lap kvm]#
The requested output was produced
(String starting with # Generated..
) and the session was exited.
ps # As expected ‘init’ created ‘sandbox.sh’ with below entry 🙂
[root@humbles-lap guest]# cat sandbox.sh
#! /bin/bash
‘cat’ ‘/etc/resolv.conf’
[root@humbles-lap guest]#
Reference # http://www.linux-kvm.org/wiki/images/c/c5/2011-forum-native-linux-kvm-tool.pdf