lfs-uefi: fix efivar-37 FTBFS
[linux_from_scratch_hints.git] / backing-up-lfs.txt
blobde49661af4a72aa34499f7f30a2ffc7c529fba95
1 AUTHOR:         Mike McCarty    Mike dot McCarty at sbcglobal dot net
3 DATE:           2010-03-04
5 LICENSE:        GNU Free Documentation License as of 2010-03-04.
7 SYNOPSIS:       How to and what to back up in an LFS system.
9 PRIMARY URI:    N/A
11 DESCRIPTION:    This hint is intended for those who need help
12                 planning a backup system for LFS.
14 ATTACHMENTS:    N/A
16 PREREQUISITES:  Have a bootable LFS system and external removable medium
17                 for storage of the backup.
19 HINT:
21 Ok, you've built your shiny new LFS system, and it boots. The book
22 suggests that you back up your system, and then proceed to build
23 whatever portions of BLFS appeal to you. Unfortunately, the book doesn't
24 tell you what you need to backup, and how to do it.
26 The first thing to take note of is that there are more than one thing
27 called a "backup", and that they differ significantly from each other,
28 and in what they are good for.
30 One type of backup, sometimes called "bare metal" or "disaster
31 recovery", is one which one can simply put in a CD-ROM, boot, answer a
32 few prompts, and after some amount of time and CD-ROM swapping have the
33 system back in the state it was in. This hint does not address that type
34 of backup.
36 Another type of backup, sometimes called "full" stores all the
37 information which is needed in order to start from a freshly installed
38 system, and then restore the system back to the state it was previously
39 in. For an LFS system, in which "install" is synonymous with "build",
40 this type of backup does not make much sense.
42 Another type of backup, sometimes called "incremental", "differential",
43 or similar terms, allows one, in conjunction with a "full" backup, to
44 bring a freshly installed system back into a previous state, by first
45 restoring from a "full" backup, and then applying changes from the
46 incremental or differential backup. Again, since "fresh install" is
47 synonymous with "build", this type of backup is not quite applicable to
48 LFS, and is also not covered in this hint.
50 Ok, so what is covered?
52 This hint describes backups which allow you to recover from accidental
53 deletion of files, and also do disaster recovery from bare metal, but do
54 not themselves contain any means to boot. Both a "full" and
55 "incremental" or "differential" style of backup can be created, but a
56 separate boot medium must be supplied by the LFS user. The hint covers
57 what needs to be backed up, and how to create a true "snapshot" which
58 represents the system state at a single point in time. It does not cover
59 the style of backup medium nor how to secure the backups themselves,
60 though suggestions are made.
62 The first consideration in any backup, is that it actually represents a
63 single moment in time. Making the backup must be an atomic action, that
64 is, one which appears to have taken place in an instant. The only way
65 absolutely to guarantee this, is for all file systems to be in a
66 consistent state, and for them not to be modified for the duration of
67 the backup. More than one technique for accomplishing that have been
68 suggested, but the simplest to achieve with an LFS system is simply to
69 reboot to single user mode. How this is accomplished depends upon what
70 you chose as your boot method, so the details of that can't be covered
71 in full here. However, if you use GRUB, as suggested in the LFS book,
72 then you can create an entry for single user mode by adding an entry
73 to /boot/grub/menu.lst similar to this:
75         # LFS 6.5 Single User Mode for Rescue and Backups
76         title LFS 6.5 Single User Mode
77         root (hd0,3)
78         kernel /boot/lfskernel-2.6.30.2 root=/dev/hda4 single
80 It is not adequate to boot your system and then use
82         # init 0
84 since that leaves you still logged in as yourself, and you won't be able
85 to unmount your file systems. You also need to make sure that root can
86 log in, and has a good password.
88 Reboot, and select the single user mode entry, and when prompted for the
89 root password, enter it. You should then be given a single user mode
90 maintenance prompt.
92 Now that you are rebooted to single user mode, you need to unmount all
93 file systems, except the root file system. So, for each file system you
94 have mounted, simply do an unmount. Obviously, you can't unmount your
95 root file system /, so it must be remounted read only. To find out what
96 you have mounted, simply use the mount command. I'll give the example
97 here of what happens when you have /dev/hda1 for /boot, /dev/hda2 for /,
98 and /dev/hda5 for /home mounted. You'll need to adapt your procedure to
99 your setup.
101         # mount
102 /dev/hda2 on / type ext3 (rw)
103 /dev/hda1 on /boot type ext3 (rw)
104 /dev/hda5 on /home type ext3 (rw)
106 I've omitted the entries for /proc, and others, since these are not true
107 file systems. You want to make note of each file system which
108 corresponds to one of your hard disc partitions.
110 Now, for each file system you intend to back up, except for /, which you
111 have mounted, issue the umount command.
113         # umount /boot
114         # umount /home
116 Finally, remount the root file system read only
118         # umount -n -o remount,ro /
120 You need the -n so umount doesn't attempt to modify /etc/mtab after the
121 file system is marked read only.
123 At this point, we have ensured that the file systems won't be modified
124 by any background stuff going on, but we don't yet know that the file
125 systems are in a consistent state. For that, we need to run fsck on each
126 of the file systems. So, going through the list you got from mount
127 earlier, run fsck on each file system. Still using the example above
129         # fsck -c /dev/hda1
130         # fsck -c /dev/hda2
131         # fsck -c /dev/hda5
133 If you have other file systems which you sometimes mount, but which are
134 not mounted automatically at boot, then use fsck on them as well. Be
135 prepared for the fscks to take some time.
137 If all the checks pass, then you are ready to begin your backup. You
138 need to mount all your file systems read only, except for the one to
139 receive the actual backup. It's common to put the backups in
140 /var/backups. In that case, you need to mark the file system containing
141 it as read write, and all others as read only. It's common, however, for
142 / not to be large enough to contain the actual backups, so /var or
143 /var/backups to be on a separate partition. In that case, you can leave
144 / mounted read only. This example shows
146         # mount -n -o remount,rw /
147         # mount -o ro /dev/hda1 /boot
148         # mount -o ro /dev/hda5 /home
150 If you are not marking / as rw, and putting the backup in
151 /home/var/backups, for example, you would use
153         # mount -n -o ro /dev/hda1 /boot
154         # mount -n /dev/hda5 /home
156 In this case, you need the -n to prevent attempting to modify /etc/mtab
157 when it is on a read only file system.
159 Now mount any other file systems which are not automatically mounted at
160 boot, and which you intend to back up, but be sure to mount them read
161 only.
163 At this point, you are ready to begin the backup procedure. Well, the
164 obvious question is, what needs to be in the backup? The answer,
165 unfortunately, is "It depends." Partly, it depends on how you set your
166 system up, and it also depends on what you want on each backup set you
167 make. However, for guidance to those who are relatively new to UNIX
168 system's administration, here is a list of what you'll typically see on
169 a freshly built LFS system, what is in each piece, and suggestions to
170 help you determine whether you want to back it up.
172 /bin            this is the main program directory, and should be
173                 included in all backups which intend to back up the
174                 system itself, but not necessarily on data only backups.
176 /boot           this is usually a collection of kernels, boot
177                 configuration files, and the like, and should be
178                 included in all backups which intend to back up the
179                 system itself, but not necessarily on data only backups.
181 /dev            this is the devices directory, usually managed by udev
182                 on LFS systems, and should not be included in backups.
184 /etc            this is necessary configuration files and scripts and
185                 should be included in all backups which intend to back
186                 up the system itself, but not necessarily on data only
187                 backups.
189 /home           this is user information and data, and is not needed to
190                 back up the system itself, but would be included in all
191                 data only backups.
193 /lib            this is various library files, and should be included in
194                 all all backups which intend to back up the system
195                 itself, but not necessarily on data only backups.
197 /lost+found     this is a file system maintenance directory, and should
198                 not be included in any backups.
200 /media          this is used to hold mount points for various removable
201                 medium drives, like USB disc drives, floppy discs,
202                 CD-ROM drives and the like. Unless you are creating a
203                 backup which is intended to contain a file system which
204                 is mounted on, say, /media/my-usb-disc, then it should
205                 not be included in any backups.
207 /mnt            this is used as a temporary mount point by root, and
208                 normally should not be included in any backups.
210 /opt            this contains add on packages, and should normally be
211                 included in backups which are intended to back up the
212                 system add ons from, for example, BLFS, unless you put
213                 your add ons into /usr/local, or the like.
215 /proc           this is not a real file system, but rather a view port
216                 into the kernel's view of the system, and should not be
217                 included in any backups.
219 /root           this is normally root's home directory, and should be
220                 included in all backups which intend to back up the
221                 system itself, but not necessarily on data only backups.
222                 This directory should be pretty spare.
224 /sbin           this is the main maintenance program directory, and
225                 should be included in all backups which intend to back
226                 up the system itself, but not necessarily on data only
227                 backups.
229 /sys            this is not a real file system, but rather a view port
230                 into the kernel's view of the system, and should not be
231                 included in any backups.
233 /tmp            this is a temporary directory, and should not be
234                 included in any backups.
236 /tools          this is the main LFS build tools directory, and is not
237                 needed to back up the system itself, but would be
238                 included in all data only backups.
240 /usr            this is user information and data, and is not needed to
241                 back up the system itself, but would be included in all
242                 data only backups. In fact, you might not have anything
243                 in it at all, if you put all your add ons into /opt. You
244                 may have only man pages in it.
246 /var            this is user information and data, and is not needed to
247                 back up the system itself, but would be included in all
248                 data only backups. In fact, you might not have anything
249                 in it at all, if you put all your add ons into /opt.
250                 Note that, if you put you backup into /var/backups, then
251                 you need to be careful not to include /var/backups in
252                 the backup set.
254 Ok, so now you've rebooted, and you've decided what to put into your
255 backup set. How do you create your backup set? Well, that depends on
256 what you like. I like to use tar, and use it to create backups. One tool
257 which I've found very useful is yakup, which has very nice abilities to
258 split the archive into CD-ROM or DVD-ROM sized pieces, and manage
259 inserting and swapping media etc. That can be done after the backup is
260 made, and with the system on line. Others may prefer to use cpio style
261 backups. It's up to you how you chose to build your backup set. I highly
262 recommend yakup, but that's just my personal preference.
264 At this point, you have your backup set made, and are ready to reboot to
265 normal user mode, after which you write your backup to removable media,
266 unless it already is on one, like a USB disc. If you have your root file
267 system mounted read only, then you need to remount it, so it can be
268 marked "clean" when you go down. Otherwise, skip the first command
269 below.
271         # mount -o remount,rw /
272         # reboot
274 What you do now depends heavily on what other software you have
275 installed. You need some way to get the backup set off your machine, and
276 save it away, preferably at a remote location. I like to use DVD-ROMs
277 for my backups, and so I have growisofs and cdrecord installed. How to
278 do that is beyond the scope of this hint.
280 One other thing you need to do is make a backup of the scripts or
281 programs you use to restore files. If you simply use a tarball which
282 fits on one DVD-ROM or CD-ROM, then this may not be necessary, as you'll
283 need a boot disc, and it should contain tar. If you use a script like
284 yakup, then one of your backup discs should have that script as one of
285 the files on it, not in the tarball.
287 Ok, disaster has struck! How do you get your information back on your
288 disc? If all that has happened is you accidentally deleted a file, then
289 simply pull that one file back from your backup set, using whatever
290 means is appropriate for the format. This may be as simple as putting a
291 DVD-ROM into the drive, issuing a mount command, and running tar. I
292 recommend testing every backup set you make by restoring at least one
293 file to another location, and ensuring that it contains the same data as
294 the file it supposedly backs up.
296 How about if, as root, you fat fingered
298         # rm -rf /fred
300 and typed instead
302         # rm -rf / fred
304 and your root directory is gone?
306 You need to get a bootable CD-ROM with some version of Linux on it. I
307 like to use KNOPPIX. Others like sysrescuecd. Almost anything will work.
308 Boot your rescue medium, insert your backup medium, like DVD, into the
309 drive, and mount it. This may require using two DVD drives, and is
310 something you should think about before disaster strikes. Another
311 possibility is to use something like Feather Linux, or Puppy Linux,
312 which can load entirely into RAM, and free up the drive. Depending upon
313 how serious the disaster is, you may need to repartition your disc, and
314 create file systems. How to do that is highly dependent upon how you set
315 your system up, and some of the details are in the LFS book. When you
316 have your disc set up where it is ready to accept the restored files,
317 then copy the restore scripts you intend to use, and use them to pull
318 all files back from the backup. Recreate any directories you have on
319 your system which are not on the backup proper, but are needed for
320 boot. This is usually just /dev, which you don't back up, but udev
321 needs in order to get set up. You then need to reinstall and set up
322 your boot block, like GRUB, per its needs. At this point, you should
323 have a bootable system.
325 I highly recommend doing at least one simulated disaster recovery, using
326 the rescue boot medium you hope never to have to use later, and verify
327 that you can recover at least one file from your backup. A real test
328 would require putting a blank hard drive in and recreating your system.
329 Doing that is very instructive, but also requires some outlay in money.
330 I highly recommend it. Don't be learning how to do disaster recovery
331 while trying to recover from a disaster.
333 ACKNOWLEDGMENTS:        N/A
335 CHANGELOG:
337 Include timestamped changes that have occurred in the hint. Add latest
338 entries at the end. Entries in this section should be as follows:
340     * 2010-03-08
341     *  * slightly obfuscate e-mail address
342     *  * fix error in mount of /dev/hda1 to indicate read only
343     *  * add information about recreating some necessary directories
344     *    which may not be present on the backup, but necessary for boot