Arrow of time
Arrow of time

FreeBSD's /rescue directory and system recovery

Share Tweet Share

One of the many neat things FreeBSD uses to increase the operating system's resilience is the /rescue directory which is …

One of the many neat things FreeBSD uses to increase the operating system's resilience is the /rescue directory which is present by default and contains basic utilities and commands which can be used in case one or more of the default binaries gets corrupted or lost. In fact, binaries in /rescue are also statically linked so they can be used even if a large part of the system fails. Basically, if you have init and a shell (any shell, possibly the one from /rescue; even init is in /rescue) working, you can get your system back.


As its name indicates, the /rescue directory is intended for rescuing the system in case of some kind of failure, most notably file system failure. It contains a good selection of the operating system's utilities which can be used to bring the system up again. The binaries in /rescue are statically linked and "crunched" together so they are actually hardlinks to a single file. This also means they are self-contained and compact.

The /rescue directory contains the following utilities (I have highlighted some interesting ones):

[*               getfacl*         ping6*
atacontrol* glabel* pkill*
atmconfig* gpart* ps*
badsect* groups* pwd*
bsdlabel* gunzip* rcorder*
bunzip2* gzcat* rcp*
bzcat* gzip* rdump*
bzip2* halt* realpath*
camcontrol* head* reboot*
cat* hostname* red*
ccdconfig* id* rescue*
chflags* ifconfig* restore*
chgrp* init* rm*
chio* ipf* rmdir*
chmod* kenv* route*
chown* kill* routed*
chroot* kldconfig* rrestore*
clri* kldload* rtquery*
cp* kldstat* rtsol*
csh* kldunload* savecore*
date* ldconfig* sed*
dd* link* setfacl*
devfs* ln* sh*
df* ls* spppcontrol*
dhclient* lzcat* stty*
dhclient-script* lzma* swapon*
disklabel* md5* sync*
dmesg* mdconfig* sysctl*
dump* mdmfs* tail*
dumpfs* mkdir* tar*
dumpon* mknod* tcsh*
echo* mount* tee*
ed* mount_cd9660* test*
ex* mount_msdosfs* tunefs*
expr* mount_nfs* umount*
fastboot* mount_ntfs* unlink*
fasthalt* mount_nullfs* unlzma*
fdisk* mount_udf* unxz*
fsck* mount_unionfs* vi*
fsck_4.2bsd* mt* whoami*
fsck_ffs* mv* xz*
fsck_msdosfs* newfs* xzcat*
fsck_ufs* newfs_msdos* zcat*
fsdb* nextboot* zfs*
fsirand* nos-tun* zpool*
gbde* pgrep*
geom* ping*

The utilities should be enough to bring a system back in case of file system corruption, missing storage devices, etc. - as long as the root file system is ok, the utilities in /rescue can be used to bring back the rest. Note that even if /bin/sh and /bin/init are gone, the kernel can be booted using /rescue/init (in fact, this will happen automatically), and the sh or tcsh shells from /rescue can be used to continue working on the system. The geom utility can be used to interface with loaded GEOM classes (if /lib/geom is still available).

A notable class of utilities which are missing are the network transfer utilities like ssh/scp - but this is because they depend on crypto libraries and are difficult to package in this way. In any case, NFS mounts can be used to transfer data.

Together with /rescue, there is usually a backup of the kernel in /boot/kernel.old (present if the system was ever updated), so even if the main kernel was nuked, the backup one could still be available (there's no silly initrd munging in BSD).

If all else fails, a Live CD can be used to boot to a reasonable environmet. This is what you get with a project which had decades of experience behind it.


#1 Re: FreeBSD's /rescue directory and system recovery

Added on 2011-10-21T03:40 by mario
Why /rescue? Isn't that what /shin was traditionally used for? Stuff in shin was statically linked for the reason you describe. How is rescue different?

#2 Re: FreeBSD's /rescue directory and system recovery

Added on 2011-10-21T03:43 by mario
Arrg, I meant /sbin which is now in my Android's autocorrect library.

#3 Re: FreeBSD's /rescue directory and system recovery

Added on 2011-10-21T10:30 by Ivan Voras
There isn't really a connection - sbin is "superuser bin", it mostly contains root-only utilities.

#4 Re: FreeBSD's /rescue directory and system recovery

Added on 2011-11-09T22:32 by BSDr

Better FreeBSD Rescue rocks the house.

I really wish the scripts for building it with nanobsd were available (and pivot_roo() too) ... stick it on a usbkey or little ssd inside the case and you're good to go.

static sshd FreeBSD rescue system:

http://www.webgroup.ch/linuxtag2006/

see thread:

http://freebsd.1045724.n5.nabble.com/Mostly-static-binaries-with-crunchgen-td4035296.html

#5 Re: FreeBSD's /rescue directory and system recovery

Added on 2011-11-12T21:44 by DES

We should add netcat. In an emergency situation, piping tar through netcat is much simpler than setting up an NFS server.

#6 Re: FreeBSD's /rescue directory and system recovery

Added on 2011-11-16T15:11 by TJ

One of the things I like about OpenBSD and DragonFly is that the binaries in /bin and /sbin are statically linked by default. No need for a second crunched copy of them in yet another directory in case of non-root-fs disasters.

I very much love FreeBSD, but when this simple change was made way back when to dynamically link /bin and /sbin by default, I instinctively arched an eyebrow knowing that this would require sillyness like /rescue


comments powered by Disqus