Removing PipeWire in Gentoo Linux

PipeWire, all the rage these days, was originally developed for video but was later enhanced to support audio as well, and is now an alternative to PulseAudio and JACK. My laptop running Gentoo Stable (amd64) with the KDE Plasma Desktop had been working fine with PipeWire for some time. The pulseaudio and screencast USE flags were both declared in the file /etc/portage/make.conf. Both audio playback and recording worked fine until a recent upgrade of the packages in my world file, when neither worked any more. The Audio Volume loudspeaker icon (the applet kde-plasma/plasma-pa) on the KDE Plasma panel had a red line through it, and the KMix loudspeaker icon (the applet kde-apps/kmix) on the panel was greyed out. Although I cannot be sure, I suspect the problem started when the first version of PipeWire that supported audio was released. The output of the command ‘ps -ef | grep pulse‘ showed me that both PulseAudio and PipeWire were running. At the time I did not know that PulseAudio is not supposed to be running at the same time as PipeWire. Sometimes when I booted the laptop and logged in, the loudspeaker icons on the Panel would appear correctly and audio output would work properly, but usually this was not the case. This behaviour made me wonder if there was some sort of race condition between the two applications at startup.

Anyway, I stopped PulseAudio being launched automatically at startup. I did this by editing the file /etc/pulse/client.conf to add the line ‘autospawn = no‘ (a comment in the as-installed file indicates that the default value for autospawn is ‘yes‘). That did indeed stop PulseAudio from being launched automatically, and left only PipeWire running. The loudspeaker icons were then displayed correctly on the Panel when I logged in to the KDE Plasma Desktop, and audio output then worked. However, PipeWire did not detect the laptop’s built-in microphone, and no Recording channel was displayed by KMix and Audio Volume. The troubleshooting chapter of the Arch Linux Wiki article on PipeWire has a section suggesting a couple of fixes for this problem (Microphone is not detected by PipeWire) but, even so, I decided to ditch PipeWire and revert to PulseAudio. As much as I dislike PulseAudio (see some of my previous posts on the various problems I have experienced with it), these days it is more or less stable on this laptop and I do not have to mess around too much with audio settings.

A few KDE packages in Gentoo Linux depend on PipeWire (they require the screencast USE flag to be set). I therefore added the following two entries to a file in the directory /etc/portage/package.use/ in order to stop PipeWire being required:

>=sys-apps/xdg-desktop-portal-1.8.1 -screencast
>=kde-apps/krfb-20.12.3 -wayland

I was then able to use the usual command ‘emerge -uvDN @world‘, followed by the command ‘emerge --ask --depclean‘, to rebuild the affected packages and remove PipeWire. I also deleted the line ‘autospawn = no‘ that I had previously added to the file /etc/pulse/client.conf, so that PulseAudio would again be launched automatically at startup. Audio playback and recording are now back to normal. I will probably try PipeWire again in the future but, for the moment, I don’t need it. According to the Gentoo Linux Wiki article on PipeWire:

Warning
As of mid 2021, PipeWire is still in active development and not everything is fully integrated, tested, or implemented – though the project is moving along. While replacing existing audio solutions on Gentoo is possible, the experience is currently not guaranteed to be perfect or free of issues and bugs.

I will therefore wait until the concensus amongst Gentoo Linux users is that PipeWire is trouble-free before I try it again.

Trouble again with PulseAudio and Thunderbird sound notifications

In an earlier post I described how I fixed a scratchy-sounding sound file which the Thunderbird e-mail client plays when a new message arrives. Well, the problem started again recently, but this time the contents of /etc/pulse/daemon.conf looked OK to me. Furthermore, the sound file sounds fine when played using following commands:

aplay ~/Music/wav/E-mail_notifications/halmsg.wav
paplay ~/Music/wav/E-mail_notifications/halmsg.wav
mplayer ~/Music/wav/E-mail_notifications/halmsg.wav
cvlc ~/Music/wav/E-mail_notifications/halmsg.wav

Now, Thunderbird uses libcanberra to play sounds, so I began to wonder if the problem lay with libcanberra. As it happens, libcanberra is maintained by the same person who invented PulseAudio. However, I notice from the libcanberra Git repository that its source code has not been changed since 2012.

My Gentoo Linux installation had libcanberra installed with support for both ALSA and PulseAudio:

root # eix -I libcanberra
[I] media-libs/libcanberra
     Available versions:  0.30-r5 {alsa gnome gstreamer +gtk +gtk3 oss pulseaudio +sound tdb udev ABI_MIPS="n32 n64 o32" ABI_PPC="32 64" ABI_S390="32 64" ABI_X86="32 64 x32"}
     Installed versions:  0.30-r5(08:27:41 18/05/18)(alsa gtk gtk3 pulseaudio sound udev -gnome -gstreamer -oss -tdb ABI_MIPS="-n32 -n64 -o32" ABI_PPC="-32 -64" ABI_S390="-32 -64" ABI_X86="32 64 -x32")
     Homepage:            http://git.0pointer.net/libcanberra.git/
     Description:         Portable sound event library

So, even though my installation uses PulseAudio, I decided to try and re-install libcanberra without PulseAudio support, only ALSA support:

root # USE="-pulseaudio" emerge -1v libcanberra
root # eix -I libcanberra
[I] media-libs/libcanberra
     Available versions:  0.30-r5 {alsa gnome gstreamer +gtk +gtk3 oss pulseaudio +sound tdb udev ABI_MIPS="n32 n64 o32" ABI_PPC="32 64" ABI_S390="32 64" ABI_X86="32 64 x32"}
     Installed versions:  0.30-r5(15:47:14 26/05/18)(alsa gtk gtk3 sound udev -gnome -gstreamer -oss -pulseaudio -tdb ABI_MIPS="-n32 -n64 -o32" ABI_PPC="-32 -64" ABI_S390="-32 -64" ABI_X86="32 64 -x32")
     Homepage:            http://git.0pointer.net/libcanberra.git/
     Description:         Portable sound event library

Lo and behold, Thunderbird (libcanberra) plays the sound file correctly now. So I have added the following line to my file /etc/portage/package.use/thunderbird in order to make the change permanent:

media-libs/libcanberra -pulseaudio

PulseAudio 🙄

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. 😡

Another look at beeps in Linux

Following my previous post I experimented further with the Linux Kernel configuration options for event beeps (sometimes called ‘system beeps’), and I now have a better understanding of how the Kernel options interact (on one of my laptops, at least).

The sound card in my Clevo W230SS laptop has a VIA VT1802S audio codec chip. I looked at the audio circuit schematic in the service manual; one of the digital input pins on the VT1802S is labelled ‘PCBEEP’, and one of its analogue output pins is labelled ‘PCBEEP’ and is connected to the laptop’s speaker circuit. So there is no PC Speaker in this laptop and it emulates the PC Speaker via the laptop’s sound card, as mentioned in my previous post.

Before I describe my latest results, there are a couple of influencing factors I forgot to mention in my previous post:

  • In some computers the BIOS Menu has one or more options for enabling/disabling beeps. The BIOS menu of my Clevo laptop does not have an option to enable/disable all beeps from the (emulated) PC Speaker, but it does have a couple of options to enable/disable ‘Power On Boot Beep’ and ‘Battery Low Alarm Beep’ (I have disabled them both). Anyway, if you are still not getting beeps after trying everything else, be sure to check the BIOS menu just in case it has an option to enable/disable the PC Speaker.

  • Make sure that bell-style is not set to ‘none‘ (you could set it to ‘audible‘ if you wanted to be sure):

    root # grep bell /etc/inputrc
    # do not bell on tab-completion
    #set bell-style none

The Kernel configuration was initially as shown below. With this configuration no beeps were emitted in a VT (Virtual Terminal) or in an X Windows terminal. As explained in my previous post, I therefore configured the XKB Event Daemon to play an audio file (bell.oga) whenever X Windows detects a BEL character (ASCII 007) or Backspace key (ASCII 008).

root # grep PCSP /usr/src/linux/.config
CONFIG_HAVE_PCSPKR_PLATFORM=y
CONFIG_PCSPKR_PLATFORM=y
# CONFIG_INPUT_PCSPKR is not set
# CONFIG_SND_PCSP is not set
root # grep BEEP /usr/src/linux/.config
CONFIG_SND_HDA_INPUT_BEEP=y
CONFIG_SND_HDA_INPUT_BEEP_MODE=1

Then I rebuilt the Kernel with CONFIG_INPUT_PCSPKR=M and CONFIG_SND_PCSP=M:

root # cd /usr/src/linux
root # mount /dev/sda1 /boot
root # make menuconfig
root # make && make modules_install
root # make install
root # grep PCSP /usr/src/linux/.config
CONFIG_HAVE_PCSPKR_PLATFORM=y
CONFIG_PCSPKR_PLATFORM=y
CONFIG_INPUT_PCSPKR=m
CONFIG_SND_PCSP=m
root # grep BEEP /usr/src/linux/.config
CONFIG_SND_HDA_INPUT_BEEP=y
CONFIG_SND_HDA_INPUT_BEEP_MODE=1

Then I created the file /etc/modprobe.d/blacklist.conf in order to blacklist the modules pcspkr and snd-pcsp so that only I could load them after boot:

root # cat /etc/modprobe.d/blacklist.conf
blacklist pcspkr
blacklist snd-pcsp

Then I added the line ‘options snd-pcsp index=2‘ to the file /etc/modprobe.d/alsa.conf so that the virtual sound card pcsp would not become the default sound card:

root # tail /etc/modprobe.d/alsa.conf
alias /dev/midi snd-seq-oss

# Set this to the correct number of cards.
options snd cards_limit=1

# See https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1313904
options snd-hda-intel patch=,clevo-hda-patch

# See Kernel Help text for CONFIG_SND_PCSP
options snd-pcsp index=2

Then I rebooted and checked that neither module was loaded:

root # lsmod | grep pcsp
root # echo -e '\a'

root #

As neither module was loaded, the situation was the same as before: a) no beep in a VT; b) no beep in Konsole/Yakuake (I will ignore KDE terminal programs anyway because of KDE bug report no. 177861);* c) the same bell.oga beep in xterm due to my use of xkbevd; d) no changes in ALSA Mixer.

* Regarding Konsole and Yakuake, see my update of October 9, 2016 at the bottom of this post.

Then I loaded the module pcspkr:

root # modprobe pcspkr
root # lsmod | grep pcsp
pcspkr                  1875  0
root # echo -e '\a'

root #

There were no changes in ALSA Mixer. But now the BEL character and Backspace in a VT did result in a beep (I’ll call this a ‘pcbeep’ to distinguish it from the different-sounding beep produced using bell.oga). There was the usual bell.oga beep in xterm due to my use of xkbevd. If I stopped xkbevd, there was no pcbeep in X Windows from the shell commands shown in my previous post, although the following commands from any terminal in X Windows (even Konsole/Yakuake) did emit a pcbeep:

user $ sudo sh -c "echo -e '\a' > /dev/console"

user $ sudo sh -c "tput bel > /dev/console"

root # echo -e '\a' > /dev/console

root # tput bel > /dev/console

Then I unloaded the module pcspkr and loaded the module snd-pcsp:

root # modprobe -r pcspkr
root # modprobe snd-pcsp
root # lsmod | grep pcsp
snd_pcsp                7918  1
root # echo -e '\a'

root #

ALSA Mixer showed a new sound card named ‘pcsp‘ (Sound Card 2) with three channels: ‘Master’, ‘Beep’ and ‘BaseFRQ’. I could mute/unmute ‘Beep’ by pressing ‘M’ on the keyboard as usual, and I could toggle ‘BaseFRQ’ between two values:18643 and 37286. The BEL character and Backspace in a VT resulted in a pcbeep. There was the usual bell.oga beep in xterm due to my use of xkbevd. If I stopped xkbevd, there was no pcbeep in X Windows from the shell commands shown in my previous post, although the following commands from any terminal in X Windows (even Konsole/Yakuake) did emit a pcbeep:

user $ sudo sh -c "echo -e '\a' > /dev/console"

user $ sudo sh -c "tput bel > /dev/console"

root # echo -e '\a' > /dev/console

root # tput bel > /dev/console

Muting ‘Beep’ in ALSA Mixer did not mute the bell.oga beeps in X Windows, but it did mute the pcbeeps in the VTs.

Unlike the situation with the pcspkr module, occasionally there were brief low-volume crackles and pops from the laptop’s speakers.

So both drivers worked, but pcspkr performed better, although it could not be muted via ALSA Mixer. My recommendation to use pcspkr rather than snd-pcsp still stands.

Unlike pcspkr, I had to force the unloading of snd-pcsp:

root # modprobe -r snd-pcsp
modprobe: FATAL: Module snd_pcsp is in use.
root # rmmod -f snd_pcsp
root #

I then removed the Kernel’s ‘digital beep’ interface for the Intel HDA driver by rebuilding the Kernel with CONFIG_SND_HDA_INPUT_BEEP=N:

root # cd /usr/src/linux
root # mount /dev/sda1 /boot
root # make menuconfig
root # make && make modules_install
root # make install
root # grep PCSP /usr/src/linux/.config
CONFIG_HAVE_PCSPKR_PLATFORM=y
CONFIG_PCSPKR_PLATFORM=y
CONFIG_INPUT_PCSPKR=m
CONFIG_SND_PCSP=m
root # grep BEEP /usr/src/linux/.config
# CONFIG_SND_HDA_INPUT_BEEP is not set
root #

After I rebooted, the behaviour was exactly the same as for CONFIG_SND_HDA_INPUT_BEEP=Y and CONFIG_SND_HDA_INPUT_BEEP_MODE=1.

