Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently working on an embedded system design and my test development machine is currently a VM running in KVM. Is it possible to have KVM mount a directory (like a chroot) and use that as the root file system for the VM?

I currently have the root filesystem in a single sparse file, and I can mount it via loop to a directory, but when making and testing changes it would be much easier to have the root fs in a directory structure on my local machine.

share|improve this question
Just to be clear, are you running Linux both as host and guest? – Gilles May 16 '11 at 20:46
Yes (and i need more chars) – tMC May 16 '11 at 21:08
up vote 2 down vote accepted

If your virtual machine has IP connectivity, mount its root filesystem over NFS. (You'll need to have the NFS client driver and its dependencies in the kernel or initrd/initramfs.)

On the host, install an NFS server and export the directory by declaring it in /etc/exports.


On the guest, read nfsroot.txt in the kernel documentation; in a nutshell, the kernel command line should contain something like

root=/dev/nfs nfsroot=

If sharing the directory tree during the VM's run time isn't an absolute requirement, and all you're after is conveniently regenerating your root filesystem before booting the VM, then it would be simple enough to write a small script or makefile that rebuilds the root filesystem image before booting. This is pretty common in embedded development. A convenient choice of root filesystem is initramfs, a variant of initrd. See also How to generate initramfs image with busybox links?.

share|improve this answer
I thought about that, but my embedded kernel doesn't support networking- yet. – tMC May 16 '11 at 21:08
@tMC: Well then, what filesystem drivers are included in your embedded kernel? Whatever you end up using will have to have a kernel driver in the guest. – Gilles May 16 '11 at 21:11
currently just the ext filesystems currently. I didn't know if there was a way to abstract the disk with some KVM fs driver or the like. The current design doesn't call for NFS in the VM, so if i add it, it would have to be a specific 'development build' – tMC May 16 '11 at 21:16
@tMC: The ext* filesystem drivers expect to have exclusive control over the underlying image. So it seems that you will have to do a specific development build if you want to use the same mounted hierarchy on both machines simultaneously. – Gilles May 16 '11 at 21:30
@tMC: It occurs to me that the best solution for you is probably an initramfs. (And if you'd considered it and were looking for something more convenient, well, I don't think there is, given your requirements.) – Gilles May 16 '11 at 23:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.