VirtualBox

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

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

ValidationKit: Exploratory notes on testbox backup and restore.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 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 - redo-backup
47 - restore
48
49Possible modifier that indicates a subset of disk on testboxes with other OSes
50installed. Support for partition level backup/restore is not explored here.
51
52
53Storage Server
54==============
55
56The storage server will have three areas used here. Using NFS for all three
57avoids extra work getting CIFS sharing right too (NFS is already a pain).
58
59 1. /exports/testbox-tftp - TFTP config area. Read-write.
60 2. /exports/testbox-backup - Images and logs. Read-write.
61 3. /exports/testbox-nfsroot - Custom debian. Read-only, no root squash.
62
63
64TFTP (/exports/testbox-tftp)
65============================
66
67The testbox-tftp share needs to be writable, root squashing is okay.
68
69We need files from both PXELINUX and SYSLINUX to make this work now. On a
70debian system, the ``pxelinux`` and ``syslinux`` packages needs to be
71installed. We actually do this further down when setting up the nfsroot, so
72it's possible to get them from there by postponing this step a little. On
73debian 8.6.0 the PXELINUX files are found in ``/usr/lib/PXELINUX`` and the
74SYSLINUX ones in ``/usr/lib/syslinux``.
75
76The initial PXE image as well as associated modules comes in three variants,
77BIOS, 32-bit EFI and 64-bit EFI. We'll only need the BIOS one for now.
78Perform the following copy operations::
79
80 cp /usr/lib/PXELINUX/pxelinux.0 testbox-tftp/
81 cp /usr/lib/syslinux/modules/*/ldlinux.* testbox-tftp/
82 cp /usr/lib/syslinux/modules/bios testbox-tftp/
83 cp /usr/lib/syslinux/modules/efi32 testbox-tftp/
84 cp /usr/lib/syslinux/modules/efi64 testbox-tftp/
85
86
87For simplicitly, all the testboxes boot using good old fashioned BIOS, no EFI.
88However, it doesn't really hurt to be prepared.
89
90The PXELINUX related files goes in the root of the testbox-tftp share. (As
91mentioned further down, these can be installed on a debian system by running
92``apt-get install pxelinux syslinux``.) We need the ``*pxelinux.0`` files
93typically found in ``/usr/lib/PXELINUX/`` on debian systems (recent ones
94anyway). It is possible we may need one ore more fo the modules [1]_ that
95ships with PXELINUX/SYSLINUX, so do copy ``/usr/lib/syslinux/modules`` to
96``testbox-tftp/modules`` as well.
97
98
99The directory layout related to the configuration files is dictated by the
100PXELINUX configuration file searching algorithm [2]_. Create a subdirectory
101``pxelinux.cfg/`` under ``testbox-tftp`` and create the world readable file
102``default`` with the following content::
103
104 PATH bios
105 DEFAULT local-boot
106 LABEL local-boot
107 LOCALBOOT
108
109This will make the default behavior to boot the local disk system.
110
111
112
113Images and logs (/exports/testbox-backup)
114=========================================
115
116The testbox-backup share needs to be writable, root squashing is okay.
117
118We use a directory layout based on dotted decimal IP addresses here, so for a
119server with the IP 10.40.41.42 all its file will be under ``10.40.41.42/``.
120
121
122Files found under ``10.40.41.42/``:
123
124``<hostname>``
125 The name of the testbox (empty file). Help finding a testbox by name.
126
127``testbox-info.txt``
128 Information about the testbox. Starting off with the name, decimal IP,
129 PXELINUX style hexadecimal IP, and more.
130
131``maintenance.log``
132 Maintenance log file recording what the maintenance service does.
133
134``disk-devices.lst``
135 Optional list of disk devices to consider backuping up or restoring. This is
136 intended for testboxes with additional disks that are used for other purposes
137 and should touched.
138
139``sda.raw.gz``
140 The gzipped raw copy of the sda device of the testbox.
141
142``sd[bcdefgh].raw.gz``
143 The gzipped raw copy sdb, sdc, sde, sdf, sdg, sdh, etc if any of them exists
144 and are disks/SSDs.
145
146
147Note! If it turns out we can be certain to get a valid host name, we might just
148 switch to use the hostname as the directory name instead of the IP.
149
150
151Debian NFS root (/exports/testbox-nfsroot)
152==========================================
153
154The testbox-nfsroot share should be read-only and must **not** have root
155squashing enabled.
156
157There are several ways of creating a debian nfsroot, but since we've got a
158tool like VirtualBox around we've just installed it in a VM, prepared it,
159and copied it onto the NFS server share.
160
161As of writing debian 8.6.0 is current, so a minimal 64-bit install of it was
162done in a VM. After installation the following modifications was done:
163
164 - ``apt-get install pxelinux syslinux initramfs-tools gddrescue joe`` and
165 optionally ``apt-get install smbclient cifs-utils``.
166
167
168 - ``/etc/default/grub`` was modified to set ``GRUB_CMDLINE_LINUX_DEFAULT`` to
169 ``""`` instead of ``"quiet"``. This allows us to see messages during boot
170 and perhaps spot why something doesn't work on a testbox. Regenerate the
171 grub configuration file by running ``update-grub`` afterwards.
172
173 - Create the directory ``/etc/systemd/system/[email protected]`` and create
174 the file noclear.conf in it with the following content::
175
176 [Service]
177 TTYVTDisallocate=no
178
179 This stops getty from clearing VT1 and let us see the tail of the boot up
180 messages, which includes messages from the testbox-maintenance service.
181
182 - Copy the ``testbox-maintenance.sh`` file found in the same directory as this
183 document to ``/root/scripts/`` (need to create the dir) and make it
184 executable.
185
186 - Create the systemd service file for the maintenance service as
187 ``/etc/systemd/system/textbox-maintenance.service`` with the content::
188
189 [Unit]
190 Description=Testbox Maintenance
191 After=network.target
192 [email protected]
193
194 [Service]
195 Type=oneshot
196 RemainAfterExit=True
197 ExecStart=/root/scripts/testbox-maintenance.sh
198 ExecStartPre=/bin/echo -e \033%G
199 ExecReload=/bin/kill -HUP $MAINPID
200 WorkingDirectory=/tmp
201 Environment=TERM=xterm
202 StandardOutput=journal+console
203
204 [Install]
205 WantedBy=multi-user.target
206
207 - Mount the testbox-nfsroot under ``/mnt/`` with write privileges. (The write
208 privileges are temporary - don't forget to remove them later on.)::
209
210 mount -t nfs myserver.com:/exports/testbox-nfsroot
211
212 - Copy the debian root and dev file system onto nfsroot. If you have ssh
213 access to the NFS server, the quickest way to do it is to use ``tar``::
214
215 tar -cz --one-file-system -f /mnt/testbox-maintenance-nfsroot.tar.gz . dev/
216
217 An alternative is ``cp -ax . /mnt/. && cp -ax dev/. /mnt/dev/.`` but this
218 is quite a bit slower, obviously.
219
220 - chroot into the nfsroot: ``chroot /mnt/``
221
222 - Enable our service: ``systemctl enable testbox-maintenance.service``
223
224 - Edit ``/etc/initramfs-tools/initramfs.conf`` and change the ``MODULES``
225 value from ``most`` to ``netboot``.
226
227 - Append ``aufs`` to ``/etc/initramfs-tools/modules``. The advanced
228 multi-layered unification filesystem (aufs) enables us to use a
229 read-only NFS root. [3]_ [4]_ [5]_
230
231 - Create ``/etc/initramfs-tools/scripts/init-bottom/00_aufs_init`` as
232 an executable file with the following content::
233
234 # Don't run during update-initramfs:
235 case "$1" in
236 prereqs)
237 exit 0;
238 ;;
239 esac
240
241 modprobe aufs
242 mkdir -p /ro /rw /aufs
243 mount -t tmpfs tmpfs /rw -o noatime,mode=0755
244 mount --move $rootmnt /ro
245 mount -t aufs aufs /aufs -o noatime,dirs=/rw:/ro=ro
246 mkdir -p /aufs/rw /aufs/ro
247 mount --move /ro /aufs/ro
248 mount --move /rw /aufs/rw
249 mount --move /aufs /root
250 exit 0
251
252 - Update the init ramdisk: ``update-initramfs -u -k all``
253
254 - Either copy the initrd.img and corresponding kernel to the
255 ``testbox-tftp/maintenance-boot/`` directory, or create
256 ``testbox-tftp/maintenance-boot`` as a symbolic link to
257 ``testbox-nfsroot/boot/``.
258
259 - Recreate ``/etc/fstab`` with::
260
261 proc /proc proc defaults 0 0
262 /dev/nfs / nfs defaults 1 1
263 # Mount tftp and backup too.
264
265 - xxx
266
267
268 - Testing the setup from a VM is kind of useful:
269 - Create a VM using the 64-bit debian profile. Let's call it "pxe-vm".
270 - Mount the TFTP share somewhere, like M: or /mnt/testbox-tftp.
271 - Reconfigure the NAT DHCP and TFTP bits::
272
273 VBoxManage setextradata pxe-vm VBoxInternal/PDM/DriverTransformations/pxe/AboveDriver NAT
274 VBoxManage setextradata pxe-vm VBoxInternal/PDM/DriverTransformations/pxe/Action mergeconfig
275 VBoxManage setextradata pxe-vm VBoxInternal/PDM/DriverTransformations/pxe/Config/TFTPPrefix M:/
276 VBoxManage setextradata pxe-vm VBoxInternal/PDM/DriverTransformations/pxe/Config/BootFile pxelinux.0
277
278 - Create the file ``testbox-tftp/pxelinux.cfg/0A00020F`` containing::
279
280 PATH bios
281 DEFAULT maintenance
282 LABEL maintenance
283 MENU LABEL Maintenance (NFS)
284 KERNEL maintenance-boot/vmlinuz-3.16.0-4-amd64
285 APPEND initrd=maintenance-boot/initrd.img-3.16.0-4-amd64 ro ip=dhcp aufs=tmpfs \
286 boot=nfs root=/dev/nfs nfsroot=10.42.1.1:/exports/testbox-nfsroot
287 LABEL local-boot
288 LOCALBOOT
289
290
291-----
292
293.. [1] See http://www.syslinux.org/wiki/index.php?title=Category:Modules
294.. [2] See http://www.syslinux.org/wiki/index.php?title=PXELINUX#Configuration
295.. [3] See https://en.wikipedia.org/wiki/Aufs
296.. [4] See http://shitwefoundout.com/wiki/Diskless_ubuntu
297.. [5] See http://debianaddict.com/2012/06/19/diskless-debian-linux-booting-via-dhcppxenfstftp/
298
299
300-----
301
302:Status: $Id: TestBoxImaging.txt 64498 2016-11-01 04:39:14Z vboxsync $
303:Copyright: Copyright (C) 2010-2016 Oracle Corporation.
304
305
Note: See TracBrowser for help on using the repository browser.

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