Next Previous Contents

9. Host file access

If you want to access files on the host machine from inside UML, you can treat it as a separate machine and either nfs mount directories from the host or copy files into the virtual machine with scp or rcp. However, since UML is running on the the host, it can access those files just like any other process and make them available inside the virtual machine without needing to use the network.

This is now possible with the hostfs virtual filesystem. With it, you can mount a host directory into the UML filesystem and access the files contained in it just as you would on the host.

Note that hostfs is currently not available on 2.5. The reason is that there was an fs.h rework early in 2.5 which required filesystem changes, and I haven't got around to updating hostfs to those changes.

9.1 Using hostfs

To begin with, make sure that hostfs is available inside the virtual machine with

UML# cat /proc/filesystems
hostfs should be listed. If it's not, either rebuild the kernel with hostfs configured into it or make sure that hostfs is built as a module and available inside the virtual machine, and insmod it.

Now all you need to do is run mount:

UML# mount none /mnt/host -t hostfs
will mount the host's / on the virtual machine's /mnt/host.

If you don't want to mount the host root directory, then you can specify a subdirectory to mount with the -o switch to mount:

UML# mount none /mnt/home -t hostfs -o /home
will mount the hosts's /home on the virtual machine's /mnt/home.

9.2 hostfs command line options

There is a hostfs option available on the UML command line which can be used confine all hostfs mounts to a host directory hierarchy or to prevent a hostfs user from destroying data on the host. The format is

 hostfs=directory,options
The only option available at present is 'append', which forces all files to be opened in append mode and disallows any deletion of files.

To specify append mode without confining hostfs to a host directory, just leave out the directory name so that the argument begins with a comma:

 hostfs=,append

9.3 hostfs as the root filesystem

It's possible to boot from a directory hierarchy on the host using hostfs rather than using the standard filesystem in a file.

To start, you need that hierarchy. The easiest way is to loop mount an existing root_fs file:

host#  mount root_fs uml_root_dir -o loop
You need to change the filesystem type of / in etc/fstab to be 'hostfs', so that line looks like this:
none    /       hostfs defaults 1 1
Then you need to chown to yourself all the files in that directory that are owned by root. This worked for me:
host#  find . -uid 0 -exec chown jdike {} \;
If you don't want to do that because that's a filesystem image that you boot as a disk, then run UML as root instead.

Next, make sure that your UML kernel has hostfs compiled in, not as a module. Then run UML with the following arguments added to the command line:

 root=/dev/root rootflags=/path/to/uml/root rootfstype=hostfs
UML should then boot as it does normally.

9.4 Building hostfs

If you need to build hostfs because it's not in your kernel, you have two choices:


Next Previous Contents