Connecting Bluetooth keyboard to Linux Mint

I was having trouble connecting my Nexxtech Bluetooth keyboard to my ThinkPad T470 running Linux Mint.

I have encountered this problem before with other computers.

I decided to record what worked for me this time so that I can easily refer to it when and if it happens again with another computer.

Once the connection is made, the keyboard seems to work well.

The article I used from Medium, written by Wainaina Gichuhi, had instructions for both GUI and the terminal.

The GUI method did not work, but the instructions for the Linux command line in a terminal worked perfectly.

In case the article disappears the instructions are adapted from the source article as follows:

Connect via Terminal

Put your mouse or keyboard in pairing mode (the instructions are provided by the device manufacturer).

At the terminal prompt, type

bluetoothctl

In the bluetoothctl prompt, type as follows:

scan on

You should see available bluetooth devices and their MAC address listed. Note your keyboard or mouse and copy the MAC address.

Then, at the prompt:

pair MAC

And then

connect MAC

and then

trust MAC

Trusting a Bluetooth device ensures that it reconnects automatically after a reboot, wake or when turned on.

Remember to replace MAC with your keyboard or mouse MAC address.

For example, when I did the scan, the MAC address for my keyboard was 20:11:10:12:24:0B

Various Tips and Tricks in Linux Bash

Find wireless device names:

nic=$(cat /proc/net/wireless | awk -F: '/^w/ {print $1}')

Check for internet connectivity:

nc -z 1.1.1.1 53 >/dev/null 2>&1 && echo "online" || echo "offline"

Explanation of the above command:
nc – netcat – Read and write data across networks – arbitrary TCP and UDP connections and listens.
-z Just scan for listening daemons, without sending any data to them.
1.1.1.1 – is a free Domain Name System (DNS) service by the American company Cloudflare in partnership with APNIC.
53 – is the port number associated with Domain Name System
> all standard and error output is directed to the null device
a zero response indicates success “online”, a non-zero response indicates “failure”

Stop/Start Cron Processing in Raspbian (Raspberry Pi OS)

sudo systemctl stop cron.service

sudo systemctl start cron.service

Mounting a VirtualBox Hard Drive image in Linux

I was looking for a way to access files on a Virtual Box hard drive. As usual StackExchange came to the rescue. Here is how I mounted a FreeDos virtual hard drive and gained access to the files that were on it:

sudo modprobe nbd
sudo qemu-nbd -r -c /dev/nbd1 /home/peter/VirtualBox\ VMs/Knoppix/FreeDos/NewVirtualDisk1.vmdk
sudo mount /dev/nbd1p1 /media/peter/vmdk/

Now the hard drive files are available on /media/peter/vmdk/

When done:
sudo umount /media/peter/vmdk

Solving “Hang” on Dell Laptop running Linux Mint

