Restoring a busted system
From NetBSD Wiki
This page is intended to explain how to restore a system that doesn't work anymore, or which you locked yourself out of by forgetting the root password or otherwise.
Contents |
Getting the system booted
If the system is still basically OK
On most systems, if you have physical access and BIOS bootblocks loaded, you can tell the bootloader (the little program that counts down before the system boots) to boot in single user mode.
During the countdown, press any key (except enter), then type the following:
> boot -s
This will boot the default kernel in single user mode. If you wish to load a different kernel (because you built a kernel with the wrong device drivers, for example), add the name of it:
> boot -s /onetbsd
(you made a backup, didn't you?!)
This will not require a password, so you can now just change your root password by mounting "/" as read-write (mount -u /) and running passwd.
On a broken system
Trying rescue
If you messed up the dynamic libraries, your basic binaries or anything extreme like that, you can still try to boot from the /rescue directory. This directory contains statically linked versions of system-critical binaries. At least you can get your system booted. To have the bootloader launch the rescue version of init and shell, use the -a flag:
> boot -sa /netbsd
This will ask for the path to init and the shell. Enter /rescue/init and /rescue/sh, respectively.
Using an external bootdisk
You can do the same trick by using a bootable CD or the floppy set (or NFS, ...) you used for the installation. Just boot as you would normally, then mount your harddisk and chroot to it. You might want to consider using fsck to check its integrity first, before making matters even worse.
Once you're chrooted, it's basically like working on your system.
Restoring files
Running an editor
The system, when booted single user, won't do anything fancy, it will just try to be as functional as possible while staying on the safe side. This also means full-screen editors won't "just work". On most systems, you just have to do the following:
# export TERM=vt100
Then at least you'll have full-screen terminal capabilities. If your normal system has a different default terminal setting, you might want to try that, instead. If nothing works, you're going to have to resort to using ed or sed, for example.
Storing your files
Single-user mode, by default, mounts your harddisk read-only in order to prevent any further damage on a damaged FS. You'll have to remount the disk in order to be able to save files:
# mount -uw /
The -u updates an already-mounted FS, the -w sets the mount to read-write. See mount for more info. Don't forget to fsck first if you are unsure about the FS integrity.
Also, additional filesystems will not be mounted, just the root filesystem.
