Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
3  
screen is just as easy as that. Ctrl A P doesn't seem much trickier than Alt F1... –  Kwaio Mar 17 at 8:04

4 Answers 4

up vote 9 down vote accepted

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

share|improve this answer
    
Nice, I wasn't aware of openvt. +1. –  jscott Mar 16 at 23:03
    
This actually seems much easier that getty. I never realised it was already installed. –  StarNamer Mar 21 at 20:11
    
Just thought I'd report that I just spent over a week with a system in single user mode repairing a RAID array and openvt proved to be very useful. Thanks for bringing a new command to my notice. –  StarNamer Mar 25 at 23:18

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.

share|improve this answer
    
This looks like what I'm looking for. I'll give it a try next time. –  StarNamer Mar 16 at 22:57
    
Tried it. It works, but since the login session isn't spawned from init, it doesn't get re-spawned if it dies. –  StarNamer Mar 18 at 10:22
    
Indeed, we're just dropping it into the background in the above example. If you require the full offering of a real vt, you're going to be hacking /etc/inittab and /etc/rc1.d/S??single at the very least. –  jscott Mar 18 at 10:27

You probably can do without an extra shell instance by using JOB CONTROL in your current shell. It is documented in the manpage of bash(1).

You can just suspend a task using the Ctrl+Z sequence by default, though it can be configured in your terminal in a different way, check the output of stty -a:

$ stty -a | grep susp
eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R;

You can check your jobs by issuing jobs:

# jobs
[1]   Stopped                 journalctl -f
[2]-  Stopped                 vim /etc/hosts
[3]+  Stopped                 tail -f /var/log/firewalld

Bring one of them to the foreground:

$ fg %3

Or resume it in the background:

$ bg %2

This method does not have many of the advantages of screen or tmux, but can be equally useful in some situations.

share|improve this answer
    
The point is that I don't want to suspend or interfere with the process running on the initial console. For example, when running ddrescue I don't want to keep interrupting and resuming it even though it's set up to do this.. –  StarNamer Mar 16 at 22:53

Consider using terminal multiplexers such as tmux or screen. Is something like the screenshot below what you're after?

tmux

share|improve this answer
    
The question mentions this already: "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.". –  Cristian Ciupitu Mar 16 at 22:26
    
As Cristian says, I'd already considered screen and felt other multiplexers were even more overkill. All I need is a simple second console. –  StarNamer Mar 16 at 22:56
    
Ah, sorry, I overlooked screen in your question. It was late. –  Marcin Kaminski Mar 17 at 0:07
    
How using a combination of 2 keys be "overkill" beside spawning new TTYs, and anchroing to them seperatly and such ? –  Kwaio Mar 17 at 8:03
    
IMO, it's a strange definition of 'overkill' but hey, whatever works for someone, I'm fine with it ;) –  Marcin Kaminski Mar 17 at 10:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.