*adjective, easily modified or changed; opposite of hardcoded

softcoded - toronto web design

    home »  site map »  e-mail » 

Rescue Me:
Help in Trying Times for Linux or Windows Users

January 2, 2004
as published in Plug In Magazine

Overview

Ever been caught without that "rescue disk" and thought that everything was lost, that you have no options but to reinstall the operating system? Well don't do it just yet.

In this article we'll introduce you to a bootable diskette that will allow you to salvage and/or repair files regardless of your operating system.


Introduction

Apple has done away with it for years now. My BIOS scornfully refers to it as a legacy device. Yes, I'm talking about the poor 3.5" floppy. It wasn't always so. There was a time when the 3.5" reigned supreme. It was much superior to the 5.25 " – especially if you remember the 1541 Commodore external drive. I still shudder at the thought. And then there was the cassette tape that you used with the ZX-81. But now I'm really showing my age.

In any case, I recently had occasion to be very thankful to this legacy device. My dual boot Win2K/Linux Red Hat 7.1 wouldn't boot into Linux any more. Probably something to do with that SCSI card I recently added. Well, I thought, it's simple enough to use my Linux boot disk and see if I can sort out the problem. But no such floppy could be found.

Allow me a quick aside to Windows-only readers. Don't change the channel. There is something here for you because even though the Windows operating system can't view a Linux partition, Linux can see Windows. I'll let you draw your own conclusions about this fact but one thing this does mean is that you can use Linux to salvage or repair Windows files.

To get back to our main problem, and to paraphrase an expression, it looked like I was "up the effluent stream with no means of propulsion". Okay, so I could boot from the installation CD but in the spirit of the new year and not forgetting "auld acquaintance" let's see what we can do with only a floppy drive. Besides, as you'll see, an irresistible temptation presented itself to me along the way.

Creating a Bootable Diskette

In the frantic search for my Linux Red Hat 7.1 boot disk I did came across a vaguely remembered diskette labelled "tomsrtbt 2.0.103". Well, could Alice resist the bottle labelled "Drink Me"?

To answer that question you really need to know what "tomsrtbt" is. To quote Tom, "tomsrtbt" stands for: "Tom's floppy which has a root file system and is also bootable." I had my boot disk ready-made but you will have to create yours by going to http://www.toms.net/rb/.

Locate the link for downloading, find an appropriate mirror and choose the file named "tomsrtbt-2.0.103.dos.zip" if you wish to create your diskette under Windows or "tomsrtbt-2.0.103.tar.gz" for Linux/Unix.

A word of warning at this point. If you are running Windows 2000 creating this diskette is a bit problematic. If you've got a Windows 98 machine handy this provides your easiest solution. Copy the zipped file to this machine, decompress it and boot into DOS to create your bootable floppy. Otherwise see, http://not.toms.net/twiki/bin/view/Tomsrtbt/CreateTomsrtbtFromWin2000. Various solutions are presented there but the next easiest seems to be to make DOS boot disks using the resources at, http://www.bootdisk.com and then create your Linux diskette.

A couple of final notes. This distribution of Linux does not support the NTFS file system. There should be no problems creating your bootable disk under Linux.

Booting From a Legacy Device

Let's assume that you have managed to create your Linux boot diskette. Reboot using this diskette, first making sure your BIOS is set to boot from the floppy drive.

Okay, I know it's taking a long time to load the operating system but in the spirit of the new year use the time to reflect on "auld acquaintance"- and be comforted that you are not using a 5.25" drive.

Choose your language - yes you get to choose your language if you don't want the default, and pretty soon you'll be looking at a screen full of all the Linux commands available. If you're a little shaky at the command line in Linux or you are one of the fearless Windows-only users who has followed us this far don't worry. The operating system commands you need are limited in number and we're going to explain them as the need arises.

At this point you can remove the diskette from the drive. You don't need it any more because you are now running from a RAM drive. Besides, you may want to format a diskette (Linux or Windows) and copy files to this drive.

That blinking cursor wants you to log in. Your only choice is to enter "root" and after that the password, "xxxx".

"ls" and "cd" Commands

The most basic command you'll need is "ls", the Linux equivalent of the DOS "dir". Try it out and you should see a list of directories (folders in Windows terminology). If you want to see more information about these directories then type "ls –l". The "-l" is a switch that gives the "long" view of your files.

Next you will want to navigate around the file system and for this you'll need "cd". Looks familiar doesn't it? In fact, it works exactly the same way as it does under DOS. Use "cd" with a directory name and that directory will become your working directory. Returning to the parent directory is as simple as "cd .." or to go to the root directory " cd /". Don't forget the space or it won't work.

Mounting a Drive

By now you are probably itching to look at your Windows file system especially if you've never seen it from Linux before. To do this the file system needs to be mounted and in order to be mounted it needs a mount point. What this boils down to is that you need to create a directory and mount a specific file system on this directory. It is conventional to create mount points in the "mnt" directory. If you are at the root directory and issue the command "ls" you should see this directory. Make it your working directory by typing "cd mnt". You'll find that there are no subdirectories here but we are going to make one. Again the command is identical to the DOS command. Type "mkdir cdrive" and press enter. Now list the contents of the current directory to see the newly created directory. There you go. You've created a directory that will be the mount point for the Windows file system.

Remember though that you are working with a RAM drive so the changes you are making and directories you are creating won't be there next time you boot from diskette.

At this point you need to know something about the way that your hard drive is organised. If you are only running Windows and have not partitioned your drive then your "c" drive will be referenced from Linux as "hda1" and the command to mount this file system is "mount /dev/hda1 /mnt/cdrive –t msdos". Try it. You'll only see a message if you've made an error. Now change directories to the "/mnt/cdrive" directory. Not sure where you are? Determine your present working directory by typing "pwd". To look at your Windows files you simply need to change to the "/mnt/cdrive" directory and use the "ls" command. Savour the moment if this is the first time that you have seen a Windows partition from Linux.

If you are running Linux then I'll assume you know which drive to mount. Again, if you only have one partition then it will be "hda1".

You should always unmount a drive when you are finished. Your "c" drive would be unmounted by typing "umount /dev/hda1". Make sure the drive you are trying to unmount is not your present working directory or you'll get a "drive busy" error.

Copying Files

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, "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 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.

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 and 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 do not 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 though I should warn you that I have always thought of "vi" as short for "vile".

"vi" is invoked by typing "vi" and "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 typing "escape" 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 ":" followed by "q!". None of your changes will have been saved and like the new year that has just begun, you can start over again with a clean slate.

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!

Conclusion

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.

About the Author

Peter Lavin runs a Web Design/Development firm in Toronto, Canada. He has been published in a number of magazines and online sites, including UnixReview.com, php|architect and International PHP Magazine. He is a contributor to the recently published O'Reilly book, PHP Hacks and is also the author of Object Oriented PHP, published by No Starch Press.

Please do not reproduce this article in whole or part, in any form, without obtaining written permission.

top