How to display a user’s avatar instead of the generic avatar on the LightDM GTK Greeter screen in Lubuntu 17.10

I recently installed Lubuntu 17.10 on my family’s PC (single-seat, multi-user). The default avatar was displayed for each user on the LightDM greeter screen, rather than each user’s individual avatar. I have experienced this problem in more than one Linux distribution (Gentoo, Sabayon and now Lubuntu 17.10), more than one Desktop Environment (KDE, GNOME and now LXDE), and more than one Desktop Manager (LightDM and SDDM), so my suspicion is that the problem lies with AccountsService rather than the DE or DM. Anyway, here is how I fixed the problem in Lubuntu 17.10. The example below is for user fitzcarraldo, and I used the same procedure for each username in the installation.

1. Create a 96×96 PNG avatar /home/fitzcarraldo/Pictures/fitzcarraldo.png

2. Edit the file /var/lib/AccountsService/users/fitzcarraldo to contain the following:

[User]
XSession=Lubuntu
SystemAccount=false
Icon=/var/lib/AccountsService/icons/fitzcarraldo	

3. Make sure that the file has 644 permissions:

$ ls -la /var/lib/AccountsService/users/fitzcarraldo
-rw-r--r-- 1 root root 85 Jan  1 02:53 /var/lib/AccountsService/users/fitzcarraldo

4. Copy the avatar to the relevant directory and make sure it has 644 permissions:

$ sudo cp /home/fitzcarraldo/Pictures/fitzcarraldo.png /var/lib/AccountsService/icons/fitzcarraldo
$ ls -la /var/lib/AccountsService/icons/fitzcarraldo
-rw-r--r-- 1 root root 14860 Jan  1 02:54 /var/lib/AccountsService/icons/fitzcarraldo

After rebooting, the desired avatar should be displayed on LightDM’s GTK Greeter screen.

Background reading

  1. KDE Bug Report No. 336994 – User Manager does not show one particular user in the list unless I login as that user
  2. Gentoo Forums – user-manager in plasma desktop not populating users
  3. Gentoo Forums – LightDM greeter username in list stuck and can’t add others
Advertisements

Prevent Lubuntu 17.10 from leaving an external HDD mounted incorrectly for other users

My family’s PC running Lubuntu 17.10 has an external USB HDD connected permanently. There are several user accounts on this machine, i.e. it is a single-seat, multi-user installation. If a user does not unmount this external HDD before logging out, it is still mounted with the privileges of the previous user when another user logs in. If the current user clicks on the media unmount symbol (⏏) in the PCManFM File Manager, LXDE prompts the user to enter the previous user’s password. So I wanted to configure the OS to unmount the external HDD when each user logs out or when another user selects ‘Switch User’. The way I did that was to use the LightDM desktop manager to unmount the external drive at the end of a session, as explained below. Then the Udisks daemon will mount the drive correctly for any user who either logs in or switches back to his/her session.

Lubuntu 17.10 as installed has an empty directory /etc/lightdm/lightdm.conf.d/ so I created two files in that directory:

$ ls -la /etc/lightdm/lightdm.conf.d/
total 16
drwxr-xr-x 2 root root 4096 Jan  1 06:18 .
drwxr-xr-x 4 root root 4096 Jan  1 05:11 ..
-rw-r--r-- 1 root root   89 Jan  1 06:18 10_lubuntu.conf
-rwxr-xr-x 1 root root   80 Jan  1 05:55 unmount_FREECOM_HDD.sh
$ cat /etc/lightdm/lightdm.conf.d/10_lubuntu.conf
[SeatDefaults]
session-cleanup-script=/etc/lightdm/lightdm.conf.d/unmount_FREECOM_HDD.sh
$ cat /etc/lightdm/lightdm.conf.d/unmount_FREECOM_HDD.sh 
#!/bin/bash
udisksctl unmount --block-device /dev/disk/by-uuid/C6576A087368B015

where ‘C6576A087368B015‘ is the UUID of the external USB HDD as found from the blkid command:

$ sudo blkid | grep "FREECOM HDD"
/dev/sdb1: LABEL="FREECOM HDD" UUID="C6576A087368B015" TYPE="ntfs" PARTUUID="0024db7f-32"

Don’t forget to make the Bash script executable. Then reboot to enable the functionality. From now on the external HDD will be correctly mounted for each user who logs in to his/her account.

Backing up users’ home directories in a Linux installation that uses systemd

This is to explain how I configured Lubuntu 17.10 on my family’s PC (single seat; multiple user accounts) to backup all users’ files to a permanently-connected external USB HDD. I wanted a basic solution that would backup automatically every user’s home directory at shutdown but not when rebooting, and would do this whichever user happens to be using the PC. We have no need to archive older versions of the same file, so overwriting a file on the external USB HDD with a newer version of that file from the PC’s HDD is fine. However, we do not want files on the external USB HDD to be deleted if the corresponding files have been deleted from the PC’s HDD. Additionally, I want a time-stamped record of the backup process to be logged to a file in my home directory so I can check periodically what has been happening. As explained in my previous post, two files are used to achieve all these things:

  • a Bash script to a) determine whether the system is being rebooted, b) remount the external USB HDD on a suitable mount point, c) copy the files to the external USB HDD, and d) write to the log file;
  • a systemd unit file to launch the Bash script.

The two files are described below.

Bash script

I created a file /usr/local/sbin/backup_home_directories.sh owned by the root user, with the following permissions and contents:

fitzcarraldo@aspirexc600:~$ ls -la /usr/local/sbin/backup_home_directories.sh
-rwxr-xr-x 1 root root 2570 Jan  8 20:37 /usr/local/sbin/backup_home_directories.sh
#!/bin/bash

# This script backs up to an external USB HDD (NTFS) labelled "FREECOM HDD" the contents of the home directories
# of the users of this Lubuntu 17.10 installation if the system is shutting down but not rebooting.
# It is launched by a systemd service /etc/systemd/system/backup-to-usb-hdd.service.

# Find out if the system is rebooting (as opposed to being shut down):
REBOOT=$( systemctl list-jobs | egrep -q 'reboot.target.*start' && echo "rebooting" || echo "not_rebooting" )
if [ $REBOOT = "not_rebooting" ]; then
# Only execute the following steps if the system is shutting down but not rebooting:
    # Clean up if the backup did not complete last time:
    umount /media/usbhdd 2>/dev/null # Make sure you enter this line correctly.
    rm -rf /media/usbhdd/* # Make sure you enter this line correctly.
    # Unmount the external USB HDD if mounted by udisks2 with the logged-in username in the path:
    umount /media/*/FREECOM\ HDD 2>/dev/null
    # Find out the USB HDD device:
    DEVICE=$( blkid | grep "FREECOM\ HDD" | cut -d ":" -f1 )
    # Create a suitable mount point if it does not already exist, and mount the device on it: 
    mkdir /media/usbhdd 2>/dev/null
    mount -t ntfs-3g $DEVICE /media/usbhdd 2>/dev/null
    # Create the backup directory on the USB HDD if it does not already exist:
    mkdir /media/usbhdd/Lubuntu_home_folders_backup 2>/dev/null
    # Backup recursively all the home directories of all the users, and add a time-stamped summary to the log file: 
    echo "********** Backing up Acer Aspire XC600 users' home directories **********" >> /home/fitzcarraldo/backup.log
    date >> /home/fitzcarraldo/backup.log
    # Log username of user shutting down the PC (may not be this user if Switch User was used):
    echo -ne "User who shutdown PC (may not be this user if Switch User has been used): " >> /home/fitzcarraldo/backup.log
    last | cut -d " " -f1 | head -1 >> /home/fitzcarraldo/backup.log
    sleep 2s
    # To backup the directories and files I prefer to use the following cp command rather than rsync:
    cp --recursive --update --preserve=all --no-dereference --force /home/ /media/usbhdd/Lubuntu_home_folders_backup 2>> /home/fitzcarraldo/backup.log
    echo "Copying completed" >> /home/fitzcarraldo/backup.log
    date >> /home/fitzcarraldo/backup.log
    echo "********** Backup completed **********" >> /home/fitzcarraldo/backup.log
    cp /home/fitzcarraldo/backup.log /media/usbhdd/Lubuntu_home_folders_backup/home/fitzcarraldo/
    # Unmount the USB HDD so that udisks2 can subsequently re-mount it with the user's username in the path:  
    umount /media/usbhdd
fi
exit 0

The Bash script unmounts the external USB HDD and mounts it to /media/usbhdd before performing a backup. This is done because the Udisks daemon (udisksd) automounts the HDD at login to a mountpoint /home/<username>/<label>  (e.g. ‘/home/fitzcarraldo/FREECOM HDD‘ when I log in, ‘/home/claudia/FREECOM HDD‘ when user claudia logs in, and so on).

systemd unit file

I created a file /etc/systemd/system/backup-to-usb-hdd.service owned by the root user, with the following permissions and contents:

fitzcarraldo@aspirexc600:~$ ls -la /etc/systemd/system/backup-to-usb-hdd.service 
-rw-r--r-- 1 root root 274 Jan  8 17:51 /etc/systemd/system/backup-to-usb-hdd.service
[Unit]
Description=Backup home directories of all users to USB HDD
DefaultDependencies=no
Before=shutdown.target halt.target
RequiresMountsFor=/home

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/backup_home_directories.sh

[Install]
WantedBy=halt.target shutdown.target

Then I enabled the unit file as follows:

fitzcarraldo@aspirexc600:~$ sudo systemctl enable backup-to-usb-hdd.service
Created symlink /etc/systemd/system/halt.target.wants/backup-to-usb-hdd.service → /etc/systemd/system/backup-to-usb-hdd.service.
Created symlink /etc/systemd/system/shutdown.target.wants/backup-to-usb-hdd.service → /etc/systemd/system/backup-to-usb-hdd.service.
fitzcarraldo@aspirexc600:~$

Reboot (or shutdown and restart) to launch it.

The log file

The log file /home/fitzcarraldo/backup.log looked like the following after shutting down a couple of times:

