14

If I want to disable my GUIs completely to save battery life, how would I proceed?

I know that I can hit Ctrl + Alt + F3 and be on the command line, but the desktop manager would be in the background still (I suppose).

So, after Ctrl + Alt + F3, I need three commands to:

  • tell me battery life from the command line
  • close desktop environments

Does this make sense?

6 Answers 6

11

If I want to disable my GUIs completely to save battery life, how would I proceed?

You can just disable your Display Manager (be it kde, lightdm, gdm, etc.) to run at boot, just run depending of your system:

sudo update-rc.d gdm remove
sudo update-rc.d kdm remove
sudo update-rc.d lightdm remove

With this you don't have to stop the desktop manager after booting. But if you don't want this, sudo /etc/init.d/<display_manager_name> stop will close the desktop manager after booting:

sudo service gdm stop
sudo service kdm stop
sudo service lightdm stop

This will work in any system that uses upstart, like Debian and derivatives.

In case your system uses systemd, you can use systemctl:

## All the next lines are executed as root
systemctl disable gdm ## or gdm3
systemctl disable kdm
systemctl disable lightdm
systemctl disable <name_of_the_service>

tell me battery life from the command line

For seeing your battery status you could either, install and run screen/byobu (which is a screen manager, and will show the percentage of the battery + other statistics) or running acpi -b.

close desktop environments

Check my previous response.

I know that I can hit Ctrl + Alt + F3 and be on the command line, but the desktop manager would be in the background still (I suppose).

Ctrl + Alt + F1-6 just switch you to one of the tty. All the programs you are running will continue executing on background.

4
  • 2
    sudo service gdm stop will not disable it on boot, but just stop the service. For Upstart jobs, sudo mv /etc/init/gdm.conf{,.norun} to disable. Aug 11, 2013 at 20:51
  • @bonsaiviking there is no configuration file in /etc/init for gdm, kdm, or lightdm, gdm store theirs in /etc/dbus-1/system.d/, kdm in /etc/default.
    – Braiam
    Aug 11, 2013 at 21:49
  • then they are not Upstart jobs. That may be where they store configuration, but the service is then probably a System V init script in /etc/init.d/ managed by rc symlinks. Use sudo update-rc.d gdm disable instead. Aug 11, 2013 at 22:20
  • On a systemd-less OS you could also choose the runlevel at runtime. Just press 'e' while on the Grub2 menu and add init N to the kernel boot line (where N is e.g. 3 for Cli multi-users with network On). A source
    – tuk0z
    Aug 1, 2016 at 15:52
4

Someone alluded to init so why not use it with the specified runlevel? On Xubuntu latest 1 works for me.

$ runlevel  \\just to show your actual runlevel, expect N 2.
$ sudo telinit $runlevel
   where $runlevel is either:
    0 : System halt.
    1 : Single-User mode.
    2 : Graphical multi-user plus networking (DEFAULT)
    3 : Same as "2", but not used.
    4 : Same as "2", but not used.
    5 : Same as "2", but not used.
    6 : System reboot.

Then it's possible to stop the desktop managers as a prior reply states or change the configuration in various ways.

Lastly if you were on Solaris or similar, you would use either init or svcadm and "who -r" to display the current runlevel.

2
  • I agree. For a while I had a system that defaulted to runlevel 3 and I would change the runlevel to 5 when I wanted a gui, and back when I was done.
    – Kevin
    Aug 5, 2013 at 19:52
  • While on SysvInit systems (i.e. systemd-less) I've always had something a bit different (only writing where it differs): $runlevel is either: 2: unused; 3: Cli multi-user plus networking; 4: unused; 5: Graphical multi-user plus networking.
    – tuk0z
    Aug 1, 2016 at 15:50
2

The problem is that on most Linux distributions, the init process launches the window manager on a terminal of its own, so:

  1. To kill all graphical interface, you'll have to be root
  2. Even if you kill the X server as root, init will restart it automatically as it occupies one of your virtual terminal

So, you'll have to configure your system so that the graphical interface is not launched by init when it starts, which will able you to launch and terminate it manually in a regular tty. That's not really convenient but it's feasible. Look for a file called /etc/inittab and refer to your distribution specific documentation to know how to prevent init from starting a graphical interface. It may just be a line to remove or comment.

Concerning your other question, you can know your battery status just typing the command acpi.

1

The "telling battery life" part is easier, I'd use byobu or similar utility for that. These managers are great in that they will separate the sessions from the terminals, which means that you can even start your work in DE in byobu, then just zap the DE and continue in tty.

Or you can implement this within shell (thinking $PS1 and a bash function).

For the zapping part, to close DE means to close all programs running within that, which can mean a loss of data. That can be seen as a reason why you need root access.

However, if you really want this, and want to be able to do it quickly anytime, you can write a script for that, "give" it to root and set setuid bit so that if anyone runs this particular script, it will run as root without any further authentication. What makes this little more complicated is that some distros won't let you do this with scripts. This can be solved by creating a C wrapper that will exec the script for you and use that wrapper instead.

I'd probably go with this approach plus consider additional features like not zapping if ran from inside the DE, not zapping anything immediately (like 60s period) or mapping it to a key in Byobu.

0

I recently discovered a nice package called grml-rescueboot which when installed on your computer allows you to place an ISO image into the /boot/grml directory and then when you issue the update-grub command will add that to your grub boot as something to boot.

IF you use their ISO image and boot from that its totally text based. But the beauty of this solution is you can always boot back into your normal setup when you are near a power source.

More info here on how to install as this package is available from most distributions just install it and read the man page.

-1

Just init 3 run the system in Text mode.

or edit /etc/inittab and change the run level to 3 if you want a GUI change the run level to 5

1
  • If you want to run your system with out GUI. just run #init 3 or if you want to run your system in text mode change the /etc/inittab to level 3 always can change to Init 5.
    – Bill
    Aug 6, 2013 at 6:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .