Learn how to use your emergency repair kit before the emergency.
Now that you have an emergency repair kit, it's worth your while to do a dry run so you know ahead of time what options will be available to you. You may even decide to modify your kit as a result of this test.
Let's go back to that sysinstall Main Menu screen [Hack #71] and see what happens when you choose Fixit. You'll be presented with the following options:
Please choose a fixit option There are three ways of going into "fixit" mode: - you can use the live filesystem CDROM/DVD, in which case there will be full access to the complete set of FreeBSD commands and utilities, - you can use the more limited (but perhaps customized) fixit floppy, - or you can start an Emergency Holographic Shell now, which is limited to the subset of commands that is already available right now. X Exit Exit this menu (returning to previous) 2 CDROM/DVD Use the "live" filesystem CDROM/DVD 3 Floppy Use a floppy generated from the fixit image 4 Shell Start an Emergency Holographic Shell
If you choose the Shell option, you'll find that they weren't kidding when they warned you'd be limited to a subset of commands. Nearly all of the commands you know and love will result in a not found error message. This is why you went to the trouble of either creating that fixit floppy or purchasing/burning a CD-ROM/DVD that contains the live filesystem.
7.5.1 Using the fixit Floppy
Let's see what you can repair with the fixit floppy. When you choose that option, follow the prompts: insert the floppy, then press Alt F4. Do make note of the message you receive:
+-----------------------------------------------------------------------+ | You are now running from FreeBSD "fixit" media. | | --------------------------------------------------------------------- | | When you're finished with this shell, please type exit. | | The fixit media is mounted as /mnt2. | | | | You might want to symlink /mnt/etc/*pwd.db and /mnt/etc/group | | to /etc/ after mounting a root filesystem from your disk. | | tar(1) will not restore all permissions correctly otherwise! | | | | Note: you might use the arrow keys to browse through the | | command history of this shell. | +-----------------------------------------------------------------------+ Good Luck! Fixit#
It's not a bad idea to create those symlinks now, before you forget. You'll have to mount your root slice first, so refer to your /etc/fstab printout for the proper name of that slice. In this example, / is on /dev/ad0s1a. I'll mount it with the read-write option:
Fixit# mount -o rw /dev/ad0s1a /mnt Fixit#
If your command is successful, you'll receive the prompt back. A quick ls through /mnt should convince you that you now have access to the hard disk's root filesystem.
If your command is not successful, run fsck_ffs until the filesystem is clean, then mount the filesystem:
Fixit# fsck_ffs /dev/ad0s1 ** /dev/ad0s1 ** Last Mounted on /mnt ** Phase 1 - Check blocks and Sizes ** Phase 2 - Check Pathnames ** Phase 3 - Check Connectivity ** Phase 4 - Check Reference Counts ** Phase 5 - Check Cyl groups 821 files, 27150 used, 99689 free (985 frags, 12338 blocks, 0.8% fragmentation) Fixit# mount -u -o rw /dev/ad0s1 /mnt
Now for those symlinks:
Fixit# ln -f -s /mnt/etc/*pwd.db /etc Fixit# ln -f -s /mnt/etc/group /etc
Note that you need to include the force (-f) switch when you make your symbolic (-s) links. You need to overwrite the existing link that links mnt2, or the fixit floppy, to /etc. You instead want to link the files on your hard drive (/mnt) to /etc.
You'll also notice that while in the Fixit# prompt, the up arrow will recall history, but tab completion does not work.
At that Fixit# prompt, you have two command sets available to you. The first is that limited command set that comes with the sysinstall utility. Note that these are the only commands available at that holographic shell prompt:
Fixit# ls stand -sh* gunzip* route* [* gzip* rtsol* arp* help/ sed* boot_crunch* hostname* sh* camcontrol* ifconfig* slattach* cpio* minigzip* sysinstall* dhclient* mount_nfs* test* dhclient-script* newfs* tunefs* etc/ ppp* usbd* find* pwd* usbdevs* fsck_ffs* rm* zcat*
The second command set is on the floppy itself, mounted as mnt2:
Fixit# ls mnt2/stand bsdlabel* dd* fixit_crunch* mount_cd9660* sleep* cat* df* ftp* mount_msdosfs* swapon* chgrp* disklabel* kill* mv* sync* chmod* dmesg* ln* reboot* tar* chown* echo* ls* restore* telnet* chroot* ex* mkdir* rm* umount* clri* expr* mknod* rmdir* vi* cp* fdisk* mount* rrestore* view*
You'll also find a minimal set of notes in:
Fixit# ls stand/help
One of the first things you'll notice, especially if you try to read one of those help documents, is the lack of a pager. You won't have any luck with more or less. However, cat and view are available for viewing files. If you've never used view before, remember to type :q to quit the viewer.
Also note that all of the restore utilities are on hand, unless you've used pax as your backup utility.
7.5.2 Using the Live Filesystem
Let's pause here for a moment and compare the fixit floppy to the live filesystem. There's one CD marked as live in a purchased set. If you burn your own ISO images, the second image for your release will contain the live filesystem. For example, here is the listing for ftp://ftp.freebsd.org/pub/FreeBSD/ISO-IMAGES/5.1-RELEASE/:
5.1-RELEASE-i386-disc1.iso 630048 KB 06/05/03 00:00:00 5.1-RELEASE-i386-disc2.iso 292448 KB 06/05/03 00:00:00 5.1-RELEASE-i386-miniinst.iso 243488 KB 06/05/03 00:00:00 CHECKSUM.MD5 1 KB 06/05/03 00:00:00
disc1.iso is the install CD, and disc2.iso is the live filesystem CD.
There are several advantages to using the live filesystem. First, you don't have to make any floppies. In fact, your entire kit can be as simple as this one CD and your printouts specific to that system. Second, the CD is bootable, so you can reach that Fixit# prompt in under a minute.
Third, you have the entire built-in command set available to you. When you enter the Fixit screen, you'll see the same welcome message as before. This time, it is the CD that is mounted as /mnt2, which is really a link to /dist:
Fixit# ls -l /mnt2 lrwxr-xr-x 1 root wheel 5 Dec 8 08:22 /mnt2@ -> /dist Fixit# ls /dist .cshrc boot/ etc/ root/ tmp/ .profile boot.catalog floppies/ rr_moved/ usr/ COPYRIGHT cdrom.inf mnt/ sbin/ var/ bin/ dev/ proc/ sys@
A quick ls /dist/bin and ls /dist/sbin will display all of the commands that come with a FreeBSD system. There isn't a limited command set with the live filesystem.
7.5.3 Emergency Repair
Now that I've shown you the various ways to enter the Fixit facility, you're probably wondering what you should be doing at that prompt. FreeBSD is quite robust and is usually capable of booting your hard drive to some sort of prompt. However, if the disk fails completely or is somehow incapable of booting to a prompt, the fixit facility is one of your options.
From here, you can run fsck on your various filesystems, which may fix the problem. You can see which filesystems are still mountable, allowing you to assess the extent of the damage. If some files were damaged, you can restore those files from backup.
If it turns out that the drive is damaged beyond repair, you can rest easy in the fact that you have a printout of your hardware and partitioning scheme, a floppy containing any necessary drivers, and a backup of all of your data. Above all, you were prepared.
7.5.4 See Also