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.
To begin with, make sure that hostfs is available inside the virtual machine with
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:
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:
mount none /mnt/home -t hostfs -o /home
will mount the hosts's /home on the virtual machine's /mnt/home.
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:
# 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:
/dev/ubd/0 / 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:
# find . -uid 0 -exec chown jdike {} \;
Next, make sure that your UML kernel has hostfs compiled in, not as a
module. Then run UML with the boot device pointing at that directory:
ubd0=/path/to/uml/root/directory
UML should then boot as it does normally.
If you need to build hostfs because it's not in your kernel, you have two choices:
Reconfigure the kernel and set the 'Host filesystem' option under 'Processor features' to 'Y'. Recompile the kernel and reboot it.
Reconfigure the kernel and set the 'Host filesystem' option under 'Processor features' to 'M'. Rebuild the kernel modules. hostfs will be in arch/um/fs/hostfs/hostfs.o. Install that in /lib/modules/`uname -r`/fs in the virtual machine, boot it up, and
insmod hostfs