How do I start a second shell when in single user mode?

This may sound like a contradiction in terms, but I've recently needed to use single user mode (aka maintenance mode) for some time (days!) while trying rebuild a broken RAID array.

While doing this, I've found myself wanting to use a second shell for such things as checking/editing the settings in various config files or looking at system logs while the main (and only) console is tied up executing some recovery process.

What would be the recommended command to launch a second shell on another tty?

Obviously, one method might be to use screen in tty1, but this doesn't have quite the ease of just switching sessions with Alt-F1, Alt-F2, etc.


Solution 1:

There's a command specifically designed for this situation: openvt. Just run openvt from your shell on tty1 and you'll find a shell running on the first tty that didn't already have something on it (tty2 probably.) There are several options you might find useful; see the openvt man page.

Since this is not a login managed by getty, when you exit the new shell you won't see a login prompt come up. The tty will just go dead since there will be no processes running on it, but you will still be able to switch back and forth (Alt-F1 Alt-F2) and see what was on the screen when you exited the shell. The deallocvt command destroys ttys that are in this zombie-like state, returning to the original "Alt-F2 does nothing" state.

Originally these commands were called open and disalloc, but eventually somebody decided to change them because they were too generic and disallocate was judged to be "not a word".

In the old days it was common for the keyboard driver and init to be configured so that Alt+Up would run open, so it would act as a hotkey to spawn a shell on a new console. You may still find a remnant of that old configuration, commented out, in your /etc/inittab. (If you aren't using some fancy new init that doesn't have an inittab.)

There's a similar question here

Solution 2:

You could spawn another getty for whichever ttys you want. Boot into single user mode, then start up a getty on tty2:

root@host:~# /sbin/getty 38400 tty2 &

You may now Alt+F2 over to the new tty. Repeat for additional ttys as needed. You could probably do something cleaner and just configure /etc/inittab to automatically handle this in single user mode.