Laptop Mode Tools revisited due to a change in its functionality

The site statistics for this blog can be quite revealing. For example, over the last two or three months I noticed that my post How to prevent a USB mouse auto-suspending in Linux when a laptop’s power supply is disconnected has consistently been one of the most viewed. Given the problems I experienced with Laptop Mode Tools 1.65 (see my Gentoo Linux Forums post Bug in laptop-mode-tools-1.65? and Gentoo Linux Bugzilla Bug Report No. 520124), I was not entirely surprised. Thanks to fellow Gentoo Linux and Laptop Mode Tools user Ted Tanberry I learned that Version 1.65 had stopped using Laptop Mode Tools module usb-autosuspend, and started using Laptop Mode Tools module runtime-pm instead. At least that was the developer’s intention, but he had not implemented it correctly. The aforementioned Gentoo Linux bug report explains in detail the problem with Version 1.65.

The situation in my Gentoo Linux installation with laptop-mode-tools-1.64 installed, providing the functionality I desired, was as follows:

a. The precise package installed:

# eix -I laptop-mode-tools
[U] app-laptop/laptop-mode-tools
Available versions: 1.64 (~)1.65 (~)1.65-r1 (~)1.66 {+acpi apm bluetooth scsi}
Installed versions: 1.64(10:04:43 21/10/14)(acpi bluetooth -apm -scsi)
Homepage: http://www.samwel.tk/laptop_mode/
Description: Linux kernel laptop_mode user-space utilities

b. The auto-suspend state when the laptop PSU was connected:

# for d in /sys/bus/usb/devices/[0-9]* ; do if [[ -e $d/product ]] ; then echo -e "`basename $d`\t`cat $d/power/control`\t`cat $d/speed`\t`cat $d/product`" ; fi ; done
1-1.2 on 1.5 USB Laser Mouse
2-1.2 on 12 Fingerprint Sensor
2-1.3 on 480 USB 2.0 Camera

c. The contents of the file /lib64/udev/rules.d/99-laptop-mode.rules:

ACTION=="change", SUBSYSTEM=="power_supply", RUN+="lmt-udev auto"
ACTION=="add|remove", SUBSYSTEM=="machinecheck", RUN+="lmt-udev auto"
ACTION=="add|remove", SUBSYSTEM=="usb", RUN+="lmt-udev force modules=usb-autosuspend devices=%k"

d. The contents of file /etc/laptop-mode/conf.d/usb-autosuspend.conf:

#
# Configuration file for Laptop Mode Tools module usb-autosuspend.
#
# For more information, consult the laptop-mode.conf(8) manual page.
#
 
 
###############################################################################
# USB autosuspend settings
# ------------------------
#
# If you enable this setting, laptop mode tools will automatically enable the
# USB autosuspend feature for all devices.
#
# NOTE: Some USB devices claim they support autosuspend, but implement it in a
# broken way. This can mean keyboards losing keypresses, or optical mice turning
# their LED completely off. If you have a device that misbehaves, add its USB ID
# to the blacklist below and complain to your hardware vendor.
################################################################################
 
# Enable debug mode for this module
# Set to 1 if you want to debug this module
DEBUG=0
 
# Enable USB autosuspend feature?
# Set to 0 to disable
CONTROL_USB_AUTOSUSPEND="auto"
 
# Set this to use opt-in/whitelist instead of opt-out/blacklist for deciding
# which USB devices should be autosuspended.
# AUTOSUSPEND_USE_WHITELIST=0 means AUTOSUSPEND_*_BLACKLIST will be used.
# AUTOSUSPEND_USE_WHITELIST=1 means AUTOSUSPEND_*_WHITELIST will be used.
AUTOSUSPEND_USE_WHITELIST=0
 
# The list of USB IDs that should not use autosuspend. Use lsusb to find out the
# IDs of your USB devices.
# Example: AUTOSUSPEND_USBID_BLACKLIST="046d:c025 0123:abcd"
AUTOSUSPEND_USBID_BLACKLIST="046d:c052"
 
# The list of USB driver types that should not use autosuspend.  The driver
# type is given by "DRIVER=..." in a USB device's uevent file.
# Example: AUTOSUSPEND_USBID_BLACKLIST="usbhid usb-storage"
AUTOSUSPEND_USBTYPE_BLACKLIST=""
 
# The list of USB IDs that should use autosuspend. Use lsusb to find out the
# IDs of your USB devices.
# Example: AUTOSUSPEND_USBID_WHITELIST="046d:c025 0123:abcd"
AUTOSUSPEND_USBID_WHITELIST=""
 
# The list of USB driver types that should use autosuspend.  The driver
# type is given by "DRIVER=..." in a USB device's uevent file.
# Example: AUTOSUSPEND_USBTYPE_WHITELIST="usbhid usb-storage"
AUTOSUSPEND_USBTYPE_WHITELIST=""
 
# Trigger auto-suspension of the USB deivce under conditional circumstances
BATT_SUSPEND_USB=1
LM_AC_SUSPEND_USB=0
NOLM_AC_SUSPEND_USB=0
 
# USB Auto-Suspend timeout in seconds
# Number of seconds after which the USB devices should suspend
AUTOSUSPEND_TIMEOUT=2

Having experienced the problems with the buggy Laptop Mode Tools 1.65, I re-installed 1.64 and had been using that successfully until a week ago. Then I noticed that 1.66 had been released, so I installed it:

# emerge laptop-mode-tools
.
.
.
>>> Installing (1 of 1) app-laptop/laptop-mode-tools-1.66::gentoo
* To enable automatic power state event handling,
* e.g. enabling laptop_mode after unplugging the battery,
* both laptop_mode and the acpid daemon must be
* added to default runlevel:
* # rc-update add laptop_mode default
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

* GNU info directory index is up-to-date.

I would not have expected that ewarn message about adding laptop_mode to the default runlevel, as the ebuild is only supposed to display the warning if laptop_mode is not assigned to the default runlevel. But, sure enough, something had removed it:

# rc-update show -v | grep laptop
laptop_mode |

I don’t know what removed laptop_mode from the default runlevel. It was certainly assigned previously, as proved by Laptop Mode Tools 1.64 working as expected when I connected and disconnected the laptop’s PSU from the mains (see my earlier post). Anyway, I re-added it:

# rc-update add laptop_mode default
* service laptop_mode added to runlevel default
# rc-update show -v | grep acpi
acpid |      default

If you use systemd instead of OpenRC, instead of adding laptop_mode to the default runlevel you would need to use the following command:

# systemctl enable laptop_mode.service

Notice that the incorrect contents of 99-laptop-mode.rules and /etc/laptop-mode/laptop-mode.conf that were present in Laptop Mode Tools 1.65 have been fixed in 1.66:

# cat /lib64/udev/rules.d/99-laptop-mode.rules
ACTION=="change", SUBSYSTEM=="power_supply", RUN+="lmt-udev auto"
ACTION=="add|remove", SUBSYSTEM=="machinecheck", RUN+="lmt-udev auto force"
ACTION=="add|remove", SUBSYSTEM=="usb", RUN+="lmt-udev force modules=runtime-pm devices=%k"

# cat /etc/laptop-mode/laptop-mode.conf | grep usb-autosuspend
#

The ebuild for Laptop Mode Tools 1.66 did not delete the now-redundant file /etc/laptop-mode/conf.d/usb-autosuspend.conf but it is presumably ignored by 1.66 anyway.

