Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Nov 1996 11:49:55 +0100 (MET)
From:      Greg Lehey <grog@lemis.de>
To:        jasonh@cei.net (Jason Hudgins)
Cc:        questions@FreeBSD.org (FreeBSD Questions)
Subject:   Re: major system screw-up
Message-ID:  <199611241049.LAA00519@freebie.lemis.de>
In-Reply-To: <1.5.4.32.19961123234840.00688b04@mail.cei.net> from Jason Hudgins at "Nov 23, 96 05:48:40 pm"

Next in thread | Previous in thread | Raw E-Mail | Index | Archive | Help
Jason Hudgins writes:
> I just installed freebsd2-1.6 to use for my companies web-server..but I
> made a booboo.
> In the passwd file I changed my root startup shell from /bin/sh to /bin/bash.
> Cept the problem is that bash is in /usr/local/bin/bash ...
> So now I can't login as root because it can't find bash..and of course
> since I can't login as root, then I can't fix my error.

Relax, you're not the first.

> So I thought I would use the fixit floppy..I mean..that's what its for
> right? 

Well, you don't need the fixit floppy for this one.

> How hard could it be?
>
> So I get the fixit floppy up...mount the hard drive on /mnt and dive into
> /mnt/etc..cept there is no editor..not even vi that I can fix the passwd
> file with.
> So I'm thinking that as long as I have the hard drive mounted, then I can
> run the binary off the hard disk..so I cd to /mnt/usr/bin..but there is no
> bin directory. Maybe /usr is mounted on a different partition.
>    /dev/wd0a is mounted on /mnt
>    /dev/wd0b doesn't exist
>    /dev/wd0c will not mount .etc..
>
> I finally give up...

Here's what to do (this is taken from a private message earlier this
month to somebody who managed to do exactly the same thing :-)

Oh yes: if you really have screwed up your /etc/passwd, and you don't
have a root shell still going, you'll have a bit of fun getting back
in again.  Do this:

> 1.  Reboot the system:
> 
>     shutdown -r now
> 
>     If you can't run shutdown, try ctrl-alt-del.  If it says
>     "reboot?", then say yes.  Otherwise run sync (three times, a
>     couple of seconds apart), and push the Big Red Button.
> 
> 2.  When the prompt Boot: appears, enter:
> 
>     Boot: -s
> 
>     This will boot you up in single-user mode.  You'll see all this in
>     CFBSD [Complete FreeBSD], pages 144 and 145.
> 
> 3.  Go through the steps at the top of page 145, up to mount /usr.
>     Before mounting /usr, you'll probably also have to do an fsck on
>     /dev/rwd0e or /dev/rwd0h if you couldn't run shutdown.

>From "The Complete FreeBSD", in case you don't have it:

+ Sometimes it's inconvenient that multiple users can access the system.
+ For example, if you're repartitioning a disk, you don't want other
+ people walking all over the disk while you're doing so.  Even if
+ you're the only user on the system, daemons may be doing things in the
+ background.  In order to avoid this problem, you can stop the boot
+ process before most of the daemons have been started and enter single
+ user mode.  To do this, specify the -s flag at boot time:
+ 
+ Boot: -s
+ 
+ The system startup will be interrupted as soon as the device probes
+ have been completed, and you will be prompted for a shell.  Always
+ choose sh: some other shells, notably bash, get confused in single
+ user mode. Only the root file system will be accessible, and it will
+ be mounted read-only.  The reason for this is that the file system may
+ be damaged and require repair before you can write to it.  If you do
+ need to write to the root file system, you should first check the
+ consistency of the file system with fsck.
+ 
+ For example,
+ 
+ npx0 on motherboard
+ npx0: INT 16 interface                end of the probes (high intensity display)
+ Enter pathname of shell or RETURN for sh:  hit RETURN
+ erase ^H, kill ^U, intr ^C
+ # fsck -y /dev/rwd0a          check the integrity of the root file system
+ ** /dev/rwd0a
+ ** Last Mounted on /
+ ** Root file system
+ ** Phase 1 - Check Blocks and Sizes
+ ** Phase 2 - Check Pathnames
+ ** Phase 3 - Check Connectivity
+ ** Phase 4 - Check Reference Counts
+ ** Phase 5 - Check Cyl groups
+ 1064 files, 8190 used, 6913 free (61 frags, 1713 blocks, 0.4% fragmentation)
+ # mount -u /                  remount root file system read/write
+ # mount /usr                  mount any other file systems you need
+ 
+ To leave single user mode and enter multi user mode, unmount any additional file
+ systems you have mounted and enter CTRL-D:
+ 
+ # umount /usr
+ # ^D
+ Skipping file system checks...
+ (the rest of the boot sequence)

> 4.  Copy /usr/bin/tcsh to /bin:
> 
>     cp -p /usr/bin/tcsh /bin

OK, I lied.  This guy used another shell.  You need to copy
/usr/local/bin/bash to /bin/bash.

> 5.  Do the rest of the stuff (umount and ^D).
> 
> 6.  Before logging off your window, check you can still log in as root
>     from another virtual screen.
> 
> That'll-teach-you-ing you what
> Grog

> So I can't get to vi..hrmm what to do next..create a new root user maybe..
> echo "<new /etc/passwd entry for superuser named mojo>" >> passwd
> echo "<new /etc/master.passwd entry for mojo with no passwd" >> master.passwd
>
> Seemed to work fine..guess I will reboot the server now and login as mojo now.
>
> When I reboot the machine...the kernel gives me lines of ridiculous errors
> chmod after chmod..
> And then it tells me that it can't start a system daemon called "cronblah"
> And FINALLY it comes up claiming that its no longer www.dancooks.com ..now
> its just (Amnesiac).
>
> Now if someone could please tell me how APPENDING a line to the passwd and
> master.passwd files could TOTALLY screw up my machine..I would be grateful.
> If someone could tell me how to fix this TOTALLY screwed up machine I
> would be even more greatful.

What puzzles me is how you managed to add anything to either file if
you weren't root.  In any case, you shouldn't write anything in
/etc/passwd: to create a new /etc/passwd, you modify
/etc/master.passwd and run pwd_mkdb.  The easy way to do this is with
vipw, which does it for you, but you need to be root to do so.

> I admit most of this garbage is probably due to my lack of experience with
> FreeBSD...I have used slackware for a long time and never had these kinds
> of difficulties..but I wanted to use FreeBSD for its great network stability.

You would run into exactly the same problems if you did this to Linux
(OK, I believe you *can* edit /etc/passwd on Linux, but it's still not
the thing to do).

> I really want to get this FreeBSD up, running, & stable as a permanent web
> server for my company..I think its a great OS made by great people. But its
> just so volatile, that if it breaks..I have a really hard time fixing it.

Once you've got your machine up in single user mode, and have /usr
mounted, run vipw.  You probably want to undo your changes.  If there
is anything wrong with it, vipw will tell you.  You'll need to
explicitly set the TERM environment variable to run vipw:

  TERM=cons25 export TERM

If that doesn't help, let me know.

Greg



Want to link to this message? Use this URL: <http://docs.FreeBSD.org/cgi/mid.cgi?199611241049.LAA00519>