Ever been caught without that rescue disk, and thought that everything was lost, and that you have no choice but to reinstall the operating system? Well don’t do it just yet. In this article we’ll introduce you to tomsrtbt, a bootable diskette that will allow you to salvage and/or repair files regardless of your operating system. (This article originally appeared in the April 2004 issue of Plug-In).
If you’re here to salvage some files by copying them to a diskette then you will also need to know how to mount and format a floppy. You’ll be able to format your diskette for DOS or for Linux by first typing fdformat /dev/ fd0H1440. To make a Linux floppy type then type, mke2fs /dev/fd0 or, alternately, mkdosfs /dev/fd0 for a DOS diskette. To copy files to your floppy you will again have to mount the drive. This can be done in exactly the same way that any other drive is mounted. First create a mount point, let’s create one called “floppy”, and then mount the drive by typing mount –t msdos /dev/fd0 /mnt/floppy. Just drop the file type switch (–t msdos) if you are mounting a Linux floppy. We’re now ready to copy files.
Copying files is identical regardless of the operating system. You simply use the cp command specifying a source and destination. For instance, to copy the file fstab in the etc directory to your floppy you would simply type cp /etc/fstab /mnt/floppy/fstab. If you wish to copy a directory and all its contents then you will need to know the -r switch. The “r” stands for recursive and will copy all files and directories within the directory specified.
In this way you can salvage as many files as needed from the hard drive. Read on for more advanced commands.
In some cases you may want to run as root on your original Linux partition. This can be done by creating a mount point for the file system, mounting it and then using the chroot command. This is exactly what I wanted to do so that I could make a boot disk for my Red Hat 7.1 installation.
First I created a mount point for the file system. In my case I knew that my Linux drive was device hda5 so I created a mount point called “rh71”, mounted this device and then simply typed the command chroot /mnt/rh71. I next changed my directory to the sbin directory, typed ./mkbootdisk --device /dev/fd0 2.4.2-2 and inserted a floppy into the drive. The number following the device is the kernel version number of my distribution. You don’t have to remember it--you can easily look it up by examining the files in the “boot” directory.
When I was finished I changed back to tomsrtbt by typing exit at the command line.
In very quick order, I had a boot disk for my Red Hat installation. I could now boot into Linux and do anything else I needed to do using X Windows.
Things don’t always work out so nicely though. Sometimes you may need to look at or change information in a file. In this case you will have to use the text editor vi. I’ll give you some quick tips on using this editor.
To invoke vi, type vi and pressing Enter. If there is a specific file that you wish to edit, type the name of the file after the command vi. Upon start-up, vi is in command mode and you need to press i for “insert” if you wish to add to or change the file. Saving your changes is done by returning to command mode by hitting the Esc key, followed by :wq. This is not an extended tutorial on using vi, so if you have made mistakes and want to abandon what you’ve done you may quickly exit by pressing the escape key and then :q!. None of your changes will have been saved.
There are many more useful commands available--for checking the integrity of the file system, for instance--but you would probably do well to learn a little more about Linux before exploring them. You don’t want to accidentally reformat your drive!
The “tomsrtbt” distribution is a nice little tool if you have trouble booting from your hard drive and don’t have a rescue disk. Using a few basic Linux commands, files can be examined, copied or changed regardless of what operating system you are running.