> -d
— Dereferences symbolic links (never follows symbolic links) and copies the files to which they point, instead of copying the links.
> -p
— Preserves all file attributes if possible. (File ownership might interfere.)
> -R
— Copies directories recursively.
You can also use the cp
command to quickly replicate directories and retain permissions by using the -avR
command-line options. Using these options preserves file and directory permissions, gives verbose output, and recursively copies and re-creates subdirectories. You can also create a log of the backup during the backup by redirecting the standard output like this:
# cp -avR
or
# cp -avR fedora /test2 1>/root/backup_log.txt
This example makes an exact copy of the directory named /fedora
on the volume named /test2
, and saves a backup report named backup_log.txt
under /root
.
Using mc
to Copy Files
The Midnight Commander is a command-line file manager that is useful for copying, moving, and archiving files and directories. The Midnight Commander has a look and feel similar to the Norton Commander of DOS fame. When you execute mc
at a shell prompt, a dual-pane view of the files is displayed. It contains drop-down menu choices and function keys to manipulate files. It also uses its own virtual file system, enabling it to mount FTP directories and display the contents of tar
files, gzipped tar
files (.tar.gz
or .tgz
), bzip
files, DEB
files, and RPM
files, as well as extract individual files from them. As if that were not enough, mc contains a File Undelete virtual file system for ext2/3
partitions. By using cd
to 'change directories' to an FTP server's URL, you can transfer files with the FTP protocol. The default font chosen for Fedora makes the display of mc
ugly when used in a tty
console (as opposed to an xterm
), but does not affect its performance.
Figure 13.4 shows the default dual-panel display. Pressing the F9 key drops down the menu, and pressing F1 displays the Help file. A 'feature' in the default GNOME terminal intercepts the F10 key used to exit mc
, so use F9 instead to access the menu item to quit, or simply click on the menu bar at the bottom with your mouse. The configuration files are well documented, and it would appear easy to extend the functionality of mc
for your system if you understand shell scripting and regular expressions. It is an excellent choice for file management on servers not running X.

FIGURE 13.4 The Midnight Commander is a highly versatile file tool. If it does not display properly on your screen, launch it with the -a
argument to force ASCII mode.
System Rescue
There will come a time when you need to engage in system rescue efforts. This need arises when the system will not even start Linux so that you can recover any files. This problem is most frequently associated with the boot loader program or partition table, but it could be that critical system files have been inadvertently deleted or corrupted. If you have been making backups properly, these kinds of system failures are easily, although not quickly, recoverable through a full restore. Still, valuable current data might not have been backed up since the last scheduled backup, and the backup archives could be found to be corrupt, incomplete, or missing. A full restore also takes time you might not have. If the problem causing the system failure is simply a damaged boot loader, a damaged partition table, a missing library, or misconfiguration, a quick fix can get the system up and running and the data can then be retrieved easily.
This section first examines a way to back up and restore the boot loader itself or, having failed to do that, restore it by hand. It then looks at a few alternatives to booting the damaged system so that you can inspect it, fix it, or retrieve data from it.
The Fedora Rescue Disc
Fedora provides a rescue disc hidden in the installation DVD. To use it, insert the disc and reboot the computer, booting from the DVD just as you did when you installed Fedora originally. At the intro screen, press the F1 key to see all the available choices, but simply enter linux rescue
at the LILO boot prompt to enter rescue mode, like so:
boot: linux rescue
You will learn more about the rescue mode later in this section, but feel free to explore it at any time. A graphical interface is not available, so you need to bone up on your command-line skills. If necessary, you can perform all the operations discussed in this section from rescue mode.
Backing Up and Restoring the Master Boot Record
The Master Boot Record (MBR) is the first 512 bytes of a hard disk. It contains the boot loader code in the first 446 bytes and the partition table in the next 64 bytes; the last two bytes identify that sector as the MBR. The MBR can become corrupted, so it makes sense to back it up.
This example uses the dd command as root to back up the entire MBR. If the boot loader code changes from the time you make this image and restore the old code, the system will not boot when you restore it all; it is easy enough to keep a boot floppy disk handy and then rerun LILO if that is what you are using.
To copy the entire MBR to a file, use this:
# dd if=/dev/hda of=/tmp/hdambr bs=512 count=1
To restore the entire MBR, use this:
# dd if=/tmp/hdambr of=/dev/hda bs=512 count=1
To restore only the partition table, skipping the boot loader code, use this:
# dd if=/tmp/hdambr of=/dev/hda bs=1 skip=446 count=66
Of course, it would be prudent to move the copy of the MBR to a floppy disk or other appropriate storage device. (The file is only 512 bytes in size.) You will need to be able to run dd on the system to restore it (which means that you will be using the Fedora rescue disc, as described later, or any equivalent to it).
Manually Restoring the Partition Table
A different way of approaching the problem is to have a printed copy of the partition table that can then be used to restore the partition table by hand with the Fedora rescue disc and the fdisk
program.