/[gentoo]/xml/htdocs/doc/en/uml.xml
Gentoo

Contents of /xml/htdocs/doc/en/uml.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download) (as text)
Sun Mar 30 18:24:58 2003 UTC (15 years, 11 months ago) by zhen
Branch: MAIN
Changes since 1.4: +21 -6 lines
File MIME type: application/xml
fix for bug 16134

1 zhen 1.3 <?xml version='1.0' encoding="UTF-8"?>
2 drobbins 1.1 <?xml-stylesheet href="/xsl/guide.xsl" type="text/xsl"?>
3    
4     <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
5    
6 zhen 1.2 <guide link="/doc/en/uml.xml">
7 drobbins 1.1 <title>Gentoo Linux Developer's guide to system testing with User-Mode Linux</title>
8     <author title="Editor"><mail link="g2boojum@gentoo.org">Grant Goodyear</mail></author>
9 zhen 1.5 <author title="Editor"><mail link="zhen@gentoo.org">John Davis</mail></author>
10 drobbins 1.1
11     <abstract>
12     This guide shows Gentoo Linux developers how to set up and use
13     user-mode linux for testing potentially system-breaking changes.
14     </abstract>
15    
16 zhen 1.5 <version>0.07</version>
17     <date>21 March 2003</date>
18 drobbins 1.1
19     <chapter>
20     <title>Obtaining User-Mode Linux</title>
21     <section>
22     <body>
23     <p>As the user-mode linux website
24     (<uri>http://user-mode-linux.sourceforge.net</uri>)
25     states, user-mode linux
26     allows a user to "run Linux inside itself". Specifically,
27     user-mode linux provides a virtual machine on which a user can "[r]un buggy
28     software, experiment with new Linux kernels or distributions, and poke around
29     in the internals of Linux, all without risking your main Linux setup." Changes
30     to Gentoo core packages such as <e>sys-apps/baselayout</e> or <e>sys-libs/glibc</e>
31     have the potential to break the system and render it unbootable; with user-mode
32     linux we can test these changes without having to worry about breaking the live
33     system.
34     </p>
35     <p>
36     Installing user-mode linux is essentially identical to a normal kernel
37     install. First install the kernel sources (appropriately patched for
38     user-mode linux), and then configure the user-mode linux kernel in the
39     usual fashion:
40     </p>
41     <pre>
42     # <i>emerge sys-kernel/usermode-sources</i>
43     # <i>cd /usr/src/uml/linux</i>
44     # <i>make menuconfig <comment>ARCH=um</comment></i>
45     # <i>make linux <comment>ARCH=um</comment></i>
46     # <i>cp linux /usr/local/bin/linux</i>
47     </pre>
48     <warn>The <e>ARCH=um</e> fragment is <e>extremely</e> important!</warn>
49     <impo>
50     For the user-mode linux kernel to properly boot a Gentoo system the
51     kernel needs to be configured to <e>not</e> automatically mount
52     <path>/dev</path> (devfs) by default.
53     Also, you will almost certainly
54     want to make sure that you have <e>tmpfs</e> (the "Virtual Memory
55     Filesystem") compiled in, since by default the Gentoo linux bootscripts
56     store their information in a small tmpfs partition.
57     (The binary kernels available
58     from the user-mode website do automatically mount <path>/dev</path>,
59     and they don't have tmpfs compiled in; don't bother with them.)
60     </impo>
61     <p>I highly recommend reading the user-mode linux documentation, but the
62     basic idea is that running the <path>/usr/local/bin/linux</path> program
63     boots the user-mode kernel and tries to bring up the system stored in
64     the file <path>root_fs</path> that should be located in the current working
65     directory.</p>
66     <p>It won't hurt to also install the user-mode linux tools.</p>
67     <pre>
68     # <i>emerge sys-apps/usermode-utilities</i>
69     </pre>
70     <p>These tools facilitate networking (among other things)
71     between the user-mode linux virtual system
72     and the host Linux system.</p>
73     </body>
74     </section>
75     </chapter>
76    
77     <chapter>
78     <title>Creating <path>root_fs</path></title>
79    
80     <section>
81     <title>Making the Gentoo chroot</title>
82     <body>
83     <p>
84     The <path>root_fs</path> file needed for user-mode linux is
85     a single file that contains an entire Gentoo Linux filesystem.
86     To generate this file you will need to have Loopback device
87     support enabled in the host (non-user-mode) kernel.
88     </p>
89     <p>Generating the <path>root_fs</path> file itself will be
90     our last step. First we will generate a Gentoo filesystem in
91 zhen 1.4 an ordinary chroot. We need the stage tarball available, which
92     could be downloaded separately, extracted from a liveCD, or
93     extracted from a liveCD .iso.
94 drobbins 1.1 </p>
95 zhen 1.4 <pre caption="Mounting a liveCD .iso">
96 drobbins 1.1 # <i>mkdir /mnt/loop</i>
97     # <i>mount -o loop /path/to/build-&lt;TAB&gt;.iso /mnt/loop</i>
98     </pre>
99     <p>
100     Setting up the chroot is essentially identical to an ordinary Gentoo
101     Linux build.
102     </p>
103     <pre>
104     # <i>mkdir /mnt/gentoo</i>
105     # <i>cd /mnt/gentoo</i>
106     # <i>tar xvjpf /path/to/build-&lt;TAB&gt;.tar.bz2</i>
107     </pre>
108     <p>
109     Go ahead and unmount the .iso. You don't need it anymore.
110     </p>
111     <pre>
112     # <i>cp /etc/resolv.conf /mnt/gentoo/etc/</i>
113     # <i>mount -o bind /proc /mnt/gentoo/proc</i>
114     # <i>mkdir -p /mnt/gentoo/usr/portage/distfiles</i>
115     # <i>mkdir -p /mnt/gentoo/usr/portage/packages</i>
116     # <i>mount -o bind /usr/portage/distfiles /mnt/gentoo/usr/portage/distfiles</i>
117     # <i>mount -o bind /usr/portage/packages /mnt/gentoo/usr/portage/packages</i>
118     # <i>chroot /mnt/gentoo /bin/bash</i>
119 zhen 1.5 <!--per bug 16134, added emerge sync to supress warning, etc-->
120     # <i>emerge sync</i>
121 drobbins 1.1 # <i>env-update</i>
122     # <i>source /etc/profile</i>
123     </pre>
124     <p>
125     By bind-mounting <path>/usr/portage/distfiles</path> and
126     <path>/usr/portage/packages</path> we avoid having to download
127     or build packages that are already present on the Gentoo host.
128     </p>
129     <p>
130     Bootstrap and build the system in the usual fashion:
131     </p>
132     <pre>
133 zhen 1.5 <!--removed the emerge sync below because it is done above-->
134 drobbins 1.1 # <i>cd /usr/portage</i>
135     # <i>nano -w /etc/make.conf</i>
136     # <i>nano -w /etc/make.profile/packages</i>
137     # <i>nano -w /usr/portage/profiles/package.mask</i>
138     # <i>scripts/bootstrap.sh &amp;&amp; emerge --usepkg system</i>
139     </pre>
140     <warn>
141 zhen 1.5 <!--Changed grub to virtual/bootloader-->
142 drobbins 1.1 The <path>/etc/make.profile/packages</path> file needs to be
143 zhen 1.5 edited to remove the virtual/bootloader ebuild from the default system (just remove the "*"
144     from the beginning of the "*virtual/bootloader" line). The virtual/bootloader ebuild
145 drobbins 1.1 tries to mount the /boot partition, which will fail in our chroot.
146     </warn>
147     <note>
148     Make sure you examine <path>/etc/make.profile/packages</path>
149     and <path>/usr/portage/profiles/package.mask</path> to be sure that
150     any to-be-tested packages that you want to install aren't masked out.
151     As currently written, <path>scripts/bootstrap.sh</path> will compile
152     the bootstrap packages from source. To use already-existing packages,
153     add <c>alias emerge="emerge --usepkg"</c> somewhere near the top of
154     the bootstrap script.
155     </note>
156     <p>
157     Add any additional packages you desire. Feel free to give your virtual
158     Gentoo system a hostname, if you so desire. In <path>/etc/fstab</path>
159     you will want <path>/dev/ROOT</path> to be <path>/dev/ubd/0</path>, with
160     a fs type of either ext2, ext3, or reiserfs. Set <path>/dev/SWAP</path>
161     to be <path>/dev/ubd/1</path>, and comment out <path>/dev/BOOT</path>.
162     </p>
163     <p>
164     Exit the chroot, unmount all of the bind mounts,
165     tar up the new Gentoo distro, and clean up:
166     </p>
167     <pre>
168     # <i>exit</i>
169     # <i>umount /mnt/gentoo/usr/portage/distfiles</i>
170     # <i>umount /mnt/gentoo/usr/portage/packages</i>
171     # <i>umount /mnt/gentoo/proc</i>
172     # <i>du -ks /mnt/gentoo</i>
173 zhen 1.5 <!-- wtf is this? 261744 /mnt/gentoo-->
174     <!-- added dir change to be more explicit-->
175     # <i>cd /mnt/gentoo</i>
176 drobbins 1.1 # <i>tar cvjpf ~/gentoo.tbz2 *</i>
177     # <i>cd</i>
178     # <i>rm -rf /mnt/gentoo</i>
179     </pre>
180 zhen 1.5
181     <p> At this point, remember to set your root password. </p>
182    
183     <pre caption="Setting root password">
184     # <c>passwd</c>
185     </pre>
186    
187     <p>You might also want to consider reviewing the final steps of the
188     <uri link="http://www.gentoo.org/doc/en/gentoo-x86-install.xml">Gentoo Linux x86 Installation Guide</uri>. </p>
189 drobbins 1.1 </body>
190     </section>
191    
192     <section>
193     <title>Making <path>root_fs</path></title>
194     <body>
195     <p>
196     Our Gentoo chroot is nearly 300 MB in size, so
197     <path>root_fs</path> needs to be at least that size.
198     We'll choose 0.5 GB as a reasonable size.
199     </p>
200     <pre>
201     # <i>dd if=/dev/zero of=root_fs seek=500 count=1 bs=1M</i>
202     # <i>mke2fs -F root_fs</i>
203     # <i>mount -o loop root_fs /mnt/loop</i>
204     # <i>tar xvjpf gentoo.tbz2 -C /mnt/loop</i>
205     # <i>umount /mnt/loop</i>
206     </pre>
207     <p>
208     It would also be nice to have a 0.5 GB swap partition.
209     </p>
210     <pre>
211     # <i>dd if=/dev/zero of=swap_fs seek=500 count=1 bs=1M</i>
212     # <i>mkswap -f swap_fs</i>
213     </pre>
214     <p>
215     Now see if it works!
216     </p>
217     <pre>
218     # <i>linux ubd0=root_fs ubd1=swap_fs</i>
219     </pre>
220     <note>
221     User-mode linux uses xterms for the virtual consoles that
222     are run at boot time, so you need to make sure that the
223     terminal from which you run user-mode linux has $DISPLAY
224     properly set (along with proper xhost/xauth permissions).
225     </note>
226     <p>
227     With any luck you should be able to log into your user-mode linux
228     Gentoo system. The only thing keeping this user-mode linux version
229     of Gentoo from being fully functional is networking from the virtual
230     machine to the host. Such networking is supposed to be trivial,
231     but I have yet to get it to work for me. Should you find a workable
232     solution, please let me know!
233     </p>
234     </body>
235     </section>
236     </chapter>
237    
238     <chapter>
239     <title>Networking</title>
240    
241     <section>
242     <body>
243     <p>
244     Thanks to Martin Schlemmer (Azarah), I now know how
245     to get networking to function from within a user-mode
246     system. The idea is that we set up a private network
247     consisting of the user-mode system and the host system,
248     and then the user-mode system routes all of its packets
249     to the host, which then forwards packets to the net.
250     Make sure that the host kernel has
251     Networking --> IP: Netfilter Configuration --> IP tables support
252     --> Full NAT --> MASQUERADE target support and
253     Network Device Support --> Ethertap network tap
254     compiled as modules; then do the following on the
255     <e>host</e> machine:
256     </p>
257     <pre>
258     # <i>modprobe ethertap</i>
259     # <i>modprobe iptable_nat</i>
260     # <i>iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE</i>
261     # <i>echo 1 > /proc/sys/net/ipv4/ip_forward</i>
262     </pre>
263     <p>
264     The iptables line sets up IP Masquerading between the private
265     network that our user-mode system will be on and the internet
266     (reachable via <c>eth0</c> in our case). The echo line then
267     turns on packet forwarding between the private network and the
268     interface that the default gateway is on (eth0 for us).
269     </p>
270     <p>
271     Now we bring up the user-mode system and see if networking
272     is functional.
273     </p>
274     <pre>
275     # <i>linux ubd0=root_fs ubd1=swap_fs eth0=ethertap,tap0,,192.168.0.254</i>
276     <comment>(login to user-mode system)</comment>
277     # <i>ifconfig eth0 192.168.0.1 up</i>
278     # <i>ping -c 2 192.168.0.254</i>
279     PING 192.168.0.254 (192.168.0.254): 56 octets data
280     64 octets from 192.168.0.254: icmp_seq=0 ttl=255 time=0.8 ms
281     64 octets from 192.168.0.254: icmp_seq=1 ttl=255 time=0.6 ms
282    
283     --- 192.168.0.254 ping statistics ---
284     2 packets transmitted, 2 packets received, 0% packet loss
285     round-trip min/avg/max = 0.6/0.7/0.8 ms
286     <i>route add default gw 192.168.0.254</i>
287     <i>netstat -rn</i>
288     Kernel IP routing table
289     Destination Gateway Genmask Flags MSS Window irtt Iface
290     192.168.0.0 0.0.0.0 255.255.255.0 U 40 0 0 eth0
291     0.0.0.0 192.168.0.254 0.0.0.0 UG 40 0 0 eth0
292     <i>scp user@192.168.0.254:/etc/resolv.conf /etc/resolv.conf</i> <comment>(if needed)</comment>
293     <i>ping -c 2 www.gentoo.org</i>
294     PING www.gentoo.org (207.170.82.202): 56 octets data
295     64 octets from 207.170.82.202: icmp_seq=0 ttl=240 time=119.6 ms
296     64 octets from 207.170.82.202: icmp_seq=1 ttl=240 time=92.0 ms
297    
298     --- www.gentoo.org ping statistics ---
299     2 packets transmitted, 2 packets received, 0% packet loss
300     round-trip min/avg/max = 92.0/105.8/119.6 ms
301     </pre>
302     <p>
303     On the user-mode system we assign the user-mode eth0 interface
304     the private IP address 192.168.0.1 and bring up the interface. The
305     host has private IP address 192.168.0.254, and we ping it to make sure
306     that our networking is, indeed, up. The route line adds a default
307     gateway, namely our host, we use scp to retrieve a working
308     <path>/etc/resolv.conf</path> (if necessary), and we ping www.gentoo.org
309     to make sure that name resolution (and general access to the internet)
310     is working from our user-mode system. Now the user-mode system can
311     <c>emerge</c> at will!
312     </p>
313     </body>
314     </section>
315     </chapter>
316    
317     <chapter>
318     <title>Testing the .iso</title>
319    
320     <section>
321     <body>
322     <p>
323     Perhaps the true ideal of Gentoo Linux testing would be
324     to boot the .iso with user-mode linux and do the complete
325     Gentoo install from within the user-mode linux virtual system.
326     </p>
327     <p>
328     Booting the .iso, or actually the initrd from the .iso, is pretty
329     straightforward.
330     </p>
331     <pre>
332     # <i>mount -o loop /path/to/build-&lt;TAB&gt;.iso /mnt/loop</i>
333     # <i>cp /mnt/loop/isolinux/rescue.gz .</i>
334     # <i>linux load_ramdisk=1 prompt_ramdisk=0 ramdisk_size=22000 \</i>
335     &gt; <i>initrd=rescue.gz root=/dev/ram0 ubd0=root_fs ubd1=swap_fs \</i>
336     &gt; <i>ubd2=/dev/cdroms/cdrom0 eth0=ethertap,tap0,,192.168.0.254</i>
337     </pre>
338     <p>Now you can follow the Gentoo install doc essentially verbatim,
339     although you'll need to know that the root filesystem will be
340     <path>/dev/ubd/0</path>, the swap "partition"
341     will be <path>/dev/ubd/1</path>, and the CD rom
342     will be <path>/dev/ubd/2</path>.</p>
343     </body>
344     </section>
345     </chapter>
346    
347    
348     </guide>

  ViewVC Help
Powered by ViewVC 1.1.20