********** Backing up Acer Aspire XC600 users' home directories **********
Mon  8 Jan 21:07:05 GMT 2018
User who shutdown PC (may not be this user if Switch User has been used): fitzcarraldo
Copying completed
Mon  8 Jan 21:07:32 GMT 2018
********** Backup completed **********
********** Backing up Acer Aspire XC600 users' home directories **********
Mon  8 Jan 21:15:31 GMT 2018
User who shutdown PC (may not be this user if Switch User has been used): fitzcarraldo
Copying completed
Mon  8 Jan 21:15:48 GMT 2018
********** Backup completed **********

Whenever the system is rebooted by any user, nothing is appended to the log file. As desired, entries are only appended to the log file when the system is shutdown by any user.

Manually initiated backups

An added benefit is that any user in the sudo group can run the Bash script from the command line at any time to backup without having to shutdown the PC, as illustrated below:

claudia@aspirexc600:~$ cat /home/fitzcarraldo/backup.log 
********** Backing up Acer Aspire XC600 users' home directories **********
Mon  8 Jan 21:07:05 GMT 2018
User who shutdown PC (may not be this user if Switch User has been used): fitzcarraldo
Copying completed
Mon  8 Jan 21:07:32 GMT 2018
********** Backup completed **********
********** Backing up Acer Aspire XC600 users' home directories **********
Mon  8 Jan 21:15:31 GMT 2018
User who shutdown PC (may not be this user if Switch User has been used): fitzcarraldo
Copying completed
Mon  8 Jan 21:15:48 GMT 2018
********** Backup completed **********
claudia@aspirexc600:~$ date && sudo backup_home_directories.sh
Tue  9 Jan 01:57:50 GMT 2018
[sudo] password for claudia:
claudia@aspirexc600:~$ cat /home/fitzcarraldo/backup.log 
********** Backing up Acer Aspire XC600 users' home directories **********
Mon  8 Jan 21:07:05 GMT 2018
User who shutdown PC (may not be this user if Switch User has been used): fitzcarraldo
Copying completed
Mon  8 Jan 21:07:32 GMT 2018
********** Backup completed **********
********** Backing up Acer Aspire XC600 users' home directories **********
Mon  8 Jan 21:15:31 GMT 2018
User who shutdown PC (may not be this user if Switch User has been used): fitzcarraldo
Copying completed
Mon  8 Jan 21:15:48 GMT 2018
********** Backup completed **********
********** Backing up Acer Aspire XC600 users' home directories **********
Tue  9 Jan 01:57:54 GMT 2018
User who shutdown PC (may not be this user if Switch User has been used): claudia
Copying completed
Tue  9 Jan 01:58:10 GMT 2018
********** Backup completed **********
claudia@aspirexc600:~$

Running a shell script at shutdown only (not at reboot) – a comparison between OpenRC and systemd

Gentoo Linux on my laptops uses OpenRC with SysVinit, whereas Lubuntu 17.10 on my family’s PC uses systemd. I have had to configure both Linux distributions to run a backup job at shutdown, so I thought it would be interesting to summarise the two approaches.

OpenRC

Create a Bash script /etc/local.d/10-run_on_shutdown.stop with the following contents:

#!/bin/bash
if [ `who -r | awk '{print $2}'` = "0" ]; then
    ########################################################################
    # Put Bash commands here to be executed on shutdown but not on reboot. #
    # For example, backup home directories to an external USB HDD.         #
    ########################################################################
fi

From now on the script will run to completion when you shutdown the machine, but not when you reboot it.

systemd

1. Create a Bash script /usr/local/sbin/run_on_shutdown.sh with the following contents:

#!/bin/bash
REBOOT=$( systemctl list-jobs | egrep -q 'reboot.target.*start' && echo "rebooting" || echo "not_rebooting" )
if [ $REBOOT = "not_rebooting" ]; then
    ########################################################################
    # Put Bash commands here to be executed on shutdown but not on reboot. #
    # For example, backup home directories to an external USB HDD.         #
    ########################################################################
fi

2. Create a unit file /etc/systemd/system/run_on_shutdown.service with the following contents:

[Unit]
Description=Run a Bash script at shutdown
DefaultDependencies=no
Before=shutdown.target halt.target
# If your script requires any mounted directories, add them below: 
RequiresMountsFor=/home

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/run_on_shutdown.sh

[Install]
WantedBy=halt.target shutdown.target

I have assumed the Bash script is to backup /home, so change the directory list in ‘RequiresMountsFor=‘ if the script necessitates that other directories are still mounted – see ‘man systemd.unit‘ for details.

3. Enable the unit file and start the service as follows:

user $ sudo systemctl enable run_on_shutdown.service
user $ sudo reboot

From now on, the script will run to completion when you shutdown the machine, but not when you reboot it.

Notes on the systemd solution:

There are plenty of posts on the Web suggesting how to run a script at shutdown in installations that use systemd, but the approaches either do not work in my case or they do not discriminate between shutting down and rebooting. For example, if you are wondering why I do not use ‘Conflicts=reboot.target‘ in the unit file, I found it does not prevent the Bash script from being launched when the system is rebooted (see the entry for ‘Conflicts=‘ in ‘man systemd.unit‘ for the functionality). If you are wondering why I do not simply place a script in /lib/systemd/system-shutdown/, it is because scripts in that directory are launched late in the shutdown process, after file systems have been mounted read-only. And if you are wondering why the Bash script tests if the system is rebooting (as distinct from shutting down) rather than the unit file being configured to do that, it is because the systemd shutdown target is active in any type of system termination, be it rebooting or halting, and it therefore does not help in discriminating between the termination types (see ‘man systemd.special‘). I tried several approaches in the unit file to see if it could be made to launch a Bash script when shutting down but not when rebooting, but the only solution that works for me in the Lubuntu 17.10 installation on my family’s PC uses the two files listed above working in conjunction with each other.

Furthermore, of all the unit files I found on the Web that actually make systemd launch a Bash script when a user initiates shutdown, only one of them prevents systemd from shutting down the machine before a time-consuming script has run to completion (for example a script to backup to an external HDD).

Some background reading

  1. Easy Systemd Startup and Shutdown Scripts for Ubuntu 16.04 and Mint 18
  2. Stack Exchange Super User : How do I run a script before everything else on shutdown with systemd?
  3. Stack Overflow : how can a systemd controlled service distinguish between shutdown and reboot?
  4. Unix & Linux Stack Exchange : Systemd : How to execute script at shutdown only (not at reboot)

Bye bye Windows 10, and good riddance

Up until a couple of days ago my family’s PC, an Acer Aspire XC600 tower purchased in early 2014, had Microsoft Windows 10 Home (64-bit) installed. Because of a problem updating Windows 10 which finally rendered the PC unbootable and the OS unrecoverable, I installed Lubuntu 17.10 (64-bit). It is performing very well and my family are finding it easy to use. Although I had no intention of installing Linux on this machine before the problem updating Windows arose, I’m now glad to be rid of Windows on this machine, as Windows has been a pain to use and maintain.

The Windows update saga

When I bought the Aspire XC600 in February 2014 it came with Windows 8 pre-installed, and I immediately upgraded it to Windows 8.1. I say ‘immediately’, but it actually took me three days to get Windows Update to install it properly; the first attempts resulted in what looked like Windows 8.1 but turned out to be incomplete installations, and several times I had to roll back to a Restore Point and try to update again.

I upgraded the machine to Windows 10 Home when Microsoft offered it free-of-charge to current users of Windows 8.1 and Windows Update informed me the update was available to install. The early Windows 10 Home was buggy, but various updates by Microsoft eventually got it to a reasonably stable state by the time the so-called ‘Anniversary Update’ (Windows 10 Version 1607) was released in 2016. I again had to struggle for several days before I managed to update Windows 10 Home to Version 1607.

In April 2017 Microsoft released the ‘Creators Update’, and in October 2017 the ‘Fall Creators Update’. However, no matter what I did it was simply impossible to upgrade Window 10 Home Version 1607 on the Aspire XC600 to either of those 2017 updates. There are hundreds if not thousands of posts on the Web regarding problems installing these updates on various PC models from various manufacturers, with similar or even identical symptoms to those I was seeing. In my case the update process froze at 33%, 75% and 83%, despite Microsoft’s update utility informing me that the CPU, RAM size and HDD free space were valid for these updates. Furthermore, I only tried to update once Windows Update had informed me the updates were available to install. I should also point out that I regularly made sure the OS had all other updates installed.

I lost count of the number of times and hours spent trying to update to the Creators Update and the Fall Creators Update. Each time I had a go at updating, after two consecutive attempts Windows 10 Home would give up and, when I eventually cycled the mains power in order to exit the frozen state, would roll back to Version 1607. However, during my latest attempt a couple of days ago, Windows 10 Home would no longer complete booting, instead popping up a window informing me the machine needed to be rebooted to complete the installation process. Every time I clicked ‘OK’ in the window, the machine would reboot and the same window popped up again. So I dug out the Windows 10 Home Recovery Disk (actually a USB pendrive) I had carefully created as soon as I had upgraded the installation from Windows 8.1 to Windows 10 in November 2016. (That pendrive had previously been the Windows 8.1 Recovery Disk that I created as soon as I upgraded the installation to Windows 8.1 in February 2014.) But, no matter what I did, the Recovery Disk would only re-install Windows 8, even though the time-date stamp of the files on the pendrive corresponded to the date on which I created the Windows 10 Recovery Disk. And, strangely, there were three so-called Recovery Partitions on the HDD.

Several attempts to re-install using the Recovery Disk had the same outcome, so I decided to install a couple of Linux binary distributions in succession, both of which worked fine and definitely removed all traces of Windows from the HDD, including the three Recovery Partitions (I checked using GParted to make sure). Then I tried again to re-install Windows 10 Home from the Recovery Disk, but it still created three Recovery Partitions and still installed Windows 8.