So, there you have it. I believe my previous post was essentially correct regarding the functional design of the Kernel options. If you have a computer without a PC Speaker but it emulates one via the computer’s sound card, you have to set either CONFIG_INPUT_PCSPKR or CONFIG_SND_PCSP to get a beep in a VT, not set just CONFIG_SND_HDA_INPUT_BEEP and CONFIG_SND_HDA_INPUT_BEEP_MODE. However, even when my laptop emits beeps in a VT from the (emulated) PC Speaker, no beeps from the (emulated) PC Speaker are emitted in X Windows unless the user is the root user and the output is redirected to /dev/console. So, if you want to emit beeps in X Windows it is still better in my opinion to use xkbevd to play an audio file of a beep, as described in my previous post.

Update (October 9, 2016): Regarding KDE’s terminal applications emitting beeps, I am currently using KDE Plasma 5.7.5 and have been able to configure Konsole and Yakuake to play an audio file of a beep (as opposed to emitting a pcbeep) as follows:

  • In Konsole, click on ‘Settings’ > ‘Configure Notifications…’, select ‘Bell in Visible Session’ and ensure ‘Play a sound’ is ticked and a file is specified there (I specify /usr/share/sounds/freedesktop/stereo/bell.oga). If you wish, do the same for ‘Bell in Non-Visible Session’.
  • For Yakuake, press F12 to display the Yakuake window, click on the ‘Open Menu’ icon, select ‘Configure Notifications…’, select ‘Bell in Visible Session’ and ensure ‘Play a sound’ is ticked and a file is specified there (I specify /usr/share/sounds/freedesktop/stereo/bell.oga). If you wish, do the same for ‘Bell in Non-Visible Session’.

To beep, or not to beep, that is the question

Introduction

If your computer running Linux has the necessary hardware and is configured appropriately, applications and shell scripts can trigger a beep to signal an event such as an invalid keyboard entry, shutdown initiation, and so on. To check the current situation with your computer, enter the command shown below. Try it first in a Linux VT (virtual terminal) and then in a terminal window in X Windows. Do you hear a beep in each case?

user $ echo -e '\a'

The above command outputs the BEL character (ASCII code 007).

An alternative to the above command is:

user $ echo -e '\007'

Another command that should produce a beep is:

user $ tput bel

The tput utility is part of the ncurses package.

If you install the package app-misc/beep you can also use the ‘beep’ command (enter the command ‘man beep‘ to see its options):

user $ beep

Although you can enter the above-mentioned commands on the command line, they are intended to be used in shell scripts to notify the user about something.

There are thousands of posts on the Web regarding beeps in Linux, the majority of them concerned with disabling beeps because many people find them annoying. Historically, such beeps were emitted by the so-called ‘PC speaker‘. Note that the PC Speaker is not the same as the speakers connected to the sound card in your computer; the term refers to a small internal loudspeaker (moving-coil or piezoelectric) wired directly to the motherboard and intended solely to emit beeps to notify the user about something. Many modern computers, especially laptops, do not have a PC Speaker and either emulate one via the sound card or do nothing at all.

The reason people sometimes use the terms ‘bell’ and ‘ring’ instead of ‘beep’ is because old teletypwriters and teleprinters actually had an electromechanical bell which would ring when a certain dedicated character was received. I use the terms ‘beep’ and ‘bell’ interchangeably, although I prefer to use the term ‘beep’ when talking about audible notifications by computers.

I was motivated to write this post after helping a Gentoo Linux user to get his laptop to produce beeps (see the Gentoo Linux Forums thread ‘i want to beep [solved]‘). Producing a beep in Linux turns out to be more complicated than you would expect, and I’m not sure I fully understand the functional design of the applicable configuration options in the Kernel, nor their relevance (if any) to the X Windows server’s bell. Now, on the face of it the functionality of the applicable Kernel configuration options appears straightforward, but that is not the case in practice. Anyway, let’s look at how I believe a beep can be achieved (and disabled) in Linux…

PC Speaker drivers

Four Kernel options relate directly to a PC Speaker:

CONFIG_HAVE_PCSPKR_PLATFORM

If this is not set in the Kernel then CONFIG_PCSPKR_PLATFORM cannot be enabled.

CONFIG_PCSPKR_PLATFORM

Enable PC-Speaker support

This option allows to disable the internal PC-Speaker
support, saving some memory.

CONFIG_INPUT_PCSPKR

PC Speaker support

Say Y here if you want the standard PC Speaker to be used for
bells and whistles.

If unsure, say Y.

To compile this driver as a module, choose M here: the
module will be called pcspkr.

CONFIG_SND_PCSP

PC-Speaker support (READ HELP!)

If you don’t have a sound card in your computer, you can include a
driver for the PC speaker which allows it to act like a primitive
sound card.
This driver also replaces the pcspkr driver for beeps.

You can compile this as a module which will be called snd-pcsp.

WARNING: if you already have a soundcard, enabling this
driver may lead to a problem. Namely, it may get loaded
before the other sound driver of yours, making the
pc-speaker a default sound device. Which is likely not
what you want. To make this driver play nicely with other
sound driver, you can add this into your /etc/modprobe.conf:
options snd-pcsp index=2

You don’t need this driver if you only want your pc-speaker to beep.
You don’t need this driver if you have a tablet piezo beeper
in your PC instead of the real speaker.

Say N if you have a sound card.
Say M if you don’t.
Say Y only if you really know what you do.

If your computer does have a PC Speaker, you would use either CONFIG_INPUT_PCSPKR or CONFIG_SND_PCSP, but not both. When configuring the Kernel you can specify ‘M’ to build the driver as an external module, in which case you can decide in userspace whether or not to load it. Or you can specify ‘Y’ to build the driver into the Kernel (do not specify both as ‘Y’ simultaneously, though).

If your computer does have a PC Speaker, an advantage of using CONFIG_SND_PCSP instead of CONFIG_INPUT_PCSPKR is that the former adds a virtual sound card named ‘pcsp’ with a channel (without volume control) named ‘Beep’, and you should be able to mute it via ALSA Mixer.

If you have a computer that has a sound card but does not have a PC Speaker (a laptop’s internal speakers are connected to a sound card, not a PC Speaker), the above two drivers do not really apply. I have always disabled them both in the Kernel, as my laptop does not have a PC Speaker.  Update (September 29, 2016): This is not always the case: if a computer uses a sound card to emulate a PC Speaker (typically laptops do this), then you do need to use one of these two drivers if you want to be able to hear event beeps in a VT — see my latest post Another look at beeps in Linux.

However, apparently for some laptops ALSA Mixer shows a channel named ‘Beep’ (with volume control) for the Intel HDA (High Definition Audio) sound card if CONFIG_INPUT_PCSPKR is set to ‘Y’ or ‘M’. I believe such laptops were designed to use their sound card to emulate a PC Speaker. I do not know whether or not the ‘digital beep’ Kernel options (see further on) are set in such cases, but Kernel bug report no. 13651 would appear to indicate that the design intention is for them to be set.

So, already things are confusing.

Of course, if your computer does have a PC Speaker and you don’t want it to emit beeps, set both CONFIG_INPUT_PCSPKR and CONFIG_INPUT_PCSP to ‘N’ in the Kernel. If either already exists as an external module and you do not wish to rebuild the Kernel, make sure the modules pcspkr and snd-pcsp are not loaded (blacklist them, for example).

Digital Beep

Now, there are two other Kernel options relating to event beeps. These are not for driving a PC Speaker, they are to enable the ALSA Intel HDA driver to emit event beeps in lieu of a PC Speaker: the so-called ‘digital beep’. In other words, these two options are intended to provide an alternative to using a PC Speaker. The two options are:

CONFIG_SND_HDA_INPUT_BEEP

Support digital beep via input layer

Say Y here to build a digital beep interface for HD-audio
driver. This interface is used to generate digital beeps.

CONFIG_SND_HDA_INPUT_BEEP_MODE

Digital beep registration mode (0=off, 1=on)

Set 0 to disable the digital beep interface for HD-audio by default.
Set 1 to always enable the digital beep interface for HD-audio by
default.

Note that the mode ‘2’ is no longer an option in newer Kernels.

So, if your installation uses the Intel HDA driver and you want your computer’s sound card to be able to emit beeps instead of a PC Speaker (which your computer may or may not have), set these two accordingly in the Kernel configuration:

user $ grep CONFIG_SND_HDA_INPUT_BEEP /usr/src/linux/.config
CONFIG_SND_HDA_INPUT_BEEP=y
CONFIG_SND_HDA_INPUT_BEEP_MODE=1

The functional design of these Kernel options is not clear, but Kernel bug report no. 13651 appears to indicate that the design intention is for CONFIG_SND_HDA_INPUT_BEEP and CONFIG_SND_HDA_INPUT_BEEP_MODE to be used in addition to either CONFIG_INPUT_PCSPKR or CONFIG_SND_PCSP, not instead of them. In other words, if your computer has a PC Speaker but you want beeps to be routed via its Intel HDA sound card instead then I believe you are expected to use either of the following two sets of options:

Option 1
CONFIG_HAVE_PCSPKR_PLATFORM=Y
CONFIG_PCSPKR_PLATFORM=Y
CONFIG_INPUT_PCSPKR=Y (or =M)
CONFIG_SND_HDA_INPUT_BEEP=Y
CONFIG_SND_HDA_INPUT_BEEP_MODE=1

Option 2
CONFIG_HAVE_PCSPKR_PLATFORM=Y
CONFIG_PCSPKR_PLATFORM=Y
CONFIG_SND_PCSP=Y (or =M)
CONFIG_SND_HDA_INPUT_BEEP=Y
CONFIG_SND_HDA_INPUT_BEEP_MODE=1

On the other hand, if your computer has a PC Speaker and your installation uses the Intel HDA driver for a sound card but you do want your computer to emit beeps from the PC Speaker, I think you would set the two options as follows in the Kernel configuration:

CONFIG_SND_HDA_INPUT_BEEP=N
CONFIG_SND_HDA_INPUT_BEEP_MODE=0

If you read the comment by ALSA developer Takashi Iwai quoted in Kernel bug report no. 13651 you’ll see that the functionality is not at all straightforward. For example, on some computers, especially laptops (which normally do not have a PC Speaker), the beep may be emitted via the sound card irrespective of whether or not you set CONFIG_SND_HDA_INPUT_BEEP.

X Windows

A beep can be emitted in X Windows, and I have seen this beep referred to as the ‘X Windows server bell’ or the ‘X Windows keyboard bell’.

Given that X Windows can emit a beep via the sound card when neither the pcspkr module nor the snd-pcsp module is loaded and CONFIG_SND_HDA_INPUT_BEEP=N and CONFIG_SND_HDA_INPUT_BEEP_MODE=0, I assume X Windows emits beeps directly to the default sound card irrespective of the settings of those Kernel options. I could be wrong, but I have not found any explanation on the Web about the underlying mechanism; the X.Org Web site FAQ ‘How can I configure the Xserver bell (xkbbell) to use the sound subsystem of my computer? (ALSA, OSS, etc.)‘ simply states:

Answer (hopefully) goes here.. 🙂

*shrug*.

Below is a summary of the commands to disable, enable and configure the beep in X Windows.

To disable beeps in X Windows:

user $ xset b off

To enable beeps in X Windows:

user $ xset b on

To change the volume, pitch and duration of the beeps:

user $ xset b

For example, to set the beep volume to 25% without changing the pitch and duration:

user $ xset b 25

To return to the default settings:

user $ xset b

To view the current settings:

user $ xset q | grep bell

which displays the following (default) values in my case:

bell percent:  50        bell pitch:    400        bell duration:    100

To set the beep automatically each time X Windows starts, add the following line before the last one in the ~/.xinitrc file if you don’t use a Display Manager, otherwise use the Desktop Environment’s system settings GUI to run it at login:

xset b 20 400 20 &

PulseAudio

To confuse matters further, note that PulseAudio intercepts X11 beeps (see: PulseAudio Documentation – User Documentation – Modules – X Window system – module-x11-bell). Therefore, if your installation uses PulseAudio and you want the ability to emit event beeps in X Windows, you also need to configure PulseAudio so it does not ignore the beeps. This can either be done from the command line:

user $ pactl upload-sample /usr/share/sounds/freedesktop/stereo/bell.oga x11-bell
user $ pactl load-module module-x11-bell sample=x11-bell display=$DISPLAY

or you can edit /etc/pulse/default.pa and make sure the following lines are included in that file (they may already exist but are commented out):

load-sample-lazy x11-bell /usr/share/sounds/freedesktop/stereo/bell.oga
load-module module-x11-bell sample=x11-bell

On the other hand, if PulseAudio is installed and you want it to ignore event beeps in X Windows, delete or comment out the above-mentioned two lines in /etc/pulse/default.pa. You can achieve the same effect from the command line:

user $ pactl unload-module module-x11-bell

Configuring userspace to emit a ‘digital beep’

Installation of PulseAudio will have created the directory /usr/share/sounds/freedesktop/ and sub-directories containing various Ogg Vorbis audio files, including the ‘digital beep’ file bell.oga. If your installation does not have PulseAudio installed, you can obtain the same file /usr/share/sounds/freedesktop/stereo/bell.oga by installing the package x11-themes/sound-theme-freedesktop instead. You can configure your installation to use this file to emit a ‘digital beep’ in X Windows (but not in a VT) by using the XKB (X Windows keyboard extension) event daemon as explained in a post on the superuser Web site. That post relates to Ubuntu, but the basic principle applies whatever the Linux distribution.

Now, in my case I am using KDE Plasma 5 in Gentoo Linux, and I cannot hear any beep/bell in Konsole and Yakuake. I came across KDE bug report no. 177861 that has been outstanding since 2008, which indicated that KDE’s terminal applications will not emit beeps even if you do have a PC Speaker and your Kernel has been correctly configured to use it, or even if you have configured your installation to use a ‘digital beep’. You may have better luck with a different Desktop Environment but in KDE you will have to use a non-KDE X Windows terminal application if you want to hear beeps produced by shell scripts.

Update (October 9, 2016): Regarding KDE’s terminal applications emitting beeps, I am currently using KDE Plasma 5.7.5 and have been able to configure Konsole and Yakuake to emit a ‘digital beep’ as follows:

  • In Konsole, click on ‘Settings’ > ‘Configure Notifications…’, select ‘Bell in Visible Session’ and ensure ‘Play a sound’ is ticked and a file is specified there (I specify /usr/share/sounds/freedesktop/stereo/bell.oga). If you wish, do the same for ‘Bell in Non-Visible Session’.
  • For Yakuake, press F12 to display the Yakuake window, click on the ‘Open Menu’ icon, select ‘Configure Notifications…’, select ‘Bell in Visible Session’ and ensure ‘Play a sound’ is ticked and a file is specified there (I specify /usr/share/sounds/freedesktop/stereo/bell.oga). If you wish, do the same for ‘Bell in Non-Visible Session’.

Below I explain how I implemented a ‘digital beep’ in KDE Plasma 5.

First I installed the XKB event daemon:

root # emerge xkbevd

The package vorbis-tools was already installed, otherwise I would have installed that too in order to install an audio player for Ogg Vorbis audio files:

root # emerge vorbis-tools

PulseAudio was also already installed, and hence an appropriate audio file for a beep already existed. Had I not previously installed PulseAudio I would have installed the following package to get an appropriate Ogg Vorbis audio file:

root # emerge sound-theme-freedesktop

I created the file /home/fitzcarraldo/.config/autostart/xkbevd.desktop containing the following:

[Desktop Entry]
Comment[en_GB]=Software terminal bell
Comment=Software terminal bell
Exec=xkbevd -bg
GenericName[en_GB]=XKB Event Daemon
GenericName=XKB Event Daemon
Icon=system-run
MimeType=
Name[en_GB]=XKB Event Daemon
Name=XKB Event Daemon
Path=
StartupNotify=true
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=fitzcarraldo	

and I changed its permissions:

user $ chmod 755 /home/fitzcarraldo/.config/autostart/xkbevd.desktop

I created the file /home/fitzcarraldo/.xkb/xkbevd.cf containing the following:

soundDirectory="/usr/share/sounds/"
soundCmd="ogg123 -q"

Bell() "freedesktop/stereo/bell.oga"

If the file /usr/share/sounds/freedesktop/stereo/bell.oga does not exist in your installation then you can copy any suitable audio file of your choice into the directory /usr/share/sounds/ or use one of the existing audio files in that directory, and specify its filename in xkbevd.cf. For example:

soundDirectory="/usr/share/sounds/"
soundCmd="aplay -q"

Bell() "beep.wav"

Notice that the choice of audio player is up to you. In the first example of xkbevd.cf I specified the ogg123 player, whereas in the second example I specified the aplay player.

The aforementioned bug in KDE Konsole and Yakuake prevented me from testing the use of the XKB event daemon, so I installed a non-KDE X Windows terminal application to see if the ‘digital beep’ would work in that:

root # emerge xterm

The command echo -e '\a' generates a beep in xterm. So the ‘digital beep’ approach does work, albeit use of the XKB event daemon means you are limited to using it in X Windows. To reiterate, as the XKB event daemon is for X Windows, no ‘digital beep’ is generated if you enter a beep command outside of X Windows (e.g. in a VT).

By the way, I’m currently using Gentoo Stable Branch and hence Version 5.6.5 of KDE Plasma, and there is another KDE bug to complicate matters further: ‘System Settings’ > ‘Autostart’ > ‘Add Program…’ does not save all the entries I make via the GUI to the .desktop file, and does not set the file permissions correctly either. I don’t know if that is an upstream bug or a bug in the Gentoo implementation of Plasma 5.6.5. Anyway, that is why I manually created xkbevd.desktop and manually set the permissions, rather than using System Settings.

Instead of launching the XKB event daemon by using a .desktop file in ~/.config/autostart/, if you don’t use a Display Manager you could launch it by adding the command in the file ~/.xinitrc.

Summary

All the following factors govern whether or not your computer will issue a beep for the BEL character:

  • the specific hardware and firmware in your computer;
  • CONFIG_HAVE_PCSPKR_PLATFORM;
  • CONFIG_PCSPKR_PLATFORM;
  • CONFIG_INPUT_PCSPKR;
  • CONFIG_SND_PCSP;
  • CONFIG_SND_HDA_INPUT_BEEP;
  • CONFIG_SND_HDA_INPUT_BEEP_MODE;
  • X Windows settings;
  • PulseAudio configuration (if installed);
  • a bug in KDE’s terminal applications (if installed).

A. If you are hearing event beeps but don’t want them:

  • Preferably, set CONFIG_HAVE_PCSPKR_PLATFORM and CONFIG_PCSPKR_PLATFORM both to ‘N’.
  • Either set both CONFIG_INPUT_PCSPKR and CONFIG_SND_PCSP to ‘N’ in your Kernel, or, if either driver exists as a module (pcspkr and snd-pcsp, respectively), blacklist it.
  • Make sure CONFIG_SND_HDA_INPUT_BEEP is set to ‘N’.
  • Make sure the X Windows bell is turned off.
  • If you also have PulseAudio installed, make sure the PulseAudio module module-x11-bell is not loaded (also check /etc/pulse/default.pa to see if it has been enabled by default).

B. If you are not hearing event beeps but you do want to hear them:

1. If you are sure your computer has a PC Speaker:

  • Make sure CONFIG_HAVE_PCSPKR_PLATFORM and CONFIG_PCSPKR_PLATFORM are set to ‘Y’.
  • Either set CONFIG_INPUT_PCSPKR to ‘M’ and CONFIG_SND_PCSP to ‘N’ in your Kernel, or, if the module snd-pcsp already exists, blacklist it.
  • Make sure the module pcspkr exists and is not blacklisted.
  • Make sure the module pcspkr is loaded after the module snd-hda-intel.
  • Make sure CONFIG_SND_HDA_INPUT_BEEP is set to ‘N’.
  • Make sure the X Windows bell is turned on and the volume is turned up.
  • If you have PulseAudio installed, make sure the PulseAudio module module-x11-bell is loaded (check /etc/pulse/default.pa to ensure it includes the applicable lines, or issue the two commands listed earlier).
  • If you use KDE, use a non-KDE terminal application until KDE bug report no. 177861 is fixed.
  • If, after doing all the above, you still do not hear a beep in X Windows, follow the procedure in the section above titled Configuring userspace to emit a ‘digital beep’.

Above I have recommended using pcspkr. However, an advantage of using snd-pcsp instead is that it adds a virtual sound card with a channel named ‘Beep’ and you should be able to mute that channel via ALSA Mixer as you wish. Therefore, if you do opt to use the module snd-pcsp instead of pcspkr then make sure you specify the module option (or Kernel Quirk if you built the driver into the Kernel) described in the Kernel Help text quoted earlier, so that pcsp does not become the default sound card instead of the Intel HDA sound card.

2. If your computer does not have a PC Speaker:

  • Preferably, set CONFIG_HAVE_PCSPKR_PLATFORM and CONFIG_PCSPKR_PLATFORM both to ‘N’. *
  • If you leave CONFIG_HAVE_PCSPKR_PLATFORM and CONFIG_PCSPKR_PLATFORM both set to ‘Y’, either set CONFIG_INPUT_PCSPKR and CONFIG_SND_PCSP both to ‘N’, or, if either module already exists, blacklist it. *
  • Make sure CONFIG_SND_HDA_INPUT_BEEP is set to ‘Y’ and CONFIG_SND_HDA_INPUT_BEEP_MODE is set to ‘1’ (I’m not sure this step is required for all computers).
  • Make sure the X Windows bell is turned on and its volume is turned up.
  • If you have PulseAudio installed, make sure the PulseAudio module module-x11-bell is loaded.
  • Use the XKB Event Daemon method to play an audio file (‘digital beep’) when the BEL character is detected in X Windows.
  • If you use KDE, use a non-KDE terminal application until KDE bug report no. 177861 is fixed.
    Update (October 9, 2016): Regarding KDE’s terminal applications emitting beeps, I am currently using KDE Plasma 5.7.5 and have been able to configure Konsole and Yakuake to emit a ‘digital beep’ — see my update in the section titled Configuring userspace to emit a ‘digital beep’.

    * If your computer’s hardware and firmware have been designed to emulate a PC Speaker via a sound card, you may find that you can use the pcspkr (or snd-pcsp) driver to generate beeps in a VT. As the saying goes, your mileage may vary.

    And Finally

    If you know precisely how all these Kernel options are supposed to interact, do comment. Or if you know the relationship, if any, between the X Windows beep (a.k.a. ‘bell’) and these Kernel options, please also comment.

    Update (September 29, 2016): See my latest post Another look at beeps in Linux for the results of some experiments with these Kernel options on my laptop, giving more insight into how to configure them and how they work.

Eliminating the loud hum from powered speakers connected to my laptop

My external powered speakers emit a loud, annoying hum if I plug them into the headphones socket of my Clevo W230SS laptop. The hum stops if I unplug the laptop’s mains charger, so the problem is due to an earth loop (a.k.a. ‘ground loop’). The charger’s recessed socket for connecting its mains lead has three prongs (IEC 60320 C6), i.e. the charger is not double-insulated. The recessed socket on a double-insulated mains charger would only have two prongs (IEC 60320 C8), and the label on a double-insulated charger in the UK usually has an icon consisting of two concentric squares. I suspect the audio circuitry in the Clevo W230SS is not very well designed, as there is virtually no hum from the same powered speakers if I plug them into the headphones socket of my Compal NBLB2 laptop while its mains charger, which has the same IEC 60320 C5/C6 coupler design as the Clevo laptop’s charger, is connected.

Now, I could have purchased a ground loop isolator, a passive device which is basically a couple of transformers (one per stereo channel), to interpose between the headphones socket on my laptop and the external powered speakers.

The YouTube video Solving Laptop Noise and Ground Loop Audio Interference contains a demonstration of what happens when you use a ground loop isolator on the headphones output of a laptop, and what happens when you use a double-insulated mains charger (two-prong coupler, rather than three-prong).

However, rather than buy a ground loop isolator I decided to try an active device, and purchased the XQ-10 portable headphones amplifier manufactured by Chinese company xDuoo. The XQ-10 is compact, fitting in the palm of my hand and weighing only 30 grammes. It has an aluminium-alloy case, and looks and feels well-made. Two cables are supplied: a USB cable to connect the XQ-10 to a phone charger or laptop in order to charge the LiPo battery in the XQ-10 (about 2 hours to charge, and about 20 hours of use on battery power), and a short 3.5 mm jack cable (male jack at both ends) to connect the XQ-10 to your laptop or phone.

xDuoo XQ-10 powered by its rechargeable battery

xDuoo XQ-10 powered by its rechargeable battery

If the XQ-10’s USB charging cable is not connected (see the photograph above) then the loud hum from my external powered speakers still occurs. But with both cables connected (see the photograph below), the XQ-10 does the job perfectly: there is no hum or hiss, even when I turn the speakers’ volume knob to maximum.

xDuoo XQ-10 with USB power/charging lead connected

xDuoo XQ-10 with USB power/charging lead connected

Although I do not need to use a headphones amplifier with the laptop when I use headphones or earphones — the volume is fine and there is no hum from headphones/earphones — I should mention that audio quality from my headphones and earphones connected to the XQ-10 is excellent (both with and without the USB charging cable connected, which is not surprising given that no earth loop exists when headphones/earphones are connected).

By the way, shop around if you do decide to buy the XQ-10, because its price on-line varies a lot. I paid GBP 17.95 for mine, and that included p&p.

No sound from headphones after resume from suspension / No sound from headphones after re-plug

It is not difficult to find posts on the Web regarding certain models of laptop that no longer produce sound from headphones after resuming from suspension, or no longer produce sound from their speakers or from headphones if you unplug and reconnect the headphones. My Clevo W230SS laptop suffered from these problems and more: sometimes the external microphone socket would no longer work either. I had to reboot the laptop in order to get audio working properly again.

The cause of these problems varies according to the specific hardware and software, and here I will describe a couple of fixes I implemented in Gentoo Linux for my Clevo W230SS laptop. Bear in mind that what works for one model of laptop may not necessarily work for a different model even if the symptoms are the same.

PROBLEM 1: No sound from headphones after resume from suspension

After my laptop resumed from suspension, headphones would no longer work until I rebooted the laptop. Sometimes an external microphone would also stop working until I rebooted. In 2014, Ubuntu user Kiril filed a bug report regarding this problem with the Clevo W230SS: [W230SS, VIA VT1802, Green Headphone Out, Front] No sound after suspend/resume. Actually, his original title for the bug report was: ‘[W230SS, VIA VT1802, Green Headphone Out, Front] No sound after fresh boot’. I didn’t have that problem: the headphone socket of my Clevo W230SS did produce sound after a ‘fresh boot’. Regarding Kiril‘s initial problem, ALSA developer Raymond Yau made several comments, including the following:

driver should not use same audio output for device 0 and device 2

independent headphone should be disabled on notebook by default

for desktop line out and headphone connected to different audio output nodes 0x03 and 0x04

this allow you to play different audio to line out and headphone

but this feature usually should be disabled for notebook

you need to file an upstream bug report to fix this bug in the indep_hp_possible function which should return false when there is no internal mic since some notebook have line out, headphone and Mic jack to support 5.1 or only enabled when headphone at extra front and line out at ext rear

the workaround is use hint to disable the indep_hp=0

https://git.kernel.org/cgit/linux/kernel/git/tiwai/sound.git/tree/Documentation/sound/alsa/HD-Audio.txt

Now, Kiril was using Ubuntu 14.04 and ALSA 1.0.27, whereas I’m using Gentoo and ALSA 1.0.29. Furthermore, apart from the two installations using different kernel versions, in Gentoo you configure and build the kernel yourself. So there is quite some difference between the two installations, which might explain why I do not have his original problem of no sound from headphones after a fresh boot. Where we did coincide, though, was that there was no sound from headphones following resumption from suspension.

First attempt at fixing the problem

Even though Independent HP does not stop headphones working after I boot my laptop, I decided to try to remove Independent HP anyway, to see if it would fix the suspend/resume problem with headphones in my case.

The Clevo W230SS has two sound cards:

root # lspci | grep Audio
00:03.0 Audio device: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor HD Audio Controller (rev 06)
00:1b.0 Audio device: Intel Corporation 8 Series/C220 Series Chipset High Definition Audio Controller (rev 05)

The HDMI audio card is Card 0, and the analogue HD Audio card is Card 1. ALSAMixer shows an Independent HP (headphone) channel for Card 1:

user $ alsamixer -c 1

The kernel documentation for the HD Audio driver explains how to fix the problem using what is called a driver ‘hint’. There is a link to the documentation in the above-mentioned bug report, and you can also find the documentation in the file /usr/src/<kernel_release>/Documentation/sound/alsa/HD-Audio.txt on your laptop if you have installed the kernel source code. As explained in the documentation, you can remove Independent HP either via the command line:

root # echo "indep_hp = no" > /sys/class/sound/hwC1D0/hints
root # echo 1 > /sys/class/sound/hwC1D0/reconfig

or by using so-called ‘Early Patching’:

Early Patching
~~~~~~~~~~~~~~
When CONFIG_SND_HDA_PATCH_LOADER=y is set, you can pass a "patch" as a
firmware file for modifying the HD-audio setup before initializing the
codec.  This can work basically like the reconfiguration via sysfs in
the above, but it does it before the first codec configuration.

Note that the term ‘patching’ here has nothing to do with patching the driver’s source code; it refers to patching the ALSA driver’s configuration of the VIA chip’s CODEC on the Intel sound card.

The format of this particular patch file containing a ‘hint’ would be as follows:

[codec]
<vendor_id> <subsystem_id> <address_of_the_CODEC>

[hint]
indep_hp = no

The values for vendor_id and subsystem_id can be found as follows:

root # cat /sys/class/sound/hwC1D0/vendor_id
0x11068446
root # cat /sys/class/sound/hwC1D0/subsystem_id
0x15582300

(As the driver is used with Card 1, remember to look in directory hwC1D0 rather than hwC0D0.)

The required value for address_of_the_CODEC is zero in this particular case. Therefore the file /lib/firmware/clevo-hda-patch (you can choose any file name you want) should have the following contents:

[codec]
0x11068446 0x15582300 0

[hint]
indep_hp = no

If you built the HA Audio driver as a module, you would need to add the following line to the file /etc/modprobe.d/alsa.conf in order to apply the patch:

options snd-hda-intel patch=,clevo-hda-patch

Notice the comma after the equals sign. This is required because the patch applies to the second card (Card 1) rather than to the first card (Card 0).

However, I had built the HD Audio driver into the kernel rather than as a module:

root # grep HDA /usr/src/linux/.config | grep -v "is not set"
CONFIG_SND_HDA=y
CONFIG_SND_HDA_INTEL=y
CONFIG_SND_HDA_PREALLOC_SIZE=2048
CONFIG_SND_HDA_HWDEP=y
CONFIG_SND_HDA_RECONFIG=y
CONFIG_SND_HDA_INPUT_BEEP=y
CONFIG_SND_HDA_INPUT_BEEP_MODE=1
CONFIG_SND_HDA_INPUT_JACK=y
CONFIG_SND_HDA_PATCH_LOADER=y
CONFIG_SND_HDA_CODEC_VIA=y
CONFIG_SND_HDA_CODEC_HDMI=y
CONFIG_SND_HDA_I915=y
CONFIG_SND_HDA_GENERIC=y
CONFIG_SND_HDA_POWER_SAVE_DEFAULT=0

Therefore adding the option to /etc/modprobe.d/alsa.conf would have no effect, as the HD Audio driver is not a module. In this case I could have appended the following parameter to the kernel boot line in the file /boot/grub/grub.cfg instead:

snd-hda-intel.patch=,clevo-hda-patch

The above kernel boot parameter could be appended to the kernel boot line either directly by editing the file grub.cfg, or indirectly by adding it to the list of boot parameters in the variable GRUB_CMDLINE_LINUX_DEFAULT="" in the file /etc/default/grub and then using the command ‘grub2-mkconfig -o /boot/grub/grub.cfg‘ as root user to regenerate the grub.cfg file. Remember to mount /boot first if it is on a different partition.

Now, I tried applying the patch using the appropriate method in each case: HD Audio driver built into the kernel, and HD Audio driver built as a module (it didn’t take me long to modify the kernel configuration and rebuild the kernel). In both cases the following messages were included in the output of the dmesg command:

[ 0.430218] snd_hda_intel 0000:00:1b.0: Applying patch firmware 'clevo-hda-patch'
[ 0.430356] snd_hda_intel 0000:00:1b.0: Direct firmware load for clevo-hda-patch failed with error -2
[ 0.430359] snd_hda_intel 0000:00:1b.0: Cannot load firmware, aborting

I’m not sure if the reason for the failure to load the patch is the same in both cases, but certainly the reason in the case of the module is that PulseAudio is already running and using the driver by the time the OS attempts to apply the patch. In the case of the kernel boot parameter, my guess is that the patch would need to be included in an initramfs in order to be able to apply it before PulseAudio starts.

The same situation occurs if you try to apply the ‘hint’ manually from the command line after start-up:

root # echo "indep_hp = no" > /sys/class/sound/hwC1D0/hints
root # echo 1 > /sys/class/sound/hwC1D0/reconfig
bash: echo: write error: Device or resource busy

The above error message occurs because PulseAudio is running and using the driver. To apply the hint and refresh the driver in this case, the solution is to stop PulseAudio beforehand:

user $ echo "autospawn = no" >> ~/.config/pulse/client.conf
user $ pulseaudio --kill
user $ su
root # echo "indep_hp = no" > /sys/class/sound/hwC1D0/hints
root # echo 1 > /sys/class/sound/hwC1D0/reconfig
root # exit
user $ pulseaudio --start

Now, having to do the above manually every time you boot your machine is impractical. To automate the procedure I did the following…

Make sure the automatic (re)spawning of PulseAudio is disabled in the file ~/.config/pulse/client.conf (you can create the file if it does not exist):

autospawn = no

Create a Bash script in the directory /etc/local.d/ for the OS to launch automatically at boot, and in that script issue the above two commands first and then start pulseaudio. I named the script ‘99-clevo-hda-fix.start‘ and made its contents the following:

#!/bin/bash
# Fix for Intel HDA problem with Clevo W230SS
# See https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1313904
# N.B. Assumes your ~/.config/pulse/client.conf contains
# 'autospawn = no' so that PulseAudio is not launched automatically.
#
# Specify the hint
echo "indep_hp = no" > /sys/class/sound/hwC1D0/hints
#
# Reinitialise the HD Audio driver so it parses the CODEC tree again
echo 1 > /sys/class/sound/hwC1D0/reconfig
#
# Start PulseAudio for my user account
su -c "pulseaudio --start" -s /bin/sh fitzcarraldo

Don’t forget to make the script executable:

root # chmod +x /etc/local.d/99-clevo-hda-fix.start

This method of applying the hint to the HD Audio driver should work irrespectively of whether the driver is a module or built-in. It’s a bit more of a hack compared to the Early Patching approach, but it does the job in my case. After logging in to the Desktop Environment, you can check if the hint has been applied by looking at the contents of /sys/class/sound/hwC1D0/hints:

root # cat /sys/class/sound/hwC1D0/hints
indep_hp = no

However, this alone does not mean the CODEC was reconfigured after the hint was applied, so you need to check if Independent HP still exists. The ALSAMixer output on my laptop now looked like the following after I implemented the above method (notice that Independent HP no longer exists):

user $ alsamixer -c 1

So, what was the result? Well, audio continued to work after I removed Independent HP, but there was still no sound from headphones after resuming from suspension. And neither was there for Kiril, so he changed the title of his bug report to that effect. Fortunately, another user, unrud, commented later in the bug report that he had written init-headphone, a Python script to fix the problem. So I decided to hack his Ubuntu package to get init-headphone working in my Gentoo Linux installation. Here is how I did it…

Second (successful!) attempt at fixing the problem

1. Download init-headphone-ubuntu-0.11.zip from https://github.com/Unrud/init-headphone-ubuntu/releases

2. Extract the contents to the directory ~/init-headphone-ubuntu-0.11/

3. Copy to pm-utils’ hook directory the script that launches init-headphone upon resuming or thawing:

root # cp /home/fitzcarraldo/init-headphone-ubuntu-0.11/etc/linux-pm-utils/init-headphone /etc/pm/sleep.d/03-init-headphone # (use whatever number you want)

4. Copy the init-headphone script itself to the system binaries directory:

root # cp /home/fitzcarraldo/init-headphone-ubuntu-0.11/src/init-headphone /usr/local/sbin/

5. The init-headphone script requires the i2c_dev and i2c_i801 modules:

REQUIRED_MODULES = ["i2c_dev", "i2c_i801"]

However, I prefer to build them into the kernel rather than as modules, so I checked to make sure they are already built into the kernel:

root # grep CONFIG_I2C /usr/src/linux/.config | grep -v "is not set"
CONFIG_I2C=y
CONFIG_I2C_BOARDINFO=y
CONFIG_I2C_COMPAT=y
CONFIG_I2C_CHARDEV=y
CONFIG_I2C_MUX=y
CONFIG_I2C_HELPER_AUTO=y
CONFIG_I2C_ALGOBIT=y
CONFIG_I2C_I801=y

Then I commented out the lines in /usr/local/sbin/init-headphone that check if the two modules are loaded:

root # diff /home/fitzcarraldo/init-headphone-ubuntu-0.11/src/init-headphone /usr/local/sbin/init-headphone
174,181c174,181
< def check_modules():
< try:
< for module in REQUIRED_MODULES:
< logging.info("Trying to add module to the kernel: %s", module)
< if subprocess.call(["modprobe", "--quiet", module]) != 0:
< logging.warning("Module is not loaded: %s", module)
< except OSError:
#def check_modules():
> # try:
> # for module in REQUIRED_MODULES:
> # logging.info("Trying to add module to the kernel: %s", module)
> # if subprocess.call(["modprobe", "--quiet", module]) != 0:
> # logging.warning("Module is not loaded: %s", module)
> # except OSError:
> # logging.warning("modprobe not found")
206c206
# check_modules()

6. I created a script /etc/local.d/99-clevo-hda-fix.start to launch init-headphone automatically at boot:

#!/bin/bash
# Fix for Intel HDA problem with Clevo W230ss
# See https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1313904
exec /usr/local/sbin/init-headphone

root # chmod +x /etc/local.d/99-clevo-hda-fix.start

7. Add the kernel boot parameter ‘acpi_enforce_resources=lax‘ to the end of the kernel boot line(s) in /boot/grub/grub.cfg (don’t forget to mount /boot first if it is on another partition). You can either edit /boot/grub/grub.cfg directly, or indirectly by adding the parameter to the list of existing parameters in GRUB_CMDLINE_LINUX_DEFAULT (if any) as shown below and issuing the command ‘grub2-mkconfig -o /boot/grub/grub.cfg‘ as root user (again, don’t forget to mount /boot first if it is on another partition):

GRUB_CMDLINE_LINUX_DEFAULT="acpi_enforce_resources=lax"

8. Create a script file /etc/local.d/99-clevo-hda-fix.start to launch the init-headphone automatically at boot:

#!/bin/bash
# Fix for Intel HDA problem with Clevo W230SS
# See https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1313904
exec /usr/local/sbin/init-headphone

9. As my user account does not have a path configured to the system binaries directory, I created a symlink to it from the directory /usr/local/bin/:

root # ln -s /usr/local/sbin/init-headphone /usr/local/bin/init-headphone

10. As I no longer needed to stop PulseAudio running at boot, I deleted the file /home/fitzcarraldo/.config/pulse/client.conf I had created earlier (or you could just change ‘autospawn = no‘ to ‘autospawn = yes‘).

You can also use init-headphone from the command line:

user $ sudo init-headphone --help

e.g.

user $ sudo init-headphone unmute

This looks like it has finally solved the problem; now headphones still work after my laptop resumes from suspension. I still don’t need to pass the ‘hint’ to the HD Audio driver, so Independent HP continues to appear in ALSAMixer and apparently does not cause any problems.

A big ‘Thank you’ from me to Unrud for creating init-headphone.