From now on I must configure the contents of /etc/laptop-mode/conf.d/runtime-pm.conf instead. After installing Laptop Mode Tools 1.66 it contained the following:

#
# Configuration file for Laptop Mode Tools module runtime-pm
#
# For more information, consult the laptop-mode.conf(8) manual page.
#


###############################################################################
# Runtime Power Management Settings
# ---------------------------------
#
#__COMMENT If you enable this setting, laptop mode tools will automatically enable
#__COMMENT the Runtime Power Management feature for all devices.
#__COMMENT
#__COMMENT NOTE: Some devices claim they support autosuspend, but implement it in a
#__COMMENT broken way. This can mean keyboards losing keypresses, or optical mice
#__COMMENT turning their LED completely off. If you have a device that misbehaves,
#__COMMENT add its DEVICE ID to the blacklist section below and complain to your
#__COMMENT hardware / device driver contact
#
################################################################################

# Enable debug mode for this module
# Set to 1 if you want to debug this module
DEBUG=0

# Enable Runtime autosuspend feature?
# Set to 0 to disable
CONTROL_RUNTIME_AUTOSUSPEND=1

# Set this to use opt-in/whitelist instead of opt-out/blacklist for deciding
# which devices should be autosuspended.
# AUTOSUSPEND_USE_WHITELIST=0 means AUTOSUSPEND_*_BLACKLIST will be used.
# AUTOSUSPEND_USE_WHITELIST=1 means AUTOSUSPEND_*_WHITELIST will be used.
AUTOSUSPEND_USE_WHITELIST=0

# The list of Device IDs that should not use autosuspend. Use system commands or
# look into sysfs to find out the IDs of your devices.
# Example: AUTOSUSPEND_DEVID_BLACKLIST="046d:c025 0123:abcd"
AUTOSUSPEND_RUNTIME_DEVID_BLACKLIST=""

# The list of device driver types that should not use autosuspend.  The driver
# type is given by "DRIVER=..." in a device's uevent file.
# Example: AUTOSUSPEND_DEVID_BLACKLIST="usbhid usb-storage"
AUTOSUSPEND_RUNTIME_DEVTYPE_BLACKLIST=""

# The list of Device IDs that should use autosuspend. Use system commands or
# look into sysfs to find out the IDs of your devices.
# Example: AUTOSUSPEND_DEVID_WHITELIST="046d:c025 0123:abcd"
AUTOSUSPEND_RUNTIME_DEVID_WHITELIST=""

# The list of device driver types that should use autosuspend.  The driver
# type is given by "DRIVER=..." in a device's uevent file.
# Example: AUTOSUSPEND_DEVTYPE_WHITELIST="usbhid usb-storage"
AUTOSUSPEND_RUNTIME_DEVTYPE_WHITELIST=""

# Trigger auto-suspension of the deivce under conditional circumstances
# Warning: DO NOT CHANGE THESE DEFAUTLS UNLESS YOU KNOW
BATT_SUSPEND_RUNTIME=1
LM_AC_SUSPEND_RUNTIME=1
NOLM_AC_SUSPEND_RUNTIME=1

# Auto-Suspend timeout in seconds
# Number of seconds after which the USB devices should suspend
AUTOSUSPEND_TIMEOUT=2

So, in order to stop my laptop’s USB mouse, USB external keyboard and some internal USB devices from going to sleep when my laptop is only on battery power, I made the following change to a line in /etc/laptop-mode/conf.d/runtime-pm.conf:

# External keyboard at one office, internal Webcam, internal fingerprint sensor, Logitek NX50 notebook mouse
AUTOSUSPEND_RUNTIME_DEVID_BLACKLIST="03f0:0024 064e:a115 147e:1001 046d:c052"

My earlier post about Laptop Mode Tools explained one method for finding the device ID for each USB device, but the lsusb command can also be used:

# lsusb
Bus 002 Device 005: ID 03f0:0024 Hewlett-Packard KU-0316 Keyboard <---- External keyboard at one office
Bus 002 Device 004: ID 064e:a115 Suyin Corp. <---- Built-in Webcam
Bus 002 Device 003: ID 147e:1001 Upek TCS5B Fingerprint sensor <---- Built-in fingerprint sensor
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 046d:c052 Logitech, Inc. <----Logitech NX50 notebook mouse
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Although the Laptop Mode Tools usb-autosuspend module is supposed to be unused in 1.66, I edited /etc/laptop-mode/conf.d/usb-autosuspend.conf (which was not deleted by the 1.66 ebuild) and changed CONTROL_USB_AUTOSUSPEND="auto" to CONTROL_USB_AUTOSUSPEND="0" just to be on the safe side.

My thoughts on systemd

When I first read about systemd a few years ago, the main ‘marketing point’ seemed to be that Linux boots faster using it rather than SysVinit — see, for example, On to better booting. When I read that article back in September 2012, a paragraph caught my eye:

It looks like the crowd lining up behind systemd is growing fast. With Fedora, OpenSUSE, Mandiva, Arch, Debian, Gentoo, Frugalware — Did I forget anyone? And RedHat will probably be joining with the release of RedHat7. Ubuntu seems to be sticking with Upstart.

As a Gentoo user I was surprised to read that the distribution was ‘lining up behind systemd’ — systemd was not even mentioned in the Gentoo Handbook — so I started a thread in the Gentoo Forums enquiring whether there were plans to change the default init system from OpenRC to systemd: Gentoo ‘lining up behind systemd’?.

Revisiting that ITWorld article two years later, I notice the paragraph was subsequently changed, as it now reads:

It looks like the crowd lining up behind systemd is growing fast. With Fedora, OpenSUSE, Mandiva, Arch, Debian, Frugalware — Did I forget anyone? And RedHat will probably be joining with the release of RedHat7. Gentoo has its own next generation rc system called OpenRC, which competes with both systemd and upstart, but provides its users with the option of installing systemd. Ubuntu seems to be sticking with Upstart.

OpenRC works fine for me; I know how to use it and I do not particularly want to have to learn how to use another system when what I use now works perfectly well for my purposes. By no means do I begrudge others the use of systemd, as long as my freedom of choice is not curtailed. Each to his own, as the saying goes. But events over the past couple of years have left me wondering about my freedom to choose in the future, and indeed about the future form of the operating system itself.

Faster startup?

As I mentioned above, the main marketing point when I first read about systemd was its boot time. When I tried systemd in May 2013 on a 2009 Acer Aspire 5536-643G25Mn laptop (dual-core CPU; 3 GB RAM) — no match for today’s state-of-the-art hardware — the times to boot from the GRUB 2 menu to the DM login screen for a fully-updated 64-bit Sabayon Linux Xfce installation were as follows:

OpenRC with rc_parallel=”NO” 33 seconds
OpenRC with rc_parallel=”YES” 31 seconds
systemd 29 seconds

I posted the above timings in the Sabayon Linux Forums and the developer of the distribution responded:

speed improvements heavily depend on the CPU and I/O subsystem. In particular, systemd is able to leverage multi-core CPUs much better (because it spawns services in parallel). Spawning services in parallel also puts more pressure on the I/O subsystem, which means that if you have faster I/O (like with SSDs), the speed boost compared to OpenRC becomes quite relevant.

