1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="LinuxDoc-Tools 0.9.21">
<TITLE>User Mode Linux HOWTO : Host file access</TITLE>
<LINK HREF="UserModeLinux-HOWTO-10.html" REL=next>
<LINK HREF="UserModeLinux-HOWTO-8.html" REL=previous>
<LINK HREF="UserModeLinux-HOWTO.html#toc9" REL=contents>
</HEAD>
<BODY>
<A HREF="UserModeLinux-HOWTO-10.html">Next</A>
<A HREF="UserModeLinux-HOWTO-8.html">Previous</A>
<A HREF="UserModeLinux-HOWTO.html#toc9">Contents</A>
<HR>
<H2><A NAME="hostfs"></A> <A NAME="s9">9.</A> <A HREF="UserModeLinux-HOWTO.html#toc9">Host file access</A></H2>
<P>
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.</P>
<P>
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.</P>
<H2><A NAME="ss9.1">9.1</A> <A HREF="UserModeLinux-HOWTO.html#toc9.1">Using hostfs</A>
</H2>
<P>To begin with, make sure that hostfs is available inside the virtual
machine with
<BLOCKQUOTE><CODE>
<PRE>
cat /proc/filesystems
</PRE>
</CODE></BLOCKQUOTE>
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.</P>
<P>
Now all you need to do is run mount:
<BLOCKQUOTE><CODE>
<PRE>
mount none /mnt/host -t hostfs
</PRE>
</CODE></BLOCKQUOTE>
will mount the host's / on the virtual machine's /mnt/host.</P>
<P>
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:
<BLOCKQUOTE><CODE>
<PRE>
mount none /mnt/home -t hostfs -o /home
</PRE>
</CODE></BLOCKQUOTE>
will mount the hosts's /home on the virtual machine's /mnt/home.</P>
<H2><A NAME="ss9.2">9.2</A> <A HREF="UserModeLinux-HOWTO.html#toc9.2">hostfs as the root filesystem</A>
</H2>
<P>It's possible to boot from a directory hierarchy on the host using hostfs
rather than using the standard filesystem in a file.</P>
<P> To start, you need that hierarchy. The easiest way is to loop mount an
existing root_fs file:
<BLOCKQUOTE><CODE>
<PRE>
# mount root_fs uml_root_dir -o loop
</PRE>
</CODE></BLOCKQUOTE>
You need to change the filesystem type of / in etc/fstab to be 'hostfs', so
that line looks like this:
<BLOCKQUOTE><CODE>
<PRE>
/dev/ubd/0 / hostfs defaults 1 1
</PRE>
</CODE></BLOCKQUOTE>
Then you need to chown to yourself all the files in that directory that are
owned by root. This worked for me:
<BLOCKQUOTE><CODE>
<PRE>
# find . -uid 0 -exec chown jdike {} \;
</PRE>
</CODE></BLOCKQUOTE>
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:
<BLOCKQUOTE><CODE>
<PRE>
ubd0=/path/to/uml/root/directory
</PRE>
</CODE></BLOCKQUOTE>
UML should then boot as it does normally.</P>
<H2><A NAME="ss9.3">9.3</A> <A HREF="UserModeLinux-HOWTO.html#toc9.3">Building hostfs</A>
</H2>
<P>If you need to build hostfs because it's not in your kernel, you have
two choices:</P>
<P>
<UL>
<LI>Compiling hostfs into the kernel: <P>
Reconfigure the kernel and set the 'Host filesystem' option under
'Processor features' to 'Y'. Recompile the kernel and reboot it.</P>
</LI>
<LI>Compiling hostfs as a module: <P>
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
<BLOCKQUOTE><CODE>
<PRE>
insmod hostfs
</PRE>
</CODE></BLOCKQUOTE>
</P>
</LI>
</UL>
</P>
<HR>
<A HREF="UserModeLinux-HOWTO-10.html">Next</A>
<A HREF="UserModeLinux-HOWTO-8.html">Previous</A>
<A HREF="UserModeLinux-HOWTO.html#toc9">Contents</A>
</BODY>
</HTML>
|