Tag Archives: linux

Revisiting Native Linux KVM Tool

Just a quick revisit of native linux kvm tool(nlkt). There were quite a few improvements upstream. So, I git pulled the latest, built kernel; built the binary executable. The nlkt binary is now renamed to ‘lkvm’ (thanks Pekka, it’ll improve searchability a lot)

Some enhancements I noticed from my testing:
– 9pfs enhancements
– Writable support for qcow2 disk-images
– sandbox support — this seems to be mostly a wrapper around ‘run’ command

After building, I posted latest kvm tool binary lkvm, kernel bzImage, linux .config and init binaries over here . Also, a couple of simple test results with latest git.

To try out a slightly long way, clone the nlkt git tree, (also ensure to have the correct directives enabled in the linux config. I posted mine above) ; build the kernel and kvm tool.

Build:

 
# cd linux-kvm
# make -j5
# cd tools/kvm 
# make
 

To give a quick try with the binaries I posted above, first let’s setup default rootfs by running the setup command. Note that we also need to have a guest directory with init and init_stage2 binaries. Where the init mounts the host file system as read-only, runs the init_stage2 to setup a tty console and call the shell executable /bin/sh

 
--------------------------------------------
[kashyap@tesla nlkt-jan11]$ #./lkvm setup default
--------------------------------------------
[kashyap@tesla nlkt-jan11]$ pwd
/var/tmp/nlkt-jan11
--------------------------------------------
[kashyap@tesla nlkt-jan11]$ tree
.
├── bzImage
├── guest
│   ├── init
│   └── init_stage2
└── lkvm

1 directory, 4 files
[kashyap@tesla nlkt-jan11]$
 

Once we boot into our default rootfs setup, let’s boot into the kernel

 
[kashyap@tesla nlkt-jan11]$ ./lkvm run -d default 
  # lkvm run -k ./bzImage -m 448 -c 4 --name default
.
.
.
Starting '/bin/sh'...
sh-4.2# 
 

We can also notice the host file system being mounted read-only in the guest:

 
--------
sh-4.2# pwd
/
--------
sh-4.2# ls
bin  etc   host  lib64	root  sys  usr	virt
dev  home  lib	 proc	sbin  tmp  var
--------
sh-4.2# ls host/ ; cd host
bin   dev  home  lib64	     media  opt   root	sbin  sys  usr
boot  etc  lib	 lost+found  mnt    proc  run	srv   tmp  var
--------
sh-4.2# touch foo
touch: cannot touch `foo': Read-only file system
sh-4.2# 
--------
 

Now, let’s try the sandbox, which will run a command as part of the init and then exits gracefully . In this case, it’s a simple ls command.

  
--------
[kashyap@tesla nlkt-jan11]$ ./lkvm sandbox -k ./bzImage -- ls
  # lkvm run -k ./bzImage -m 448 -c 4 --name guest-9990
.
.
.
Mounting...
Starting '/bin/sh'...
bin  etc   host  lib64	root  sys  usr	virt
dev  home  lib	 proc	sbin  tmp  var
[    2.052463] Unregister pv shared memory for cpu 1
[    2.052546] Unregister pv shared memory for cpu 0
[    2.052578] Unregister pv shared memory for cpu 3
[    2.055887] Unregister pv shared memory for cpu 2
[    2.057093] Restarting system.
[    2.057407] machine restart

  # KVM session ended normally.
[kashyap@tesla nlkt-jan11]$ 
--------
 

NOTE: I just cleared some of the stdout for brevity.

UPDATE: Pekka Enberg reminded me in a comment below that I missed to note two more additional user-visible features — PPC64 architecture support ; Serial console emulation is much more faster. (I totally agree there.)

Advertisement

2 Comments

Filed under Uncategorized

Share an interactive ssh session b/n two users with ‘tmux’

I recently started using tmux, a terminal multiplexer much similar to GNU screen(which I still use on a lot on RHEL machines). Personally, I find tmux more elegant and less cryptic while configuring. Specially, sharing interactive(or read-only) ssh sessions w/ remote folks for debugging is very trivial.

Get it:

  $ yum install tmux -y   

Create a tmux session(let’s say on testbox1) by specifying path to a socket(its name can be anything)to be used:

 $ tmux -S /var/tmp/share-ses 
# Where -S is the absolute path to the server socket.

Now, to share the above created session w/ a remote user, ask the person to ssh into testbox1, and then try the below for sharing a session interactively or read-only mode:

  • Read/Write session, so that both users can interactively edit on the shell:
  •  $ tmux -S /var/tmp/share-ses attach 
  • For ‘Read-Only’ session(for remote user) :
  • $ tmux -S /var/tmp/share-ses attach -r 
    # Where r is 'read-only' mode for the remote user,
    # so he/she can just 'watch' the session.
    

To detach from the session: $ tmux detach (or use the binding — Ctl+b d when in ‘read-only’ mode)

3 Comments

Filed under Uncategorized