VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/docs/TestBoxImaging.txt@ 64599

Last change on this file since 64599 was 64599, checked in by vboxsync, 8 years ago

updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.8 KB
Line 
1
2Testbox Imaging (Backup / Restore)
3==================================
4
5
6Introduction
7------------
8
9This document is explores deloying a very simple drive imaging solution to help
10avoid needing to manually reinstall testboxes when a disk goes bust or the OS
11install seems to be corrupted.
12
13
14Definitions / Glossary
15======================
16
17See AutomaticTestingRevamp.txt.
18
19
20Objectives
21==========
22
23 - Off site, no admin interaction (no need for ILOM or similar).
24 - OS independent.
25 - Space and bandwidth efficient.
26 - As automatic as possible.
27 - Logging.
28
29
30Overview of the Solution
31========================
32
33Here is a brief summary:
34
35 - Always boot testboxes via PXE using PXELINUX.
36 - Default configuration is local boot (hard disk / SSD)
37 - Restore/backup action triggered by machine specific PXE config.
38 - Boots special debian maintenance install off NFS.
39 - A maintenance service (systemd style) does the work.
40 - The service reads action from TFTP location and performs it.
41 - When done the service removes the TFTP machine specific config
42 and reboots the system.
43
44Maintenance actions are:
45 - backup
46 - backup-again
47 - restore
48 - refresh-info
49 - rescue
50
51Possible modifier that indicates a subset of disk on testboxes with other OSes
52installed. Support for partition level backup/restore is not explored here.
53
54
55How to use
56----------
57
58To perform one of the above maintenance actions on a testbox, run the
59``testbox-pxe-conf.sh`` script::
60
61 /mnt/testbox-tftp/pxeclient.cfg/testbox-pxe-conf.sh 10.165.98.220 rescue
62
63Then trigger a reboot. The box will then boot the NFS rooted debian image and
64execute the maintenance action. On success, it will remove the testbox hex-IP
65config file and reboot again.
66
67
68Storage Server
69==============
70
71The storage server will have three areas used here. Using NFS for all three
72avoids extra work getting CIFS sharing right too (NFS is already a pain).
73
74 1. /export/testbox-tftp - TFTP config area. Read-write.
75 2. /export/testbox-backup - Images and logs. Read-write.
76 3. /export/testbox-nfsroot - Custom debian. Read-only, no root squash.
77
78
79TFTP (/export/testbox-tftp)
80============================
81
82The testbox-tftp share needs to be writable, root squashing is okay.
83
84We need files from both PXELINUX and SYSLINUX to make this work now. On a
85debian system, the ``pxelinux`` and ``syslinux`` packages needs to be
86installed. We actually do this further down when setting up the nfsroot, so
87it's possible to get them from there by postponing this step a little. On
88debian 8.6.0 the PXELINUX files are found in ``/usr/lib/PXELINUX`` and the
89SYSLINUX ones in ``/usr/lib/syslinux``.
90
91The initial PXE image as well as associated modules comes in three variants,
92BIOS, 32-bit EFI and 64-bit EFI. We'll only need the BIOS one for now.
93Perform the following copy operations::
94
95 cp /usr/lib/PXELINUX/pxelinux.0 /mnt/testbox-tftp/
96 cp /usr/lib/syslinux/modules/*/ldlinux.* /mnt/testbox-tftp/
97 cp -R /usr/lib/syslinux/modules/bios /mnt/testbox-tftp/
98 cp -R /usr/lib/syslinux/modules/efi32 /mnt/testbox-tftp/
99 cp -R /usr/lib/syslinux/modules/efi64 /mnt/testbox-tftp/
100
101
102For simplicitly, all the testboxes boot using good old fashioned BIOS, no EFI.
103However, it doesn't really hurt to be prepared.
104
105The PXELINUX related files goes in the root of the testbox-tftp share. (As
106mentioned further down, these can be installed on a debian system by running
107``apt-get install pxelinux syslinux``.) We need the ``*pxelinux.0`` files
108typically found in ``/usr/lib/PXELINUX/`` on debian systems (recent ones
109anyway). It is possible we may need one ore more fo the modules [1]_ that
110ships with PXELINUX/SYSLINUX, so do copy ``/usr/lib/syslinux/modules`` to
111``testbox-tftp/modules`` as well.
112
113
114The directory layout related to the configuration files is dictated by the
115PXELINUX configuration file searching algorithm [2]_. Create a subdirectory
116``pxelinux.cfg/`` under ``testbox-tftp`` and create the world readable file
117``default`` with the following content::
118
119 PATH bios
120 DEFAULT local-boot
121 LABEL local-boot
122 LOCALBOOT
123
124This will make the default behavior to boot the local disk system.
125
126Copy the ``testbox-pxe-conf.sh`` script file found in the same directory as
127this document to ``/mnt/testbox-tftp/pxelinux.cfg/``. Edit the copy to correct
128the IP addresses near the top, as well as any linux, TFTP and PXE details near
129the bottom of the file. This script will generate the PXE configuration file
130when performing maintenance on a testbox.
131
132
133Images and logs (/export/testbox-backup)
134=========================================
135
136The testbox-backup share needs to be writable, root squashing is okay.
137
138In the root there must be a file ``testbox-backup`` so we can easily tell
139whether we've actually mounted the share or are just staring at an empty mount
140point directory.
141
142The ``testbox-maintenance.sh`` script maintains a global log in the root
143directory that's called ``maintenance.log``. Errors will be logged there as
144well as a ping and the action.
145
146We use a directory layout based on dotted decimal IP addresses here, so for a
147server with the IP 10.40.41.42 all its file will be under ``10.40.41.42/``:
148
149``<hostname>``
150 The name of the testbox (empty file). Help finding a testbox by name.
151
152``testbox-info.txt``
153 Information about the testbox. Starting off with the name, decimal IP,
154 PXELINUX style hexadecimal IP, and more.
155
156``maintenance.log``
157 Maintenance log file recording what the maintenance service does.
158
159``disk-devices.lst``
160 Optional list of disk devices to consider backuping up or restoring. This is
161 intended for testboxes with additional disks that are used for other purposes
162 and should touched.
163
164``sda.raw.gz``
165 The gzipped raw copy of the sda device of the testbox.
166
167``sd[bcdefgh].raw.gz``
168 The gzipped raw copy sdb, sdc, sde, sdf, sdg, sdh, etc if any of them exists
169 and are disks/SSDs.
170
171
172Note! If it turns out we can be certain to get a valid host name, we might just
173 switch to use the hostname as the directory name instead of the IP.
174
175
176Debian NFS root (/export/testbox-nfsroot)
177==========================================
178
179The testbox-nfsroot share should be read-only and must **not** have root
180squashing enabled. Also, make sure setting the set-uid-bit is allowed by the
181server, or ``su` and ``sudo`` won't work
182
183There are several ways of creating a debian nfsroot, but since we've got a
184tool like VirtualBox around we've just installed it in a VM, prepared it,
185and copied it onto the NFS server share.
186
187As of writing debian 8.6.0 is current, so a minimal 64-bit install of it was
188done in a VM. After installation the following modifications was done:
189
190 - ``apt-get install pxelinux syslinux initramfs-tools zip gddrescue joe``
191 and optionally ``apt-get install smbclient cifs-utils``.
192
193
194 - ``/etc/default/grub`` was modified to set ``GRUB_CMDLINE_LINUX_DEFAULT`` to
195 ``""`` instead of ``"quiet"``. This allows us to see messages during boot
196 and perhaps spot why something doesn't work on a testbox. Regenerate the
197 grub configuration file by running ``update-grub`` afterwards.
198
199 - Create the directory ``/etc/systemd/system/[email protected]`` and create
200 the file ``noclear.conf`` in it with the following content::
201
202 [Service]
203 TTYVTDisallocate=no
204
205 This stops getty from clearing VT1 and let us see the tail of the boot up
206 messages, which includes messages from the testbox-maintenance service.
207
208 - Mount the testbox-nfsroot under ``/mnt/`` with write privileges. (The write
209 privileges are temporary - don't forget to remove them later on.)::
210
211 mount -t nfs myserver.com:/export/testbox-nfsroot
212
213 Note! Adding ``-o nfsvers=3`` may help with some NTFv4 servers.
214
215 - Copy the debian root and dev file system onto nfsroot. If you have ssh
216 access to the NFS server, the quickest way to do it is to use ``tar``::
217
218 tar -cz --one-file-system -f /mnt/testbox-maintenance-nfsroot.tar.gz . dev/
219
220 An alternative is ``cp -ax . /mnt/. && cp -ax dev/. /mnt/dev/.`` but this
221 is quite a bit slower, obviously.
222
223 - Edit ``/etc/ssh/sshd_config`` setting ``PermitRootLogin`` to ``yes`` so we can ssh
224 in as root later on.
225
226 - chroot into the nfsroot: ``chroot /mnt/``
227
228 - ``mount -o proc proc /proc``
229
230 - ``mount -o sysfs sysfs /sys``
231
232 - ``mkdir /mnt/testbox-tftp /mnt/testbox-backup``
233
234 - Recreate ``/etc/fstab`` with::
235
236 proc /proc proc defaults 0 0
237 /dev/nfs / nfs defaults 1 1
238 10.42.1.1:/export/testbox-tftp /mnt/testbox-tftp nfs tcp,nfsvers=3,noauto 2 2
239 10.42.1.1:/export/testbox-backup /mnt/testbox-backup nfs tcp,nfsvers=3,noauto 3 3
240
241 We use NFS version 3 as that works better for our NFS server and client,
242 remove if not necessary. The ``noauto`` option is to work around mount
243 trouble during early bootup on some of our boxes.
244
245 - Do ``mount /mnt/testbox-tftp && mount /mnt/testbox-backup`` to mount the
246 two shares. This may be a good time to execute the instructions in the
247 sections above relating to these two shares.
248
249 - Edit ``/etc/initramfs-tools/initramfs.conf`` and change the ``MODULES``
250 value from ``most`` to ``netboot``.
251
252 - Append ``aufs`` to ``/etc/initramfs-tools/modules``. The advanced
253 multi-layered unification filesystem (aufs) enables us to use a
254 read-only NFS root. [3]_ [4]_ [5]_
255
256 - Create ``/etc/initramfs-tools/scripts/init-bottom/00_aufs_init`` as
257 an executable file with the following content::
258
259 #!/bin/sh
260 # Don't run during update-initramfs:
261 case "$1" in
262 prereqs)
263 exit 0;
264 ;;
265 esac
266
267 modprobe aufs
268 mkdir -p /ro /rw /aufs
269 mount -t tmpfs tmpfs /rw -o noatime,mode=0755
270 mount --move $rootmnt /ro
271 mount -t aufs aufs /aufs -o noatime,dirs=/rw:/ro=ro
272 mkdir -p /aufs/rw /aufs/ro
273 mount --move /ro /aufs/ro
274 mount --move /rw /aufs/rw
275 mount --move /aufs /root
276 exit 0
277
278 - Update the init ramdisk: ``update-initramfs -u -k all``
279
280 Note! It may be necessary to do ``mount -t tmpfs tmpfs /var/tmp`` to help
281 this operation succeed.
282
283 - Copy ``/boot`` to ``/mnt/testbox-tftp/maintenance-boot/``.
284
285 - Copy the ``testbox-maintenance.sh`` file found in the same directory as this
286 document to ``/root/scripts/`` (need to create the dir) and make it
287 executable.
288
289 - Create the systemd service file for the maintenance service as
290 ``/etc/systemd/system/testbox-maintenance.service`` with the content::
291
292 [Unit]
293 Description=Testbox Maintenance
294 After=network.target
295 [email protected]
296
297 [Service]
298 Type=oneshot
299 RemainAfterExit=True
300 ExecStart=/root/scripts/testbox-maintenance.sh
301 ExecStartPre=/bin/echo -e \033%G
302 ExecReload=/bin/kill -HUP $MAINPID
303 WorkingDirectory=/tmp
304 Environment=TERM=xterm
305 StandardOutput=journal+console
306
307 [Install]
308 WantedBy=multi-user.target
309
310 - Enable our service: ``systemctl enable /etc/systemd/system/testbox-maintenance.service``
311
312 - xxxx ... more ???
313
314 - Before leaving the chroot, do ``mount /proc /sys /mnt/testbox-*``.
315
316
317 - Testing the setup from a VM is kind of useful (if the nfs server can be
318 convinced to accept root nfs mounts from non-privileged clinet ports):
319
320 - Create a VM using the 64-bit debian profile. Let's call it "pxe-vm".
321 - Mount the TFTP share somewhere, like M: or /mnt/testbox-tftp.
322 - Reconfigure the NAT DHCP and TFTP bits::
323
324 VBoxManage setextradata pxe-vm VBoxInternal/PDM/DriverTransformations/pxe/AboveDriver NAT
325 VBoxManage setextradata pxe-vm VBoxInternal/PDM/DriverTransformations/pxe/Action mergeconfig
326 VBoxManage setextradata pxe-vm VBoxInternal/PDM/DriverTransformations/pxe/Config/TFTPPrefix M:/
327 VBoxManage setextradata pxe-vm VBoxInternal/PDM/DriverTransformations/pxe/Config/BootFile pxelinux.0
328
329 - Create the file ``testbox-tftp/pxelinux.cfg/0A00020F`` containing::
330
331 PATH bios
332 DEFAULT maintenance
333 LABEL maintenance
334 MENU LABEL Maintenance (NFS)
335 KERNEL maintenance-boot/vmlinuz-3.16.0-4-amd64
336 APPEND initrd=maintenance-boot/initrd.img-3.16.0-4-amd64 ro ip=dhcp aufs=tmpfs \
337 boot=nfs root=/dev/nfs nfsroot=10.42.1.1:/export/testbox-nfsroot
338 LABEL local-boot
339 LOCALBOOT
340
341
342-----
343
344.. [1] See http://www.syslinux.org/wiki/index.php?title=Category:Modules
345.. [2] See http://www.syslinux.org/wiki/index.php?title=PXELINUX#Configuration
346.. [3] See https://en.wikipedia.org/wiki/Aufs
347.. [4] See http://shitwefoundout.com/wiki/Diskless_ubuntu
348.. [5] See http://debianaddict.com/2012/06/19/diskless-debian-linux-booting-via-dhcppxenfstftp/
349
350
351-----
352
353:Status: $Id: TestBoxImaging.txt 64599 2016-11-08 16:28:34Z vboxsync $
354:Copyright: Copyright (C) 2010-2016 Oracle Corporation.
355
356
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette