Skip to main content

If you don't have an IBM ID and password, register here.

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. This profile includes the first name, last name, and display name you identified when you registered with developerWorks. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

System recovery with Knoppix

What to do when good disks go bad

Carla Schroder (dworks@bratgrrl.com), Consultant, Tux Computing
Carla Schroder is a freelance PC tamer and author, administering Linux and Windows systems for small businesses and writing how-tos for real people. Carla discovered computers and high-tech around 1994, and is living proof that self-taught middle-aged persons make fine computer gurus. Watch for her upcoming O'Reilly book, The Linux Cookbook.

Summary:  This article shows how to access a non-booting Linux system with a Knoppix CD, get read-write permissions on configuration files, create and manage partitions and filesystems, and copy files to various storage media and over the network. You can use Knoppix for hardware and system configuration detection and for creating and managing partitions and filesystems. You can do it all from Knoppix's excellent graphical utilities, or from the command line.

Date:  23 Oct 2003
Level:  Intermediate

Comments:  

Knoppix, which is a complete bootable Linux on a CD, has become my rescue disk of choice. An excellent introduction to Knoppix appeared in developerWorks a few months ago ("Knoppix gives bootable, one-disk Linux" by Cameron Laird).

My old mainstays were Tom's Root Boot, "The most GNU/Linux on one floppy disk," and Peter Anvin's SuperRescue CD, "An overfeatured rescue CD." Both are first-rate Linux rescue disks. One of my favorite show-off tricks is to do a complete bare-metal system rebuild, using only a Tom's Root Boot disk and an Internet connection.

As CD-ROMs became standard on PCs, I wore out several SuperRescue CDs. However, it is based on Red Hat 7.2, which is a great Red Hat but is also an old Red Hat. So, 7.2 does not have the hardware support, such as USB or wireless, found in later distributions.

A star is born

Knoppix, the hot new kid on the block, offers some great features:

  • First-rate hardware detection and support, including PCMCIA, USB, and wireless
  • Latest and greatest Debian and KDE
  • Fast booting, usually around two minutes
  • Commercially produced disks that can be purchased for a minimal price

That last bit didn't become important to me until I moved to an area with no high-speed Internet. Dial-up only, which made 700 MB downloads rather impractical.

Knoppix incorporates the best of Debian, KDE, and its own system utilities. In this article, we'll look at how to do things both from the command line and using graphical utilities. Be sure to use values appropriate for your systems, such as partition numbers, filenames, and network hosts.


Getting started

If you want to run KDE or any other graphical desktop or window manager, you'll want at least 96 MB of RAM and a Pentium equivalent or better. In text mode, without X, it needs 20 MB to be happy and will even run on an old 486. It will use your existing Linux swap file.


Boot options

After booting up the Knoppix CD, it will pause at a command prompt for 30 seconds, then continue booting. There are a large number of boot options; hit F2 to see them. For example, this is how I boot Knoppix 3.2 on one of my test systems:

knoppix lang=us knoppix wheelmouse knoppix desktop=icewm

The default keyboard mapping is German, so I always boot with knoppix lang=us. By default, Knoppix boots to the KDE desktop. knoppix 2 boots to text mode, without starting X. failsafe starts up with minimal hardware detection.

Knoppix runs entirely in memory, or if you want to sound "leet," in a ramdisk. In fact you can see the ramdisk in the file tree. Remember, sometimes it will be slow, because it must fetch executables from the CD, which is slower than a hard drive. It can be installed to a hard disk, but that is a topic for another day.


Rescuing a non-booting Linux system

This is the most common scenario. Something goes haywire, and boom, no boot. No problem: boot up Knoppix and find all your local partitions nicely iconicized on the KDE desktop. (Or cruise the file tree to /mnt.) Click on the correct icon, and there are all your files. But they are wisely mounted read-only. Again, no problem: right-click the desktop icon to bring up a nice menu with a "Change read/write mode" option. This mounts the filesystem on the partition as read/write. Now you can edit any file.

The default user is knoppix. For operations that require root privileges, you need to su to root and assign a root password:

knoppix@ttyp0[knoppix]# su
root@ttyp0[knoppix]# passwd

To mount a filesystem read/write from the command line:

root@ttyp0[knoppix]# mount -t reiserfs -o rw /dev/hda5 /mnt/hda5

To unmount:

root@ttyp0[knoppix]# umount /mnt/hda5

If you get an error message "Could not unmount device, device is busy," something is reading the filesystem. Close files and cd out of the filesystem.

How do you know what mountpoint and filesystem to specify? Just read /etc/fstab:

root@ttyp0[knoppix]# cat /etc/fstab
...
# Added by Knoppix
/dev/hda5 /mnt/hda5 reiserfs noauto,users,exec 0 0


Hardware detection

Before going on a mad config file editing spree, it often pays to examine hardware information. Knoppix excels at this, as it has the latest editions of Linux's excellent hardware and system utilities: fdisk, lspci, iwconfig, ifconfig, dmesg, /proc, and so forth. (Checking hardware information is also handy for testing a system for Linux compatibility before you buy it. Sound cards, softmodems, and wireless NICs are especially troublesome; manufacturers often change the chipsets without changing the model numbers, and you need to know the chipsets to determine if Linux drivers are available. The Knoppix CD also contains a number of sound files, 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 to System > Info Center.


Rescuing data files

Usually the first rescue chore is to copy data files off of the troubled drive. This is my favorite method when there are large numbers of files to copy: install a second hard drive, then boot Knoppix, then copy files from the old disk to the new disk. Even if you don't have nice hot-swappable drives or removable drive cages, it takes just a couple of minutes to pop the case open and hook one up. Do you have a brand new blank drive, or an old one that needs to be wiped clean and reformatted? No problem, do the disk preparation from Knoppix.


Partitioning and formatting

First, install the second hard drive. Then boot Knoppix and open a root shell. If there are partitions already on the second disk, simply re-format whatever ones you need. Note that SCSI drives are designated sd, while IDE drives are hd. This command displays the existing disk partitions; be sure to use values appropriate for your system:

root@ttyp0[knoppix]# fdisk -l /dev/hdb

To format a disk partition:

root@ttyp0[knoppix]# mkfs.ext2 -c /dev/hdb1

This creates a plain-vanilla ext2 filesystem. -c checks for bad blocks. Of course, 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 futz with fdisk, as changes are not written to disk until you give the command to do so. So, you can try different options and preview the partition table before committing to any changes. This sequence of commands creates a single partition:

root@ttyp0[knoppix]# fdisk /dev/hdb

Type "m" at any time to display 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 the defaults. Or, if you don't want to use the whole disk, hit Enter once to accept the default starting point, then select the size you want:

+1000M

Hit "p" at any time to preview the new partition table. When everything looks good, 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". Want to delete a partition? Easy as pie: press "d" and follow the prompts.


QTParted

Even easier is firing up KDE and using QTParted (System > QTParted). QTParted creates, deletes, and non-destructively moves and resizes partitions (even NTFS). So, you can make room to copy your data without losing anything.


Copying files the GUI way

I like graphical file managers. It's a lot simpler to drag and drop than to type out long command strings. Click on the icons on the KDE desktop that represent your source drive and the drive you want to copy them to. Each one opens in its own file manager, for fast and easy drag and drop. Be sure to make the destination drive writeable.


Copying files at the command line

Remember to create a directory to move files into:

# mkdir /mnt/hdb1/home/carla/backup
# cp -r /mnt/hda5/home/carla /mnt/hdb1/home/carla/backup


Cloning an entire drive

You'll need two hard drives the same size, or a destination drive larger than the source drive. Make sure no partitions are mounted on either drive. In this example /dev/hda is the source drive, /dev/hdb is the destination drive. The dd command makes an exact, byte-for-byte copy, including the MBR (master boot record):

# dd if=/dev/hda of=/dev/hdb


Mounting confusion

Are you losing track of what's mounted, and in what state? No problem, here comes /proc to the rescue:

# cat /proc/mounts

This displays all mounted filesystems, the filesystem types, read/write status, and other attributes. How many hard drives are on the system? One of these will tell you (and remember, SCSI drives are sd, IDE are hd):

# fdisk -l

or

# dmesg | grep hd

or

# dmesg | grep sd


Copying to CD

KDE and Knoppix make this easy. Assuming there is a CD writer on the system, simply right-click on the desktop icon for the partition containing your files, and you will see "Create Data CD with K3b." Do File > New Project, drag and drop the files you want to copy, and there you go. K3b is very good at autodetecting and autoconfiguring your CD drives; it should do it all for you. If something goes awry, please refer to the developerWorks article "Burning CDs on Linux", which also teaches how to burn CDs from the command line.


Copying to other media

Zip drives, floppy disks, and USB storage devices will be automatically recognized by Knoppix, and icons will be placed on the desktop. Simply make the drive you want to copy files to writeable, then drag and drop until it's all done.


Copying over the network

You can configure Knoppix to connect to a network, just like any other Linux. Knoppix has its own graphical configuration utility: on the main menu find Knoppix > Network/Internet. Again Knoppix's excellent hardware detection comes into play; it even works on wireless NICs (assuming it's a wireless NIC that is supported in Linux!). Simply answer a series of questions, and you're done.

It's just as easy from the command line. As root, run:

# netcardconfig

Once your network settings are configured, there are several options for transferring files. cp is fine for locally mounted filesystems. Copying files over an untrusted 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 transfer and lets you move files without setting up NFS or Samba. You'll need an 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


SSH quickstart

What, you have no ssh server? If you really do not yet have ssh installed, here is a quick-start guide to running SSH. But before using it for even routine remote administration tasks, you should study ssh in more depth. Note also that there have been a number of important security patches issued recently.

OpenSSH comes with all major Linux distributions, and yours should already have it. (To find out, type locate sshd.) If not, download and install it. It doesn't need to be on a special machine; any Linux PC can run SSH. Start it up like so:

# /etc/init.d/ssh start

Then, all you need is for the same user to have accounts on both machines. Using root is easiest, but potentially dangerous. And, of course, you can create user accounts on Knoppix as needed, with useradd and passwd. Then run the scp command as in the example above, and there you go.

The first time you connect, you'll get a "The authenticity of host X can't be established...are you sure you want to continue connecting?" message. Answer "yes." It will ask for the root password of the SSH server, and then you're home free. To move files as a non-root user:

# scp -rp /mnt/hda5/home/carla carla@192.168.1.5:/home/carla/tmp


Open a root shell on the host system

This lets you operate on the host system, as though you were logged into it directly. Identify the partition the host system is on, then open a Knoppix root shell and mount it:

root@ttyp0[knoppix]# mount /dev/hda1 /mnt/hda1
root@ttyp0[knoppix]# chroot /mnt/hda1
root@Knoppix:/


Knoppix glitches

Running programs from a CD can cause some odd troubles, especially on notebooks. It is common for power management to mess up a Knoppix session: when you wake up the machine, Knoppix doesn't respond to commands anymore. The only cure I know is to disable power management, or simply hit the power switch and start over.

Sometimes Knoppix gets stuck during boot, and hangs partway into KDE (or any X session) startup. Switch to the first virtual console (Ctrl + Alt + F1) to see the live system messages; this should tell you where the problem is. Hit Alt + F5 to get back to the default X session. For example, on one of my test systems it got stuck doing SCSI detection. Why? Who knows. I disabled SCSI detection by adding knoppix no scsi to the boot command, and that took care of it.


Knoppix creative ferment

Linux has always inspired amazing creativity. Knoppix has taken off in a big way, and there are dozens of inventive Knoppix-inspired projects, such as Inside Security Rescue Toolkit, OpenGroupware Knoppix, Damn Small Linux, and Overclockix. See the Resources section below for more information and links to how-tos for making your own customized Knoppix distribution.


Resources

About the author

Carla Schroder is a freelance PC tamer and author, administering Linux and Windows systems for small businesses and writing how-tos for real people. Carla discovered computers and high-tech around 1994, and is living proof that self-taught middle-aged persons make fine computer gurus. Watch for her upcoming O'Reilly book, The Linux Cookbook.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in

If you don't have an IBM ID and password, register here.


Forgot your IBM ID?


Forgot your password?
Change your password


By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. This profile includes the first name, last name, and display name you identified when you registered with developerWorks. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)


By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Linux, Open source
ArticleID=11346
ArticleTitle=System recovery with Knoppix
publish-date=10232003
author1-email=dworks@bratgrrl.com
author1-email-cc=tomyoung@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).