Is there a way to make a "Screen" session survive reboot?

Solution 1:

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/

Solution 2:

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


Solution 3:

You cannot. Certainly not on the same machine


Solution 4:

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 probably won't persist by this method, I don't think it would be possible to guarantee that.

Tags:

Gnu Screen