Clearly it was not going to be possible to re-install Windows 10 Home using the Recovery Disk, so I instead used Windows Update in Windows 8 to update the installation to Windows 8.1, a process that took several hours and reboots. Once Windows 8.1 was installed, I tried to upgrade to Window 10, first using Windows Update and, when that told me there were no updates, by using the Recovery Disk. Neither approach was successful, so I was stuck with a working, fully-updated Windows 8.1. The trouble was, Windows 8.1 is no longer supported by Microsoft (‘Mainstream Support End Date’ is 9 January 2018). Not to mention that Windows 8.1 is even worse than Windows 10.

The move to Linux

At this point I’d had more than enough of Microsoft Windows. Therefore I used my laptop to download the ISO for Lubuntu 17.10 and create a LivePendrive, and I installed Lubuntu on the Aspire XC600. Although I use a source-based Linux distribution on two laptops, for ease and speed of installation and maintenance I opted to install a binary-based distribution on the family PC. I chose Lubuntu specifically because it uses the LXDE desktop environment, which is closer in look and feel to classic Windows than e.g. the Unity or GNOME desktop environments in Ubuntu, and is not as ‘CPU-hungry’ as KDE. I found that Lubuntu worked extremely well out-of-the-box, including scanning and printing using my Canon MP510 MFP. I used the GUI Software utility (‘System Tools’ > ‘Software’ from the LXDE application menu) to uninstall AbiWord and Gnumeric and install the LibreOffice suite. I added user accounts for the members of my family (‘System Tools’ > ‘Users and Groups’). Since the machines on my home network use SMB to share files, I installed samba and sambaclient and edited the smb.conf file via the command line, and browsing SMB shares worked first time. We have a decent family PC again.

There was not much more for me to do to make the installation behave exactly how I wanted it to:

  • I configured the installation so that each user’s avatar appears on the login screen (LightDM GTK Greeter).
  • I have an external USB HDD permanently connected to the PC so that users’ files can be backed up. I configured the installation to unmount automatically this external USB HDD when any user logs out. The USB HDD is automatically mounted anyway when another user logs in, and, by unmounting it automatically at logout, the next user can access the USB HDD properly via the GUI File Manager (the USB drive is mounted as /media/<username>/FREECOM HDD).
  • I installed Language Support so that I can switch to some other languages I use, and I configured LXDE so I can click on an icon on the panel (or use a keyboard shortcut) to switch between the associated keyboard layouts.
  • I installed the anti-virus utility ClamAV, the ClamAV daemon and the ClamTk GUI front-end, and configured the installation to scan automatically any files downloaded to each user’s ~/Downloads directory, and to quarantine infected files and notify the user via a pop-up window and log file.
  • I configured the installation to create a network route when I log in, so that I can access in a Web browser the GoAccess dashboard for database reports produced by my network server.
  • I configured the installation to backup the files in each user’s ~/home directory to an external USB HDD at shutdown (impossible in Windows 10 Home — see my comments further on).
  • I installed Skype Preview for Linux, which worked out-of-the-box with a GUCEE HD92 HD 720p USB Webcam with built-in microphone.

I intend to explain in future posts how I implemented each of the above.

Backing up users’ files at shutdown

Windows XP and Vista on my family’s previous PCs were able to run a batch file (BACKUP.BAT) automatically at shutdown to backup the users’ files to an external USB HDD (and, crucially, to wait until the batch job was completed before powering down the PC). To achieve this I used the utility Xecutor by Xpertdesign Software, which enabled users to use the normal Windows method of shutting down yet allowed the batch file to run to completion. However, such utilities do not work in Windows 8 and onwards. A kludge that is often suggested is to add an extra button on the Desktop or Taskbar to run the backup commands then shutdown the machine afterwards, but I did not want to do that because there is no guarantee my family would click on it rather than shutting down Windows the normal way.

Another method of configuring Windows to run a batch file at shutdown is to use the GPE (Group Policy Editor) a.k.a. GPOE (Group Policy Object Editor) to configure the Registry. However, Windows 10 Home does not include the GPE, so I was unable to use the GPE to configure Windows 10 Home to run a batch file to backup users’ files to an external USB HDD at shutdown. (Actually, as Windows 8/8.1/10 makes it almost impossible to interrupt the shutdown process once the user has initiated shutdown, I wonder if a backup batch file would actually run to completion if the GPE were used in an edition of Windows that provides it, such as Windows 10 Enterprise.) It is possible to configure the Task Scheduler in Windows 10 Home to run a batch file at shutdown, but it is impossible to pause the shutdown process to allow the backup batch file to run to completion. Believe me, I tried everything, and it is impossible to backup automatically all users’ files for multiple user accounts at shutdown with Windows 10 Home (even though it was possible in Windows XP). So I had to resort to a kludge recommended by Microsoft, which is to configure the Task Scheduler to run the batch file at startup instead of shutdown. Clearly this is less safe than backing up before shutting down the PC.

Actually, it is possible to install/enable the GPE in Windows 10 Home — there are many Web sites explaining how to do this — but Microsoft has restricted many GPOs (Group Policy Objects) in Windows 10 Home, and therefore adding a GPO using the GPE or by editing the Registry directly in Windows 10 Home will have no effect. Even if you enable the GPE in Windows 10 Home, the policies will not work until you buy a licence for the Windows 10 Pro or Enterprise editions. In summary, in Windows 10 Home it is a waste of time either installing/enabling the GPE or editing the Registry directly.

However, now that Lubuntu 17.10 is installed I was able to configure it to run a Bash script automatically to backup all the users’ files before the machine actually actually shuts down or reboots. In a future post I’ll explain how I achieved that.

Summary

In my opinion Microsoft jumped the shark a long time ago. I had plenty of trouble with Windows Vista (to the extent I had to ditch it in the end), but Windows 7 was not bad (although on a couple of occasions I had a big scare with ‘Windows Backup and Restore’ that necessitated restoring the MBR via the command line). Windows 8 and 8.1 were awful, and Windows 10 is not much better in my opinion. Furthermore, I think it is very bad form for Microsoft to release updates to Windows 10 that cannot be installed on a machine that is only four years old and still has a reasonable specification: 64-bit Intel Pentium G2030 @ 3.00GHz, 4GB DDR3 RAM (upgradable to 8GB), Intel HD Graphics (Xeon E3-1200 v2/3rd Gen), and 1TB 7200RPM HDD. I’m now glad Windows 10 is history on this PC and I’m typing this in a Linux installation.

Moving to the slotted WINE package system in Gentoo Linux

Earlier this year the Gentoo Linux developers responsible for maintaining the package app-emulation/wine decided to split it and slot it so that different versions of WINE can be installed and co-exist simultaneously:

clevow230ss fitzcarraldo # eselect news read 34
2017-04-10-split-and-slotted-wine
  Title                     app-emulation/wine split and slotting
  Author                    NP-Hardass 
  Posted                    2017-04-10
  Revision                  1

Starting with Wine 2.0, Wine in Gentoo is transitioning away from its
traditional packaging and toward a new, split and slotted, Wine.

As many Wine users know, there are often regressions or an application
works better on one version of wine than another.  Going forward, 
packaging in Gentoo will allow simultaneous installation of multiple
versions of Wine.

Additionally, to expedite vanilla releases as well as permit multiple
configurations for each Wine installation, the major patchsets have
been split out into separate packages.

Going forward, app-emulation/wine will transition to:
app-emulation/wine-vanilla: upstream Wine with no external patchsets
             (like if the old packaging forced USE="-staging -d3d9")
app-emulation/wine-staging: Wine with Wine-Staging's patchset
             (like if the old packaging forced USE="+staging -d3d9")
app-emulation/wine-d3d9: Wine with Ixit's Gallium Nine patchset
             (like if the old packaging forced USE="-staging +d3d9")
app-emulation/wine-any: Wine with any of the patchsets or flags
             (exactly like the old packaging regarding USE flags)

wine-any exists to allow the user to build any combination that they'd
like (like the old packaging).  This means the user could use wine-any
to use both Wine-Staging and Gallium Nine.  Alternatively, the user
could use wine-any to try out another configuration from other
packages.  For example, the user could build wine-vanilla without
PulseAudio, and could build wine-any with PulseAudio.  The sky is the
limit on how a user may choose to use app-emulation/wine-any.

Users may opt for any specific package, or may emerge virtual/wine,
which is provided for dependency resolution.
Maintainers: Please note, app-emulation/wine will be dropped, so
please use virtual/wine going forward.

Users may call each version specifically, or may call a symlink based
on their installed patchset, for example wine-2.1, wine-staging-2.2,
or wine-d3d9.

Symlinks for wine are managed with app-eselect/eselect-wine.
# eselect wine set wine-vanilla-2.0
/usr/bin/wine -> /usr/bin/wine-vanilla-2.0
# eselect wine set --staging wine-staging-2.4
/usr/bin/wine-staging -> /usr/bin/wine-staging-2.4

Earlier this year the Gentoo Linux Forums thread ‘wine: questions on recent changes‘ discussed the new system and how to use it. Several users, myself included, posted questions in that thread asking how to go about the change. I received differing advice and remained uncertain about what to do. At the time, the slotted packages for the new system had not yet been unmasked, so I left my installation as it was and decided to put off making the change for as long as possible. Today when I synchronised my installation with the Portage tree there was a Gentoo Linux news item ‘2017-11-21 Old Wine versions moving to wine-overlay’. So the time had come for me to make the switch from app-emulation/wine-2.3 to the new slotted WINE package system. Here is what I did…

Previous situation

I had been using WINE Staging:

