62

When I log in Ubuntu, I would like all windows opened at previous session (terminal and Firefox mainly) to be re-opened automatically at the same size and position.

How to proceed?

Gerard Roche
  • 1,477
Eric
  • 791

11 Answers11

18

For 12.04 (and 11.10)

The short answer is: hibernation is the best option because the gnome-session-save functionality was removed after 11.04 since it was buggy, and the official tweak to manually re-enable this functionality does not appear to work. Part B of this answer describes how to use an alternative hibernation method, TuxOnIce, which is more compatible and reliable right now than the built-in hibernation.

A. Trying to enable the old Gnome session saving functionality

  • Note: as described at the end, this official tweak does not appear to work -- you may want to skip directly to B. Hibernation with TuxOnIce
  • This Launchpad bug discusses restoring the "save session" functionality. It is currently marked "fixed", because a patch was introduced in the gnome-session package in April 2012, allowing users to manually re-enable this functionality. The patch describes itself as:

    • add GNOME_SESSION_SAVE environment variable for people wanting to
      use the save session still, knowing that it can break your system
      if used unwisely (LP: #771896)
  • You can enable this by setting the GNOME_SESSION_SAVE variable to a non-null value. Here's how:

    • Press Alt+F2, type gedit ~/.pam_environment, and press enter.
    • Add the line GNOME_SESSION_SAVE=1 at the end of the file as shown below:

    • enter image description here

    • Press Ctrl+S to save, and Ctrl+Q to quit the editor.

    • Now reboot (logout should also work, but just to be safe)
  • What the patch (source) does is disable the Options tab in Startup Applications, which used to contain the Remember running applications when logging out option. BUT it checks the GNOME_SESSION_SAVE variable, and if set (non-null), it should enable session-saving just as if the Remember... box existed and was checked. That's why the bug is labeled as "fixed"
    • if (g_getenv ("GNOME_SESSION_SAVE") != NULL)
                      maybe_load_saved_session_apps (manager);
    • Unfortunately, it doesn't seem to work, as confirmed by comment 32 in the bug tracker.
    • I even tried disabling the patch and rebuilding gnome-session from source. That makes the Options checkbox show up again, but it does nothing.
    • But hey, it may somehow work for you!! :)

B. What works for now: Enhanced Hibernation with TuxOnIce

  • Hibernation saves your current system state (including your session, applications open, etc.) to the hard disk, and shuts the computer down. When you start it again, it reads the saved state and restores it, just as if you had never turned the computer off. This technology is mostly used by laptop users to save on battery power, but there's no reason it can't be used on desktops as well.
  • Hibernation support is available in Ubuntu/Linux but was disabled in 12.04 because it wasn't working properly on a number of systems. See this question and this bugreport if you want more information.

    A more compatible alternative: TuxOnIce

  • TuxOnIce (wiki|homepage) is an alternative to the kernel's built-in hibernation technology, and is supposed to be more compatible, more reliable and more flexible.

  • It is easily installed, and if it doesn't work for you, as easily removed.
  • It does require installing TuxOnIce's custom kernel, but the instructions that follow should make it easy. If you've never opened the terminal before, you may want to now :-)

    0. Requirements

    The only requirement for TuxOnIce is that your swap partition be at least as large as the amount of memory (RAM) you have. You can check this by:

  • Start the terminal with Ctrl+Alt+T

  • Type free -m, and you should see something like this:

                 total       used       free     shared    buffers     cached
    Mem:          1024        731        260          0          0        190
    -/+ buffers/cache:        540        451
    Swap:         1536          6       1530
    
  • The number after Swap: (e.g. 1536) should be more than the number after Mem: (e.g. 1024)

  • If this is not the case, and your swap is smaller than your memory, you must either resize and increase the size of your swap partition, or configure TuxOnIce to use a special swap file. That is beyond the scope of this answer, but if you ask another question and mention it in the comments, I will answer and explain how.

    1. Installing the TuxOnIce kernel

  • Start the terminal with Ctrl+Alt+T

  • Copy and paste the following into the terminal. This adds the TuxOnIce PPA and installs the custom kernel and headers.
    • sudo apt-add-repository ppa:tuxonice/ppa -y

      and once the ppa is added:

    • sudo apt-get update
      sudo apt-get install tuxonice-userui linux-generic-tuxonice -y 
      sudo apt-get install linux-headers-generic-tuxonice -y
  • Now reboot.
  • Ubuntu should now start up with the TuxOnIce kernel. If there are any problems, keep the Shift pressed at startup and you will get the Grub menu. Use the arrow keys to go to Previous Linux Versions, press enter, and press enter again to go back to the working kernel.

    2. Testing hibernation functionality.

  • Open some of the applications you normally use, e.g. Firefox, Thunderbird, LibreOffice, etc.

  • Open the terminal again, with Ctrl+Alt+T.
  • Type sudo pm-hibernate, press enter, enter your password.
  • You should see the lock screen for a second, and then the TuxOnIce hibernation progress screen, like the one below:

    enter image description here

    • If TuxOnIce works, your computer will shutdown.
    • Start it again, and wait. TuxOnIce should resume from the point you hibernated, including all the windows you opened at the position you opened.
  • If all this worked, go to Step 3, which lets you enable Hibernate from the dashboard.

    3. Enabling hibernation from the dashboard

  • Press Alt+F2, type the below and then press enter:

    gksudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
  • Paste the below, press Ctrl+S to save and Ctrl+Q to exit the editor:

    [Re-enable hibernate by default]
    Identity=unix-user:*
    Action=org.freedesktop.upower.hibernate
    ResultActive=yes

    enter image description here

  • Restart, and you should see the Hibernate option as shown below:

    enter image description here

    4. Removing TuxOnIce

    • If TuxOnIce doesn't work for you, or you simply wish to remove it, start the terminal and enter:

       sudo apt-get remove tuxonice-userui linux-generic-tuxonice linux-headers-generic-tuxonice -y
    • and remember to disable the Hibernate option in the menu with:

      sudo rm /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla
    • Then restart.

ish
  • 141,990
11

For 11.04 and earlier

Try this

System > Start up Applications > Options and check Automatically remember running applications when logging off and click remember current applications.

Open Help
  • 694
8

It doesn't seem to be possible to have all applications remember their last window position and size. This behaviour seems to have been removed a long long time ago. My understanding is that it is the application's responsability to remember its own position and size. And here in lies the rub.

A search through the bug tracker yields many reports that in some way relevant to this issue.

So what applications remember position & size and what versions of Ubuntu do the applications have this functionaility?

Note : Please edit and fill the applications and versions of Ubuntu you have tested for this functionaility. i.e. the application remembers window position and/or size.

Sepecify the version of Ubuntu you have tested and if one or both window postition and size is remembered.

13.04

window postion | size

  • Y, Y - Nautilus
  • N, Y - Firefox erratic mutiple monitor placements
  • N, N - Terminal The terminal has custom settings to remember a specific size everytime, but it will not remember the last position
  • N, Y - Chromium
  • Y, Y - Banshee
  • N, - - Calculator Is not resizable*
  • N, Y - Gedit

Bug Reports Examples

Here are some random bug reports from some simple search in the bug tracker e.g. "remember window position".

2013

2012

2011

2009

2008

2007

Gerard Roche
  • 1,477
5

How to save a session on Ubuntu 11.04 or above:

  1. Download and install DConf-Editor.

  2. Type dconf on the dash and run it.

DASH-IMG

Open the next labels in order: org --> gnome

Then select gnome-session

Now you should see the auto-save-session option as the following image, activate it.

APP-IMG

DONE!

Now when you turn off your computer, the current session will save automatically. The next time you turn it will be exactly as you left.

Lucio
  • 19,191
  • 32
  • 112
  • 191
3

The current believe is that the proper session saving/restoring feature is to use either suspend or hibernate. I agree though that hibernate and suspend can be a pain to get working if they did not out of the box ...

But have a look at ...

CryoPID

CryoPID allows you to capture the state of a running process in Linux and save it to a file. This file can then be used to resume the process later on, either after a reboot or even on another machine.

CryoPID was spawned out of a discussion on the Software suspend mailing list about the complexities of suspending and resuming individual processes.

CryoPID consists of a program called freeze that captures the state of a running process and writes it into a file. The file is self-executing and self-extracting, so to resume a process, you simply run that file. See the table below for more details on what is supported.

Features

  • Can run as an ordinary user! (no root privileges needed)
  • Works on both 2.4 and 2.6.
  • Works on x86 and AMD64.
  • Can start & stop a process multiple times
  • Can migrate processes between machines and between kernel versions (tested between 2.4 to 2.6 and 2.6 to 2.4).

It is not very well documented though and the last DEB released was for Heron and the website was last updated in 2005 so it might be useless. Here are the tarballs:

And also have a look at Tuxonice

