1 |
swift 07/07/20 07:18:24 |
2 |
|
3 |
Added: xen-guide.xml |
4 |
Log: |
5 |
Adding Xen draft (bug #105117), still needs work (like the comments on the bug state) |
6 |
|
7 |
Revision Changes Path |
8 |
1.1 xml/htdocs/doc/en/draft/xen-guide.xml |
9 |
|
10 |
file : http://sources.gentoo.org/viewcvs.py/gentoo/xml/htdocs/doc/en/draft/xen-guide.xml?rev=1.1&view=markup |
11 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo/xml/htdocs/doc/en/draft/xen-guide.xml?rev=1.1&content-type=text/plain |
12 |
|
13 |
Index: xen-guide.xml |
14 |
=================================================================== |
15 |
<?xml version='1.0' encoding='UTF-8'?> |
16 |
<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/draft/xen-guide.xml,v 1.1 2007/07/20 07:18:24 swift Exp $ --> |
17 |
|
18 |
<!DOCTYPE guide SYSTEM "/dtd/guide.dtd"> |
19 |
|
20 |
<guide link="/doc/en/draft/xen-guide.xml" disclaimer="draft"> |
21 |
|
22 |
<title>Configuring Gentoo with Xen</title> |
23 |
|
24 |
<author title="Author"> |
25 |
<mail link="swift@g.o">Sven Vermeulen</mail> |
26 |
</author> |
27 |
|
28 |
<abstract> |
29 |
This guide describes how to start using Xen on your Gentoo system |
30 |
</abstract> |
31 |
|
32 |
<!-- The content of this document is licensed under the CC-BY-SA license --> |
33 |
<!-- See http://creativecommons.org/licenses/by-sa/2.5 --> |
34 |
<license/> |
35 |
|
36 |
<version>0.1</version> |
37 |
<date>2007-07-14</date> |
38 |
|
39 |
<chapter> |
40 |
<title>Introduction</title> |
41 |
<section> |
42 |
<body> |
43 |
|
44 |
<p> |
45 |
The <uri link="http://www.xensource.com/">Xen</uri> technology allows you to run |
46 |
multiple operating systems on a single physical system, govern resource |
47 |
consumption and even migrate domains (which are the virtual environments in |
48 |
which a guest operating system runs) from one Xen-powered system to another. Xen |
49 |
requires the host operating system to support Xen (which, in this case, will be |
50 |
a Linux kernel) but guest operating systems can run unmodified <e>if</e> your |
51 |
hardware supports Intel Virtualization Technology (VT-x) or AMD Virtualization |
52 |
Technology (SVM). Otherwise your guest operating systems must also support Xen. |
53 |
</p> |
54 |
|
55 |
<p> |
56 |
This guide will talk you through the configuration steps necessary to get Xen up |
57 |
and running on Gentoo Linux. We will not discuss Xen itself (the Xen project has |
58 |
<uri |
59 |
link="http://www.cl.cam.ac.uk/research/srg/netos/xen/readmes/user">decent |
60 |
documentation</uri> available) nor will we talk about specialized setups that |
61 |
might be very interesting for Xen setups but are not Xen-related (like exporting |
62 |
Portage through NFS, booting Linux using PXE, etc.) |
63 |
</p> |
64 |
|
65 |
</body> |
66 |
</section> |
67 |
</chapter> |
68 |
<chapter> |
69 |
<title>Preparing Domain0</title> |
70 |
<section> |
71 |
<title>Introduction</title> |
72 |
<body> |
73 |
|
74 |
<p> |
75 |
<e>Domain0</e> is the primary domain under Xen, hosting the host operating |
76 |
system which governs all other domains. In this chapter we will prepare an |
77 |
existing Gentoo installation to become the host operating system in this domain |
78 |
and build the Xen-powered kernel so that Gentoo is ready to host other Xen |
79 |
domains. |
80 |
</p> |
81 |
|
82 |
</body> |
83 |
</section> |
84 |
<section> |
85 |
<title>Rebuilding the Gentoo Installation ?</title> |
86 |
<body> |
87 |
|
88 |
<p> |
89 |
A drastic change that might be necessary is to rebuild the entire Gentoo |
90 |
installation with a different <c>CFLAGS</c> setting. Guest operating systems |
91 |
running under Xen might otherwise see major performance degradation. If you, |
92 |
however, are planning on checking out Xen rather than installing it for |
93 |
production use and are not terribly fond of rebuilding all programs, you can |
94 |
skip this step. In this case you will notice performance degradation but you |
95 |
will still be able to use Xen. |
96 |
</p> |
97 |
|
98 |
<impo> |
99 |
It is advised that, if you change your <c>CFLAGS</c> and build your system with |
100 |
a gcc lower than version 4, you do not have <c>-Os</c> set as it has been |
101 |
reported to produce broken code. |
102 |
</impo> |
103 |
|
104 |
<pre caption="Editing the CFLAGS and rebuild the Gentoo installation"> |
105 |
~# <i>nano -w /etc/make.conf</i> |
106 |
<comment>(Add -mno-tls-direct-seg-refs)</comment> |
107 |
CFLAGS="-O2 -march=pentium4 -pipe -mfpmath=sse <i>-mno-tls-direct-seg-refs</i>" |
108 |
|
109 |
~# <i>emerge -e world</i> |
110 |
</pre> |
111 |
|
112 |
<p> |
113 |
If you boot your system using an initial ramdisk (initrd) you need to |
114 |
rebuild the initrd as well (which is best done by running all steps you would do |
115 |
when you rebuild your kernel). |
116 |
</p> |
117 |
|
118 |
</body> |
119 |
</section> |
120 |
<section> |
121 |
<title>Installing Xen</title> |
122 |
<body> |
123 |
|
124 |
<p> |
125 |
Xen actually contains many components, so you'll need to install a couple of |
126 |
packages. Because it is still <uri |
127 |
link="/doc/en/handbook/handbook-x86.xml?part=3&chap=3#doc_chap2">~arch |
128 |
masked</uri> you first need to unmask it by adding the following lines to |
129 |
<path>/etc/portage/package.keywords</path>: |
130 |
</p> |
131 |
|
132 |
<pre caption="Unmasking Xen"> |
133 |
app-emulation/xen |
134 |
app-emulation/xen-tools |
135 |
sys-kernel/xen-sources |
136 |
</pre> |
137 |
|
138 |
</body> |
139 |
</section> |
140 |
<section> |
141 |
<title>Building the Kernel</title> |
142 |
<body> |
143 |
|
144 |
<p> |
145 |
Next we'll build the Linux kernel with Xen support. This kernel, whose sources |
146 |
are available at <path>/usr/src/linux-2.6.x.z-xen</path>, will be our main |
147 |
running kernel (i.e. the one running domain 0). In the <c>XEN</c> section you'll |
148 |
find drivers for all kinds of input/output, each driver having a <e>backend</e> |
149 |
and <e>frontend</e> implementation available. For the domain 0 kernel you need |
150 |
to select the <e>backend</e> implementation: these are used by the other |
151 |
domains (who use the <e>frontend</e> drivers) to communicate directly with |
152 |
the hardware. |
153 |
</p> |
154 |
|
155 |
<p> |
156 |
Of course, don't forget to select <c>Xen-compatible</c> at <c>Processor type and |
157 |
features</c>. If you're wondering about networking: each interface in a domain |
158 |
has a point-to-point link to an interface on domain 0 (called |
159 |
<path>vifX.Y</path> where X is the domain number and Y the Yth interface of that |
160 |
domain), so you can configure your network the way you want (bridging, NAT, |
161 |
etc.) |
162 |
</p> |
163 |
|
164 |
<p> |
165 |
Once the kernel is built you'll find the kernel image immediately in the kernel |
166 |
source directory (not inside <path>arch/</path> or any other directory) called |
167 |
<path>vmlinuz</path>. Copy it to <path>/boot</path> and then configure your |
168 |
bootloader to use the Xen hypervisor (one of the components installed |
169 |
previously) which is stored as <path>/boot/xen.gz</path>. In the bootloader |
170 |
configuration, add your newly built kernel as the kernel that Xen should |
171 |
boot. For instance, for GRUB: |
172 |
</p> |
173 |
|
174 |
<pre caption="GRUB Configuration for Xen"> |
175 |
title Xen 3.0 / Gentoo Linux 2.6.x.y |
176 |
root (hd0,0) |
177 |
kernel /xen.gz |
178 |
module /kernel-2.6.x.y-xen0 root=/dev/hda3 |
179 |
</pre> |
180 |
|
181 |
<p> |
182 |
Now reboot your system into Xen. Once you are booted, you need to load the Xen |
183 |
daemon: |
184 |
</p> |
185 |
|
186 |
<pre caption="Loading the Xen daemon"> |
187 |
~# <i>/etc/init.d/xend start</i> |
188 |
</pre> |
189 |
|
190 |
<p> |
191 |
Now check if you can do whatever you normally do on your system. If this is the |
192 |
case, you can edit your bootloader configuration to always boot into Xen and add |
193 |
the Xen deamon to the default runlevel so that it is started automatically the |
194 |
next time you boot. |
195 |
</p> |
196 |
|
197 |
</body> |
198 |
</section> |
199 |
</chapter> |
200 |
<chapter> |
201 |
<title>Creating an Unpriviledged Domain</title> |
202 |
<section> |
203 |
<title>Building the Kernel</title> |
204 |
<body> |
205 |
|
206 |
<p> |
207 |
Go to the Xen-powered Linux kernel source and update the configuration. It is |
208 |
wise to keep as many topics as possible similar to the main kernel except the |
209 |
<c>XEN</c> settings where drivers should now have their <e>frontend</e> |
210 |
implementation selected instead of the <e>backend</e>. Then build the kernel |
211 |
and place the resulting <path>vmlinuz</path> file where you want (we assume this |
212 |
is <path>/mnt/data/xen/kernel</path>): |
213 |
</p> |
214 |
|
215 |
<pre caption="Building the guest kernel"> |
216 |
~# <i>make</i> |
217 |
~# <i>cp vmlinuz /mnt/data/xen/kernel/kernel-2.6.x.y-xen</i> |
218 |
</pre> |
219 |
|
220 |
</body> |
221 |
</section> |
222 |
<section> |
223 |
<title>Creating the Domain Disks</title> |
224 |
<body> |
225 |
|
226 |
<p> |
227 |
For best performance, it is best to dedicate a partition (or logical volume) to |
228 |
a domain rather than a file based filesystem. However, if you are going to use |
229 |
Xen primarily for tests using a file based filesystem does have its advantages |
230 |
(especially regarding maintenance). |
231 |
</p> |
232 |
|
233 |
<p> |
234 |
You can create a file based filesystem using <c>dd</c> and <c>mke2fs</c> (or |
235 |
any other file system creation tool). For instance, to create a 2Gbyte ext3 |
236 |
filesystem: |
237 |
</p> |
238 |
|
239 |
<pre caption="Creating a file based filesystem"> |
240 |
~# <i>dd if=/dev/zero of=/mnt/data/xen/disks/ext3root.img bs=1M count=2048</i> |
241 |
~# <i>mke2fs -j /mnt/data/xen/disks/ext3root.img</i> |
242 |
</pre> |
243 |
|
244 |
</body> |
245 |
</section> |
246 |
<section> |
247 |
<title>Configuring a Domain</title> |
248 |
<body> |
249 |
|
250 |
<p> |
251 |
Next we create a Xen configuration file for a domain. You can store these |
252 |
configuration files where you want, for instance at |
253 |
<path>/mnt/data/xen/configs</path>. As an example, we create a configuration |
254 |
file for a small Gentoo environment which uses the disk image we created |
255 |
previously: |
256 |
</p> |
257 |
|
258 |
<pre caption="Creating a domain configuration file"> |
259 |
~# <i>nano -w /mnt/data/xen/configs/gentoo</i> |
260 |
|
261 |
kernel = "/mnt/data/xen/kernel/kernel-2.6.x.y-xen" |
262 |
memory = 512 |
263 |
name = "gentoo" |
264 |
<comment>(Map the disk image to the virtual /dev/sda1)</comment> |
265 |
disk = ['file:/mnt/data/xen/disks/ext3root.img,sda1,w'] |
266 |
root = "/dev/sda1 ro" |
267 |
</pre> |
268 |
|
269 |
</body> |
270 |
</section> |
271 |
<section> |
272 |
<title>Launching the New Domain</title> |
273 |
<body> |
274 |
|
275 |
<p> |
276 |
Now we're all set and we can launch the new domain. If the disk image contained |
277 |
an operating system, we could just create and attach the domain using the |
278 |
<c>xm</c> command (Xen manager): |
279 |
</p> |
280 |
|
281 |
<pre caption="Creating and starting a new domain"> |
282 |
~# <i>xm create /mnt/data/xen/configs/gentoo -c</i> |
283 |
</pre> |
284 |
|
285 |
<p> |
286 |
The domain would be booted inside the terminal in which you executed the |
287 |
command. However, in our case, the disk image is empty so the domain wouldn't be |
288 |
able to do much. To fix this, you can loop-mount the image and install Gentoo as |
289 |
you're used to. |
290 |
</p> |
291 |
|
292 |
<p> |
293 |
If you want to disconnect from the domain, press <path>Ctrl+]</path>. You can |
294 |
always reconnect to the domains' console using <c>xm console gentoo</c>. |
295 |
However, there is only one console per domain, so only use it when you can't |
296 |
access the domain otherwise (for instance, through SSH). |
297 |
</p> |
298 |
|
299 |
</body> |
300 |
</section> |
301 |
</chapter> |
302 |
<chapter> |
303 |
<title>Networking on Unpriviledged Domains</title> |
304 |
<section> |
305 |
<title>Introduction</title> |
306 |
<body> |
307 |
|
308 |
<p> |
309 |
Xen supports at least two ways of configuring your (virtual) network: |
310 |
<e>routed</e> and <e>bridged</e>. |
311 |
</p> |
312 |
|
313 |
<p> |
314 |
When selecting the <e>routed</e> approach, the interface inside your |
315 |
unpriviledged domain is connected to a virtual interface on your |
316 |
administrative domain. On your administrative domain (domain 0), the virtual |
317 |
interface has the same IP address as <path>eth0</path> whereas the |
318 |
interface inside your unpriviledged domain has an IP address on the same |
319 |
network. Any communication to that IP address can only occur from the |
320 |
administrative domain, unless you set up specific routing rules. |
321 |
</p> |
322 |
|
323 |
<p> |
324 |
When selecting the <e>bridged</e> approach, <brite>TODO</brite>. |
325 |
</p> |
326 |
|
327 |
</body> |
328 |
</section> |
329 |
<section> |
330 |
<title>Regular Routed Interfaces</title> |
331 |
<body> |
332 |
|
333 |
<p> |
334 |
Before you set up the interface on your unpriviledged domain, make sure that |
335 |
Xen's <path>netloop</path> and <path>netbk</path> drivers are loaded. A quick |
336 |
hint: if you have <path>netloop</path> as a module, load it with |
337 |
<c>nloopbacks=0</c> so that it doesn't create pointless interfaces to the |
338 |
loopback device. Then, edit your domain configuration file and add a <c>vif</c> |
339 |
instruction to it. |
340 |
</p> |
341 |
|
342 |
<pre caption="Configuring a virtual interface"> |
343 |
~# <i>nano -w /mnt/data/xen/configs/gentoo</i> |
344 |
|
345 |
<comment>(Add the vif instruction)</comment> |
346 |
vif = [ 'ip=192.168.1.101, vifname=veth1' ] |
347 |
</pre> |
348 |
|
349 |
<p> |
350 |
In the above example, the interface will be created for the unpriviledged domain |
351 |
(in which it will be called <path>eth0</path>) and Xen will link the address |
352 |
192.168.1.101 with the domain 0 <path>eth0</path> interface through interface |
353 |
<path>veth1</path>. That doesn't mean that the virtual <path>eth0</path> |
354 |
interface will automatically have IP 192.168.1.101 assigned to it, but rather |
355 |
that, if you don't give it that IP, it will not be connected with the |
356 |
administrative domain and thus cannot be reached. |
357 |
</p> |
358 |
|
359 |
<p> |
360 |
Now edit <path>/etc/xen/xend-config.xsp</path> as follows to select routed |
361 |
network configuration: |
362 |
</p> |
363 |
|
364 |
<pre caption="Editing xend-config.xsp"> |
365 |
~# <i>nano -w /etc/xen/xend-config.xsp</i> |
366 |
|
367 |
<comment>(Comment out the following lines)</comment> |
368 |
<i>#</i>(network-script network-bridge) |
369 |
<i>#</i>(vif-script vif-bridge) |
370 |
|
371 |
<comment>(Enable the following lines)</comment> |
372 |
(network-script network-route) |
373 |
(vif-script vif-route) |
374 |
</pre> |
375 |
|
376 |
</body> |
377 |
</section> |
378 |
</chapter> |
379 |
</guide> |
380 |
|
381 |
|
382 |
|
383 |
-- |
384 |
gentoo-doc-cvs@g.o mailing list |