Rescuing a non-bootingLinux system
How to Reinstall The Grub Loader - Specific to Ubuntu releases.
If the Grub boot installer is not working correctly due to the MBR (Master Boot Record) being overwritten or corrupted follow these steps.
Boot from an appropriate installation disk. The following was checked using the Ubuntu Feisty Fawn 7.04 release. ISO.
When the boot menu is displayed press F6 which will display a command line prompt. Add "init=/bin/bash" to the existing information and press enter.When the install stops at the command line prompt type "fdisk -l /dev/sda ( for sata drives or /dev/hda for IDE drives ).
The listing will display the drive partition information of that PC. Locate the name of the partition with the Linux type 83 filesystem and note the partition name. eg. /dev/sda3. You need to mount this partition, using the above example type the following " mount /dev/sda3 /mnt".
Once done "cd /mnt". You are now on the Linux partition. It is assumed that the "menu.lst" file in the /boot/grub directory is intact and correct. Type "grub" and at trhe grub prompt type "find /boot/grubstage1". The result displayed should be noted. Even though in the above example the Sata drive was shown as "sda3" the result for this find option would be "(hd02)"
While still at the grub prompt type "root (hd02) " (still using the above example). Then at the grub prompt "setup (hd0)" this will write the boot infomation to the first partition which is hdo.If the above worked then a listing will be displayed with " /boot/grub/menu.lst" succeeded message.Restart the computer and hopefully this has replaced the MBR with the correct Linux "menu.lst" file information. This is the most common scenario.Something goes haywire, and boom, no boot. No problem: boot upKnoppix and find all your local partitions nicely iconicized on theKDE desktop. (Or cruise the file tree to /mnt.) Click on the correcticon, and there are all your files. But they are wisely mountedread-only. Again, no problem: right-click the desktop icon to bringup a nice menu with a "Change read/write mode" option. Thismounts the filesystem on the partition as read/write. Now you canedit any file.
The default user is knoppix.For operations that require root privileges, you need to suto root and assign a root password:
knoppix@ttyp0[knoppix]#su
root@ttyp0[knoppix]# passwd
To mount afilesystem read/write from the command line:
root@ttyp0[knoppix]#mount -t reiserfs -o rw /dev/hda5 /mnt/hda5
Tounmount:
root@ttyp0[knoppix]# umount/mnt/hda5
If you get an error message "Couldnot unmount device, device is busy," something is reading thefilesystem. Close files and cd out ofthe filesystem.
How do you know what mountpoint and filesystemto specify? Just read /etc/fstab:
root@ttyp0[knoppix]#cat /etc/fstab
...
# Added by Knoppix
/dev/hda5 /mnt/hda5reiserfs noauto,users,exec 0 0
Hardwaredetection
Before going on a mad config file editingspree, it often pays to examine hardware information. Knoppix excelsat this, as it has the latest editions of Linux's excellent hardwareand system utilities: fdisk, lspci, iwconfig, ifconfig, dmesg, /proc,and so forth. (Checking hardware information is also handy fortesting a system for Linux compatibility before you buy it. Soundcards, softmodems, and wireless NICs are especially troublesome;manufacturers often change the chipsets without changing the modelnumbers, and you need to know the chipsets to determine if Linuxdrivers are available. The Knoppix CD also contains a number of soundfiles, for quick sound testing, starting with "OpenMusic"on the welcome screen.)
fdisk -l displays all partitions on all hard drives.
lspci -v gives detailed information about every device and chipset connected to the PCI bus.
cat /proc/cpuinfo tells exactly what CPU is installed.
ifconfig displays, and also manipulates, network interface settings. Most commonly Ethernet cards and ppp, the modem interface.
iwconfig is like ifconfig, but for wireless network cards.
dmesg is interesting. man dmesg isn't all that helpful if you're not a kernel hacker. Just using dmesg | grep <device> is a useful troubleshooting and system discovery tool. To see everything, run dmesg with no options.
And of course KDE provides a nice GUI to see all this; go toSystem > Info Center.
Rescuing datafiles
Usually the first rescue chore is to copy datafiles off of the troubled drive. This is my favorite method whenthere are large numbers of files to copy: install a second harddrive, then boot Knoppix, then copy files from the old disk to thenew disk. Even if you don't have nice hot-swappable drives orremovable drive cages, it takes just a couple of minutes to pop thecase open and hook one up. Do you have a brand new blank drive, or anold one that needs to be wiped clean and reformatted? No problem, dothe disk preparation from Knoppix.
Partitioningand formatting
First, install the second hard drive.Then boot Knoppix and open a root shell. If there are partitionsalready on the second disk, simply re-format whatever ones you need.Note that SCSI drives are designated sd,while IDE drives are hd. This commanddisplays the existing disk partitions; be sure to use valuesappropriate for your system:
root@ttyp0[knoppix]#fdisk -l /dev/hdb
To format a diskpartition:
root@ttyp0[knoppix]# mkfs.ext2 -c/dev/hdb1
This creates a plain-vanilla ext2filesystem. -c checks for bad blocks. Ofcourse, you can make it anything you like: ext3, ReiserFS,whatever:
root@ttyp0[knoppix]# mke2fs -j -c/dev/hdb1
root@ttyp0[knoppix]# mkreiserfs /dev/hdb1
What,no partitions? First, here's how to create them the command-line way,with fdisk. It's medium-safe to futzwith fdisk, as changes are not written to disk until you give thecommand to do so. So, you can try different options and preview thepartition table before committing to any changes. This sequence ofcommands creates a single partition:
root@ttyp0[knoppix]#fdisk /dev/hdb
Type "m" at any time todisplay a table of fdisk commands. Then,type "n" to create a new partition. Now, type "p"to create a primary partition. Hit Enter twice to accept thedefaults. Or, if you don't want to use the whole disk, hit Enter onceto accept the default starting point, then select the size youwant:
+1000M
Hit "p"at any time to preview the new partition table. When everything looksgood, press "w" to write the changes to disk. By default,fdisk creates a "type 83"partition, which means Linux. To see a list of partition types, press"l". To change the partition type, hit "t". Wantto delete a partition? Easy as pie: press "d" and followthe prompts.
QTParted
Eveneasier is firing up KDE and using QTParted (System > QTParted).QTParted creates, deletes, and non-destructively moves and resizespartitions (even NTFS). So, you can make room to copy your datawithout losing anything.
Copying files the GUIway
I like graphical file managers. It's a lot simplerto drag and drop than to type out long command strings. Click on theicons on the KDE desktop that represent your source drive and thedrive you want to copy them to. Each one opens in its own filemanager, for fast and easy drag and drop. Be sure to make thedestination drive writeable.
Copying files atthe command line
Remember to create a directory to movefiles into:
# mkdir/mnt/hdb1/home/carla/backup
# cp -r /mnt/hda5/home/carla/mnt/hdb1/home/carla/backup
Cloningan entire drive
You'll need two hard drives the samesize, or a destination drive larger than the source drive. Make sureno partitions are mounted on either drive. In this example /dev/hdais the source drive, /dev/hdb is the destination drive. The ddcommand makes an exact, byte-for-byte copy, including the MBR (masterboot record):
# dd if=/dev/hda of=/dev/hdb
Mounting confusion
Areyou losing track of what's mounted, and in what state? No problem,here comes /proc to the rescue:
#cat /proc/mounts
This displays all mountedfilesystems, the filesystem types, read/write status, and otherattributes. How many hard drives are on the system? One of these willtell you (and remember, SCSI drives are sd,IDE are hd):
#fdisk -l
or
# dmesg |grep hd
or
# dmesg |grep sd
Copying to CD
KDEand Knoppix make this easy. Assuming there is a CD writer on thesystem, simply right-click on the desktop icon for the partitioncontaining your files, and you will see "Create Data CD withK3b." Do File > New Project, drag and drop the filesyou want to copy, and there you go. K3b is very good at autodetectingand autoconfiguring your CD drives; it should do it all for you. Ifsomething goes awry, please refer to the developerWorksarticle "BurningCDs on Linux", which also teaches how to burn CDsfrom the command line.
Copying to othermedia
Zip drives, floppy disks, and USB storage deviceswill be automatically recognized by Knoppix, and icons will be placedon the desktop. Simply make the drive you want to copy files towriteable, then drag and drop until it's all done.
Copyingover the network
You can configure Knoppix to connectto a network, just like any other Linux. Knoppix has its owngraphical configuration utility: on the main menu find Knoppix >Network/Internet. Again Knoppix's excellent hardware detectioncomes into play; it even works on wireless NICs (assuming it's awireless NIC that is supported in Linux!). Simply answer a series ofquestions, and you're done.
It's just as easy from thecommand line. As root, run:
# netcardconfig
Once your network settings are configured, thereare several options for transferring files. cpis fine for locally mounted filesystems. Copying files over anuntrusted network should be done with scp(secure copy), and in fact Knoppix won't let you use anything else.scp uses ssh for encrypted file transferand lets you move files without setting up NFS or Samba. You'll needan ssh server running somewhere on the network to receive the files.This command copies an entire directory:
#scp -rp /mnt/hda5/home/carla 192.168.1.5:/home/carla/tmp
SSHquickstart
What, you have no ssh server? If you reallydo not yet have ssh installed, here is a quick-start guide to runningSSH. But before using it for even routine remote administrationtasks, you should study ssh in more depth. Note also that there havebeen a number of important security patches issued recently.
OpenSSHcomes with all major Linux distributions, and yours should alreadyhave it. (To find out, type locate sshd.)If not, download and install it. It doesn't need to be on a specialmachine; any Linux PC can run SSH. Start it up like so:
#/etc/init.d/ssh start
Then, all you need is forthe same user to have accounts on both machines. Using root iseasiest, but potentially dangerous. And, of course, you can createuser accounts on Knoppix as needed, with useraddand passwd. Then run the scpcommand as in the example above, and there you go.
The firsttime you connect, you'll get a "The authenticity of host X can'tbe established...are you sure you want to continue connecting?"message. Answer "yes." It will ask for the root password ofthe SSH server, and then you're home free. To move files as anon-root user:
# scp -rp /mnt/hda5/home/carlacarla@192.168.1.5:/home/carla/tmp
Opena root shell on the host system
This lets you operateon the host system, as though you were logged into it directly.Identify the partition the host system is on, then open a Knoppixroot shell and mount it:
root@ttyp0[knoppix]#mount /dev/hda1 /mnt/hda1
root@ttyp0[knoppix]# chroot/mnt/hda1
root@Knoppix:/
Knoppixglitches
Running programs from a CD can cause some oddtroubles, especially on notebooks. It is common for power managementto mess up a Knoppix session: when you wake up the machine, Knoppixdoesn't respond to commands anymore. The only cure I know is todisable power management, or simply hit the power switch and startover.
Sometimes Knoppix gets stuck during boot, and hangspartway into KDE (or any X session) startup. Switch to the firstvirtual console (Ctrl + Alt + F1) to see the live system messages;this should tell you where the problem is. Hit Alt + F5 to get backto the default X session. For example, on one of my test systems itgot stuck doing SCSI detection. Why? Who knows. I disabled SCSIdetection by adding knoppix no scsi tothe boot command, and that took care of it.
Knoppixcreative ferment
Linux has always inspired amazingcreativity. Knoppix has taken off in a big way, and there are dozensof inventive Knoppix-inspired projects, such as Inside SecurityRescue Toolkit, OpenGroupware Knoppix, Damn Small Linux, andOverclockix. See the Resourcessection below for more information and links to how-tos for makingyour own customized Knoppix distribution.
Resources
As always, man pages, while not exactly riveting reading, contain complete command and option listings. The following man pages are most useful in rescue operations:
man fdisk
man mkfs
man fstab
man ifconfig
man mount
man proc
man dmesg
man iwconfig
man chroot
man scp
man sshd bin/bash
man dd
man lspci