clevow230ss fitzcarraldo # eix -I wine
[?] app-emulation/wine
     Available versions:  [M]2.0^t [M](~)2.1^t [M](~)2.2^t [M](~)2.3^t [M]**9999^t {+X +alsa capi cups custom-cflags d3d9 dos +fontconfig +gecko gphoto2 gsm gstreamer +jpeg +lcms ldap +mono mp3 ncurses netapi nls odbc openal opencl +opengl osmesa oss pcap +perl pipelight +png prelink pulseaudio +realtime +run-exes s3tc samba scanner selinux +ssl staging test themes +threads +truetype udev +udisks v4l vaapi +xcomposite xinerama +xml ABI_MIPS="n32 n64 o32" ABI_PPC="32 64" ABI_S390="32 64" ABI_X86="(+)32 (+)64 x32" ELIBC="glibc" KERNEL="FreeBSD" LINGUAS="ar bg ca cs da de el en en_US eo es fa fi fr he hi hr hu it ja ko lt ml nb_NO nl or pa pl pt_BR pt_PT rm ro ru sk sl sr_RS@cyrillic sr_RS@latin sv te th tr uk wa zh_CN zh_TW"}
     Installed versions:  2.3^t(19:16:31 20/05/17)(X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl staging threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -d3d9 -dos -gstreamer -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -pipelight -prelink -s3tc -samba -selinux -test -themes -vaapi -xinerama ABI_MIPS="-n32 -n64 -o32" ABI_PPC="-32 -64" ABI_S390="-32 -64" ABI_X86="32 64 -x32" ELIBC="glibc" KERNEL="-FreeBSD" LINGUAS="en pt_BR -ar -bg -ca -cs -da -de -el -en_US -eo -es -fa -fi -fr -he -hi -hr -hu -it -ja -ko -lt -ml -nb_NO -nl -or -pa -pl -pt_PT -rm -ro -ru -sk -sl -sr_RS@cyrillic -sr_RS@latin -sv -te -th -tr -uk -wa -zh_CN -zh_TW")
     Homepage:            https://www.winehq.org/
     Description:         Free implementation of Windows(tm) on Unix

[I] app-emulation/winetricks
     Available versions:  20170823^t **99999999^t {gtk kde rar}
     Installed versions:  20170823^t(02:50:56 06/09/17)(gtk kde -rar)
     Homepage:            https://github.com/Winetricks/winetricks https://wiki.winehq.org/Winetricks
     Description:         Easy way to install DLLs needed to work around problems in Wine

Found 2 matches

The file /etc/portage/package.accept_keywords/wine in my installation included the following line:

app-emulation/wine ~amd64

The file /etc/portage/package.use/wine in my installation included the following line:

app-emulation/wine -ldap -pipelight staging abi_x86_32

New situation

The file /etc/portage/package.accept_keywords/wine in my installation now includes the lines listed below. The reason why I had to include app-emulation/wine-vanilla is explained further on.

virtual/wine ~amd64
app-emulation/wine-staging ~amd64
app-emulation/wine-vanilla ~amd64

The file /etc/portage/package.use/wine in my installation now includes the lines listed below. The reason why I had to include app-emulation/wine-vanilla is explained further on.

virtual/wine -d3d9 staging abi_x86_32
app-emulation/wine-staging X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl staging threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -d3d9 -dos -gstreamer -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -pipelight -prelink -s3tc -samba -selinux -test -themes -vaapi -xinerama abi_x86_32
app-emulation/wine-vanilla X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl staging threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -d3d9 -dos -gstreamer -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -pipelight -prelink -s3tc -samba -selinux -test -themes -vaapi -xinerama abi_x86_32

(Note that e.g. the pipelight USE flag does not actually exist in the package app-emulation/wine-vanilla, but it does no harm to include “-pipelight” in the line for app-emulation/wine-vanilla in the file package.use.)

After adding the above-mentioned lines to the two files, I then had to uninstall the masked package app-emulation/wine-2.3 and the package app-emulation/winetricks-20170823 that depended on it:

clevow230ss fitzcarraldo # emerge -aC app-emulation/wine app-emulation/winetricks

Then I had to install the package virtual/wine, which pulled in the package app-emulation/wine-staging as I wanted, but also pulled in the package app-emulation/vanilla:

clevow230ss fitzcarraldo # emerge -a virtual/wine

Then I had to select wine-staging:

clevow230ss fitzcarraldo # eselect wine list
clevow230ss fitzcarraldo # eselect wine set

Finally, I had to install winetricks, which would now use the selected slotted package:

clevow230ss fitzcarraldo # emerge winetricks

How I arrived at the contents of package.accept_keywords and package.use

Note that, before I added the line for app-emulation/wine-vanilla to /etc/portage/package.use/wine and /etc/portage/package.accept_keywords/wine, this is what Portage wanted to install:

clevow230ss fitzcarraldo # emerge -p virtual/wine

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] app-emulation/wine-gecko-2.47-r1  ABI_X86="32 (64)" 
[ebuild  N     ] app-emulation/wine-desktop-common-20150204 
[ebuild  N     ] app-eselect/eselect-wine-1.2.2 
[ebuild   R    ] net-nds/openldap-2.4.44  ABI_X86="32*" 
[ebuild  N     ] app-emulation/wine-vanilla-2.0.2  USE="X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms ldap mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -dos -gstreamer -mono -netapi -odbc -opencl -osmesa -oss -pcap -prelink -samba (-selinux) {-test} -xinerama" ABI_X86="32 64 (-x32)" LINGUAS="en pt_BR -ar -bg -ca -cs -da -de -el -en_US -eo -es -fa -fi -fr -he -hi -hr -hu -it -ja -ko -lt -ml -nb_NO -nl -or -pa -pl -pt_PT -rm -ro -ru -sk -sl -sr_RS@cyrillic -sr_RS@latin -sv -te -th -tr -uk -wa -zh_CN -zh_TW" 
[ebuild  N    ~] app-emulation/wine-staging-2.19  USE="X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl (staging) threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -dos -gstreamer -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -pipelight -prelink -s3tc -samba (-selinux) {-test} -themes -vaapi -xinerama" ABI_X86="32 64 (-x32)" LINGUAS="en pt_BR -ar -bg -ca -cs -da -de -el -en_US -eo -es -fa -fi -fr -he -hi -hr -hu -it -ja -ko -lt -ml -nb_NO -nl -or -pa -pl -pt_PT -rm -ro -ru -sk -sl -sr_RS@cyrillic -sr_RS@latin -sv -te -th -tr -uk -wa -zh_CN -zh_TW" 
[ebuild  N    ~] virtual/wine-0-r6  USE="staging -d3d9" ABI_X86="32 64" 

The following USE changes are necessary to proceed:
 (see "package.use" in the portage(5) man page for more details)
# required by app-emulation/wine-vanilla-2.0.2::gentoo[ldap]
# required by virtual/wine-0-r6::gentoo
# required by virtual/wine (argument)
>=net-nds/openldap-2.4.44 abi_x86_32
# required by app-emulation/wine-vanilla-2.0.2::gentoo[gecko]
# required by virtual/wine-0-r6::gentoo
# required by virtual/wine (argument)
>=app-emulation/wine-gecko-2.47-r1 abi_x86_32

!!! The following installed packages are masked:
- dev-qt/qtwebkit-4.8.7::gentoo (masked by: package.mask)
/usr/portage/profiles/package.mask:
# Andreas Sturmlechner  (16 Nov 2017)
# Qt4WebKit is ancient and full of security holes.
# Masked for removal in 30 days. Bug #620684

For more information, see the MASKED PACKAGES section in the emerge
man page or refer to the Gentoo Handbook.

clevow230ss fitzcarraldo #

After I added a line for app-emulation/wine-vanilla to /etc/portage/package.use/wine and /etc/portage/package.accept_keywords/wine, this is what Portage wanted to do:

clevow230ss fitzcarraldo # emerge -p virtual/wine                        

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] app-emulation/wine-gecko-2.47-r1  ABI_X86="32 (64)" 
[ebuild  N     ] app-eselect/eselect-wine-1.2.2 
[ebuild  N     ] app-emulation/wine-desktop-common-20150204 
[ebuild  N    ~] app-emulation/wine-vanilla-2.20  USE="X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -dos -gstreamer -kerberos -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -prelink -samba (-selinux) {-test} -xinerama" ABI_X86="32 64 (-x32)" LINGUAS="en pt_BR -ar -bg -ca -cs -da -de -el -en_US -eo -es -fa -fi -fr -he -hi -hr -hu -it -ja -ko -lt -ml -nb_NO -nl -or -pa -pl -pt_PT -rm -ro -ru -sk -sl -sr_RS@cyrillic -sr_RS@latin -sv -te -th -tr -uk -wa -zh_CN -zh_TW" 
[ebuild  N    ~] app-emulation/wine-staging-2.19  USE="X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl (staging) threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -dos -gstreamer -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -pipelight -prelink -s3tc -samba (-selinux) {-test} -themes -vaapi -xinerama" ABI_X86="32 64 (-x32)" LINGUAS="en pt_BR -ar -bg -ca -cs -da -de -el -en_US -eo -es -fa -fi -fr -he -hi -hr -hu -it -ja -ko -lt -ml -nb_NO -nl -or -pa -pl -pt_PT -rm -ro -ru -sk -sl -sr_RS@cyrillic -sr_RS@latin -sv -te -th -tr -uk -wa -zh_CN -zh_TW" 
[ebuild  N    ~] virtual/wine-0-r6  USE="staging -d3d9" ABI_X86="32 64" 

The following USE changes are necessary to proceed:
 (see "package.use" in the portage(5) man page for more details)
# required by app-emulation/wine-vanilla-2.20::gentoo[gecko]
# required by virtual/wine-0-r6::gentoo
# required by virtual/wine (argument)
>=app-emulation/wine-gecko-2.47-r1 abi_x86_32
clevow230ss fitzcarraldo #

So I added the above-mentioned USE change for app-emulation/wine-gecko to /etc/portage/package.use/wine, and then Portage wanted to do the following:

