Debian Codegraph @

UG9/en/xen.adoc

raw
1 [[ch-xen]]
2 == Using Xen with DRBD
3
4 indexterm:[Xen]This chapter outlines the use of DRBD as a Virtual
5 Block Device (VBD) for virtualization environments using the Xen
6 hypervisor.
7
8 [[s-xen-primer]]
9 === Xen primer
10
11 Xen is a virtualization framework originally developed at the
12 University of Cambridge (UK), and later being maintained by XenSource,
13 Inc. (now a part of Citrix). It is included in reasonably recent
14 releases of most Linux distributions, such as Debian GNU/Linux (since
15 version 4.0), SUSE Linux Enterprise Server (since release 10), Red Hat
16 Enterprise Linux (since release 5), and many others.
17
18 Xen uses paravirtualization — a virtualization method
19 involving a high degree of cooperation between the virtualization host
20 and guest virtual machines — with selected guest operating systems for
21 improved performance in comparison to conventional virtualization
22 solutions (which are typically based on hardware
23 emulation). Xen also supports full hardware emulation
24 on CPUs that support the appropriate virtualization extensions; in Xen
25 parlance, this is known as HVM ( "hardware-assisted virtual machine").
26
27 NOTE: At the time of writing, CPU extensions supported by Xen for HVM
28 are Intel's Virtualization Technology (VT, formerly codenamed
29 "Vanderpool"), and AMD's Secure Virtual Machine (SVM, formerly known
30 as "Pacifica").
31
32 Xen supports indexterm:[Xen, live migration]_live migration_, which refers to the
33 capability of transferring a running guest operating system from one
34 physical host to another, without interruption.
35
36 When a DRBD resource is used as a replicated Virtual Block Device
37 (VBD) for Xen, it serves to make the entire contents of a domU's
38 virtual disk available on two servers, which can then be configured
39 for automatic fail-over. That way, DRBD does not only provide
40 redundancy for Linux servers (as in non-virtualized DRBD deployment
41 scenarios), but also for any other operating system that can be
42 virtualized under Xen — which, in essence, includes any operating
43 system available on 32- or 64-bit Intel compatible architectures.
44
45 [[s-xen-drbd-mod-params]]
46 === Setting DRBD module parameters for use with Xen
47
48 For Xen Domain-0 kernels, it is recommended to load the DRBD module
49 with the parameter `disable_sendpage` set to `1`. To do so, create (or open) the file
50 `/etc/modprobe.d/drbd.conf` and enter the following line:
51
52 [source,drbd]
53 ----------------------------
54 options drbd disable_sendpage=1
55 ----------------------------
56
57 [[s-xen-create-resource]]
58 === Creating a DRBD resource suitable to act as a Xen VBD
59
60 Configuring a DRBD resource that is to be used as a Virtual Block
61 Device for Xen is fairly straightforward -- in essence, the typical
62 configuration matches that of a DRBD resource being used for any other
63 purpose. However, if you want to enable live migration
64 for your guest instance, you need to enable indexterm:[Dual-Primary
65 mode]<<s-dual-primary-mode,dual-primary mode>>for this resource:
66
67 [source,drbd]
68 ----------------------------
69 resource <resource> {
70 net {
71 allow-two-primaries yes;
72 ...
73 }
74 ...
75 }
76 ----------------------------
77
78 Enabling dual-primary mode is necessary because Xen, before initiating
79 live migration, checks for write access on all VBDs a resource is
80 configured to use on both the source and the destination host for the
81 migration.
82
83 [[s-xen-configure-domu]]
84 === Using DRBD VBDs
85
86 In order to use a DRBD resource as the virtual block device, you must
87 add a line like the following to your Xen domU configuration:
88 indexterm:[Xen]
89
90 [source,drbd]
91 ----------------------------
92 disk = [ 'drbd:<resource>,xvda,w' ]
93 ----------------------------
94
95 This example configuration makes the DRBD resource named _resource_
96 available to the domU as `/dev/xvda` in read/write mode (`w`).
97
98 Of course, you may use multiple DRBD resources with a single domU. In
99 that case, simply add more entries like the one provided in the
100 example to the `disk` option, separated by commas.
101
102
103 NOTE: There are three sets of circumstances under which you cannot use
104 this approach:
105
106 * You are configuring a fully virtualized (HVM) domU.
107
108 * You are installing your domU using a graphical installation utility,
109 _and_ that graphical installer does not support the `drbd:` syntax.
110
111 * You are configuring a domU without the `kernel`, `initrd`, and
112 `extra` options, relying instead on `bootloader` and
113 `bootloader_args` to use a Xen pseudo-bootloader, _and_ that
114 pseudo-bootloader does not support the `drbd:` syntax.
115
116 ** pygrub+ (prior to Xen 3.3) and `domUloader.py` (shipped with Xen on
117 SUSE Linux Enterprise Server 10) are two examples of
118 pseudo-bootloaders that do not support the `drbd:` virtual block device
119 configuration syntax.
120
121 ** `pygrub` from Xen 3.3 forward, and the `domUloader.py` version that
122 ships with SLES 11 _do_ support this syntax.
123
124 Under these circumstances, you must use the traditional `phy:` device
125 syntax and the DRBD device name that is associated with your resource,
126 not the resource name. That, however, requires that you manage DRBD
127 state transitions outside Xen, which is a less flexible approach than
128 that provided by the `drbd` resource type.
129
130 [[s-manage-domu]]
131 === Starting, stopping, and migrating DRBD-backed domU's
132
133 .Starting the domU
134 Once you have configured your DRBD-backed domU, you may start it as
135 you would any other domU:
136 ----------------------------
137 # xm create <domU>
138 Using config file "/etc/xen/<domU>".
139 Started domain <domU>
140 ----------------------------
141
142 In the process, the DRBD resource you configured as the VBD will be
143 promoted to the primary role, and made accessible to Xen as expected.
144
145
146 .Stopping the domU
147 This is equally straightforward:
148 ----------------------------
149 # xm shutdown -w <domU>
150 Domain <domU> terminated.
151 ----------------------------
152
153 Again, as you would expect, the DRBD resource is returned to the
154 secondary role after the domU is successfully shut down.
155
156
157 .Migrating the domU
158 This, too, is done using the usual Xen tools:
159 ----------------------------
160 # xm migrate --live <domU> <destination-host>
161 ----------------------------
162
163 In this case, several administrative steps are automatically taken in
164 rapid succession:
165 * The resource is promoted to the primary role on _destination-host_.
166 * Live migration of _domU_ is initiated on the local host.
167 * When migration to the destination host has completed, the resource
168 is demoted to the secondary role locally.
169
170 The fact that both resources must briefly run in the primary role on
171 both hosts is the reason for having to configure the resource in
172 dual-primary mode in the first place.
173
174
175 [[s-xen-internal]]
176 === Internals of DRBD/Xen integration
177
178 Xen supports two Virtual Block Device types natively:
179
180 .`phy`
181 This device type is used to hand "physical" block devices, available
182 in the host environment, off to a guest domU in an essentially
183 transparent fashion.
184
185 .`file`
186 This device type is used to make file-based block device images
187 available to the guest domU. It works by creating a loop block device
188 from the original image file, and then handing that block device off
189 to the domU in much the same fashion as the `phy` device type does.
190
191 If a Virtual Block Device configured in the `disk` option of a domU
192 configuration uses any prefix other than `phy:`, `file:`, or no prefix
193 at all (in which case Xen defaults to using the `phy` device type),
194 Xen expects to find a helper script named ``block-``_prefix_ in the Xen
195 scripts directory, commonly `/etc/xen/scripts`.
196
197 The DRBD distribution provides such a script for the `drbd` device
198 type, named `/etc/xen/scripts/block-drbd`. This script handles the
199 necessary DRBD resource state transitions as described earlier in this
200 chapter.
201
202 [[s-xen-pacemaker]]
203 === Integrating Xen with Pacemaker
204
205 indexterm:[Xen]indexterm:[Heartbeat]In order to fully capitalize on
206 the benefits provided by having a DRBD-backed Xen VBD's, it is
207 recommended to have Pacemaker manage the associated domU's as
208 Pacemaker resources.
209
210 You may configure a Xen domU as a Pacemaker resource, and automate
211 resource failover. To do so, use the Xen OCF resource agent. If you
212 are using the `drbd` Xen device type described in this chapter, you
213 will _not_ need to configure any separate `drbd` resource for use by
214 the Xen cluster resource. Instead, the `block-drbd` helper script will
215 do all the necessary resource transitions for you.