/[gentoo]/xml/htdocs/doc/en/xen-guide.xml
Gentoo

Contents of /xml/htdocs/doc/en/xen-guide.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.14 - (show annotations) (download) (as text)
Sun Oct 7 13:32:49 2012 UTC (22 months, 3 weeks ago) by swift
Branch: MAIN
Changes since 1.13: +76 -213 lines
File MIME type: application/xml
Bug #437222 - Update Xen document to reflect later releases

1 <?xml version='1.0' encoding='UTF-8'?>
2 <!DOCTYPE guide SYSTEM "/dtd/guide.dtd">
3 <!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/xen-guide.xml,v 1.13 2012/07/24 12:12:51 swift Exp $ -->
4
5 <guide disclaimer="draft">
6 <title>Configuring Gentoo with Xen</title>
7
8 <author title="Author">
9 <mail link="swift@gentoo.org">Sven Vermeulen</mail>
10 </author>
11 <author title="Editor">
12 <mail link="nightmorph"/>
13 </author>
14
15 <abstract>
16 This guide describes how to start using Xen on your Gentoo system
17 </abstract>
18
19 <!-- The content of this document is licensed under the CC-BY-SA license -->
20 <!-- See http://creativecommons.org/licenses/by-sa/2.5 -->
21 <license/>
22
23 <version>9</version>
24 <date>2012-10-07</date>
25
26 <chapter>
27 <title>Introduction</title>
28 <section>
29 <body>
30
31 <p>
32 The <uri link="http://www.xen.org/">Xen</uri> technology allows you to run
33 multiple operating systems on a single physical system, govern resource
34 consumption and even migrate domains (which are the virtual environments in
35 which a guest operating system runs) from one Xen-powered system to another. Xen
36 requires the host operating system to support Xen (which, in this case, will be
37 a Linux kernel) but guest operating systems can run unmodified <e>if</e> your
38 hardware supports Intel Virtualization Technology (VT-x) or AMD Virtualization
39 Technology (SVM). Otherwise your guest operating systems must also support Xen.
40 </p>
41
42 <p>
43 This guide will talk you through the configuration steps necessary to get Xen up
44 and running on Gentoo Linux. We will not discuss Xen itself (the Xen project has
45 <uri link="http://xen.org/support/documentation.html">decent documentation</uri>
46 available) nor will we talk about specialized setups that might be very
47 interesting for Xen setups but are not Xen-related (like exporting Portage
48 through NFS, booting Linux using PXE, etc.)
49 </p>
50
51 </body>
52 </section>
53 </chapter>
54 <chapter>
55 <title>Preparing Domain0</title>
56 <section>
57 <title>Introduction</title>
58 <body>
59
60 <p>
61 <e>Domain0</e> is the primary domain under Xen, hosting the host operating
62 system which governs all other domains. In this chapter we will prepare an
63 existing Gentoo installation to become the host operating system in this domain
64 and build the Xen-powered kernel so that Gentoo is ready to host other Xen
65 domains.
66 </p>
67
68 </body>
69 </section>
70 <section>
71 <title>Rebuilding the Gentoo Installation?</title>
72 <body>
73
74 <p>
75 A dramatic change that might be necessary is to rebuild the entire Gentoo
76 installation with a different <c>CFLAGS</c> setting. Guest operating systems
77 running under Xen might otherwise see major performance degradation. If you,
78 however, are planning on checking out Xen rather than installing it for
79 production use and are not terribly fond of rebuilding all programs, you can
80 skip this step. In this case you will notice performance degradation but you
81 will still be able to use Xen.
82 </p>
83
84 <impo>
85 It is advised that, if you change your <c>CFLAGS</c> and build your system with
86 a gcc lower than version 4, you do not have <c>-Os</c> set as it has been
87 reported to produce broken code.
88 </impo>
89
90 <pre caption="Editing the CFLAGS and rebuild the Gentoo installation">
91 ~# <i>nano -w /etc/portage/make.conf</i>
92 <comment>(Add -mno-tls-direct-seg-refs ONLY if you have a 32-bit dom0)</comment>
93 <comment>(You don't need this flag if you have a 64-bit dom0)</comment>
94 CFLAGS="-O2 -march=pentium4 -pipe <i>-mno-tls-direct-seg-refs</i>"
95
96 ~# <i>emerge -e world</i>
97 </pre>
98
99 <p>
100 If you boot your system using an initial ramdisk (initrd) you need to
101 rebuild the initrd as well (which is best done by running all steps you would do
102 when you rebuild your kernel).
103 </p>
104
105 </body>
106 </section>
107 <section>
108 <title>Installing Xen</title>
109 <body>
110
111 <p>
112 Xen actually contains many components, so you'll need to install a few
113 packages.
114 </p>
115
116 <pre caption="Installing Xen">
117 ~# <i>emerge xen xen-tools gentoo-sources</i>
118 </pre>
119
120 </body>
121 </section>
122 <section>
123 <title>Building the Kernel</title>
124 <body>
125
126 <p>
127 Next we'll build the Linux kernel with Xen support. This kernel, whose sources
128 are available at <path>/usr/src/linux</path>, will be our main
129 running kernel (i.e. the one running domain 0). In the <c>XEN</c> section you'll
130 find drivers for all kinds of input/output, each driver having a <e>backend</e>
131 and <e>frontend</e> implementation available. For the domain 0 kernel you need
132 to select the <e>backend</e> implementation: these are used by the other
133 domains (who use the <e>frontend</e> drivers) to communicate directly with
134 the hardware. However, you should be able to configure the kernel to provide
135 support for both frontend (guest) and backend (host) drivers.
136 </p>
137
138 <p>
139 If you're wondering about networking: each interface in a domain
140 has a point-to-point link to an interface on domain 0 (called
141 <path>vifX.Y</path> where X is the domain number and Y the Yth interface of that
142 domain), so you can configure your network the way you want (bridging, NAT,
143 etc.)
144 </p>
145
146 <pre caption="Enabling Xen Support">
147 Processor type and features ---&gt;
148 [*] Paravirtualized guest support ---&gt;
149 [*] Xen guest support
150 </pre>
151
152 <pre caption="Kernel Config">
153 Bus options (PCI etc.) ---&gt;
154 [*] Xen PCI Frontend
155
156 [*] Networking support ---&gt;
157 Networking options ---&gt;
158 &lt;*&gt; 802.1d Ethernet Bridging
159 [*] Network packet filtering framework (Netfilter) ---&gt;
160 [*] Advanced netfilter configuration
161 [*] Bridged IP/ARP packets filtering
162
163 Device Drivers ---&gt;
164 [*] Block devices (NEW) ---&gt;
165 &lt;*&gt; Xen block-device backend driver
166 [*] Network device support ---&gt;
167 &lt;*&gt; Xen backend network device
168 Xen driver support ---&gt;
169 [*] Xen memory balloon driver (NEW)
170 [*] Scrub pages before returning them to system (NEW)
171 &lt;*&gt; Xen /dev/xen/evtchn device (NEW)
172 [*] Backend driver support (NEW)
173 &lt;*&gt; Xen filesystem (NEW)
174 [*] Create compatibility mount point /proc/xen (NEW)
175 [*] Create xen entries under /sys/hypervisor (NEW)
176 &lt;M&gt; userspace grant access device driver (NEW)
177 &lt;M&gt; user-space grant reference allocator driver (NEW)
178 &lt;M&gt; xen platform pci device driver (NEW)
179 </pre>
180
181 <p>
182 The shown kernel configuration should allow the kernel image to boot both as a
183 host as well as a guest. However, if you want to, you can slim down the guest
184 image kernel considerably. Refer to the Xen documentation for more information.
185 </p>
186
187 <p>
188 Once the kernel is built you'll find the kernel image immediately in the
189 build directory (not inside <path>arch/</path> or any other directory) called
190 <path>vmlinuz</path>. Copy it to <path>/boot</path> and then configure your
191 bootloader to use the Xen hypervisor (one of the components installed
192 previously) which is stored as <path>/boot/xen.gz</path>. In the bootloader
193 configuration, add your newly built kernel as the kernel that Xen should
194 boot. For instance, for GRUB:
195 </p>
196
197 <pre caption="GRUB Configuration for Xen">
198 title Xen Gentoo Linux 3.5
199 root (hd0,0)
200 kernel /boot/xen.gz
201 module /boot/kernel-3.5.x.y-xen0 root=/dev/sda3
202 </pre>
203
204 <p>
205 Now reboot your system into Xen and check if you can do whatever you
206 normally do on your system. If this is the case, you can edit your
207 bootloader configuration to always boot into Xen.
208 </p>
209
210 <note>
211 If you wish to start guest domains automatically on boot add <c>xendomains</c>
212 to the default runlevel as well and create a symlink in
213 <path>/etc/xen/auto/</path> to the Xen configuration files for the domains
214 you wish to start.
215 </note>
216
217 </body>
218 </section>
219 </chapter>
220 <chapter>
221 <title>Creating an Unpriviledged Domain</title>
222 <section>
223 <title>Building the Kernel</title>
224 <body>
225
226 <p>
227 Go to the Xen-powered Linux kernel source and, if necessary, update the
228 configuration. It is wise to keep as many topics as possible similar to
229 the main kernel. Then build the kernel
230 and place the resulting <path>vmlinuz</path> file where you want (we assume this
231 is <path>/mnt/data/xen/kernel</path>):
232 </p>
233
234 <pre caption="Building the guest kernel">
235 ~# <i>make O=~/build/domU</i>
236 ~# <i>cp ~/build/domU/vmlinuz /mnt/data/xen/kernel/kernel-3.5.x.y-xen</i>
237 </pre>
238
239 </body>
240 </section>
241 <section>
242 <title>Creating the Domain Disks</title>
243 <body>
244
245 <p>
246 For best performance, it is best to dedicate a partition (or logical volume) to
247 a domain rather than a file based filesystem. However, if you are going to use
248 Xen primarily for tests using a file based filesystem does have its advantages
249 (especially regarding maintenance).
250 </p>
251
252 <p>
253 You can create a file based filesystem using <c>dd</c> and <c>mke2fs</c> (or
254 any other file system creation tool). For instance, to create a 4 Gbyte ext4
255 filesystem:
256 </p>
257
258 <pre caption="Creating a file based filesystem">
259 ~# <i>dd if=/dev/zero of=/mnt/data/xen/disks/ext4root.img bs=1M count=4096</i>
260 ~# <i>mkfs.ext4 /mnt/data/xen/disks/ext4root.img</i>
261 </pre>
262
263 </body>
264 </section>
265 <section>
266 <title>Configuring a Domain</title>
267 <body>
268
269 <p>
270 Next we create a Xen configuration file for a domain. You can store these
271 configuration files where you want, for instance at
272 <path>/mnt/data/xen/configs</path>. As an example, we create a configuration
273 file for a small Gentoo environment which uses the disk image we created
274 previously:
275 </p>
276
277 <pre caption="Creating a domain configuration file">
278 ~# <i>nano -w /mnt/data/xen/configs/gentoo</i>
279
280 kernel = "/mnt/data/xen/kernel/kernel-3.5.x.y-xen"
281 memory = 512
282 name = "gentoo"
283 <comment>(Map the disk image to the virtual /dev/sda1)</comment>
284 disk = ['file:/mnt/data/xen/disks/ext4root.img,sda1,w']
285 root = "/dev/sda1 ro"
286 </pre>
287
288 <p>
289 If you are using a block device (such as an lvm volume or partition) for
290 the disk use 'phy:' instead of 'file:' and leave off /dev. For example:
291 </p>
292
293 <pre caption="Using a block device">
294 <comment>(LVM Volume)</comment>
295 disk = [ 'phy:lvm/xen-guest-root,sda1,w' ]
296
297 <comment>(Physical Partition)</comment>
298 disk = [ 'phy:sdb6,sda1,w' ]
299 </pre>
300
301 <p>
302 You can find example configuration files in <path>/etc/xen</path>.
303 </p>
304
305 </body>
306 </section>
307 <section>
308 <title>Launching the New Domain</title>
309 <body>
310
311 <p>
312 Now we're all set and we can launch the new domain. If the disk image contained
313 an operating system, we could just create and attach the domain using the
314 <c>xl</c> command:
315 </p>
316
317 <pre caption="Creating and starting a new domain">
318 ~# <i>xl create /mnt/data/xen/configs/gentoo -c</i>
319 </pre>
320
321 <p>
322 The domain would be booted inside the terminal in which you executed the
323 command. However, in our case, the disk image is empty so the domain won't boot
324 up in anything useful. To fix this, you can loop-mount the image and install
325 Gentoo as you're used to.
326 </p>
327
328 <p>
329 If you want to disconnect from the domain, press <path>Ctrl+]</path>. You can
330 always reconnect to the domains' console using <c>xl console gentoo</c>.
331 However, there is only one console per domain, so only use it when you can't
332 access the domain otherwise (for instance, through SSH).
333 </p>
334
335 </body>
336 </section>
337 </chapter>
338 <chapter>
339 <title>Networking on Unpriviledged Domains</title>
340 <section>
341 <title>Introduction</title>
342 <body>
343
344 <p>
345 Xen works best when using a bridged mode network configuration.
346 This means that your default network interface on
347 the administrative domain becomes a bridge which accepts connections to the
348 virtual domains as well as to the IP address your administrative domain has.
349 </p>
350
351 </body>
352 </section>
353 <section>
354 <title>Bridged Interfaces</title>
355 <body>
356
357 <p>
358 Create a bridge interface by creating a new link to the networking init script
359 as provided by Gentoo:
360 </p>
361
362 <pre caption="Creating a bridge interface">
363 # <i>cd /etc/init.d</i>
364 # <i>ln -s net.lo net.br0</i>
365 </pre>
366
367 <p>
368 Next, edit <path>/etc/conf.d/net</path> and setup the bridge:
369 </p>
370
371 <pre caption="Enabling the bridge br0 interface">
372 # <i>nano -w /etc/conf.d/net</i>
373
374 bridge_br0="eth0"
375 config_br0="192.168.1.200 netmask 255.255.255.0 brd 192.168.1.255"
376 routes_br0="default via 192.168.1.1"
377 </pre>
378
379 <p>
380 Finally, install the <e>net-misc/bridge-utils</e> package, and make sure the
381 <path>net.br0</path> init script is loaded at boot.
382 </p>
383
384 <pre caption="Finishing the bridge setup">
385 # <i>emerge net-misc/bridge-utils</i>
386 # <i>rc-update add net.br0 default</i>
387 </pre>
388
389 </body>
390 </section>
391 </chapter>
392 <chapter>
393 <title>Further Resources</title>
394 <section>
395 <title>Xen Documentation</title>
396 <body>
397
398 <ul>
399 <li>
400 <uri link="http://www.xen.org/support/documentation.html">Official Xen
401 documentation</uri>
402 </li>
403 <li>
404 <uri link="http://wiki.xen.org/">Xen Wiki</uri>
405 </li>
406 </ul>
407
408 </body>
409 </section>
410 <section>
411 <title>Xen Tools</title>
412 <body>
413
414 <ul>
415 <li>
416 <uri
417 link="http://virt-manager.org/">app-emulation/virt-manager</uri>
418 is a graphical tool for administering virtual machines
419 </li>
420 </ul>
421
422 </body>
423 </section>
424 </chapter>
425 </guide>

  ViewVC Help
Powered by ViewVC 1.1.20