Ubuntu – Is there a way to get terminal sessions to persist across reboot

command line

OS X has this. Ideally I would like the reboot to appear as if it never happened from the POV of the terminal (let's ignore remote sessions and assume 0 background processes for now). Meaning, I would like to see the stdin, stdout, stderr (i.e. scrollback) history in each of my terminal tabs.

NOTE: This is NOT about bash history. This is about persisting terminal sessions between reboots.

Best Answer

  • No, at least in gnome-terminal and other VTE-based emulators it's not possible in an implicit and convenient way.

    (You can, of course, explicitly go through all your tabs before the reboot, "Select All" and copy-paste the contents into files, and view those files with some viewer after the reboot. If I understand you, this is not what you're looking for. Also, colors and other formatting would be lost.)

    VTE, the terminal emulation widget behind gnome-terminal and many other terminal emulators stores most of the scrollback contents (not the latest bits, though) in temporary files under /tmp by default. The major design decisions that prevent doing what you're looking for are:

    • These files are unlinked right after being created. This is so that they are automatically removed (and the disk space is freed up) even if the terminal emulator exits uncleanly for whatever reason. In order to preserve them, they should be linked back to the filesystem tree (I don't know if it's possible) or copied into another file (which is a slow action if the scrollback is large, let alone properly handling potentially running out of disk space).

    • The files are under /tmp which is wiped out by many distros upon a reboot. A different, persistent location should be chosen instead, or some cooperation is needed with the boot scripts.

    • These files are encrypted (as of VTE version 0.40) to overcome the privacy issue of data leakage in case someone gets access to the disk. The encryption key is only available in gnome-terminal's memory. In order for these files to persist, either the encryption layer should be skipped (bringing back the old privacy concerns), or the keys should be placed on the disk at least temporarily for the duration of the reboot (... er, until that user logs in again and starts up gnome-terminal again... doesn't sound too much better). Feasible only if you don't care about privacy, or if the filesystem is guaranteed to be encrypted.

    There are other smaller issues to be addressed as well, e.g. flushing incomplete blocks of these files that contain the last bits of the scrollback data.

    I hope I could outline some of the design decisions VTE took that prevent doing what you're looking for. I can't see how your request could be addressed while keeping the current design goals as well. Maybe there's another terminal emulator that does what you're looking for, presumably sacrificing some of VTE's features; I don't know.