Take the 2-minute tour ×

The question says it all. I am using screen utility and would like to preserve the session when machine reboots. If not possible may be you can recommend other alternatives to screen that would allow to preserve the sessions between reboots.

I am using Ubuntu Server 10.04 if that matters.

EDIT: I have several sessions opened via screen. When machine reboots all those sessions are lost and I have to reopen them again. What I wanted was to find a way to preserve those screen sessions.

share|improve this question
what are you trying to to? do you want to preserve the history or everything running in your screen session? –  Marcel G Sep 21 '10 at 15:55
Wouldn't doing this defeat the purpose of rebooting? –  Brian Knoblauch Sep 21 '10 at 19:56
what do you mean by 'sessions'? Do you mean that you have ssh connections to other hosts in several screen windows? If that is what you mean, then writing a .screenrc file and specifying the user@host you want to slogin to should do the trick ..., if you have enabled ssh passwordless logins. Then when you start screen, all the ssh connections will automatically start. You could even start it from rc.local (a bit tricky, because you need to start it from su - yourusername), so when you login you can reattach the running screen session. –  natxo asenjo Nov 6 '10 at 12:02
add comment

6 Answers

up vote 5 down vote accepted

First of all, let's clarify a couple of important things:

  1. How many machines are involved? In other words, are you connecting to a remote machine, or is everything on your local machine?
  2. If there is a remote machine involved, which machine is rebooting: is it the server or the client?

If there is one machine involved, or if the server is being rebooted, then you're mostly out of luck.

If you're logging into a remote machine, but need to reboot your local machine, then it's no problem as long as you're running screen on the remote machine instead of your local machine. I realize this is pretty obvious to any experienced (even slightly experienced) user of screen, but I mention it just in case it may be helpful.

Yet another possibility (again, whether this is helpful for you depends on your circumstances) is to run the machine with screen on a VM. Suppose it's a remote physical server and it needs to be rebooted, but it's got a guest OS on (e.g.) VMware. You can suspend the guest OS and start it up again after the hardware reboots. It all depends on why you need to reboot, which wasn't specified, and how much control you have over the machine, and whether you're willing to go to all that trouble.

There's no EASY solution, and it's possible none of the solutions will work for you. But best of luck.

If you're logging into many machines, it might seem like too much of a pain to run screen on all the remote machines separately, and it is. In this case it is useful to have an intermediate machine running screen, which can have many screen windows, each logged into another remote machine. As long as the intermediate machine stays up, you can reboot your own local machine (or pack it up in your bag and take it home for the night, or whatever) and screen keeps running on the intermediate machine. (And obviously if any of the remote machines go down, you lose the connection to that machine, but the rest of your screen sessions are fine.)

But in most likelihood you're referring to either the remote machine or the only machine being rebooted, in which case there's no simple way to do this. CryoPID sounds promising at first, but its web site says it doesn't work for screen.

But there is one other somewhat promising option worth exploring. (Whether it will work for you depends to a large degree exactly what you're trying to do.) Check this out on github.com: https://github.com/skoneka/screen-session/tree/master/ScreenSession/

share|improve this answer
+1 for cryoPID, didn't know about that! –  The Unix Janitor Nov 6 '10 at 13:05
ScreenSession looks interesting, from the description of it this is exactly what I wanted –  Sergey G Nov 9 '10 at 15:06
add comment

No can do. Certainly not on the same machine

share|improve this answer
add comment

In some rare circumstances this is possible (see CryoPID), but in general this is difficult, so cannot be done.

share|improve this answer
CryoPID looks interesting, thanks for the link. –  Sergey G Sep 21 '10 at 18:54
add comment

Instead of using screen, use a small Virtualbox VM and work inside that. Then you can just hibernate it, reboot the host, then wake the VM back up (just like closing and reopening the lid of a laptop). SSH connections to remote hosts won't probably won't persist by this method, I don't think it would be possible to guarantee that.

share|improve this answer
add comment

more importantly, why are you rebooting all the time? Unix servers are not windows servers, they are designed for high up times, machines are known to have uptimes of years (without kernel security patches). If your rebooting due to kernel security patches, then have a look at something like ksplice.

share|improve this answer
add comment

In all of this, screen itself is pretty marginal. it's not screen that you want to "save" is it, but the environments within the various screen sessions, whatever they are. You seem to be suggesting that saving a screen session would cover an ssh process inside it and all sorts. What is running inside screen is none of screens business at all, and those are things that would be hard to "save"... whatever that really would mean if implementable.

share|improve this answer
add comment

Your Answer