Indeed a few users of newer machines with 8 GB or more RAM and/or SSD drives wrote in the Sabayon Linux Forums that their boot times had almost been halved (e.g. from circa 40 seconds to circa 21 seconds). However, I expect the boot times for OpenRC and systemd would not be dramatically different from each other on any of my existing machines and, in any case, I’m not bothered about saving a few seconds in boot time on my machines (and I don’t reboot often either).

Nowadays one hears less mention of faster boot times from systemd proponents. For example, the author of the December 2011 article Here We Go Again, Another Linux Init: Intro to systemd mentioned ‘Faster Startups’ early on, whereas in a September 2014 article Understanding and Using Systemd, the same author states:

For whatever reason, it seems that the proponents of SysVInit replacements are obsessed with boot times. My systemd systems, like CentOS 7, don’t boot up all that much faster than the others. It’s not something I particularly care about in any case, since most boot speed measurements only measure reaching the login prompt, and not how long it takes for the system to completely start and be usable.

Erosion of choice?

A couple of Gentoo developers commented in the above-mentioned 2012 Gentoo Forums thread that adoption of systemd as the default init system in Gentoo would be extremely unlikely. Several posters pointed out that alternative init systems exist and Gentoo users could simply install an alternative if desired. However, I started to wonder about the long-term availability of choice when I began to see blog posts such as Red Hat Flag and, indeed, when I myself was affected by systemd’s subsumption of udev (see e.g. udev is doomed) earlier this year and, more recently, when a Gentoo developer had to create the package upower-pm-utils because systemd subsumed hibernate & suspend support from upower (UPower 0.99.0 was released to ~arch as of 2014-06-01).

Whatever one’s views on systemd, the impact on non-systemd users when systemd developers change something that previously worked fine is frustrating. Gentoo developers have been doing a good job working around such nugatory subsumptions, but it’s extra work for them and extra effort for the Gentoo user who doesn’t use systemd. I began to wonder how long this state of affairs could continue.

Another layer of abstraction?

Although my main laptop has Gentoo installed with OpenRC, on a couple of other machines I tinker with Sabayon Linux, which uses systemd. Sabayon Linux is pre-compiled Gentoo with an overlay and its own binary package manager, so there is some synergy in using the two distributions. Also, it is clear from several threads requesting help in the Gentoo Forums that a number of Gentoo users are migrating to systemd. In answering or just reading forum posts involving systemd, and in writing blog posts of my own explaining how to use systemd for certain tasks, in some cases it feels to me as if systemd sometimes adds a layer of abstraction that is not necessarily helpful. Two examples that spring to mind are given below.

  1. The Gentoo Forums thread [SOLVED]I don’t understand transient hostnames in which a Gentoo user using systemd was trying to stop the hostname being changed when he connected to some networks:

    I’m running a systemd based system for the first time and I’m having an issue with my hostname. Basically, when I connect to (some) networks the network assigns me a transient hostname. This transient hostname seems to completely break everything with my desktop manager (KDM). I have to log out, and then log in with the new transient hostname (which is presumably assigned shortly after I log in and network manager connects to the network). Is this expected? I have set my hostname as described in the handbook and the systemd wiki page. How do I make my hostname *never* change based on dhcp crap?

    After I pointed out that it is possible to force a persistent hostname by specifying the hostname in NetworkManager.conf if NetworkManager is being used with either systemd or OpenRC, he wrote:

    My hostname is now written in 3 places (/etc/hosts, /etc/hostname, and /etc/NetworkManager/NetworkManager.conf). Oh, and I have some random executable (hostnamectl) sitting on my system doing a seemingly poor job of ‘controlling’ my hostname.

    Out of curiosity I then experimented with hostnamectl and compared the outcome with the outcome of setting the hostname in an installation that does not use systemd, and the results differed, so I’m not sure of the scope of hostnamectl.

  2. Time (Arch Wiki)

    The hardware clock can be queried and set with the timedatectl command. To change the hardware clock time standard to localtime, use:

    # timedatectl set-local-rtc 1

    If you want to revert to the hardware clock being in UTC, do:

    # timedatectl set-local-rtc 0

    These will generate /etc/adjtime automatically and update the RTC accordingly; no further configuration is required.

    During kernel startup, at the point when the RTC driver is loaded, the system clock may be set from the hardware clock. Whether this occurs depends on the hardware platform, the version of the kernel and kernel build options. If this does occur, at this point in the boot sequence, the hardware clock time is assumed to be UTC and the value of /sys/class/rtc/rtcN/hctosys (N=0,1,2,..) will be set to 1.

    Later, the system clock is set again from the hardware clock by systemd, dependent on values in /etc/adjtime. Hence, having the hardware clock using localtime may cause some unexpected behavior during the boot sequence; e.g system time going backwards, which is always a bad idea (there is a lot more to it). To avoid it systemd (>215) will only synchronize back, if the hardware clock is set to UTC and keep the kernel uninformed about the local timezone. As a consequence timestamps on a FAT filesystem touched by the Linux system will be in UTC.

    Note: The use of timedatectl requires an active dbus. Therefore, it may not be possible to use this command under a chroot (such as during installation). In these cases, you can revert back to the hwclock command.

Swimming against the tide?

There have been a number of dissenting voices on the Internet. Some argue against systemd on technical grounds, others on philosophical grounds. Here are are few examples:

One of the few distributions bucking the trend is Void Linux, which has replaced systemd with runit as the default init system, with systemd becoming an option.

Slackware and Gentoo are two distributions that do not use systemd by default, although it is actually reasonably straightforward to switch to systemd in Gentoo. It seems one or two people are moving to Gentoo, or contemplating it, because systemd isn’t the default in Gentoo (see, for examples, Re: OT: Open letter to the Linux World and IgnorantGuru’s Hiatus).

Several threads in the Gentoo Forums contain prolonged discussions on systemd, and it is clear that some Gentoo users have strong reservations about systemd. As I write this, a poll in the Gentoo Forums shows only 13 per cent of respondents support the idea of Gentoo adopting systemd as the default init system. I suspect that users of binary-based distributions find this lack of enthusiasm odd, but I believe it is because Gentoo is a source-based distribution and its users are usually more familiar with Linux internals and more comfortable, more adept and more interested in getting ‘under the hood’ than are users of binary-based distributions. Gentoo is not quite Linux From Scratch, but Gentoo users build their installations almost from the ground up (Gentoo does not even have an installer application, for example). I believe that anything interfering with the current way of doing things, or adding a level of abstraction, is not of interest to many Gentoo users. On the other hand, I think users of binary-based distributions who just want to get something done in the quickest way possible are less likely to object.

The beginnings of a new OS?

systemd is not just an init system, it has grown into much more than that and continues to add functionality (referred to by some as ‘feature creep’). Below is the current list of functionality provided in systemd, and the list is growing.

init system, journal logging, login management, device management, temporary and volatile file management, binary format registration, backlight save/restore, rfkill save/restore, bootchart, read-ahead, encrypted storage setup, EFI/GPT partition discovery, virtual machine/container registration, minimal container management, hostname management, locale management, time management, random seed management, sysctl variable management, console management, network management, time synchronisation

I think more of the seasoned GNU/Linux users are waking up to the impact of what Lennart Poettering (the chief architect of systemd) and his fellow systemd ‘cabal’ (his word) members are doing. They are re-designing GNU/Linux from the ground up, and I don’t think it would be an exaggeration to call the end result ‘systemd/Linux’, a de facto new OS. Personally I’m not interested in using that, but I think the vast majority of existing users or newcomers to ‘Linux’ — to use the popular term for the OS — simply don’t care. As long as it works out-of-the-box, that’s all that matters to most people.