TuxOnIce is most easily described as the Linux equivalent of Windows' hibernate functionality, but better. It saves the contents of memory to disk and powers down. When the computer is started up again, it reloads the contents and the user can continue from where they left off. No documents need to be reloaded or applications reopened and the process is much faster than a normal shutdown and start up.

ppa:tuxonice/ppa 

The PPA has precompiled Ubuntu kernels with TuxOnIce already compiled in, the userui binary and the hibernate script. So it might not be for the fainthearted.


There is one workaround that might be worth looking in to:

  • Create a script that has all the programs you tend to open. Or create 2,3,4,5,6 of those scripts and bind a key to this script. Like control + alt + 1|2|3|4|5|6 or if that is in use something else. Hit the key and let the script open all the programs from that script.

  • And you can use something like this how to shift applications from workspace 1 to 2 using command to toss them onto another workspaces if you want them grouped.

Not what you asked for but it seems we are deemed to look for workarounds :)

Rinzwind
  • 309,379
3

12.04

As a workaround you can re-enable hibernation in 12.04 and use it shut down your pc and then wake it up with all your application still in use.

Type in terminal :

sudo gedit /var/lib/polkit-1/localauthority/50-local.d/hibernate.pkla

and then add this string to the text file :

[Re-enable Hibernate]
Identity=unix-user:* Action=org.freedesktop.upower.hibernate
ResultActive=yes

This way :

enter image description here

Then hibernate option will be displayed again on shutdown menu :

enter image description here

Hope it will help.

Seth
  • 59,332
neonboy
  • 515
1

You need to enable to see all aplications on the startup-aplication. Run this bash command on a terminal: sudo sed -i 's/NoDisplay=true/NoDisplay=false/g' /etc/xdg/autostart/*.desktop After that you will see all the aplications in Startup Applications.

I take this tip from this link http://www.webupd8.org/2012/04/things-to-tweak-after-installing-ubuntu.html, maybe it will interest you.

Sorry foy my english!

Saludos!

ali3n
  • 27
1

In CCSM, use the Place Windows and Resize Window plugins.

screenshot of CCSM - Window Management

They are in the Window Management category, in CompizConfig Settings Manager.

Eliah Kagan
  • 119,640
jasmines
  • 11,311
1

You can enable a feature similar to this. You can do this by having Ubuntu remember the locations and running applications on log off / shut down. To do so navigate to System > Startup Applications and in the Options tab check "Automatically remember running applications when logging off" and press the "Remember current applications" button.

img

Marco Ceppi
  • 48,827
0

i've created a GNOME shell extension "Smart Auto Move" to handle this use case. it uses a heuristic based on window title, application class, and startup order to keep track of windows and restore them to the same position/workspace on subsequent launches: https://extensions.gnome.org/extension/4736/smart-auto-move/

-1

1.

CryoPID But It is not very well documented though and the last DEB released was for Heron and the website was last updated in 2005 so it might be useless.

CryoPID allows you to capture the state of a running process in Linux and save it to a file. This file can then be used to resume the process later on, either after a reboot or even on another machine.

CryoPID consists of a program called freeze that captures the state of a running process and writes it into a file. The file is self-executing and self-extracting, so to resume a process, you simply run that file. See the table below for more details on what is supported.

Features

  • Can run as an ordinary user! (no root privileges needed)
  • Works on both 2.4 and 2.6.
  • Works on x86 and AMD64.
  • Can start & stop a process multiple times
  • Can migrate processes between machines and between kernel versions (tested between 2.4 to 2.6 and 2.6 to 2.4).

Here are the tarballs:

2.

Tuxonice probably this is your better bet and may work.

TuxOnIce is most easily described as the Linux equivalent of Windows' hibernate functionality, but better. It saves the contents of memory to disk and powers down. When the computer is started up again, it reloads the contents and the user can continue from where they left off. No documents need to be reloaded or applications reopened and the process is much faster than a normal shutdown and start up.

sudo add-apt-repository ppa:tuxonice/ppa

The PPA has precompiled Ubuntu kernels with TuxOnIce already compiled in, the userui binary and the hibernate script. So it might not be for the fainthearted.


There is one workaround that might be worth looking in to:

  • Create a script that has all the programs you tend to open. Or create 2,3,4,5,6 of those scripts and bind a key to this script. Like control + alt + 1|2|3|4|5|6 or if that is in use something else. Hit the key and let the script open all the programs from that script.

  • And you can use something like this how to shift applications from workspace 1 to 2 using command to toss them onto another workspaces if you want them grouped.

I am not allowed to copy someones answer, so source.

Rahul Virpara
  • 11,860