I found this workaround and applied it to my Dell Inspiron 3551 (purchased with Ubuntu pre-loaded, but currently running Linux Mint 19.1 (Tessa)

Source: https://easylinuxtipsproject.blogspot.com/p/bugs.html#ID25

Random freezes on Intel-based computers

25. On certain hardware combinations with Intel CPU’s, you can experience random freezes of your system. In particular the Bay Trail series of Intel CPU’s is known to be affected by this.

(The Dell Inspiron 3551 fits this description exactly.)


This can often be solved by sharply reducing the maximum sleep state of the CPU when idle (maximal C-state). Namely from 6 (or 9) to 1.

The price you pay for that is some extra power consumption, which is of course rather annoying for laptops (you’ll notice a somewhat higher battery drain speed). But at least your machine should run stable now.

Proceed like this:

a. Launch a terminal window.
(You can launch a terminal window like this: *Click*)

b. First check your current max C-state. Use copy/paste to transfer the following command line into the terminal:

cat /sys/module/intel_idle/parameters/max_cstate

Press Enter.

The output will probably be 6 or 9.

c. Now copy/paste the following line into the terminal, in order to edit a settings file:

xed admin:///etc/default/grub

Press Enter.

d. Delete this existing line:

GRUB_CMDLINE_LINUX=””

Replace it by this line (use copy/paste to transfer it):

GRUB_CMDLINE_LINUX=”intel_idle.max_cstate=1″

e. Save the changes and close the modified file.

f. Then execute this command line in the terminal:

sudo update-grub

g. Reboot.

h. Check the change with this command:

cat /sys/module/intel_idle/parameters/max_cstate

The output should be 1 now.

[P]ersonal[A]udio[R]ecorder – Part Two

I’ve only done an elementary amount of BASH scripting, so as a learning tool I decided to automate even further, the process I described in Part One. Many streaming URLs are very long and complicated, so it makes sense to collect them and then make them accessible for automated “copy” and “paste”.

We live in a country of different time zones and therefore it is very convenient to be able to “listen” to the radio (especially the Canadian Broadcasting Corporation or CBC) in a different region at a different time. This can be used to hear something that was missed the first time, or to listen “ahead” to something when it is first aired.

So my desire to automate the “stream recording” process led me to find a list of CBC streaming URLs. Having done this I then compiled a list of places and stream URLs and put them in a text file in the form:
line1: place (in quotes)
line2: url (unquoted)

This can then be read into a Bash Array and converted to a Bash Associative Array so that a URL can be associated with a place or radio station name.

I learned a lot putting this script together, and it took a maddening amount of debugging as I learned some of the idiosyncrasies of Bash syntax. In particular I learned that quotes and/or the lack of them can lead to great frustration and disbelief.

In the process I also learned that processing command options and arguments is a non-trivial exercise. Fortunately I discovered argbash and despite some initial confusion about the “argbash process” I plugged on and learned how to use it.

The script I ended up writing is certainly not bomb-proof, but it suits my purpose pretty well and it can easily be used to schedule audio recordings of one minute to many minutes (up to the limit of available disk space!) of recording from any one of forty-two different radio streams. This list can certainly be expanded. There are literally hundreds, if not thousands, of radio streams available. For now I am interested in the CBC streams, along with a local internet radio station called “Cabin Radio”.

I also learned how to use “zenity” to prompt an interactive user of the “stream_record” script with pretty Gtk dialogue boxes.

Using a Linux box as a PAR (Personal Audio Recorder – think PVR only Audio instead of Video)

I was interviewed by a friend who was doing a seasonal special for a local Internet Radio station. The timing for the playback of the program was not conducive to listening for it “live”. So I looked online for some advice on how to set up a recording of an internet radio program given a time and date and using a URL for the radio stream.

My preference was that the whole process would work from the Linux command line. That would allow me to use the very handy “at” command. More complicated circumstances would also allow a command line to be invoked as a “cron” job. I settled on the “at” command in this particular case. It simply meant that I needed to make sure that the computer was up and running at the appropriate time of day.

An internet search gave me a possible command line solution using VLC. See below for the useful links:

https://www.sourcefabric.org/blog/schedule-stream-recordings-from-the-command-line-part-1-yd2znuky
https://www.sourcefabric.org/blog/schedule-stream-recordings-from-the-command-line-part-2-vvm0irq2

Given that these blog posts were almost five years old, I wanted to make sure that the advice was still valid. Some tests with the software revealed that the instructions were pretty much still sufficiently correct to be useful.

Now that I knew that VLC could do the job of saving an audio file, and that the “at” command could be used to do the scheduling, all that was left was to find the URL for the radio stream. This proved to be a little bit of an exercise in reverse engineering. The radio station advertises a “Listen Live” link. As might be expected, that works fine for listening live, but the URL is not suitable for the VLC command line. Fortunately, the radio station also advertises a “live link”. The “live link” points to a “foo.pls” file. Looking into the “foo.pls” file with a text editor reveals that it is a text file, and in that text file there is a URL that turns into the one that can be used with VLC.

So to sum up the whole process:

Use the “at” command to schedule the recording of the stream:

at 06:00

(The “at” command is very flexible in terms of how the date and time are specified. This is one of the simplest forms. i.e. At 6:00 am do the following. )

This will start an interactive exchange consisting of the command to run at the specified time. More than one command can be provided. After the last command type Ctrl-D.

In this case, the command is:

cvlc “http://stream_url” –sout file/mp3:/home/peter/Audio/foo$(date ‘+%F_%H_%M_%S’).mp3 –run-time 30 –stop-time 30 vlc://quit

This will record the stream as an MP3 in the specified file with the date and time as part of the file name.

See the two blog links above for an explanation of the –run-time and –stop-time options for VLC

Gracefully Reboot Ubuntu/Mint/Debian (and perhaps others)

There you are, staring at a crashed Gnome session.

CTRL-ALT-BKSPC

does nothing.

CTRL-ALT-F1

won’t bring you to a terminal where you could

cd to /etc/init.d
and
restart gdm

In short, your choices seem to be limited to holding down the power button and chancing file system corruption or nothing.

But wait!
There are two more options that you may not have known about!

Here are two ways to first try and kill just the process on your current terminal (thus allowing you to get back into your machine and at least attempt)

shutdown -h now

and if that fails, to bring your machine down in a more graceful manner than a hard shutdown.

First, we’ll try and kill all the process on your current terminal. To do this, hold down the following keys –

ALT + SysReq + k

What the heck is a SysReq key? Look for it on your PrtSc or Print Screen key. (On laptop keyboards, the key may not be labelled with SysReq, but it will likely work anyway.)

The k in this instance stands for Kill.

If that doesn’t work for you, it’s time to take drastic action. You’ll now enter a series of keystrokes that will tell your computer to do some housekeeping before shutting down.

ALT + SysReq + r

This stands for Raw keyboard mode.

ALT + SysReq + e

This terminates all processes

ALT + SysReq + i

Kill’s all processes that weren’t terminated nicely.

ALT + SysReq + s

This syncs the disk.

ALT + SysReq + u

Remounts all filesystems as read only.

ALT + SysReq + b

Reboots.

That’s a heck of a lot better than simply holding down the power button and hoping everything works out okay.

How will you ever remember all those keystrokes?
There is a long held mnemonic that makes it a bit easier:

Raising Elephants Is So Utterly Boring – REISUB
or perhaps it is easier to remember that it spells BUSIER backwards!

You should use this method only if other methods (mentioned above) fail.

Kernel Panic Workaround

I’ve been getting kernel panic boot errors on my Dell Inspiron 3551 Ubuntu Linux laptop. I found a workaround on pastebin. I implemented it, and from my limited testing, it looks as if it has solved the problem (yay!). I’m pasting it here so that it does not disappear from pastebin.

Using intel_pstate instead of acpi-cpufreq to manage cpu frequency seems to prevent kernel panics on the Inspiron 3551 due to a regression in step_wise.c in the default Ubuntu kernel. This is a guide on how to switch to the intel_pstate driver.

Install cpupower:

sudo apt-get install linux-tools-common linux-tools-generic

Edit /etc/default/grub:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_pstate=enable"

sudo update-grub

Reboot and check if the intel_pstate driver is enabled:

cpupower frequency-info

intel_pstate has two frequency governors: performance and powersave, but not ondemand. Switch between the two with:

sudo cpupower frequency-set -g powersave

sudo cpupower frequency-set -g performance

You can check which governor is active with cpupower or with sysfs:

cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor

If you like, Intel Turbo Boost can be disabled with:

echo 1 > /sys/devices/system/cpu/intel_pstate/no_turbo

Dell installs tlp so edit /etc/default/tlp changing line 22:

CPU_SCALING_GOVERNOR_ON_AC=performance
CPU_SCALING_GOVERNOR_ON_BAT=powersave

I made performance default as powersave is slower than ondemand:

60 seconds after login ubuntu executes /etc/init.d/ondemand which changes the cpu frequency scheduler to powersave if intel_pstate is enabled. Edit this file changing the governor in line 40:

*powersave*)
#GOVERNOR="powersave"
GOVERNOR="performance"
break
;;
*)

That's all :)