And as far as distribution developers are concerned, the status quo says it all: most have already switched their distributions to systemd or have committed to doing so in the future. I suspect it is because they see systemd as being easier to maintain, thus making their lives easier, and they also see systemd as being easier for their desktop users (and with a boot time closer to Windows 8/8.1 Fast Startup). Ultimately the systemd ‘cabal’ will effectively make the different package managers obsolete too, as the latest plan Revisiting How We Put Together Linux Systems shows.

In my opinion, the end result of the radical systemd redesign of the OS could be greater take-up of the OS on the desktop, but the distinction between distributions will lessen and many will cease to exist, as there will be little point choosing one over another. The greater commonality and the larger user base of systemd/Linux will attract more crackers than at present. In some respects the de facto new OS will be much more like Windows or Mac OS than the current GNU/Linux.

Widening the net?

In a Chromium OS discussion group thread earlier this year — The future of initsystem in Chromium OS — a systemd proponent (a Fedora developer?) offered to help the Chrome OS developers switch from Upstart to systemd, but the Chrome OS developers saw no reason to do so without proof of tangible benefits. I believe there is too much revenue at stake to risk switching an important component of the OS of a commercial product (Chromebooks) on a whim. With Chromebooks looking increasingly like the main threat to Microsoft’s hegemony on the desktop, I’m sure Google has no interest in jeopardising that without a very good reason.

The future?

The future seemed clear to me once Mark Shuttleworth announced Ubuntu would drop Upstart and adopt systemd (he made the announcement after Debian developers decided to adopt systemd). Given the number of Ubuntu users (I’ve seen figures in the tens of millions bandied about), I believe Ubuntu will be the making or breaking of systemd. In my opinion, as was the case with PulseAudio (another Lennart Poettering project) there will be a couple of choppy years with plenty of posts in the Ubuntu Forums seeking help, more bugs will be shaken out, and I believe the vast majority of Linux users will end up as accepting users of systemd. In some cases systemd does make configuration a little easier for a newcomer (see, for example, my post Configuring the Linux clock). Personally I find systemd no easier to use than what I use now; in some cases I find systemd more complicated than what I use now (e.g. OpenRC’s local.d). My concerns regarding abstraction, subsumption, loss of choice and the morphing of the OS into something closer to the Windows approach remain, although I can see that many people, including newcomers to Linux, would actually welcome those things. Ironically, although I used to get frustrated with the large number of Linux distributions and their differences, the implications of greater commonality now worry me from a security (predominantly cybercrime) point of view. I am satisfied and comfortable with the existing GNU/Linux tools, configuration files, modus operandi and OpenRC (which works with no problems whatsoever in my case), so I have no desire to migrate to systemd on my main machine running Gentoo Linux. I will also continue to tinker with Sabayon Linux, and thus with systemd, but it will be several years hence before this jury returns a verdict on systemd.

Configuring the Linux clock

A problem often reported by users in Linux forums is that the time displayed by the system clock is incorrect. Typically the problem is that it displays UTC instead of local time. The most common cause is incorrect configuration, although dual booting with Windows will also change the Linux system clock’s time unless either a) Linux is configured to use local time for the hardware clock, or b) Windows is configured to use UTC* and Windows’ time synchronisation with an Internet time server is disabled.

* A change to the Windows Registry is required in order to enable Windows to use UTC for hardware clock time, but even then you may still face problems (see e.g. Force Windows 8 to use UTC when dealing with BIOS clock).

Some terms you need to know: ‘hardware clock’, ‘RTC’ (real-time clock), ‘CMOS clock’ and ‘BIOS clock’ are terms commonly used for the same thing. The hardware clock is non-volatile. ‘system clock’ is the software clock the operating system uses. It is volatile (it is in the kernel). The system clock is normally set from the hardware clock when the operating system boots, taking into account various configuration options. I recommend that you read the manual for the hwclock command, as it explains in detail about clocks in Linux:

# man hwclock

To configure your time zone and clocks correctly, follow the steps below.

If your installation uses the OpenRC init system

  1. Set the time zone:

    1. Specify your time zone in the file /etc/timezone. If you are in Spain, for example, the contents of that file should be ‘Europe/Madrid‘ (without the quotes).

      # nano /etc/timezone

      You can find out which time zones are available by looking in the directory /usr/share/zoneinfo/ and its sub-directories.

    2. Provide the information for your time zone. If you are in Spain, for example, you would enter the following command:

      # cp /usr/share/zoneinfo/Europe/Madrid /etc/localtime

      Note: Some people recommend making /etc/localtime a symlink rather than creating it by copying a file from /usr/share/zoneinfo/, however I recommend copying. You should definitely not use a symlink if /usr is on a different partition (see Ref. 1).

  2. Set the system clock’s time to your local time now (I’ll assume it is 23:54:30 on 21 September 2014 when you press Enter):

    # date 092123542014.30

  3. Specify whether the hardware clock time is UTC:

    # hwclock --utc

    or local time:

    # hwclock --localtime

    It is preferable for the hardware clock time to be in UTC. However, if you dual boot with Windows it is recommended for the hardware clock time to be in local time rather than UTC unless both the following are true: a) the Windows Registry has been configured for hardware clock time in UTC; b) Windows’ time synchronisation with an Internet time server is disabled.

  4. Set the hardware clock’s time by specifying your local time (I’ll assume it is 23:54:50 on 21 September 2014 when you press Enter):

    # rm /etc/adjtime
    # hwclock --set --date="2014-09-21 23:54:50"

    Note: You must specify local time in the above command, even if you intend the hardware clock time to be UTC.

    Note that the third line in /etc/adjtime should be ‘UTC’ if the hardware clock time is in UTC, or ‘LOCAL’ if the hardware clock time is in local time. For example:

    # cat /etc/adjtime
    0.000000 1412038530 0.000000
    1412038530
    UTC

  5. Tell OpenRC whether the hardware clock uses UTC or local time, and to update the hardware clock time from the system clock time at every shutdown (taking into account any time zone difference between the two clocks):

    # nano /etc/conf.d/hwclock

    1. Make clock="UTC" (or clock="local" if you dual boot with Windows and the Windows Registry is not configured to use UTC for hardware clock time).

    2. Make clock_systohc="YES" to adjust the hardware clock time at shutdown based on the software clock time (taking time zone into account). However, you don’t need to bother doing this if your kernel configuration has CONFIG_RTC_SYSTOHC=y and your installation is configured to synchronise the system clock with a NTP time server (see my post Synchronise your Gentoo Linux clock with an Internet time server). You can check if the hardware clock time is being updated from the software clock time (taking time zone into account) by looking at the kernel messages displayed when in verbose mode during shutdown to see if the following message is displayed:

      Setting hardware clock using the system clock [UTC] ...

    3. Make clock_hctosys="YES" to adjust the system clock time at start up based on the hardware clock time (taking time zone into account). However, you don’t need to bother doing this if your kernel configuration has CONFIG_RTC_HCTOSYS=y. You can check by looking at the kernel messages displayed when in verbose mode during boot to see if the following message is displayed:

      Setting system clock using the hardware clock [UTC] ...

  6. Reboot and check everything is working as expected:

    # date
    Tue 30 Sep 01:55:55 BST 2014
    # hwclock
    Tue 30 Sep 2014 01:55:59 BST -0.031877 seconds

    The hwclock command always shows local time, even if you keep your hardware clock in UTC.

  7. Optionally (but I recommend it), configure your installation to synchronise the system clock with an Internet NTP server (see my post Synchronise your Gentoo Linux clock with an Internet time server).