clevow230ss fitzcarraldo # emerge -p virtual/wine

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] app-emulation/wine-gecko-2.47-r1  ABI_X86="32 (64)" 
[ebuild  N     ] app-eselect/eselect-wine-1.2.2 
[ebuild  N     ] app-emulation/wine-desktop-common-20150204 
[ebuild  N    ~] app-emulation/wine-vanilla-2.20  USE="X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -dos -gstreamer -kerberos -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -prelink -samba (-selinux) {-test} -xinerama" ABI_X86="32 64 (-x32)" LINGUAS="en pt_BR -ar -bg -ca -cs -da -de -el -en_US -eo -es -fa -fi -fr -he -hi -hr -hu -it -ja -ko -lt -ml -nb_NO -nl -or -pa -pl -pt_PT -rm -ro -ru -sk -sl -sr_RS@cyrillic -sr_RS@latin -sv -te -th -tr -uk -wa -zh_CN -zh_TW" 
[ebuild  N    ~] app-emulation/wine-staging-2.19  USE="X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl (staging) threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -dos -gstreamer -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -pipelight -prelink -s3tc -samba (-selinux) {-test} -themes -vaapi -xinerama" ABI_X86="32 64 (-x32)" LINGUAS="en pt_BR -ar -bg -ca -cs -da -de -el -en_US -eo -es -fa -fi -fr -he -hi -hr -hu -it -ja -ko -lt -ml -nb_NO -nl -or -pa -pl -pt_PT -rm -ro -ru -sk -sl -sr_RS@cyrillic -sr_RS@latin -sv -te -th -tr -uk -wa -zh_CN -zh_TW" 
[ebuild  N    ~] virtual/wine-0-r6  USE="staging -d3d9" ABI_X86="32 64" 
clevow230ss fitzcarraldo #

I was happy with that, so I went ahead without the --pretend option:

clevow230ss fitzcarraldo # emerge -a virtual/wine

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild  N     ] app-emulation/wine-gecko-2.47-r1  ABI_X86="32 (64)" 
[ebuild  N     ] app-eselect/eselect-wine-1.2.2 
[ebuild  N     ] app-emulation/wine-desktop-common-20150204 
[ebuild  N    ~] app-emulation/wine-vanilla-2.20  USE="X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -dos -gstreamer -kerberos -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -prelink -samba (-selinux) {-test} -xinerama" ABI_X86="32 64 (-x32)" LINGUAS="en pt_BR -ar -bg -ca -cs -da -de -el -en_US -eo -es -fa -fi -fr -he -hi -hr -hu -it -ja -ko -lt -ml -nb_NO -nl -or -pa -pl -pt_PT -rm -ro -ru -sk -sl -sr_RS@cyrillic -sr_RS@latin -sv -te -th -tr -uk -wa -zh_CN -zh_TW" 
[ebuild  N    ~] app-emulation/wine-staging-2.19  USE="X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl (staging) threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -dos -gstreamer -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -pipelight -prelink -s3tc -samba (-selinux) {-test} -themes -vaapi -xinerama" ABI_X86="32 64 (-x32)" LINGUAS="en pt_BR -ar -bg -ca -cs -da -de -el -en_US -eo -es -fa -fi -fr -he -hi -hr -hu -it -ja -ko -lt -ml -nb_NO -nl -or -pa -pl -pt_PT -rm -ro -ru -sk -sl -sr_RS@cyrillic -sr_RS@latin -sv -te -th -tr -uk -wa -zh_CN -zh_TW" 
[ebuild  N    ~] virtual/wine-0-r6  USE="staging -d3d9" ABI_X86="32 64" 

Would you like to merge these packages? [Yes/No] Yes
>>> Verifying ebuild manifests
>>> Running pre-merge checks for app-emulation/wine-vanilla-2.20
>>> Running pre-merge checks for app-emulation/wine-staging-2.19
>>> Emerging (1 of 6) app-emulation/wine-gecko-2.47-r1::gentoo
>>> Emerging (2 of 6) app-eselect/eselect-wine-1.2.2::gentoo
>>> Installing (1 of 6) app-emulation/wine-gecko-2.47-r1::gentoo
>>> Installing (2 of 6) app-eselect/eselect-wine-1.2.2::gentoo
>>> Emerging (3 of 6) app-emulation/wine-desktop-common-20150204::gentoo
>>> Installing (3 of 6) app-emulation/wine-desktop-common-20150204::gentoo
>>> Emerging (4 of 6) app-emulation/wine-vanilla-2.20::gentoo
>>> Emerging (5 of 6) app-emulation/wine-staging-2.19::gentoo
>>> Installing (4 of 6) app-emulation/wine-vanilla-2.20::gentoo
>>> Installing (5 of 6) app-emulation/wine-staging-2.19::gentoo
>>> Emerging (6 of 6) virtual/wine-0-r6::gentoo
>>> Installing (6 of 6) virtual/wine-0-r6::gentoo
>>> Recording virtual/wine in "world" favorites file...
>>> Jobs: 6 of 6 complete                           Load avg: 6.80, 7.34, 7.06
>>> Auto-cleaning packages...

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

 * GNU info directory index is up-to-date.
clevow230ss fitzcarraldo # eselect wine list
Available wine versions:
  [1]   wine-staging-2.19
  [2]   wine-vanilla-2.20 *
clevow230ss fitzcarraldo # eselect wine set 1
clevow230ss fitzcarraldo # eselect wine list
Available wine versions:
  [1]   wine-staging-2.19 *
  [2]   wine-vanilla-2.20
clevow230ss fitzcarraldo # emerge app-emulation/winetricks
Calculating dependencies... done!
>>> Verifying ebuild manifests
>>> Emerging (1 of 1) app-emulation/winetricks-20170823::gentoo
>>> Installing (1 of 1) app-emulation/winetricks-20170823::gentoo
>>> Recording app-emulation/winetricks in "world" favorites file...
>>> Jobs: 1 of 1 complete                           Load avg: 0.51, 2.78, 5.09
>>> Auto-cleaning packages...

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

 * GNU info directory index is up-to-date.
clevow230ss fitzcarraldo #

Summary

So, in summary, this is what I did in order to install and use app-emulation/wine-staging:

1. Add the following lines to /etc/portage/package.accept_keywords/wine:

virtual/wine ~amd64
app-emulation/wine-staging ~amd64
app-emulation/wine-vanilla ~amd64

2. Add the following lines to /etc/portage/package.use/wine:

virtual/wine -d3d9 staging abi_x86_32
app-emulation/wine-staging X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl staging threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -d3d9 -dos -gstreamer -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -pipelight -prelink -s3tc -samba -selinux -test -themes -vaapi -xinerama abi_x86_32
app-emulation/wine-vanilla X alsa cups fontconfig gecko gphoto2 gsm jpeg lcms mp3 ncurses nls openal opengl perl png pulseaudio realtime run-exes scanner ssl staging threads truetype udev udisks v4l xcomposite xml -capi -custom-cflags -d3d9 -dos -gstreamer -ldap -mono -netapi -odbc -opencl -osmesa -oss -pcap -pipelight -prelink -s3tc -samba -selinux -test -themes -vaapi -xinerama abi_x86_32
# required by app-emulation/wine-vanilla-2.20::gentoo[gecko]
# required by virtual/wine-0-r6::gentoo
>=app-emulation/wine-gecko-2.47-r1 abi_x86_32

3. Uninstall the old, un-slotted WINE packages:

root # emerge -aC app-emulation/wine app-emulation/winetricks

4. Merge the new virtual WINE package:

root # emerge -a virtual/wine

5. Select the slotted WINE package I wish to use (WINE Staging):

root # eselect wine list
root # eselect wine set wine-staging-2.19

6. Merge the winetricks package, which will now recognise the slotted WINE package selected:

root # emerge app-emulation/winetricks

After completing the above process, I was still able to launch as before the various Microsoft Windows applications installed on my laptop under WINE.

UPDATE (December 1, 2017): As explained by user Chiltoo in a new post in the Gentoo Linux Forums thread mentioned earlier in the above post, a bug in Portage Version 2.3.13-r1 results in app-emulation/wine-vanilla being installed unnecessarily, as borne out in my post above.

The work-around he proposed does indeed work for me. Below are the commands I have just used for the work-around (I have left the new entries I made in package.accept_keywords and package.use in those files):

clevow230ss fitzcarraldo # emerge -aC app-emulation/wine-vanilla app-emulation/wine-staging virtual/wine app-emulation/wine-desktop-common app-emulation/wine-gecko app-eselect/eselect-wine app-emulation/winetricks
clevow230ss fitzcarraldo # emerge -1 app-emulation/wine-staging && emerge virtual/wine && emerge winetricks

The outcome of the above two commands in my case is:

clevow230ss fitzcarraldo # eix --installed --compact wine
[I] app-emulation/wine-desktop-common (20150204@01/12/17): Various desktop menu items and icons for wine
[I] app-emulation/wine-gecko (2.47-r1(2.47)@01/12/17): A Mozilla Gecko based version of Internet Explorer for Wine
[I] app-emulation/wine-staging (2.19(2.19)@01/12/17): Free implementation of Windows(tm) on Unix, with Wine-Staging patchset
[I] app-emulation/winetricks (20170823@01/12/17): Easy way to install DLLs needed to work around problems in Wine
[I] app-eselect/eselect-wine (1.2.2@01/12/17): Manage active wine version
[I] virtual/wine (0-r6@01/12/17): Virtual for Wine that supports multiple variants and slotting
Found 6 matches
clevow230ss fitzcarraldo # eselect wine list
Available wine versions:
  [1]   wine-staging-2.19 *
clevow230ss fitzcarraldo #

The superfluous app-emulation/wine-vanilla is no longer installed, which is a cleaner outcome.

Prevent Linux firewalls interfering with Samba commands in a home network that uses broadcast NetBIOS name resolution

Or “How come devices in a home network can browse SMB shares but Linux Samba commands and Windows nbtstat commands do not work properly?”

Introduction

In a previous post I explained how it is possible to browse SMB shares when using broadcast NetBIOS name resolution in a home network consisting of machines running Linux, Windows and other operating systems. Browsing SMB/Samba shares will work as expected, but Samba commands such as ‘smbtree‘, ‘smbclient‘ and ‘nmblookup‘ will not work properly if the Linux machines use a firewall that has not been configured for broadcast NetBIOS name resolution. This post is to explain how to do that.

If broadcast NetBIOS name resolution is being used and none of the Linux machines has a firewall enabled, or if their firewalls have been correctly configured, the output of e.g. the ‘smbtree‘ command on one of those machines would look something like the example below.

anne@akhanaten:~$ smbtree
Enter anne's password: 
HOME
        \\AKHANATEN                     Samba 4.3.11-Ubuntu
                \\AKHANATEN\IPC$                IPC Service (Samba 4.3.11-Ubuntu)
                \\AKHANATEN\guest               guest account
                \\AKHANATEN\matthew             matthew share
                \\AKHANATEN\marilla             marilla share
                \\AKHANATEN\anne                anne share
        \\TUTANKHAMUN                   Samba 4.5.10
                \\TUTANKHAMUN\Samsung_Xpress_C460FW     Samsung Xpress C460FW
                \\TUTANKHAMUN\Canon_MP560_Printer       Canon PIXMA MP560
                \\TUTANKHAMUN\Canon_MP510_Printer       Canon PIXMA MP510
                \\TUTANKHAMUN\Virtual_PDF_Printer       Virtual PDF Printer
                \\TUTANKHAMUN\IPC$              IPC Service (Samba 4.2.11)
                \\TUTANKHAMUN\Public
                \\TUTANKHAMUN\anne-share
                \\TUTANKHAMUN\print$
                \\TUTANKHAMUN\netlogon          Network Logon Service
        \\BTHUB5                        BT Home Hub 5.0A File Server
                \\BTHUB5\IPC$                   IPC Service (BT Home Hub 5.0A File Server)
        \\THUTMOSEIII                   Windows 10 computer

If Linux firewalls have not been correctly configured, the output would be missing some information about other machines in the network. For example, compare the output above with the output below from the same network, this time with the Linux firewalls configured using typical rules for Samba specified in Web articles, blog posts and forums.

anne@akhanaten:~$ smbtree
Enter anne's password: 
HOME
        \\AKHANATEN                     Samba 4.3.11-Ubuntu
                \\AKHANATEN\IPC$                IPC Service (Samba 4.3.11-Ubuntu)
                \\AKHANATEN\guest               guest account
                \\AKHANATEN\matthew             matthew share
                \\AKHANATEN\marilla             marilla share
                \\AKHANATEN\anne                anne share
        \\TUTANKHAMUN                   Samba 4.5.10
        \\BTHUB5                        BT Home Hub 5.0A File Server
        \\THUTMOSEIII                   Windows 10 computer

To avoid this problem you need to add a further Linux firewall rule to the set of rules usually used for Samba. Below I first list the usual firewall rules for Samba, then I give the additional rule necessary if using broadcast NetBIOS name resolution. In each case I give the applicable rules for a pure IPTABLES firewall and for UFW (Uncomplicated Firewall). The rules listed here assume the IP address range of the home network is 192.168.1.0/24, so change the range to suit the specific network.

Firewall rules typically specified for machines using Samba

IPTABLES

The rules listed below assume the machine uses interface eth0, so change the interface to suit the specific machine.

# NetBIOS Name Service (name resolution)
iptables -A INPUT -i eth0 -p udp --dport 137 -s 192.168.1.0/24 -j ACCEPT

# NetBIOS Datagram Service (BROWSER service)
iptables -A INPUT -i eth0 -p udp --dport 138 -s 192.168.1.0/24 -j ACCEPT

# NetBIOS Session Service (data transfer legacy SMB/NetBIOS/TCP)
iptables -A INPUT -i eth0 -p tcp --dport 139 -s 192.168.1.0/24 -j ACCEPT

# Microsoft Directory Service (data transfer SMB/TCP)
iptables -A INPUT -i eth0 -p tcp --dport 445 -s 192.168.1.0/24 -j ACCEPT

UFW

In some Linux distributions the ufw application allows a single command to add Samba support, such as:

user $ sudo ufw allow Samba

or

user $ sudo ufw allow CIFS

These ‘application profiles’ are specified in files in the directory /etc/ufw/applications.d/, so you could add application profiles or modify existing ones if you wish. In one of my installations the file /etc/ufw/applications.d/ufw-fileserver includes the following application profile for Samba, for example:

[CIFS]
title=SMB/CIFS server
description=SMB/CIFS server
ports=137,138/udp|139,445/tcp

If such an application profile does not exist in your installation, typical Samba rules can be added in UFW using the following two commands:

user $ sudo ufw allow from 192.168.1.0/24 to any port 137,138 proto udp
user $ sudo ufw allow from 192.168.1.0/24 to any port 139,445 proto tcp

The correct addition of the rules can be checked using the following command:

user $ sudo ufw status verbose
Password:
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
137,138/udp (CIFS)         ALLOW IN    192.168.1.0/24
139,445/tcp (CIFS)         ALLOW IN    192.168.1.0/24

The extra rule required when using broadcast NetBIOS name resolution

The reason why an extra rule is required when using broadcast NetBIOS name resolution is because UFW (which is based on IPTABLES) is ‘stateful’, as is a purely IPTABLES firewall (unless explicitly configured not to be stateful). The firewall does not consider packets it receives in response to its broadcast to be ESTABLISHED or RELATED, and therefore drops those packets. So, despite the IPTABLES and UFW rules listed above including a rule to accept incoming UDP packets on Port 137, any UDP packets received on Port 137 that do not constitute a one-to-one, two-way communication flow are dropped by the firewall. The extra rule below overrules this and makes the firewall accept packets coming from other devices’ Port 137 in response to broadcast NetBIOS Name Service packets. To do this, the extra rule uses a CT (Connection Tracking) helper named ‘netbios-ns‘ (obviously meaning ‘NetBIOS Name Service’). In order to use this rule the kernel must have been configured to use the IPTABLES ‘raw‘ table and to use CT (see the section ‘Kernel configuration’ further on).

IPTABLES

# All NetBIOS clients must have the netbios-ns helper enabled for broadcast name resolution to work
iptables -t raw -A OUTPUT -p udp -m udp --dport 137 -j CT --helper netbios-ns

By the way, in addition to flushing the usual tables, flush the ‘raw‘ table too when you restart the firewall:

iptables -t raw -F OUTPUT

UFW

Add the following lines to the end of the file /etc/ufw/before.rules

# The following is needed to enable Samba commands to
# work properly for broadcast NetBIOS name resolution
#
# raw table rules
*raw
:OUTPUT ACCEPT [0:0]
-F OUTPUT
-A OUTPUT -p udp -m udp --dport 137 -j CT --helper netbios-ns
COMMIT

Note that the output of the command ‘ufw status verbose‘ will not include the above rule. This is not a bug.

Kernel configuration

If you are using a binary-based distribution such as Ubuntu Linux, the kernel will probably have been configured to include the needed modules (CONFIG_IP_NF_RAW=m, CONFIG_IP6_NF_RAW=m and CONFIG_NETFILTER_XT_TARGET_CT=m), and the installation configured to load the modules automatically. However, if you are using a source-based distribution such as Gentoo Linux make sure the kernel configuration includes these three options before you build the kernel, and also add the module names ‘iptable_raw‘ and ‘xt_CT‘ to the module list in the file /etc/conf.d/modules as shown in the example below, so that the modules are loaded at boot:

modules="r8169 nvidia agpgart fuse bnep rfcomm hidp uvcvideo cifs mmc_block rtsx_pci snd-seq-midi vboxdrv vboxnetadp vboxnetflt iptable_raw xt_CT"

You can use the following two commands to check if the two modules are loaded:

user $ sudo lsmod | grep iptable_raw
user $ sudo lsmod | grep xt_CT

How to check the additional rule is active

You can use the command below whether you are using pure IPTABLES or UFW.

user $ sudo iptables -nvL -t raw
Password: 
Chain PREROUTING (policy ACCEPT 2613 packets, 1115K bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 2773 packets, 475K bytes)
 pkts bytes target     prot opt in     out     source               destination         
   16  1248 CT         udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:137 CT helper netbios-ns

The packet and byte counts will increase whenever you use a Samba command.

Bibliography

  1. The netfilter.org "iptables" project
  2. Iptables Tutorial
  3. Introduction to IPTables
  4. Gentoo Wiki : iptables
  5. Arch Linux Wiki : Samba : "Browsing" network fails with "Failed to retrieve share list from server"
  6. Ubuntu : Manpage : ufw-framework
  7. Gentoo Wiki : UFW

Dealing with the kernel image and kernel source code in Sabayon Linux

Some Sabayon Linux users do not know the particulars of the Linux kernel installation or how to upgrade the kernel image. A recent post by a new user in the Sabayon Linux Forums illustrates this (translated from the German):

I’m just setting up my first sabayon box.

In the manual you should see which kernel is selected with:

eselect kernel list

But this is empty for me:

(not found)

When installing one or other packages I also already have a corresponding error message. What am I doing wrong?

The command ‘eselect kernel list‘ lists the versions of kernel source code currently installed (directories such as /usr/src/linux-4.8.17-sabayon/, /usr/src/linux-4.9.38-sabayon/ or whatever) and indicates to which kernel source code directory the symlink /usr/src/linux/ is currently pointing (see Kernel/Configuration – Set symlink in the Gentoo Linux Wiki).

My guess is that this user wanted to rebuild the kernel image. Anyway, the situation in Sabayon Linux he described occurs as a result of either not having installed the kernel source code or not having installed the version of kernel source code corresponding to the version of the installed kernel image.

Before I go into detail on how to do the above, it is essential to understand the basics of the Entropy package management system and how to maintain a sane installation in Sabayon Linux. You should regularly: a) update the local database containing a list of available packages and their versions; b) upgrade installed packages to their latest available version; c) check and fix dependencies and libraries; d) remove any old versions of installed packages:

root # equo update
root # equo upgrade
root # equo conf update
root # equo deptest
root # equo libtest
root # equo upgrade --purge
root # equo cleanup

Do not blindly enter the above commands if you do not know what they do; first read the explanations in the list of equo functions in the Sabayon Linux Wiki.

I have found that sometimes the command ‘equo upgrade --purge‘ does not report all the packages that have to be removed manually. I therefore repeat the command a few times until no more packages are listed for removal.

Right, now let’s look at why the aforementioned Sabayon Linux user was in trouble…

If you happen to have the directory /boot on a separate partition to / (root) and you specified in the file /etc/fstab that /boot should not be mounted automatically when the machine boots, do not forget to mount the boot partition first.

I would see the same message as the aforementioned Sabayon Linux user if the kernel image and source code were not set up correctly in my Sabayon Linux installation:

sabayon fitzcarraldo # eselect kernel list
Available kernel symlink targets:
  (none found)
sabayon fitzcarraldo #

Obviously a kernel image must be present, so first let’s check which version of the kernel image package is installed:

sabayon fitzcarraldo # equo search --installed linux-sabayon
╠  @@ Searching...
╠      @@ Package: sys-kernel/linux-sabayon-4.8.17 branch: 5, [__system__]
╠          Installed:     version: 4.8.17 ~ tag: NoTag ~ revision: 0
╠          Slot:          4.8
╠          Homepage:      https://github.com/Sabayon/kernel
╠          Description:   Official Sabayon Linux Standard
╠                         kernel image
╠          License:       GPL-2 freedist
╠   Keywords:  linux-sabayon
╠   Found:     1 entry
sabayon fitzcarraldo #

As you can see above, Version 4.8.17 of the kernel image package was installed in my case.

Note that the kernel source code is not installed by default in Sabayon Linux, so my guess is that the aforementioned user didn’t have the kernel source code installed. Here’s how to find out which version of the kernel source code package is installed, if any:

sabayon fitzcarraldo # equo search --installed sabayon-sources
╠  @@ Searching...
╠      @@ Package: sys-kernel/sabayon-sources-4.11.10 branch: 5, [__system__]
╠          Installed:     version: 4.11.10 ~ tag: NoTag ~ revision: 0
╠          Slot:          4.11
╠          Homepage:      https://github.com/Sabayon/kernel
╠          Description:   Official Sabayon Linux Standard
╠                         kernel sources
╠          License:       GPL-2 freedist
╠   Keywords:  sabayon-sources
╠   Found:     1 entry
sabayon fitzcarraldo #

As you can see above, in my case I had previously installed Version 4.11.10 of the kernel source code, and it didn’t correspond to the kernel image in use.

If you want to rebuild the kernel, you also need to have the linux kernel headers installed, and those are not installed by default in Sabayon Linux, so let’s check if that package is already installed while we’re at it:

sabayon fitzcarraldo # equo search --installed linux-headers
╠  @@ Searching...
╠      @@ Package: sys-kernel/linux-headers-4.4 branch: 5, [__system__]
╠          Installed:     version: 4.4 ~ tag: NoTag ~ revision: 0
╠          Slot:          0
╠          Homepage:      https://www.kernel.org/
╠                         https://www.gentoo.org/
╠          Description:   Linux system headers
╠          License:       GPL-2
╠   Keywords:  linux-headers
╠   Found:     1 entry
sabayon fitzcarraldo #

As you can see above, in my case I had previously installed Version 4.4 of the linux kernel headers. However, if you don’t already have the package installed, install it:

sabayon fitzcarraldo # equo install linux-headers
╠  @@ Calculating dependencies...
╠  ## [R] [sabayon-weekly] sys-kernel/linux-headers-4.4|0   [4.4|0]
╠  @@ Packages needing to be installed/updated/downgraded: 1
╠  @@ Packages needing to be removed: 0
╠  @@ Download size: 937.6kB
╠  @@ Freed disk space: 0.0b
╠  @@ You need at least: 1.9MB of free space
╠  ::: >>>  (1/1) 1 package
╠    ## Downloading: 1 package
╠    ## ( mirror #1 ) [sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2] @ http://na.mirror.garr.it
╠   ## Aggregated download: 1 item
╠    # [1] na.mirror.garr.it => sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2
╠    ## Checking package checksum...
╠       : [sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2] GPG validated
╠       : SHA1 disabled
╠       : [sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2] SHA256 validated
╠       : SHA512 disabled
╠    ## ( mirror #1 ) [sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2] success @ http://na.mirror.garr.it
╠    ##  Aggregated transfer rate: 1.3MB/second
╠  +++ >>>  (1/1) sys-kernel/linux-headers-4.4
╠    ## Unpacking: sys-kernel:linux-headers-4.4.150ec398796671a9b475328e5ae3f180b9b096c3~0.tbz2
╠    ## Package phase: setup
╠    ## Package phase: preinstall
╠    ## Installing package: sys-kernel/linux-headers-4.4
╠    ## [Linux system headers]
╠    ## Updating installed packages repository: sys-kernel/linux-headers-4.4
╠    ## Cleaning previously installed application data.
╠    ## Package phase: postremove
╠    ## Package phase: postinstall
╠    ## Cleaning: sys-kernel/linux-headers-4.4
╠  @@ Installation complete.
╠  @@ No configuration files to update.
sabayon fitzcarraldo #

To make sure you have the latest versions of the packages sys-kernel/linux-sabayon (the kernel image) and sys-kernel/sabayon-sources (the kernel source code), install the packages as follows:

sabayon fitzcarraldo # equo install linux-sabayon sabayon-sources
╠  @@ Calculating dependencies...
╠  ## [N] [sabayon-weekly] sys-kernel/linux-sabayon-4.11.10|0
╠  ## [R] [sabayon-weekly] sys-kernel/sabayon-sources-4.11.10|0   [4.11.10|0]
╠  @@ Packages needing to be installed/updated/downgraded: 2
╠  @@ Packages needing to be removed: 0
╠  @@ Download size: 198.9MB
╠  @@ Used disk space: 211.3MB
╠  @@ You need at least: 609.1MB of free space
╠  ::: >>>  (1/1) 2 packages
╠    ## Downloading: 2 packages
╠    ## ( mirror #1 ) [sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2] @ http://na.mirror.garr.it
╠    ## ( mirror #1 ) [sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2] @ http://na.mirror.garr.it
╠   ## Aggregated download: 2 items
╠    # [1] na.mirror.garr.it => sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2
╠    # [2] na.mirror.garr.it => sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2
╠    ## Checking package checksum...
╠       : [sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2] GPG validated
╠       : SHA1 disabled
╠       : [sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2] SHA256 validated
╠       : SHA512 disabled
╠    ## Checking package checksum...
╠       : [sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2] GPG validated
╠       : SHA1 disabled
╠       : [sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2] SHA256 validated
╠       : SHA512 disabled
╠    ## ( mirror #1 ) [sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2] success @ http://na.mirror.garr.it
╠    ## ( mirror #1 ) [sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2] success @ http://na.mirror.garr.it
╠    ##  Aggregated transfer rate: 3.7MB/second
╠  +++ >>>  (1/2) sys-kernel/linux-sabayon-4.11.10
╠    ## Unpacking: sys-kernel:linux-sabayon-4.11.10.1f22c24cc709872f47d62d3c9e44af879fe18888~0.tbz2
╠    ## Package phase: setup
 * To avoid automounting and auto(un)installing with /boot,
 * just export the DONT_MOUNT_BOOT variable.

 * Your boot partition was detected as being mounted at /boot.
 * Files will be installed there for linux-sabayon to function correctly.
 * Preparing kernel and its modules
╠    ## Package phase: preinstall

 * Your boot partition was detected as being mounted at /boot.
 * Files will be installed there for linux-sabayon to function correctly.
╠    ## Installing package: sys-kernel/linux-sabayon-4.11.10
╠    ## [Official Sabayon Linux Standard kernel image]
╠    ## Updating installed packages repository: sys-kernel/linux-sabayon-4.11.10
╠    ## Package phase: postinstall
 * Removing extents option for ext4 drives from /etc/fstab
Generating grub configuration file ...
Found background: /boot/grub/default-splash.png
Found linux image: /boot/kernel-genkernel-x86_64-4.11.0-sabayon
Found initrd image: /boot/initramfs-genkernel-x86_64-4.11.0-sabayon
Found linux image: /boot/kernel-genkernel-x86_64-4.8.0-sabayon
Found initrd image: /boot/initramfs-genkernel-x86_64-4.8.0-sabayon
done

 * You are currently booting with kernel:
 * kernel-genkernel-x86_64-4.8.0-sabayon
 *
 * Use 'eselect bzimage' in order to switch between the available ones


 * If you are upgrading from a previous kernel, you may be interested
 * in the following document:
 *   - General upgrade guide: https://wiki.gentoo.org/wiki/Kernel/Upgrade

 * Updating module dependencies for 4.11.0-sabayon ...
depmod: WARNING: Ignored deprecated option -r                                                                                                                                                                                               [ ok ]
 * Please report kernel bugs at:
 * http://bugs.sabayon.org
 * The source code of this kernel is located at
 * =sys-kernel/sabayon-sources-4.11.10.
 * Sabayon Linux recommends that portage users install
 * sys-kernel/sabayon-sources-4.11.10 if you want
 * to build any packages that install kernel modules
 * (such as ati-drivers, nvidia-drivers, virtualbox, etc...).
╠    ## Cleaning: sys-kernel/linux-sabayon-4.11.10
╠  +++ >>>  (2/2) sys-kernel/sabayon-sources-4.11.10
╠    ## Unpacking: sys-kernel:sabayon-sources-4.11.10.bd94789f59b1e0b33118e122a23a0164c7205b8a~0.tbz2
╠    ## Package phase: setup
 * To avoid automounting and auto(un)installing with /boot,
 * just export the DONT_MOUNT_BOOT variable.

 * Your boot partition was detected as being mounted at /boot.
 * Files will be installed there for sabayon-sources to function correctly.
 * Preparing kernel and its modules
╠    ## Package phase: preinstall
╠    ## Installing package: sys-kernel/sabayon-sources-4.11.10
╠    ## [Official Sabayon Linux Standard kernel sources]
╠    ## Updating installed packages repository: sys-kernel/sabayon-sources-4.11.10
╠    ## Package phase: preremove
╠    ## Cleaning previously installed application data.
╠    ## Package phase: postremove
╠    ## Package phase: postinstall

 * If you are upgrading from a previous kernel, you may be interested
 * in the following document:
 *   - General upgrade guide: https://wiki.gentoo.org/wiki/Kernel/Upgrade

╠    ## Cleaning: sys-kernel/sabayon-sources-4.11.10
╠  @@ Installation complete.
╠  @@ No configuration files to update.
sabayon fitzcarraldo #

Now upgrade the OS installation to the latest kernel image and reboot the machine so that the new kernel image is loaded:

sabayon fitzcarraldo # kernel-switcher switch linux-sabayon-4.11.10
sabayon fitzcarraldo # reboot

Check that the new kernel version is running:

sabayon fitzcarraldo # uname -a
Linux sabayon.local 4.11.0-sabayon #1 SMP Sat Jul 15 09:33:23 UTC 2017 x86_64 Intel(R) Pentium(R) CPU G2030 @ 3.00GHz GenuineIntel GNU/Linux
sabayon fitzcarraldo #

The minor in the version number reported by the uname command does not necessarily correspond to the minor in the version number of the kernel image package. This is not an error: see Misunderstandings about the kernel in the Sabayon Wiki regarding this apparent discrepancy.

The symlink to the kernel source code will now exist:

sabayon fitzcarraldo # eselect kernel list
Available kernel symlink targets:
  [1]   linux-4.11.0-sabayon *
sabayon fitzcarraldo #

If everything works correctly, you can uninstall the earlier version(s) of the kernel image package:

sabayon fitzcarraldo # equo search --installed linux-sabayon
sabayon fitzcarraldo # equo remove linux-sabayon-4.8.17

In my case an earlier version of the kernel source code package was not installed, but if one had been then I would have uninstalled that package too:

sabayon fitzcarraldo # equo search --installed sabayon-sources
sabayon fitzcarraldo # equo remove sabayon-sources-4.8.17

You can also remove old kernel image files manually from the /boot directory if they were not removed automatically:

sabayon fitzcarraldo # ls /boot
sabayon fitzcarraldo # rm -i /boot/*genkernel-x86_64-4.8.0-sabayon

Regenerate the file grub.cfg so that the GRUB 2 menu at boot only lists the kernel images actually present in the /boot directory:

sabayon fitzcarraldo # grub-mkconfig -o /boot/grub/grub.cfg

If you’re running Sabayon Linux inside a VirtualBox virtual machine, you’ll also need to install in the guest installation the correct version of the VirtualBox Guest Additions for the new version of the kernel you just installed in the guest installation. Uninstall the old version if it has not already been uninstalled automatically, then search for the version that corresponds to the kernel you installed in the guest installation:

sabayon fitzcarraldo # equo remove virtualbox-guest-additions
sabayon fitzcarraldo # equo search virtualbox-guest-additions
sabayon fitzcarraldo # equo install virtualbox-guest-additions-5.1.22#4.11.0-sabayon

xdotool comes to the rescue

In a previous post I explained how I implemented a method for adding my current location and the local time to my e-mail signature wherever I happen to be in the World, irrespective of the time on the laptop’s hardware clock and system clock. In that post I described how I created a keyboard shortcut using the Linux application AutoKey. Unfortunately AutoKey has not been updated for several years and no longer works properly in KDE Plasma 5 on my laptops. Therefore I decided to replace it with a KDE keyboard shortcut, and this is to explain how I did it.

First create a custom shortcut in KDE:

  1. ‘System Settings’ > ‘Shortcuts’ > ‘Custom Shortcuts’
  2. ‘Edit’ > ‘New’ > ‘Global Shortcut’ > ‘Command/URL’, and name the New Action ‘Insert current time’
  3. On the Comment pane for ‘Insert current time’, add the comment ‘Insert current time at specified location’ (without the quotes)
  4. On the Trigger pane, configure the shortcut to be Ctrl+Alt+Space
  5. On the Action pane, enter the Command/URL as ‘/home/fitzcarraldo/timezone_signature_GeoNames.sh‘ (without the quotes)
  6. Click ‘Apply’

Next modify the Bash script timezone_signature_GeoNames.sh so that it contains the following (obviously change the username and path to suit):

#!/bin/bash

place=$(kdialog --title "Current Location" --inputbox "Enter your location:")

placetime=$(perl /home/fitzcarraldo/now1.pl $place)

# xdotool does not output a space in a string, so we have to extract each field from the string
# and print each field individually, separated by a space character.

city=$(echo $placetime | awk -F "|" '{print $1}')
country=$(echo $placetime | awk -F "|" '{print $2}' | sed 's/[)(]//g')
region=$(echo $placetime | awk -F "|" '{print $4}')

datetime=$(/usr/bin/zdump $region | awk -F " " '{print $2" "$3" "$4" "$5" "$6" "$7}')
dayofweek=$(echo $datetime | awk -F " " '{print $1}')
month=$(echo $datetime | awk -F " " '{print $2}')
day=$(echo $datetime | awk -F " " '{print $3}')
time=$(echo $datetime | awk -F " " '{print $4}')
year=$(echo $datetime | awk -F " " '{print $5}')
timezone=$(echo $datetime | awk -F " " '{print $6}')

activewindow=$(xdotool getactivewindow)

xdotool type --window $activewindow "Sent from:"
for oneword in $city; do
    xdotool key --window $activewindow space
    sleep 0.1s
    xdotool type --window $activewindow --delay 100 $oneword
done
xdotool key --window $activewindow comma
for oneword in $country; do
    xdotool key --window $activewindow space
    sleep 0.1s
    xdotool type --window $activewindow --delay 100 $oneword
done
xdotool key --window $activewindow Return
xdotool type --window $activewindow "Local time now: "
xdotool type --window $activewindow $dayofweek
xdotool type --window $activewindow " "
xdotool type --window $activewindow $month
xdotool type --window $activewindow " "
xdotool type --window $activewindow $day
xdotool type --window $activewindow " "
xdotool type --window $activewindow $time
xdotool type --window $activewindow " "
xdotool type --window $activewindow $year
xdotool type --window $activewindow " "
if [ ${timezone:0:1} = "-" ]; then
    timezone="UTC-"${timezone#*-}
elif [ ${timezone:0:1} = "+" ]; then
    timezone="UTC+"${timezone#*+}
fi
xdotool type --window $activewindow $timezone
xdotool type --window $activewindow " "
xdotool key --window $activewindow Return
xdotool key --window $activewindow Return
echo

The Perl script now1.pl is listed in my my earlier post. Notice that the script timezone_signature_GeoNames.sh in my earlier post was much simpler. This was because the AutoKey shortcut took care of sending the text to the currently active window. Without AutoKey, I now had to do this myself in the script timezone_signature_GeoNames.sh, and the command xdotool came to the rescue. The developer explains what xdotool does as follows:

This tool lets you simulate keyboard input and mouse activity, move and resize windows, etc. It does this using X11’s XTEST extension and other Xlib functions.

Additionally, you can search for windows and move, resize, hide, and modify window properties like the title. If your window manager supports it, you can use xdotool to switch desktops, move windows between desktops, and change the number of desktops.

So I installed xdotool via the Gentoo package manager:

# emerge xdotool
# eix xdotool
[I] x11-misc/xdotool
     Available versions:  3.20150503.1-r1^t ~3.20160805.1^t {examples}
     Installed versions:  3.20150503.1-r1^t(22:51:30 02/04/17)(-examples)
     Homepage:            http://www.semicomplete.com/projects/xdotool/
     Description:         Simulate keyboard input and mouse activity, move and resize windows

Anyway, my Bash script using xdotool works a treat with Thunderbird (and KWrite, LibreOffice Writer, etc.). I used to experience a problem with certain characters, for example a colon was printed as a semi-colon (see the xdotool bug report xdotool writes the wrong case #121), but that no longer happens in my current KDE Plasma 5 installation:

Sent from: Galeão International Airport, Brazil
Local time now: Thu Jul 6 15:11:40 2017 UTC-03

What a useful tool xdotool is!

Stuttering audio in Linux: PulseAudio strikes again

I unmasked PulseAudio 10.0 back in January 2017 and installed it in my Gentoo Stable amd64 installation, and everything worked fine… until a couple of days ago, when the audio in streaming YouTube videos started to stutter every so often. It sounded rather like a scratched LP jumping. At first I thought the problem lay with Firefox, but the stuttering audio also occurred in Chrome. Then I wondered if my Internet connection was to blame; perhaps the ISP’s service had deteriorated. But a Windows 10 machine on my home network didn’t suffer from the problem, so that seemed to rule out the Internet connection. I tested the broadband throughput, and it was circa 32 Mbps, actually a little higher than the last time I tested it last year.

Now, Gentoo is a rolling distribution and I update my laptops regularly, but I couldn’t think what had been upgraded in the last couple of months that could be causing the problem. Although PulseAudio had not been upgraded since January, I began to wonder if PulseAudio could be involved, as my audio woes in the past have usually been due to PulseAudio.

I have always had PulseAudio installed with USE=”-realtime”:

user $ eix -I pulseaudio
[I] media-sound/pulseaudio
     Available versions:  10.0 {+X +alsa +alsa-plugin +asyncns bluetooth +caps dbus doc equalizer +gdbm +glib gnome gtk ipv6 jack libressl libsamplerate lirc native-headset neon ofono-headset +orc oss qt4 realtime selinux sox ssl system-wide systemd tcpd test +udev +webrtc-aec zeroconf ABI_MIPS="n32 n64 o32" ABI_PPC="32 64" ABI_S390="32 64" ABI_X86="32 64 x32"}
     Installed versions:  10.0(16:07:53 19/04/17)(X alsa alsa-plugin asyncns bluetooth caps dbus gdbm glib gnome gtk ipv6 jack orc qt4 ssl tcpd udev webrtc-aec zeroconf -doc -equalizer -libressl -libsamplerate -lirc -native-headset -neon -ofono-headset -oss -realtime -selinux -sox -system-wide -systemd -test ABI_MIPS="-n32 -n64 -o32" ABI_PPC="-32 -64" ABI_S390="-32 -64" ABI_X86="32 64 -x32")
     Homepage:            http://www.pulseaudio.org/
     Description:         A networked sound server with an advanced plugin system

but I wondered if PulseAudio’s real-time scheduling was somehow the cause of the problem, so I edited /etc/pulse/daemon.pa and added ‘realtime-scheduling = no‘ (I assume the default is ‘yes‘, as it was commented as such in the file):

; realtime-scheduling = yes
realtime-scheduling = no

Problem solved. PulseAudio is indeed a demon. 😡