PROBLEM 2: No sound from headphones after re-plug

The other problem I experienced with the Clevo W230SS was that, if I unplugged working headphones, audio switched to the laptop’s speakers as expected, but, if I then plugged-in the headphones again, no more sound came from the headphones. If I again unplugged the headphones, sound would again come from the speakers. If I did all this whilst ALSAMixer was running, then:

  1. if I unplugged the headphones, as expected the ALSAMixer volume level indicator for the speaker would rise from zero and the volume level indicator for the headphones would drop to zero;
  2. if I plugged in the headphones, as expected the ALSAMixer volume level indicator for the speaker would drop to zero and the volume level indicator for the headphones would rise from zero.

Now, it is possible that this problem was due to the same thing that caused the loss of audio to headphones when the laptop resumed from suspension. Anyway, before I came across init-headphone I found the following in the Arch Linux Wiki article on PulseAudio:

Switch on connect

This is a module used to switch the output sound to the newly connected device. For example, if you plug in a USB headset, the output will be switched to that. If you unplug it, the output will be set back to the last device. This used to be quite buggy but got a lot of attention in PulseAudio 8.0 and should work quite well now.

If you just want to test the module then you can load it at runtime by calling:

root # pactl load-module module-switch-on-connect

If you want to make the change persistent you will have to add it to your local pulseaudio settings or to /etc/pulse/default.pa (system wide effect). In either case, add this line:

load-module module-switch-on-connect

So, as the file /etc/pulse/default.pa in my installation did not have that line, I added it:

# Added by fitzcarraldo
# https://wiki.archlinux.org/index.php/PulseAudio
# The headphone socket no longer worked if I
# removed and re-inserted the jack plug.
load-module module-switch-on-connect

This seemed to help, but I am not certain module-switch-on-connect is really having an effect when I plug and unplug headphones, and I have not bothered to disable it to see what happens now that init-headphone is in use (I’m just happy that audio is all working now, whatever the reason!). ALSA’s Auto-Mute Mode* appears to perform the same role as module-switch-on-connect: When I unplug the headphones with Auto-Mute Mode enabled in ALSAMixer, there is a noticeable delay before sound starts to come from the laptop’s speakers, whereas there is no such delay when I unplug the headphones with Auto-Mute Mode disabled via ALSAMixer, so presumably module-switch-on-connect is doing its job.

* The documentation file /usr/src/<kernel_release>/Documentation/sound/alsa/HD-Audio-Controls.txt explains what Auto-Mute Mode does.

Anyhow, one or both of the two software modifications (init-headphone and module-switch-on-connect) seem to have cured the problem of no sound from headphones after they are disconnected then reconnected to the laptop.

Change the mp3 bitrate for ripping in K3b

I’ve been using K3b successfully (it’s currently at version 2.0.3-r1 in Gentoo Linux) to rip Audio CDs to mp3 files, but despite changing the bitrate to 192 kbps in the ‘K3b Lame Mp3 Encoder’ plugin settings, K3b was still ripping mp3 files at 128 kbps. I found out that I needed to make another change too.

The default bitrate for ripped mp3 tracks is 128 kbps in K3b. To use a different bitrate, I needed to do the following:

1. ‘Settings’ > ‘Configure K3b…’

2. Click on ‘Plugins’

3. Click on the spanner next to ‘K3b Lame Mp3 Encoder’, and change the bitrate on the Settings tab to 192 (or whatever you want). However, this alone does not have any effect, so also click on the spanner next to ‘K3b External Audio Encoder’, click on ‘Mp3 (Lame)’ in the list of ‘Configured Encoders’, click on ‘Edit’ and insert ‘-b 192‘ (or whatever bitrate you want) in the list of lame options, like so:

lame -r --bitwidth 16 --little-endian -b 192 -s 44.1 -h --tt %t --ta %a --tl %m --ty %y --tc %c --tn %n - %f

Here’s what happens before I added the ‘-b 192‘ to the settings for ‘Mp3 (Lame)’ in ‘K3b External Audio Encoder’:

$ file 01\ -\ Meu\ Bem\ Querer.mp3
01 - Meu Bem Querer.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, JntStereo

And after adding the ‘-b 192‘ to the settings for ‘Mp3 (Lame)’ in ‘K3b External Audio Encoder’:

$ file 01\ -\ Meu\ Bem\ Querer.mp3
01 - Meu Bem Querer.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, JntStereo

Notice the bit rate of the file has changed.

A new laptop

At the beginning of this month my trusty Compal NBLB2 laptop completed five years of heavy use. The HDD was almost full (mostly with my work files) and the laptop’s size and weight were starting to become troublesome on my frequent work trips. So I decided to bite the bullet and buy a new laptop. As Compal is an OEM and I was able to specify various components when buying the NBLB2, I decided to buy an OEM laptop again this time. In the end I decided on the Clevo W230SS, which I ordered from pcspecialist. The configuration I specified is listed below:

  • 13.3″ matte full HD LED IPS widescreen (1920×1080).
  • Intel Core i7 quad-core mobile processor i7-4810MQ (2.80GHz) 6MB.
  • 16GB Kingston SODIMM DDR3 1600MHz (2 x 8GB).
  • NVIDIA GeForce GTX 860M – 2.0GB DDR5, 640 CUDA cores.
  • 750GB WD Scorpio Black WD7500BPKX, SATA 6 Gb/s, 16MB cache (7200 rpm).
  • 8x Samsung slim USB 2.0 external DVD-RW.
  • Integrated 6-in-1 memory card reader (SD/MiniSD/SDHC/SDXC/MMC/RSMMC).
  • Arctic MX-4 Extreme thermal conductivity compound.
  • Intel 2-channel High Definition Audio + mic & headphone jacks.
  • Gigabit LAN & Wireless Intel AC-7260 HMC (867Mbps, 802.11AC) + Bluetooth.
  • 3 USB 3.0 ports + 1 USB 2.0 port.
  • Backlit UK keyboard.
  • 2-button touchpad.
  • 2.0 megapixel Webcam.
  • 6-cell lithium ion battery (62.16WH).
  • Power lead & 120W AC adaptor.
  • 3-year warranty (1 year collect & return; 1 year parts; 3 years labour).
  • 1-year dead pixel guarantee inc. labour & carriage.
  • No operating system required.

The laptop has both a VGA port and an HDMI port. The VGA port is important to me because I need to connect to various models of legacy monitors and projectors in the various offices where I work.

The time from ordering the laptop to its delivery was nine days, and I was impressed with the service by pcspecialist; I received e-mails at each stage of building, testing and delivery (including the option to change the delivery date), and was informed of the name of the courier company, the time of delivery and even the name of the van driver!

My two previous laptops were configured to dual-boot Linux and Windows, but this time I decided not to bother with Windows and install only Gentoo Linux. I virtually never use Windows on the Compal anyway, opting instead to run Microsoft Office 2007 with WINE in Linux, so I decided to save some money this time. I followed the Gentoo AMD64 Handbook to install the operating system and, with one exception which I will mention further on, the Handbook is a very accurate guide.

I have the Testing branch of Gentoo (‘~amd64’) installed on the Compal, but decided to install the Stable branch of Gentoo (‘amd64’) on the Clevo. Since several of the packages I wanted to install are in the Testing branch, I would declare them in /etc/portage/package.accept_keywords/ in order to be able to install them regardless.

Below are some rough notes on what I did, in case they are of any interest to others contemplating installing Gentoo on a laptop with a similar specification. I have to say I like the Clevo W230SS very much so far, although I find the NVIDIA Optimus hardware and driver more complicated to configure than the AMD ATI GPUs on my previous two laptops, and the NVIDIA driver does not work as well with the xrandr command as does the AMD FGLRX driver for ATI GPUs.

When I pressed F2 at boot to check the configuration of the American Megatrends BIOS, I found that UEFI was turned off, and I left it that way. The HDD was apparently MBR not GPT. I was happy to use PC BIOS and MBR rather than UEFI and GPT as that meant I would not have to fiddle with new technology with which I am unfamiliar, and GPT is not necessary as the HDD capacity is less than 2 TiB.

I then booted the HDD for the first time to check if pcspecialist had left anything on it after testing, and the Windows 7 Home Premium ‘Setup is preparing your computer for first use’ screen was displayed. As I had not ordered Windows and therefore had no Microsoft key, and as I did not want Windows on the laptop in any case, I used GParted on a SystemRescueCD Live pen drive to repartition and format the HDD.

I followed the Gentoo AMD64 Handbook but used SystemRescueCd rather than a Gentoo LiveCD or LiveDVD, and therefore I did not have to perform the installation procedure from the very beginning of the Handbook. After downloading the latest SystemRescueCd ISO and installing it to a pen drive (see the instructions on the SystemRescueCd Web site), I booted SystemRescueCd from the pen drive and connected the SystemRescueCd Xfce Live environment to the Web via WiFi. I did not bother to connect an Ethernet cable to the laptop and performed the entire installation of Gentoo to the HDD under WiFi.

I did not need to use the method given in the Gentoo Handbook for creating partitions; I used GParted on SystemRescueCD instead of fdisk or parted on the command line. I was therefore able to ignore the first few pages and started following the Handbook in earnest from Activating the swap partition onwards.

The Handbook recommends creating a ‘BIOS boot partition’ as well as a ‘boot partition’. This is really only necessary for UEFI machines or if the GRUB Embedding Area on the HDD is too small (the GNU Grub Manual 2.00 says the space reserved for the GRUB Embedding Area has to be at least 31 KiB). I did not need to create a ‘BIOS boot partition’, as GParted would only let me create the first partition starting 1 MiB from the beginning of the HDD. Actually, GParted will not let you create /dev/sda1 right at the beginning of the disk; it always seems to want the partition to start 1 MiB from the beginning of the HDD, so I don’t understand why the Handbook wants you to create a ‘BIOS boot partition’ before the Boot partition in the case of MBR HDDs, as there would still be 1 MiB of empty space before the ‘BIOS boot partition’, rendering the latter a waste of space and effort. (As I understand it, the situation is different in the case of GPT because the EFI boot partition must be FAT32, so you have no choice but to create a ‘BIOS boot partition’ if you’re using a GPT HDD.) Perhaps if you are using fdisk or parted on the command line then the situation is different and those commands do allow you to put the first partition right at the beginning of the HDD. So I created the following partitions by using GParted:

/dev/sda1 /boot (Primary Partition)
/dev/sda2 swap (Primary Partition)
/dev/sda3 (Extended Partition)
/dev/sda5 / (Logical Partition)
/dev/sda6 /home (Logical Partition)
/dev/sda7 NTFS partition (Logical Partition)

I specified the ext2 file system for /boot, and ext4 for / and /home. I have used these file systems for many years on previous laptops, and they are very reliable. I decided to add an NTFS partition to store my work files separately from my home files, and in case I ever want to access the laptop using Windows from e.g. a bootable external USB drive or whatever.

When creating the logical partitions sda5, sda6 and sda7, GParted always left 1 MiB unallocated before each logical partition. And I don’t know why GParted would not create a partition named /dev/sda4.

The precise partition configuration is listed below:

# fdisk -l

Disk /dev/sda: 698.7 GiB, 750156374016 bytes, 1465149168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x291ba0e7

 
Device     Boot     Start        End    Sectors   Size Id Type
/dev/sda1            2048     264191     262144   128M 83 Linux
/dev/sda2          264192   33822719   33558528    16G 82 Linux swap / Solaris
/dev/sda3        33822720 1465147391 1431324672 682.5G  5 Extended
/dev/sda5        33824768  302260223  268435456   128G 83 Linux
/dev/sda6       302262272  839133183  536870912   256G 83 Linux
/dev/sda7       839135232 1465147391  626012160 298.5G  7 HPFS/NTFS/exFAT

# blkid
/dev/sda1: LABEL="BOOT" UUID="f6ffc085-66fe-4bbe-b080-cec355749f85" TYPE="ext2" PARTUUID="291ba0e7-01"
/dev/sda2: UUID="c49e011a-bb8b-4ade-8fda-6c11ca53d660" TYPE="swap" PARTUUID="291ba0e7-02"
/dev/sda5: LABEL="ROOT" UUID="525a90f1-8ad2-44a3-ade3-20f18a0a9595" TYPE="ext4" PARTUUID="291ba0e7-05"
/dev/sda6: LABEL="HOME" UUID="5b60d470-a92a-45b3-9607-3ff3ab483b97" TYPE="ext4" PARTUUID="291ba0e7-06"
/dev/sda7: LABEL="NTFS" UUID="16F4D9B04A85A7E5" TYPE="ntfs" PARTUUID="291ba0e7-07"

The output from the lspci command in SystemRescueCd was as follows:

# lspci
00:00.0 Host bridge: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor DRAM Controller (rev 06)
00:01.0 PCI bridge: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor PCI Express x16 Controller (rev 06)
00:02.0 VGA compatible controller: Intel Corporation 4th Gen Core Processor Integrated Graphics Controller (rev 06)
00:03.0 Audio device: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor HD Audio Controller (rev 06)
00:14.0 USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB xHCI (rev 05)
00:16.0 Communication controller: Intel Corporation 8 Series/C220 Series Chipset Family MEI Controller #1 (rev 04)
00:1a.0 USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB EHCI #2 (rev 05)
00:1b.0 Audio device: Intel Corporation 8 Series/C220 Series Chipset High Definition Audio Controller (rev 05)
00:1c.0 PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express Root Port #1 (rev d5)
00:1c.2 PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express Root Port #3 (rev d5)
00:1c.3 PCI bridge: Intel Corporation 8 Series/C220 Series Chipset Family PCI Express Root Port #4 (rev d5)
00:1d.0 USB controller: Intel Corporation 8 Series/C220 Series Chipset Family USB EHCI #1 (rev 05)
00:1f.0 ISA bridge: Intel Corporation HM87 Express LPC Controller (rev 05)
00:1f.2 SATA controller: Intel Corporation 8 Series/C220 Series Chipset Family 6-port SATA Controller 1 [AHCI mode] (rev 05)
00:1f.3 SMBus: Intel Corporation 8 Series/C220 Series Chipset Family SMBus Controller (rev 05)
01:00.0 3D controller: NVIDIA Corporation GM107M [GeForce GTX 860M] (rev a2)
03:00.0 Network controller: Intel Corporation Wireless 7260 (rev bb)
04:00.0 Unassigned class [ff00]: Realtek Semiconductor Co., Ltd. Device 5287 (rev 01)
04:00.1 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller (rev 12)

The output from the lsusb command in SystemRescueCd was as follows:

# lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 004: ID 5986:055c Acer, Inc <-- The Webcam!
Bus 003 Device 003: ID 8087:07dc Intel Corp.
Bus 003 Device 002: ID 0dd8:17c0 Netac Technology Co., Ltd
Bus 003 Device 005: ID 090c:3261 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.)
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 002: ID 8087:8000 Intel Corp.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:8008 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The output from the lsmod command in SystemRescueCd was as follows:

# lsmod
Module                  Size  Used by
nilfs2                117674  0 
ccm                    16515  2 
arc4                   12390  2 
iwlmvm                149978  0 
mac80211              421465  1 iwlmvm
btusb                  24725  0 
iwlwifi                88602  1 iwlmvm
bluetooth             258391  2 btusb
cfg80211              320349  3 iwlwifi,mac80211,iwlmvm
x86_pkg_temp_thermal    12390  0 
6lowpan_iphc           16649  1 bluetooth
coretemp               12390  0 
iTCO_wdt               12390  0 
mei_me                 12576  0 
iTCO_vendor_support    12938  1 iTCO_wdt
crct10dif_pclmul       12479  0 
crc32_pclmul           12483  0 
crc32c_intel           16568  0 
i2c_i801               16533  0 
ghash_clmulni_intel    12523  0 
mei                    58244  1 mei_me
tpm_infineon           12437  0 
joydev                 16535  0 
tpm_tis                16533  0 
rfkill                 18094  3 cfg80211,bluetooth
serio_raw              12439  0 
tpm                    26448  2 tpm_tis,tpm_infineon
lpc_ich                20629  0 
shpchp                 29571  0 
microcode              41719  0 
raid10                 37123  0 
raid456                57671  0 
async_raid6_recov      12621  1 raid456
async_pq               12640  2 raid456,async_raid6_recov
async_xor              12573  3 async_pq,raid456,async_raid6_recov
async_memcpy           12464  2 raid456,async_raid6_recov
async_tx               12840  5 async_pq,raid456,async_xor,async_memcpy,async_raid6_recov
raid1                  28900  0 
raid0                  16515  0 
multipath              12390  0 
linear                 12390  0 
usb_storage            52365  2 
nouveau               793903  0 
i915                  586099  2 
ttm                    66567  1 nouveau
drm_kms_helper         37632  2 i915,nouveau
drm                   216971  5 ttm,i915,drm_kms_helper,nouveau
i2c_algo_bit           12633  2 i915,nouveau
i2c_core               28421  6 drm,i915,i2c_i801,drm_kms_helper,i2c_algo_bit,nouveau
rtsx_pci_sdmmc         16538  0 
mmc_core               80530  1 rtsx_pci_sdmmc
rtsx_pci_ms            12442  0 
memstick               13784  1 rtsx_pci_ms
mxm_wmi                12672  1 nouveau
r8169                  49390  0 
rtsx_pci               35470  2 rtsx_pci_ms,rtsx_pci_sdmmc
mii                    13085  1 r8169
mfd_core               12807  2 lpc_ich,rtsx_pci
wmi                    13114  2 mxm_wmi,nouveau
video                  16832  2 i915,nouveau

The output from the SystemRescueCd lsmod command told me that the nouveau driver works with this laptop, that the iwlwifi driver works too, and that the r8169 driver was the likely driver I would need for the wired Ethernet connection (I did not bother to connect an Ethernet cable whilst using SystemRescueCd).

The output from the SystemRescueCd ifconfig command told me the new names of the eth0 and wlan0 interfaces: enp4s0f1 and wlp3s0. I force udev/eudev to use interface names eth0 and wlan0 on my Compal laptop (by adding the parameter net.ifnames=0 to the kernel boot line and by using the command ‘ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules‘). However, although I dislike freedesktop.org’s so-called ‘predictable network interface names‘, I decided to stick with the new interface naming scheme on the Clevo.

As shown in the Handbook, make sure you cd into the directory /mnt/gentoo/ before downloading the Gentoo Stage 3 tarball, otherwise you will end up with the tarball in the wrong directory.

I stuck with the CPU FLAGS specified in the default make.conf file to start with, then, as soon as it was possible during the installation process, I installed app-portage/cpuinfo2cpuflags, ran it to obtain the correct CPU flags and modified /etc/portage/make.conf accordingly (I duplicated the CPU flags in USE="..." and CPU_FLAGS_X86="..." as recommended in Gentoo news item 2015-01-28-cpu_flags_x86-introduction).