If your installation uses systemd

  1. Set the time zone:

    1. Find out the available time zones:

      # timedatectl list-timezones

    2. Specify your time zone (I’ll assume you are in Spain in this example):

      # timedatectl set-timezone Europe/Madrid

  2. Set the system clock time to your local time (I’ll assume it is 23:54:30 on 21 September 2014 when you press Enter):

    # timedatectl set-time "2014-09-21 23:54:30"

  3. Inform systemd that the hardware clock uses UTC, and set the current UTC in the hardware clock now:

    # timedatectl set-local-rtc 0

    Note that, by default, systemd assumes the hardware clock uses UTC. Although systemd can be configured to assume the hardware clock uses local time, for technical reasons it is not recommended (see man timedatectl and Arch Wiki article Time for an explanation of why this is not advisable).

    Note that the third line in /etc/adjtime should be ‘UTC’ if the hardware clock time is in UTC, or ‘LOCAL’ if the hardware clock time is in local time. For example:

    # cat /etc/adjtime
    0.000000 1412038530 0.000000
    1412038530
    UTC

  4. Reboot and check everything is working as expected:

    $ timedatectl

  5. Optionally (but I recommend it), configure your installation to synchronise the system clock with an Internet NTP server (see my post Synchronising the clock using NTP in Sabayon Linux).

References

[1] Gentoo Forums – how exactly to set timezone in /etc/localtime ?[solved]

Synchronising the clock using NTP in Sabayon Linux

In my previous post I explained how to install Sabayon Linux via the command line from the Sabayon Linux ‘SpinBase’ ISO.

If the system clock in your current installation is not being synchronised with an external time server over the Internet, the simplest way to achieve this is to install the net-misc/ntp package and configure systemd as shown below.

Note that I use net-misc/ntp rather than net-misc/chrony because the latter does not work in my Sabayon Linux installation; after I have configured the Chrony daemon, the command ‘systemctl status chronyd‘ returns the error message ‘Can’t initialise from real time clock, driver not loaded’. Of course, if Chrony happens to be installed and is working fine, you don’t need to do anything at all. But if Chrony is not working correctly and you want to try the ntp daemon instead, before performing the steps below you’ll first need to disable Chrony as explained under ‘Caveat’ at the end of this post.

  1. Install the ntp package:

    # equo install ntp

  2. Enable the ntp daemon so that it starts at boot:

    # systemctl enable ntpd
    # timedatectl set-ntp true

  3. Start the ntp daemon running now:

    # systemctl start ntpd

  4. Check whether the daemon is running:

    # systemctl status ntpd

Below I show the console output for the complete sequence from Step 2 to Step 4 with the command ‘timedatectl status‘ between each step so that you can see the effect. Note that I had previously set the hardware clock time (which, by default, systemd assumes to be UTC) to be the same time as local time. Since BST and UTC do not coincide, clearly both clocks should not both contain 10:06, so watch what happens below once the NTP daemon is launched.

sabayon fitzcarraldo # timedatectl status
      Local time: Mon 2014-09-22 10:06:06 BST
  Universal time: Mon 2014-09-22 09:06:06 UTC
        RTC time: Mon 2014-09-22 10:06:07
        Timezone: Europe/London (BST, +0100)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2014-03-30 00:59:59 GMT
                  Sun 2014-03-30 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2014-10-26 01:59:59 BST
                  Sun 2014-10-26 01:00:00 GMT
sabayon fitzcarraldo # systemctl enable ntpd
ln -s '/usr/lib/systemd/system/ntpd.service' '/etc/systemd/system/multi-user.target.wants/ntpd.service'
sabayon fitzcarraldo # timedatectl status
      Local time: Mon 2014-09-22 10:06:39 BST
  Universal time: Mon 2014-09-22 09:06:39 UTC
        RTC time: Mon 2014-09-22 10:06:39
        Timezone: Europe/London (BST, +0100)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2014-03-30 00:59:59 GMT
                  Sun 2014-03-30 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2014-10-26 01:59:59 BST
                  Sun 2014-10-26 01:00:00 GMT
sabayon fitzcarraldo # timedatectl set-ntp true
sabayon fitzcarraldo # timedatectl status
      Local time: Mon 2014-09-22 10:06:57 BST
  Universal time: Mon 2014-09-22 09:06:57 UTC
        RTC time: Mon 2014-09-22 10:06:58
        Timezone: Europe/London (BST, +0100)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2014-03-30 00:59:59 GMT
                  Sun 2014-03-30 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2014-10-26 01:59:59 BST
                  Sun 2014-10-26 01:00:00 GMT
sabayon fitzcarraldo # systemctl start ntpd
sabayon fitzcarraldo # timedatectl status
      Local time: Mon 2014-09-22 10:07:13 BST
  Universal time: Mon 2014-09-22 09:07:13 UTC
        RTC time: Mon 2014-09-22 09:07:13
        Timezone: Europe/London (BST, +0100)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2014-03-30 00:59:59 GMT
                  Sun 2014-03-30 02:00:00 BST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2014-10-26 01:59:59 BST
                  Sun 2014-10-26 01:00:00 GMT
sabayon fitzcarraldo # systemctl status ntpd
ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled)
   Active: active (running) since Mon 2014-09-22 10:07:11 BST; 23s ago
 Main PID: 2420 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─2420 /usr/sbin/ntpd -g -n

Sep 22 10:07:11 sabayon ntpd[2420]: Listen normally on 5 eth0 fe80::a00:27ff:fe86:21f3 UDP 123
Sep 22 10:07:11 sabayon ntpd[2420]: peers refreshed
Sep 22 10:07:11 sabayon ntpd[2420]: Listening on routing socket on fd #22 for interface updates
Sep 22 10:07:13 sabayon ntpd[2420]: Deferring DNS for 0.gentoo.pool.ntp.org 1
Sep 22 10:07:14 sabayon ntpd[2420]: Deferring DNS for 1.gentoo.pool.ntp.org 1
Sep 22 10:07:15 sabayon ntpd[2420]: Deferring DNS for 2.gentoo.pool.ntp.org 1
Sep 22 10:07:16 sabayon ntpd[2420]: Deferring DNS for 3.gentoo.pool.ntp.org 1
Sep 22 10:07:18 sabayon ntpd_intres[2422]: DNS 0.gentoo.pool.ntp.org -> 85.236.36.4
Sep 22 10:07:18 sabayon ntpd_intres[2422]: DNS 1.gentoo.pool.ntp.org -> 78.46.197.35
Sep 22 10:07:18 sabayon ntpd_intres[2422]: DNS 2.gentoo.pool.ntp.org -> 91.234.160.19
sabayon fitzcarraldo #

Notice that the NTP daemon synchronised the RTC (hardware clock) time to UTC (I had previously set the hardware clock time to be the same as local time to show what would happen when the NTP deamon was launched). That is correct: notice ‘RTC in local TZ: no‘ in the output above, meaning that systemd by default assumes the time in the RTC is UTC.

