Thursday, January 19, 2012

Easy choice between WMs using grub and xinitrc

This seems a nice way to be able to choose at grub level which DE you want to load.

At startup

You can also have a choice of window managers and desktop environments at startup, using just ~/.xinitrc and GRUB and no display manager. The idea is to take advantage of the fact that Arch doesn't make any particular use of the runlevel system. The following ~/.xinitrc tests for the current runlevel and will start Openbox and GNOME on runlevels 5 and 4 respectively:

rl=$(runlevel | grep -o [0-6])  case $rl in     4) exec gnome-session;;     5) exec openbox-session;; esac

Choosing between different runlevels is simply a matter of cloning a GRUB entry and adding the desired runlevel to the kernel arguments. Inserting the runlevel at the end of the 'kernel' line indicates that the inittab default of runlevel 5 should be overridden and replaced with the desired runlevel, 4 in this instance:

title Arch Linux GNOME
root (hd0,2)
kernel /boot/vmlinuz-linux root=/dev/sda1 ro 4
initrd /boot/initramfs-linux.img

Finally, you will need to ensure that the ~/.xinitrc file is actually run at the chosen runlevel. Using the tip from Start X at boot#/etc/inittab, you can edit the inittab to simply run startx on the desired runlevel which will in turn use your ~/.xinitrc script:

x:45:once:/bin/su PREFERED_USER -l -c "/bin/bash --login -c startx >/dev/null 2>&1"

Notice that "45" means that this will happen on both runlevels 4 and 5. The final differentiation between 4 and 5 will then come in ~/.xinitrc as described above. This is preferable to attempt differentiating in the inittab file as we stick pretty close to using the various configuration files as they were intended.

source: https://wiki.archlinux.org/index.php/Xinitrc


first published here: http://bbs.archbang.org/viewtopic.php?pid=6507#p6507

No comments:

Blog Archive