I found configuring make.conf for USE flags confusing (see Configuring the USE variable). Although the KDE profile I eselected already contained quite a few of the global USE flags I thought I wanted/needed, I ended up duplicating several of them in make.conf rather than going through the output from the emerge --info command to see which USE flags are already included. I will clean up make.conf sometime in the future. The way to check which USE flags are provided by the profile is to temporarily comment out the USE variable lines in make.conf (and presumably any in /etc/portage/package.use/*) then run the emerge --info command. Anyway, here is what make.conf looked like after I had edited it:

CFLAGS="-O2 -march=native -pipe"
CXXFLAGS="${CFLAGS}"
LDFLAGS="-Wl,-O1,--as-needed"
# WARNING: Changing your CHOST is not something that should be done lightly.
# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.
CHOST="x86_64-pc-linux-gnu"
MY_CPUFLAGS="aes avx avx2 fma3 mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3"
CPU_FLAGS_X86="aes avx avx2 fma3 mmx mmxext popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3"

UNWANTED="-apm -branding -eds -evo -kerberos -gnome -gtk -libav -mono -nepomuk -oss -qt5 -systemd"
MY_MEDIA="alsa audiofile cdda cddb cdr dri dvb dvd dvdr dvdread jack ipod musicbrainz pulseaudio sdl v4l wmf xine"
MY_CODECS="a52 aac dts dv ffmpeg flac gsm lame matroska mp3 musepack ogg openal speex theora x264 xvid"
MY_SYSTEM="acl acpi avahi bash-completion bidi bluetooth bzip2 cjk dbus gcj gnutls icu lm_sensors lzo networkmanager nptl pam policykit udev unicode usb wifi xcb zeroconf"
MY_FILESYS="inotify"
MY_PRINT="cups foomaticdb gimp ppds scanner"
MY_XSYS="cairo dga gphoto2 gtk openexr opengl png qt4 svg tiff X xinerama"
MY_DESKTOP="gmp kde libnotify pda rdesktop semantic-desktop startup-notification"
MY_BROWSER="nsplugin"
MY_COMMS="aim icq imap jabber mbox msn rss slp yahoo"
USE="${USE} ${UNWANTED} ${MY_MEDIA} ${MY_CODECS} ${MY_SYSTEM} ${MY_FILESYS} ${MY_PRINT} ${MY_XSYS} ${MY_DESKTOP} ${MY_BROWSER} ${MY_COMMS} ${MY_CPUFLAGS}"

PORTDIR="/usr/portage"
DISTDIR="${PORTDIR}/distfiles"
PKGDIR="${PORTDIR}/packages"
# The following line is for Layman:
source /var/lib/layman/make.conf
# The following line is for my local overlay:
PORTDIR_OVERLAY="/usr/local/portage ${PORTDIR_OVERLAY}"
LINGUAS="en en_GB pt_BR es_ES"
GRUB_PLATFORMS="pc"
MAKEOPTS="-j9"

INPUT_DEVICES="evdev synaptics"
VIDEO_CARDS="intel modesetting nvidia"

GENTOO_MIRRORS="rsync://mirror.bytemark.co.uk/gentoo/ http://mirror.qubenet.net/mirror/gentoo/ rsync://rsync.mirrorservice.org/distfiles.gentoo.org/"
SYNC="rsync://rsync.uk.gentoo.org/gentoo-portage"

I don’t have the ‘source’ line and ‘SYNC’ line in my ~amd64 installation on the Compal because they are running later versions of Portage and Layman, for which the method has changed.

When following the Gentoo Handbook and merging some packages, sometimes messages about required USE flags were displayed. In some of those cases, after studying the messages carefully I repeated the merge command but included the --autounmask-write option, then used the etc-update command to apply the edits to the /etc/portage/package.use/* files, then repeated the merge command. In some cases, e.g. if only one or two USE flag changes needed, I created the new file /etc/portage/package.use/* and performed the edit manually. For example, /etc/portage/package.use/networkmanager containing:

net-misc/networkmanager nss -dhclient dhcpcd -gnutls modemmanager

I am not sure which modules to declare in /etc/conf.d/modules, since the only ones I have to declare in that file in my Compal laptop installation are VirtualBox modules and other modules are loaded automatically. Anyway, I added the r8169, nvidia and fuse modules to that file to start with. Later I added some more and it currently looks like this:

modules="r8169 nvidia fuse agpgart bnep rfcomm hidp mmc_block uvcvideo cifs"

I added ‘agpgart‘ because of what user Arthanis wrote in his post in the Gentoo Forums thread [SOLVED] Optimus and Nvidia but there is no module named agpgart in my installation, so I am not sure to what he was referring.

The modules loaded so far are listed below:

# lsmod
Module                  Size  Used by
cifs                  438492  0 
mmc_block              25911  0 
mmc_core               85695  1 mmc_block
hidp                   14125  0 
rfcomm                 32181  12 
bnep                   10116  2 
fuse                   76386  2 
nvidia               8385213  33 
ecb                     1921  1 
iwlmvm                143855  0 
r8169                  67544  0 
btusb                  22292  0 
bluetooth             281605  33 bnep,hidp,btusb,rfcomm
uvcvideo               71061  0 
videobuf2_vmalloc       2800  1 uvcvideo
videobuf2_memops        1799  1 videobuf2_vmalloc
videobuf2_core         34587  1 uvcvideo
mii                     3875  1 r8169
iwlwifi                75755  1 iwlmvm
x86_pkg_temp_thermal     4567  0

The rest of the drivers are in-kernel.

Version 216 of sys-fs/udev was installed, which predates the change in udev to stop loading firmware (see the Gentoo Forums thread udev-217 stalls booting) so I may have trouble with loading CPU microcode and WiFi firmware (and video firmware? — see further on) in future when sys-fs/udev-217 becomes stable in the Gentoo Portage tree.

I configured netifrc for enp4s0f1 only (I didn’t bother with WiFi) for DHCP, as per Gentoo Handbook section Configuring the system, as I only wanted to be sure of a network connection after rebooting until I could get NetworkManager working, at which I point I would ditch the netifrc stuff completely. As I have to travel frequently because of my work, I find NetworkManager more convenient.

Apart from configuring the kernel (I lost count of how many times I had to rebuild it), the only problem was when I installed GRUB 2 (Gentoo Handbook section Configuring the bootloader). There appears to be an error in the Gentoo Handbook; see Gentoo Forums thread grub2 install for the fix.

X Windows and NVIDIA Optimus

However, getting X Windows working was a major hassle. First I followed the Gentoo Wiki article X server to install the packages xorg-server and xorg-drivers, then I followed the Gentoo Wiki article NVIDIA Driver with Optimus Laptops to try and get the closed-source NVIDIA driver working, but X Windows could not find a screen. (I have no idea what sys-apps/qingy is or whether it is needed, but, as the Wiki article mentions it, I installed it anyway but did not add the xrandr commands to the end of the /etc/X11/Sessions/KDE-4 file, but I did add the xrandr commands to the /usr/share/config/kdm/Xsetup file.) Then I followed Gentoo user Arthanis‘ Gentoo Forums post [SOLVED] Optimus and Nvidia (changing the edid_firmware name to suit). I was confused by his reference to rcu_idle_delay, by which he meant CONFIG_RCU_FAST_NO_HZ (see Understanding RCU when Configuring the Linux Kernel). Thank goodness for his post, though, as I would never have worked it out myself. All my main laptops since 2000 have had ATI GPUs, and they were easier to set up than this NVIDIA Optimus stuff. Although the laptop has both Intel and NVIDIA graphics hardware, I think the laptop is muxless (i.e. does not have hybrid graphics/NVIDIA HybridPower), so I left CONFIG_VGASWITCHERROO=n in the kernel, but I have no idea if that is correct. This whole dual GPU/IGP switching thing confuses me.

After I followed Arthanis‘ post and rebooted, the KDM screen consisted of tiled ‘mini-screens’, with the KDM log-in window in the top left mini-screen. I solved this by adding a Virtual command in xorg.conf — see the Gentoo Forums post XOrg refusing to start after a fresh build by user qweb.ric.

Below are the current contents of xorg.conf:

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      0  "nvidia" 0 0
    Inactive       "intel"
    InputDevice    "Keyboard0" "CoreKeyboard"
    InputDevice    "Mouse0" "CorePointer"
EndSection

#Section "Files"
#EndSection

Section "InputDevice"
    Identifier     "Mouse0"
    Driver         "mouse"
    Option         "Protocol"
    Option         "Device" "/dev/input/mice"
    Option         "Emulate3Buttons" "no"
    Option         "ZAxisMapping" "4 5"
EndSection

Section "InputDevice"
    Identifier     "Keyboard0"
    Driver         "kbd"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    Option         "DPMS"
EndSection

Section "Device"
    Identifier     "nvidia"
    Driver         "nvidia"
    BusID          "PCI:1:0:0"
EndSection

Section "Device"
    Identifier     "intel"
    Driver         "modesetting"
    BusID          "PCI:0:2:0"
EndSection

Section "Screen"
    Identifier     "nvidia"
    Device         "nvidia"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "UseDisplayDevice" "none"
    SubSection     "Display"
        Depth       24
#        Modes      "nvidia-auto-select"
        Virtual     1920 1080
    EndSubSection
EndSection

Section "Screen"
    Identifier     "intel"
    Device         "intel"
    Monitor        "Monitor0"
EndSection

To get tapping to work on the touchpad I had to create the file /etc/X11/xorg.conf.d/50-synaptics.conf as usual:

Section "InputClass"
    Identifier "touchpad catchall"
    Driver "synaptics"
    MatchIsTouchpad "on"
    MatchDevicePath "/dev/input/event*"
    Option "TapButton1" "1"
    Option "TapButton2" "2"
    Option "TapButton3" "3"
    Option "VertEdgeScroll" "on"
    Option "VertTwoFingerScroll" "on"
    Option "HorizEdgeScroll" "on"
    Option "HorizTwoFingerScroll" "on"
    Option "CircularScrolling" "on"
    Option "CircScrollTrigger" "0"
    Option "EmulateTwoFingerMinZ" "40"
    Option "EmulateTwoFingerMinW" "8"
    Option "CoastingSpeed" "0"
    Option "FingerLow" "35"
    Option "FingerHigh" "40"
EndSection

Section "InputClass"
    Identifier "touchpad ignore duplicates"
    MatchIsTouchpad "on"
    MatchDevicePath "/dev/input/mouse*"
    Option "Ignore" "on"

And I also created the file /etc/X11/xorg.conf.d/30-keyboard.conf:

Section "InputClass"
    Identifier "keyboard"
    # See /usr/share/X11/xkb/rules/base.lst for Options.
    MatchIsKeyboard "yes"
    Option "XkbLayout" "gb,us,br,es"
    Option "XkbModel" "pc104"
    Option "XkbVariant" ""
    Option "XkbOptions" "grp:alt_shift_toggle"
EndSection

and the file /etc/X11/xorg.conf.d/10-evdev.conf:

Section "InputClass"
        Identifier "evdev pointer catchall"
        MatchIsPointer "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
EndSection

Section "InputClass"
        Identifier "evdev keyboard catchall"
        MatchIsKeyboard "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
EndSection

#Section "InputClass"
#        Identifier "evdev touchpad catchall"
#        MatchIsTouchpad "on"
#        MatchDevicePath "/dev/input/event*"
#        Driver "evdev"
#EndSection

Section "InputClass"
        Identifier "evdev tablet catchall"
        MatchIsTablet "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
EndSection

Section "InputClass"
        Identifier "evdev touchscreen catchall"
        MatchIsTouchscreen "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
EndSection

(See my post about xorg.conf for a later version (not Stable in the Portage tree yet) of X Windows on the Compal, Fixing unperceived errors in my X Windows configuration.)

I forgot to do the following:

# rc-update add dbus default
# rc-update add consolekit default

See the Gentoo Forums thread [ConsoleKit session] Failed to connect to socket (resolved) for the error message I was getting when the KDE Desktop appeared. In addition to the aforementioned error message, a window with a KDE Daemon crash message popped-up at log-in and KDE Plasma would crash when I dragged the System Tray widget to the Panel. Once the dbus and consolekit services were added to the default runlevel, all was good.

NetworkManager

After I merged NetworkManager I forgot to do:

# rc-update add NetworkManager default

but once I did that and the following:

# rc-update del net.enp4s0f1 default

then NetworkManager worked.

There was no /etc/NetworkManager/NetworkManager.conf, so I created that manually:

[main]
plugins=keyfile
dhcp=dhcpcd
no-auto-default=*

[keyfile]
hostname=clevow230ss

KDE plasma-nm crashes most times I try to create or edit a connection, so sometimes I have to edit the file /etc/NetworkManager/system-connections/* using nano. The current Stable version of plasma-nm in Gentoo is 0.9.3.4 and I believe the latest version of plasma-nm has fixed this bug, so eventually it should work correctly.

Audio

I followed Gentoo Wiki article ALSA and compiled ALSA into the kernel rather than modules. Card 0 is HDMI and Card 1 is HDA (the opposite to what is usually expected). KDE Multimedia settings worked when I selected Analogue Audio, but I had to install pavucontrol in order to be able to switch off HDMI and get audio in the Web browser etc. to be played via the laptop speakers/headphones. Later I will try the Gentoo Wiki ALSA article’s suggestion of adding snd-hda-intel.index=1,0 to the kernel boot line to switch the order of the cards.

Although I set what I think are the relevant MMC parameters in the kernel configration, the Memory Card slot does not work. Perhaps some kernel configuration settings remain to be set. I will have a look later. Gentoo Forums thread SD card under Gentoo Linux may help.

Bluetooth

Bluetooth is working after I made some kernel configuration settings and loaded the modules bnep, rfcomm and hidp via /etc/conf.d/modules (lsmod showed that btusb and bluetooth were already loaded automatically, but I added them anyway to /etc/conf.d/modules). I also had to do:

# rc-update bluetooth add default

The external portable USB portable CD/DVD writer (Samsung SE-208GB/RSBD) I bought from pcspecialist works well. I have tried it so far with an Audio CD, a data DVD and burning data to a CD-R.

Webcam

The built-in Webcam does not work. Update (April 29, 2015): I discovered today that the Webcam works fine; the problem was a bug in the version of the guvcview application I tried. So all is good. According to lsusb the Webcam is:

Bus 001 Device 010: ID 5986:055c Acer, Inc

The lsmod command shows the uvcvideo module is loaded. When I ‘rmmod uvcvideo‘ then ‘modprobe uvcvideo‘ the dmesg command shows the following:

[ 6508.624505] uvcvideo: Found UVC 1.00 device BisonCam, NB Pro (5986:055c)
[ 6508.627349] input: BisonCam, NB Pro as /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.4/1-1.4:1.0/input/input43
[ 6508.627425] usbcore: registered new interface driver uvcvideo
[ 6508.627427] USB Video Class driver (1.1.1)

The application guvcview displays a black window, and the Konsole from which guvcview was launched displays repeated ‘Ignoring empty buffer ...‘ messages:

$ guvcview
guvcview 1.6.1
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.0.28/work/alsa-lib-1.0.28/src/pcm/pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.0.28/work/alsa-lib-1.0.28/src/pcm/pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.0.28/work/alsa-lib-1.0.28/src/pcm/pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.0.28/work/alsa-lib-1.0.28/src/pcm/pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.0.28/work/alsa-lib-1.0.28/src/pcm/pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib /var/tmp/portage/media-libs/alsa-lib-1.0.28/work/alsa-lib-1.0.28/src/pcm/pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
video device: /dev/video0
Init. BisonCam, NB Pro (location: usb-0000:00:1a.0-1.4)
{ pixelformat = 'MJPG', description = 'MJPEG' }
{ discrete: width = 640, height = 480 }
        Time interval between frame: 1/30, 
{ discrete: width = 160, height = 120 }
        Time interval between frame: 1/30, 
{ discrete: width = 176, height = 144 }
        Time interval between frame: 1/30, 
{ discrete: width = 320, height = 240 }
        Time interval between frame: 1/30, 
{ discrete: width = 352, height = 288 }
        Time interval between frame: 1/30, 
{ discrete: width = 640, height = 360 }
        Time interval between frame: 1/30, 
{ discrete: width = 1280, height = 720 }
        Time interval between frame: 1/30, 
{ discrete: width = 1280, height = 1024 }
        Time interval between frame: 1/30, 
{ discrete: width = 1920, height = 1080 }
        Time interval between frame: 1/30, 
{ discrete: width = 640, height = 480 }
        Time interval between frame: 1/30, 
{ pixelformat = 'YUYV', description = 'YUV 4:2:2 (YUYV)' }
{ discrete: width = 640, height = 480 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 160, height = 120 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 176, height = 144 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 320, height = 240 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 352, height = 288 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 640, height = 360 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 1280, height = 720 }
        Time interval between frame: 1/10, 
{ discrete: width = 1280, height = 1024 }
        Time interval between frame: 1/5, 
{ discrete: width = 1920, height = 1080 }
        Time interval between frame: 1/5, 
{ discrete: width = 640, height = 480 }
        Time interval between frame: 1/30, 1/15, 
{ pixelformat = 'RGB3', description = 'RGB3' }
{ discrete: width = 640, height = 480 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 160, height = 120 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 176, height = 144 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 320, height = 240 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 352, height = 288 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 640, height = 360 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 1280, height = 720 }
        Time interval between frame: 1/30, 
{ discrete: width = 1280, height = 1024 }
        Time interval between frame: 1/30, 
{ discrete: width = 1920, height = 1080 }
        Time interval between frame: 1/30, 
{ pixelformat = 'BGR3', description = 'BGR3' }
{ discrete: width = 640, height = 480 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 160, height = 120 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 176, height = 144 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 320, height = 240 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 352, height = 288 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 640, height = 360 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 1280, height = 720 }
        Time interval between frame: 1/30, 
{ discrete: width = 1280, height = 1024 }
        Time interval between frame: 1/30, 
{ discrete: width = 1920, height = 1080 }
        Time interval between frame: 1/30, 
{ pixelformat = 'YU12', description = 'YU12' }
{ discrete: width = 640, height = 480 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 160, height = 120 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 176, height = 144 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 320, height = 240 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 352, height = 288 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 640, height = 360 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 1280, height = 720 }
        Time interval between frame: 1/30, 
{ discrete: width = 1280, height = 1024 }
        Time interval between frame: 1/30, 
{ discrete: width = 1920, height = 1080 }
        Time interval between frame: 1/30, 
{ pixelformat = 'YV12', description = 'YV12' }
{ discrete: width = 640, height = 480 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 160, height = 120 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 176, height = 144 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 320, height = 240 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 352, height = 288 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 640, height = 360 }
        Time interval between frame: 1/30, 1/15, 
{ discrete: width = 1280, height = 720 }
        Time interval between frame: 1/30, 
{ discrete: width = 1280, height = 1024 }
        Time interval between frame: 1/30, 
{ discrete: width = 1920, height = 1080 }
        Time interval between frame: 1/30, 
vid:5986 
pid:055c
driver:uvcvideo
checking format: 1196444237
VIDIOC_G_COMP:: Inappropriate ioctl for device
fps is set to 1/30
drawing controls

fps is set to 1/30
Checking video mode 640x480@32bpp : OK
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
Ignoring empty buffer ...
< Here I pressed Ctrl-C >
write /home/fitzcarraldo/.guvcviewrc OK
free controls
cleaned allocations - 100%
Closing portaudio ...OK
Closing GTK... OK

I tried all the available uvcvideo quirks (see Linux UVC driver and tools – FAQ: What are quirks and how do I use them?) but the result was always the same.

# rmmod uvcvideo
# modprobe uvcvideo quirks=0x00000200
# rmmod uvcvideo
# modprobe uvcvideo quirks=0x00000100
# rmmod uvcvideo
# modprobe uvcvideo quirks=0x00000080
# rmmod uvcvideo
# modprobe uvcvideo quirks=0x00000020
# rmmod uvcvideo
# modprobe uvcvideo quirks=0x00000010
# rmmod uvcvideo
# modprobe uvcvideo quirks=0x00000008
# rmmod uvcvideo
# modprobe uvcvideo quirks=0x00000004
# rmmod uvcvideo
# modprobe uvcvideo quirks=0x00000002
# rmmod uvcvideo
# modprobe uvcvideo quirks=0x00000001

There is possibly a bug in the uvcvideo driver (see [Kernel-packages] [Bug 1362358] Re: uvcvideo doesn’t work with USB webcam with linux 3.16), so I will have to try a later kernel at some point.

Update (April 29, 2015): I discovered today that nothing is wrong with the uvcvideo driver or the Webcam. The problem I described above was caused by a bug in the guvcview application itself. The Gentoo Stable version is guvcview-1.6.1, so I specified Gentoo Testing version guvcview-2.0.1 in /etc/portage/package.accept_keywords/guvcview and installed it, and now guvcview displays the Webcam output perfectly.

Transferring Thunderbird account settings and e-mails

My Compal laptop dual-boots Gentoo and Windows 7. Thunderbird is installed in both OSs, and both Windows Thunderbird and Linux Thunderbird use the same Mail folder on the NTFS Windows partition, but with different prefs.js files (i.e. Windows Thunderbird uses a prefs.js file on the Windows partition, and Linux Thunderbird uses a prefs.js file in the /home partition). In order to port my Thunderbird e-mails from the Windows partition on the Compal to the /home partition on the Clevo, I did the following:

  1. Installed Thunderbird on the Clevo.
  2. Launched Thunderbird and cancelled the Thunderbird wizard for creating a new account.
  3. Closed Thunderbird.
  4. Copied the Mail folder from the Compal’s Windows Thunderbird folder into the new Linux Thunderbird profile folder on the Clevo.
  5. Copied the prefs.js file from the Windows Thunderbird folder into the new Linux Thunderbird profile folder on the Clevo.
  6. Edited the prefs.js file to change all the Windows paths to Linux paths.

I also copied the three Address Book files abook.mab, history.mab and impab.mab across, but the first e-mail address in the Address Book differed between the two laptops so I exported the address books from Thunderbird in Linux (‘Address Book’ > ‘Tools’ > ‘Export…’ to create .ldif files) on the Compal and imported them into Thunderbird on the Clevo, but the result was no different to copying the .mab files, so it looks correct (the number of entries in the address books on each laptop was the same). Looking at a fresh installation of Thunderbird, I notice there is no impab.mab file, only the other two, and also the impab.mab file on the Compal has a 2011 date whereas the abook.mab and history.mab have current dates, so I wonder if the impab.mab file is redundant in the latest versions of Thunderbird.

A few panics (mine and the kernel’s!)

I had a couple of panic moments when rebooting after making changes to the kernel: if I had left a USB pen drive or a USB HDD plugged into the Clevo when I rebooted, the kernel would oops during boot-up. I initially thought these kernel panics were due to my mis-configuration of the kernel, but finally realised what was causing the oops when one of the error messages referred to a partition sdc1 on a pen drive. Actually, I had enabled too many kernel options in my first kernel build so it was probably better that I restarted the Gentoo installation anyway (I only restarted the installation from scratch once). The Compal boots normally if it has USB storage devices plugged in when it boots, so I’m not sure why it happens on the Clevo. Both laptops have the HDD first in the boot order, so I don’t know why the Clevo complains.

External monitor

I used xrandr commands to get my external monitor (an Acer AL1916W with a max resolution of 1440×900) to display the Clevo’s desktop correctly. I used the following command to view the available monitors and modes:

$ xrandr -q
Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 16384 x 16384
eDP-1-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 282mm x 165mm
   1920x1080     60.00*+  40.00  
   1400x1050     59.98  
   1280x1024     60.02  
   1280x960      60.00  
   1024x768      60.04    60.00  
   960x720       60.00  
   928x696       60.05  
   896x672       60.01  
   800x600       60.00    60.32    56.25  
   700x525       59.98  
   640x512       60.02  
   640x480       60.00    59.94  
   512x384       60.00  
   400x300       60.32    56.34  
   320x240       60.05  
VGA-1-0 disconnected (normal left inverted right x axis y axis)
DisplayPort-1-0 connected (normal left inverted right x axis y axis)
   1920x1080     60.00 +  40.00  
HDMI-1-0 disconnected (normal left inverted right x axis y axis)

I don’t know why the connected AL1916W monitor is shown as having only one display mode, and why that mode is 1920×1080. The AL1916W supports several modes up to 1440×900, and these are all displayed by the xrandr command on the Compal. It seems the NVIDIA driver is unable to read the external monitor’s EDID whereas the AMD ATI FGLRX driver is able to do so. Anyway I did the following to force the NVIDIA driver to display the Desktop correctly, which I later automated in a Bash script launched from a Desktop Configuration File:

$ xrandr --output DisplayPort-1-0 --off
$ xrandr --newmode "1440x900" 106.50 1440 1528 1672 1904 900 903 909 934 -hsync +vsync # Only need to add new mode once per X session.
$ xrandr --addmode DisplayPort-1-0 1440x900
$ xrandr --output eDP-1-0 --off && xrandr --output DisplayPort-1-0 --mode 1440x900

I pressed the AL1916W monitor’s MENU button and selected AUTO to make sure the monitor’s display is as sharp as possible.

Scanners

I have an HP ScanJet 3400C scanner and my Canon PIXMA MP560 MFP also has a scanner. I had to install hplip in order to be able to use XSane, gscan2pdf and Simple Scan with the HP ScanJet 3400C scanner. I also found that the HP ScanJet 3400C must be switched off in order to be able to use the Canon MP560 scanner, whereas I don’t need to switch off the Canon MP560 in order to be able to use the HP ScanJet 3400C!

Skype and PulseAudio

As Qt 4.8.5 has not yet been marked stable in Gentoo, and therefore there is not a stable version of Qt with the abi_x86_32 USE flag, I installed Skype using the hack given by Gentoo user pablo_supertux in his Gentoo Forums post [SOLVED] Skype and the new multilib, which works well.

The laptop’s volume settings jumped to 100% periodically, and this is another of PulseAudio’s irritating quirks. To stop this happening I edited the file /etc/pulse/daemon.conf and changed:

; flat-volumes = yes

to:

flat-volumes = no

i.e. I uncommented the line and changed ‘yes‘ to ‘no‘.

I had disabled Skype from automatically adjusting audio settings. If I still find that PulseAudio is causing volume levels to change at start-up (see my earlier posts), I will create a script in /etc/local.d/ to set them automatically for me.

Things left for me to do:

  1. Get the Webcam working. Update (April 29, 2015): Done! It turned out there was nothing wrong with the uvcvideo driver or the hardware; the guvcview application had a bug. I installed a newer version of guvcview and it works correctly. So all is good.
  2. Get the Memory Card slot working. Boot SystemRescueCd and see if SDHC and/or SDXC memory cards are accessible. Update (April 28, 2015): Done! See my next post Realtek 5287 PCIe controller for memory card reader for the changes I made to the kernel configuration.
  3. Check the Bash backup scripts I created for the Compal and edit them if necessary so that they work on the Clevo. Update (April 29, 2015): Done!
  4. When Qt 4.8.6 is made Stable in the Portage tree, install Skype using Portage. Update (May 16, 2015): Done!
  5. Check which other applications and utilities I installed on the Compal need to be installed on the Clevo. Update (April 29, 2015): Done!
  6. Install the Samsung Unified Printer driver and get it working with the Samsung printers in the office. Update (April 29, 2015): Done!
  7. Investigate why the Clevo cannot print to my Canon PIXMA MP560 via WiFi. Update (May 15, 2015): Done! The problem was with the printer, not the Clevo. The printer was not always connecting to my home WiFi network.
  8. Install UFW and either a) the KDE KControl Module for UFW or b) UFW Frontends, and add firewall rules for Samba/CIFS and KDE Connect. Update (June 30, 2015): Done! Finally got around to doing it. ufw was giving an error message for IPv6, though, but I fixed that by rebuilding the kernel with some more parameters selected: CONFIG_NETFILTER_XT_TARGET_HL=m, CONFIG_IP6_NF_MATCH_RT=m and CONFIG_IP6_NF_TARGET_HL=m.
  9. Investigate why Samba cannot access the family Acer Aspire XC600 running Windows 8.1. The Samba service is running on the Clevo, and both Samba 3 and Samba 4 on the Compal can access shares on the Aspire XC600 and on the Clevo, so something must be wrong with the installation on the Clevo. Update (May 17, 2015): Done! The problem was that I had not merged kde-base/kdebase-kioslaves with the samba USE flag. Once I did that, Dolphin could browse Samba shares on the family PC running Windows 8.1.
  10. Find out the manual commands for switching between the Intel IGP and NVIDIA GPU that Gentoo user Arthanis mentioned in his post [SOLVED] Optimus and Nvidia. Update (June 30, 2015): Done! See the latest post in the aformentioned Gentoo Forums thread. Sometime in the next month or so I’ll post in this blog the full details of my solution.
  11. Investigate why the KDE Network widget plasma-nm is crashing when I add/edit connections (see a recent KDE blog post Plasma-nm 0.9.3.6 release about the last update to plasma-nm-4.* which fixes some bugs). I suppose I need to wait for plasma-nm-0.9.3.5 to become stable in the Portage main tree. Update (April 30, 2015): Done! I got fed up with the buggy ‘Stable’ plasma-nm-0.9.3.4 so I added plasma-nm-0.9.3.5 to /etc/portage/package.accept_keywords/plasma-nm and Version 0.9.3.5 is no longer crashing.
  12. Get qr-tools (QR Code application) working on the Clevo. Update (April 29, 2015): Done!

Update (September 24, 2016): I upgraded xorg-server from 1.17.4 to 1.18.4 today and had to change the following line in /etc/X11/xorg.conf:

Screen 0 "nvidia" 0 0

to:

Screen 1 "nvidia" 0 0

See the Gentoo Forums post What’s up with xorg-server 1.18 and Optimus? for further details

Downloading YouTube video or only audio

One of my favourite Linux applications is the command-line utility youtube-dl, which I use quite often to download YouTube videos or extract only the audio, either for leisure or work purposes.

Downloading a video

  1. Copy the URL of the YouTube video from the browser’s address bar. I’ll use the video ‘Como fazer um bom churrasco de Picanha‘ as an example.

  2. Ascertain the types and resolutions available for that particular video:

    $ youtube-dl -F https://www.youtube.com/watch?v=8BuQCD8eh9k
    8BuQCD8eh9k: Downloading webpage
    8BuQCD8eh9k: Extracting video information
    8BuQCD8eh9k: Downloading DASH manifest
    [info] Available formats for 8BuQCD8eh9k:
    format code extension resolution  note
    171         webm      audio only  DASH audio  118k , audio@128k (44100Hz), 5.05MiB
    140         m4a       audio only  DASH audio  129k , m4a_dash container, aac @128k (44100Hz), 5.99MiB
    141         m4a       audio only  DASH audio  256k , m4a_dash container, aac @256k (44100Hz), 11.90MiB
    160         mp4       256x144     DASH video  111k , 15fps, video only, 5.03MiB
    242         webm      426x240     DASH video  190k , 1fps, video only, 7.19MiB
    133         mp4       426x240     DASH video  248k , 30fps, video only, 11.33MiB
    243         webm      640x360     DASH video  378k , 1fps, video only, 13.83MiB
    134         mp4       640x360     DASH video  465k , 30fps, video only, 12.98MiB
    244         webm      854x480     DASH video  744k , 1fps, video only, 27.11MiB
    135         mp4       854x480     DASH video  873k , 30fps, video only, 25.98MiB
    247         webm      1280x720    DASH video 1378k , 1fps, video only, 49.45MiB
    136         mp4       1280x720    DASH video 1837k , 30fps, video only, 58.40MiB
    17          3gp       176x144
    36          3gp       320x240
    5           flv       400x240
    43          webm      640x360
    18          mp4       640x360
    22          mp4       1280x720 (best)

  3. Chose which video resolution you would like to download. For example I’ll download the highest resolution available for this particular video (Format 22, which is a 1280×720 MPEG-4 file):

    $ youtube-dl -f 22 -o Como_fazer_um_bom_churrasco_de_Picanha.mp4 https://www.youtube.com/watch?v=8BuQCD8eh9k
    8BuQCD8eh9k: Downloading webpage
    8BuQCD8eh9k: Extracting video information
    8BuQCD8eh9k: Downloading DASH manifest
    [download] Destination: Como_fazer_um_bom_churrasco_de_Picanha.mp4
    [download] 100% of 83.77MiB in 07:09

Extracting audio from YouTube videos

Let’s say you just want an audio file of the video’s sound track. There are several options, so I’ll just show a few simple examples here:

  1. MP3 file at default quality:

    $ youtube-dl --extract-audio --audio-format mp3 -t https://www.youtube.com/watch?v=8BuQCD8eh9k
    8BuQCD8eh9k: Downloading webpage
    8BuQCD8eh9k: Extracting video information
    8BuQCD8eh9k: Downloading DASH manifest
    [download] Destination: Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.m4a
    [download] 100% of 11.90MiB in 00:56
    [ffmpeg] Correcting container in "Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.m4a"
    [ffmpeg] Destination: Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.mp3
    Deleting original file Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.m4a (pass -k to keep)

    You can see from the console output above that youtube-dl downloads an M4A file and then uses ffmpeg to convert it to the audio file type you specified. You can check the file’s properties:

    $ file Como\ fazer\ um\ bom\ churrasco\ de\ Picanha-8BuQCD8eh9k.mp3
    Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.mp3: Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 64 kbps, 44.1 kHz, Stereo

  2. MP3 file of 128 kbps:

    $ youtube-dl --extract-audio --audio-format mp3 --audio-quality 128K -t https://www.youtube.com/watch?v=8BuQCD8eh9k
    8BuQCD8eh9k: Downloading webpage
    8BuQCD8eh9k: Extracting video information
    8BuQCD8eh9k: Downloading DASH manifest
    [download] Destination: Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.m4a
    [download] 100% of 11.90MiB in 01:23
    [ffmpeg] Correcting container in "Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.m4a"
    [ffmpeg] Destination: Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.mp3
    Deleting original file Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.m4a (pass -k to keep)
    $ file Como\ fazer\ um\ bom\ churrasco\ de\ Picanha-8BuQCD8eh9k.mp3
    Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.mp3: Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, Stereo

  3. M4A file at best quality available for that particular video:

    $ youtube-dl --extract-audio --audio-format best -t https://www.youtube.com/watch?v=8BuQCD8eh9k
    8BuQCD8eh9k: Downloading webpage
    8BuQCD8eh9k: Extracting video information
    8BuQCD8eh9k: Downloading DASH manifest
    [download] Destination: Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.m4a
    [download] 100% of 11.90MiB in 01:07
    [ffmpeg] Correcting container in "Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.m4a"
    Post-process file Como fazer um bom churrasco de Picanha-8BuQCD8eh9k.m4a exists, skipping

To see the many options available in youtube-dl:

$ man youtube-dl

or:

$ youtube-dl --help

Have fun!