By the way, in case you’re wondering, the NTP daemon of course synchronises the time in the system clock too. You do not need to worry: the system clock uses the local time of the time zone you previously configured (see my previous post), so the Linux date command and the clock of the Desktop Environment will show you local time by default.

Caveat
Note that I am using the ntp daemon instead of the Chrony daemon or the OpenNTPD daemon. If Chrony happens to be installed and active in your Sabayon Linux installation, before performing any of the above steps you’ll first need to do the following:

  1. Uninstall the Chrony package:

    # equo remove chrony

  2. Disable the Chrony daemon so that it does not start at boot:

    # systemctl disable chronyd
    # timedatectl set-ntp false

  3. Stop the Chrony daemon running now:

    # systemctl stop chronyd

  4. Check whether the daemon is still running:

    # systemctl status chronyd

Change systemd’s binary logging to text logging in Sabayon Linux

systemd logs system messages in a binary file which the developers call a ‘journal’. However, if you would prefer system messages to be logged in a text file, here is how to do it for Sabayon Linux. The steps will probably be similar in other distributions.

1. See what log files currently exist in your installation:

# ls /var/log
anaconda btmp cups faillog kdm.log mysql portage sandbox tallylog Xorg.0.log
boot.log chrony entropy journal lastlog news samba spice-vdagentd wtmp Xorg.0.log.old

Notice that the traditional text log file /var/log/messages is not present. The systemd binary log files are in a sub-directory of /var/log/journal/:

# ls /var/log/journal
5d387e19d28644c5b24f06f8bc6e9b9c
# ls /var/log/journal/5d387e19d28644c5b24f06f8bc6e9b9c
system.journal user-1000.journal

2. Edit the file /etc/systemd/journald.conf and change #Storage=auto to Storage=none

# nano /etc/systemd/journald.conf

3. Install the system logger syslog-ng:

# equo install syslog-ng

If it’s not already installed, install the logrotate package:

# equo install logrotate

4. Enable the service so that it starts the next time you boot:

# systemctl enable syslog-ng.service
ln -s '/usr/lib/systemd/system/syslog-ng.service' '/etc/systemd/system/syslog.service'
ln -s '/usr/lib/systemd/system/syslog-ng.service' '/etc/systemd/system/multi-user.target.wants/syslog-ng.service'

5. Start the service now:

# systemctl start syslog-ng.service

6. Check if the text log file /var/log/messages has been created:

# ls /var/log
anaconda btmp cups faillog kdm.log messages news samba spice-vdagentd wtmp Xorg.0.log.old
boot.log chrony entropy journal lastlog mysql portage sandbox tallylog Xorg.0.log

If you now reboot you’ll see that the text file /var/log/messages is being used to log system messages, and you can view it easily using commands such as cat, more, less, nano or whatever, and search through it using grep etc. Note that the systemd journal service is still running; it is just not logging to a binary file any more and is forwarding system messages to syslog-ng.

How to install Sabayon Linux via the command line using the ‘text installer’

If you have trouble installing Sabayon Linux from one of the ISOs that include KDE, GNOME or Xfce, you could try installing from the ‘SpinBase’ ISO or ‘Minimal’ ISO instead and add a desktop environment later.

And sometimes the Sabayon Linux installer is unable to install the distribution correctly for the GPU or APU in your machine, so installing the distribution to use the X.Org VESA video driver then later trying another video driver can also be a way to get you to a working installation.

Whichever ‘spin’ of Sabayon Linux I try to install, I find my success varies considerably with the release of ISO. So, if you end up with a blank screen when you reboot after installing the distribution, try installing it again with a different ISO, such as a Monthly release instead of a Daily release. If none of the current ISOs result in a working installation, you may have to wait a few days for a new Daily release to be uploaded. Despite the name, the Daily ISOs are not necessarily released daily.

I recommend you practice installation in VirtualBox before trying with an actual HDD. You can do this on a PC running VirtualBox under Windows, Mac OS or Linux. N.B. If the console goes black at any time in VirtualBox, press Enter to refresh the contents.

The steps below worked for me with a Sabayon Linux ISO dated 14 September 2014 in VirtualBox running under Windows 8.1 on a machine with Intel HD Graphics APU. In the steps below I configure the installation for the time zone in which São Paulo is situated and specify British English and Brazilian Portuguese as the languages to be used. Obviously you should choose instead the time zone and language that you want in your installation.

1. Download the Daily SpinBase ISO (Sabayon_Linux_DAILY_x86_SpinBase.iso) from one of the ISO repositories (see the Download link on the distribution’s Web site).

2. Create a LiveDVD from the ISO (see my post Help for Windows users: How to create a Linux LiveCD, LiveDVD or LivePenDrive from an ISO file if you don’t know how to do that).

3. Boot the LiveDVD.

4. You have two choices here, really. Try (a) first and, if the LiveDVD will not continue to load the OS or it will but you end up with an installation that does not work, then re-boot the LiveDVD and perform (b) instead.

Either:

a) Press ‘Enter‘ at the Sabayon Linux boot menu, to start the OS from the LiveDVD.

or:

b) Press F5 at the Sabayon Linux boot menu, then Esc to close the pop-up list of boot parameters. Then delete the “---” at the end of the list of kernel boot parameters, delete the “vga=791“, add “xdriver=vesa” to the end of the list and press ‘Enter‘ to start the OS from the LiveDVD. Note that, unlike the other Sabayon Linux ISO releases, the SpinBase ISO does not include video drivers for X Windows. However, by booting the LiveDVD with xdriver=vesa the installation on the HDD will include that parameter in /etc/default/sabayon-grub and /boot/grub/grub.cfg.

In either case, Sabayon Linux on the LiveDVD should start in text mode and you should see a root user prompt:

sabayon ~ #

5. Enter the following command and follow the prompts to enter the relevant information to install Sabayon to your HDD:

# installer

Select 2) 'Use text mode' then work your way through steps 1 to 5, answering the installer’s prompts:

1) Timezone settings
2) Set root password
3) Create user
4) Network settings
5) Install Destination

When you select Step 5 (Install Destination) you will be presented with three ‘Autopartitioning Options’ (Replace Existing Linux System(s); Use All Space; Use Free Space). When you make your choice from those three options, you will then be presented with the options for partitioning:

Partition Scheme Options

[ ] 1) Standard Partition

[x] 2) LVM

[ ] 3) BTRFS

Select a partition scheme configuration.

Please make your choice from above ['q' to quit | 'c' to continue | 'r' to refresh]:

You may find that the installer crashes if you have selected either the default LVM partition scheme or the BTRFS partition scheme. If it does crash, run the installer again but select Option 1 instead (Standard Partition), which will create standard ext4 partitions. Actually, I prefer this option.

Quite a few Python-related error messages may be displayed towards the end of the installation process. I just ignore them.

6. Once the installer has completed installation, press Enter to quit, and you will see a root user prompt again.

7. Enter the following command to reboot (If you installed using VirtualBox, make sure you remove the ISO from the virtual CD/DVD drive, or you will just reboot from the ISO instead of the virtual HDD):

systemctl reboot

If you still have the LiveDVD in the drive, select ‘Boot from first hard drive’ in the LiveDVD’s boot menu.

8. You will see a log-in prompt:

sabayon login:

Log-in as user ‘root’ with the root user’s password you specified during installation.

9. List the available time zones:

# timedatectl list-timezones

(Press the Space Bar to page through the list, and the Q key to exit the list.)

10. Specify the timezone you want:

# timedatectl set-timezone America/Sao_Paulo

11. List the current locale:

# localectl list-locales
en_US
en_US.iso88591
en_US.utf8

12. If you want to change the current locale or add a locale, edit the locale.gen file:

# nano /etc/locale.gen

I wanted to have just British English and Brazilian Portuguese, so I made the file contain only the following:

en_GB.UTF-8 UTF-8
en_GB ISO-8859-1
pt_BR.UTF-8 UTF-8
pt_BR ISO-8859-1

If I only wanted one language (I’ll use Brazilian Portuguese as an example), I would have made it contain the following instead:

pt_BR.UTF-8 UTF-8
pt_BR ISO-8859-1

13. Generate the locale(s) you want:

# locale-gen
* Generating 4 locales (this might take a while) with 1 jobs
* (1/4) Generating en_GB.UTF-8 ... [ ok ]
* (2/4) Generating en_GB.ISO-8859-1 ... [ ok ]
* (3/4) Generating pt_BR.UTF-8 ... [ ok ]
* (4/4) Generating pt_BR.ISO-8859-1 ... [ ok ]
* Generation complete

14. List the locales you have configured, just to be sure:

# localectl list-locales
en_GB
en_GB.iso88591
en_GB.utf8
pt_BR
pt_BR.iso88591
pt_BR.utf8

15. Set the language you want to use:

# localectl set-locale LANG=pt_BR.UTF-8

16. List the console keymaps available:

# localectl list-keymaps

17. Chose the console keymap you wish to use:

# localectl set-keymap br-abnt2

N.B. The above systemd command does not change the console keymap specified in /boot/grub/grub.cfg, which remains as “vconsole.keymap=us“. You will have to fix that later by editing /etc/default/sabayon-grub and running grub2-mkconfig -o /boot/grub/grub.cfg, as I show further on.

18. List the X11 keymaps available:

# localectl list-x11-keymap-layouts

19. Chose the X11 keymap you wish to use:

# localectl set-x11-keymap br

20. Update the environment variables and profile to adopt what you specified:

# env-update && source /etc/profile

21. Reboot (Remove the LiveDVD if still have not already done so):

# systemctl reboot

22. Log-in as the root user.

23. Fix the console keymap specified in grub.cfg:

# nano /etc/default/sabayon-grub

and replace “vconsole.keymap=us” with “vconsole.keymap=br-abnt2“.

# grub2-mkconfig -o /boot/grub/grub.cfg

24. Make sure the Entropy package database in your installation is up to date:

# equo update

25. Roll (upgrade) all installed packages to their latest version:

# equo upgrade

If you are prompted regarding any package licences, just accept them.

26. Update any superseded configuration files:

# equo conf update

27. Check if there are any missing/incorrect dependencies:

# equo deptest

28. Check if there are any missing/incorrect libraries:

# equo libtest

29. Install the X.Org VESA video driver:

# equo install xf86-video-vesa

This is needed because the VESA video driver does not get installed even if you specify “xdriver=vesa” initially in the kernel boot parameter list when booting a LiveDVD using SpinBase.

30. Install the desktop environment of your choice (I’ll choose KDE):

# equo install kde-meta

31. If you are installing KDE, also install the KDE language pack(s) for the locale(s) configured earlier:

# equo install kde-l10n-en_GB kde-l10n-pt_BR

32. Install the Sabayon Linux theme for KDE and KDM (I find this package is not installed automatically, and stops KDM from working if it is not present):

# equo install sabayon-artwork-kde

33. Reboot:

# systemctl reboot

34. Log-in as the root user and, if you installed KDE, enable KDM as the desktop manager (log-in screen):

# systemctl enable kdm

35. Then reboot:

# systemctl reboot

The installation on your HDD should now boot to the KDM log-in screen. You should be able to enter your user name and password, and the installation should launch the Desktop Environment and display the Desktop. From here you will be able to open a Konsole/Terminal window and install other packages. If you want to change the video driver from the X.Org VESA driver to a driver for an AMD, Intel or NVIDIA GPU/APU, you will need to install the relevant driver package and edit /etc/X11/xorg.conf and /etc/default/sabayon-grub accordingly (and regenerate grub.cfg). Post in the Sabayon Linux Forums to ask for help if you need it. Good luck!

Make Firefox for Linux use Dolphin to ‘Open Containing Folder’

When I click on the Download Manager icon on the tool bar, Firefox for Linux 32.0 opens a small pane listing downloads in progress, if any, and a link ‘Show All Downloads’. If I click on the link, Firefox pops up a window listing all the files downloaded via the browser, each with a folder icon beside it. Hovering the mouse pointer over the folder icon displays a tooltip ‘Open Containing Folder’. For as long as I can remember with Firefox for Linux, clicking that folder icon resulted in the Audacious music player launching and playing an MP4 file that happens to be in my ~/Downloads/ directory!

Firstly, I have no idea why Firefox was launching a media player instead of opening the directory. Secondly, I have no idea why Firefox wanted to open that specific file rather than any of the other files in the directory. Thirdly, I have no idea why it was launching Audacious, because Audacious is not even specified as the default media player for MP4 files in KDE’s ‘System Settings’ > ‘File Associations’.

This has annoyed me for a long time, but only today did I resolve to fix it, although it was not so easy to find a working solution by searching the Web. It seems it is a common problem with Firefox in Linux, and I found threads in various forums recommending the creation of a set of preferences by using about:config. Some of those threads state that one of those preferences should specify Konqueror; other threads state that one of the preferences should specify a shell script. In the end I discovered a post in an openSUSE Forums thread from 2012 Re: How use Dolphin to “open containing folder” from firefox downloads? providing a broken link to a thread at a different Web site and, fortunately, quoting the solution which worked for me, which is to create a file named ~/.local/share/applications/defaults.list containing the following:

[Default Applications]
x-directory/normal=kde4-dolphin.desktop;kde4-kfmclient_dir.desktop;

Now when I click on the ‘Open Containing Folder’ icon in Firefox, Dolphin launches and displays the contents of ~/Downloads/ just as I would have expected from the beginning.

Opening multiple browser tabs simultaneously — AutoKey comes to the rescue

hotkey to launch an application

I sometimes consult several dictionary Web sites concurrently. Typically I have them open simultaneously on different browser tabs so that I can switch between them quickly. Naturally I have the sites bookmarked, but it is still a bit of a nuisance to have to open each site by clicking on the browser’s ‘Open a new tab’ icon and then clicking on a bookmark. So I thought it would be nice if I could have an icon in the browser or on the Desktop that I could click to open all the desired Web pages at once.

Well, I could have created a Desktop Configuration File in ~/Desktop/ to launch a command such as the one listed below, and given the file a nice icon.

firefox http://www.oxforddictionaries.com/ http://michaelis.uol.com.br/moderno/portugues/index.php http://www.conjuga-me.net/ http://www.priberam.pt/dlpo/ http://www.wordreference.com/

Then I would have been able to double-click on the icon on my Desktop, which would have launched a separate Firefox window with those five required Web sites in different tabs. But what if I happened to have an existing window maximised? I would then have to move it to be able to see the icon on the Desktop. So I decided that was not an ideal approach.

Next I thought about the possibility of a Firefox extension, so I searched the Mozilla Add-ons site and found one called Open Multiple Locations. But, from what I read, it seems the extension is no longer being maintained. Furthermore, it appears it would have to be launched from the browser’s File menu, which would still be a little inconvenient.

Then I remembered that I have the excellent utility AutoKey installed, so why not define a hotkey sequence to do what I wanted? This is what I did.

When you install AutoKey, it creates a directory ~/.config/autokey/data/My Phrases/ which contains directories named Addresses and Sample Scripts. The latter two directories contain examples of what you can do with AutoKey. Now, one of the example scripts in Sample Scripts is Insert Date.py, a very simple script which enables you to issue the Linux date command with a hotkey combination, preconfigured as Ctrl-Alt-d (Click on the Insert Date entry in the left pane of the AutoKey window and notice in the lower right pane that the hotkey is listed and there are Set and Clear buttons to enable you to change it).

So I used the Desktop Environment’s GUI to navigate to the directory ~/.config/autokey/data/My Phrases/ and created a directory which I called ~/.config/autokey/data/My Phrases/My Scripts/. I copied the file ~/.config/autokey/data/My Phrases/Sample Scripts/Insert Date.py into the new directory and renamed it Launch_Firefox_with_dictionaries.py then set its AutoKey hotkey combination to be Ctrl-Alt-f and edited it to contain the desired command:

output = system.exec_command("firefox http://www.oxforddictionaries.com/ http://michaelis.uol.com.br/moderno/portugues/index.php http://www.conjuga-me.net/ http://www.priberam.pt/dlpo/ http://www.wordreference.com/")
keyboard.send_keys(output)

Now, when I am using a browser (be it Firefox, Chrome, Konqueror or whatever) or any other application and I need to consult those dictionaries, I just press Ctrl-Alt-f and up pops a Firefox window containing five tabs with the Web sites I wish to be able to use. Done and done.

Of course, if you happen to be using a Desktop Environment that has its own shortcut tool, you can use that instead. For example, in KDE I could have instead used ‘System Settings’ > ‘Shortcuts and Gestures’ | ‘Custom Shortcuts’ and configured Ctrl-Alt-f to run the above-mentioned command to launch Firefox with those five URLs. (You need to log out of KDE and log in again for the shortcut to become active.) That would have achieved exactly the same result as with AutoKey.

WINE tips: File associations for Windows applications in Linux (continued)

There is a downside to the approach described in my previous post regarding file associations for Windows applications run via WINE, at least in the case of KDE.

By using KDE’s ‘System Settings’ > ‘File Associations’ to change the application launch command from:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine /home/fitzcarraldo/.wine-visio5/drive_c/Program\ Files/Visio/Visio32.EXE

to:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix %U

the launch command in KDE’s Kicker application launcher menu is also changed to the latter. Trying to launch the Windows application from the Kicker menu (Wine > Programs > a_Windows_application) then fails. Presumably this is because the wine command expects a filename (the %U in the command string) but that is not being provided.

Alternative 1

One solution is to use a shell script as described in my earlier post: WINE tips: How to associate IrfanView with an image file type in Linux. Kicker can still be used to launch the application (e.g. Wine > Programs > IrfanView) when the menu command is of the following form but no filename is provided (even though the %f is left in the command string):

/home/fitzcarraldo/launch_IrfanView.sh %f

Alternative 2

Another solution – well, really a work-around – is to accept that the Windows application cannot be launched from the Kicker menu and to create a separate Desktop Configuration File in /home/fitzcarraldo/Desktop/ which uses a different command to launch the application. For example, in my previous post the file association I configured via ‘System Settings’ > ‘File Associations’ for Visio was:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix %U

and therefore the command in the Kicker menu entry is the same, but I created a Desktop Configuration File which I named ‘/home/fitzcarraldo/Desktop/Visio 5 Professional‘ which contains the command:

env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine /home/fitzcarraldo/.wine-visio5/drive_c/Program\ Files/Visio/Visio32.EXE

$ ls -la ~/Desktop/Visio*
-rwxrwxrwx 1 fitzcarraldo users 562 Aug 26 17:42 /home/fitzcarraldo/Desktop/Visio 5 Professional

Notice that the command to launch the Windows application does not contain a filename parameter (%U), so when I double-click on the icon on the Desktop it launches Visio.

Summary

Ideally, KDE should be changed to allow the application launching command in ‘System Settings’ > ‘File Associations’ to be edited to be different to the application launching command in the Kicker menu. In the absence of that, you have two alternatives in the case of WINE:

  1. Create a shell script to launch the application. This allows you to launch the Windows application via Kicker and by double-clicking on a file of the applicable type.

    or

  2. Create a separate Desktop Configuration File in e.g. the ~/Desktop/ directory. This allows you to launch the Windows application by double-clicking on a Desktop Configuration File for the application and by double-clicking on a file of the applicable type. However you cannot launch the application from its entry in the Kicker menu.

WINE tips: File associations of Windows applications in Linux

I have several applications for Windows installed under WINE in Linux. These applications launch correctly if I double-click on a file for that application, but, in the case of some of these applications, the file itself is not opened. Therefore I first have to launch the application and then load the file from within the application (File > Open, or whatever). Some time ago I explained how to fix this in the case of IrfanView by creating a shell script – see my post WINE tips: How to associate IrfanView with an image file type in Linux – but there is an easier way to do it in many cases, as illustrated by the example below for another Windows application I use regularly in Linux. I finally got fed up with not being able to open .vsd (Visio drawing) files by double-clicking on them in Linux, and decided to fix this. The same procedure applies, whatever the Windows application.

I use KDE, but the principle applies whatever Desktop Environment you are using. Just use the relevant File Association configuration tool for that Desktop Environment.

  1. I selected ‘System Settings’ > ‘File Associations’ from the KDE Kickoff menu launcher.

  2. I entered ‘vsd’ (without the quotes) in the search field in order to find the application associated with that file type.

    The ‘Known Types’ box then displayed the following:

    >- application

  3. When I expanded that by clicking on it, the ‘Known Types’ box displayed the following two application file types:

    v- application
            vnd.ms-visio.viewer
            vnd.visio

  4. Clicking on either displayed ‘Visio 5.0 Professional’ in the ‘Application Preference Order’ box. I selected it and clicked on ‘Edit…’, which opened a Properties window for the application’s desktop configuration file.

  5. I clicked on the ‘Application’ tab. The ‘Command’ box contained the following command:
    env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine /home/fitzcarraldo/.wine-visio5/drive_c/Program\ Files/Visio/Visio32.EXE

    (The wine command itself has to be preceded by the definition of the WINEPREFIX and WINEARCH environment variables because I specified those environment variables originally when I installed the application via WINE.)

    I changed the command to be the following:

    env WINEPREFIX="/home/fitzcarraldo/.wine-visio5" WINEARCH="win32" wine C:\\windows\\command\\start.exe /Unix %U

    for both vnd.ms-viso.viewer and vnd.visio application file types, and clicked on ‘OK’ and ‘Apply’.

That’s all there was to it. Now when I double-click on any file ending with ‘.vsd’, Visio launches as before but the actual file is opened in the application. Very straightforward, and I really should have made the effort to fix it sooner. :-)

Follow

Get every new post delivered to your Inbox.

Join 52 other followers