Author Archives: NC

Navigating the insides of LibreOffice

LibreOffice has Indent and Unindent functionality built-in. But what if you want to manage hanging indent the way it’s done in Microsoft Word, with Ctrl-T and Ctrl-Shift-T keystrokes? Here’s a pair of macro functions that do the work (they will need to be assigned to keystrokes using the Customize functionality in LibreOffice):

Sub HangingMore()
  oCursor = ThisComponent.CurrentController.getViewCursor()
  oCursor.ParaLeftMargin = oCursor.ParaLeftMargin + 1270
  oCursor.ParaFirstLineIndent = oCursor.ParaFirstLineIndent - 1270
End Sub

Sub HangingLess()
  oCursor = ThisComponent.CurrentController.getViewCursor()
  oCursor.ParaLeftMargin = oCursor.ParaLeftMargin - 1270
  oCursor.ParaFirstLineIndent = oCursor.ParaFirstLineIndent + 1270
End Sub

The macros are basically mirror images of each other. Each begins by capturing the properties of wherever the text cursor is into the oCursor variable. Those properties are then manipulated directly. The names of those properties should be self-explaining; the only trick is, margins and  indents are stored in 100ths of a millimeter. In other words, the number 1270 corresponds to 1.27 cm, or half-inch. Metrically-minded users may want to change this to the nice round 1000…

Restoring lost Wi-Fi connectivity on Linux

Situation: an aging Dell Optiplex machine running Pop!_OS has lost its Wi-Fi connectivity following a kernel upgrade.

A piece of background knowledge: Pop!_OS relies on Network Manager to manage Wi-Fi connectivity. This will be important in the later stages (steps 4 and 5 below), but has no bearing on the earlier stages.

Step-by-step solution: connect the computer to the LAN by cable, log in as root (or use sudo if you prefer), and complete the following steps.

STEP 1. Get the list of PCI devices installed on the machine:

# lspci -nn

Review the output and identify the line that describes the Wi-Fi card. In our case, the relevant line is:

03:00.0 Network controller [0280]: Broadcom Inc. and subsidiaries 
  BCM4312 802.11b/g LP-PHY [14e4:4315] (rev 01)

STEP 1 RESULT: we know that our Wi-Fi card is manufactured by Broadcom and its hardware ID is 14e4:4315.  (incidentally, 14e4 is the code for Broadcom and 4315 is the code for the model of the device.)

STEP 2. Figure out what driver and firmware are required for the Wi-Fi card identified in Step 1. Start at Linux Wireless:

https://wireless.wiki.kernel.org/en/users/drivers

One by one, open pages for products made by the relevant manufacturer until you find the page for the driver that matches the hardware ID determined in Step 1 (or simply search the site for the hardware ID). In our case, the driver for the 14e4:4315 card is b43. A quick Internet search further reveals that the driver b43 is a part of package firmware-b43-installer, which needs a companion package, linux-firmware, to work.

STEP 2 RESULT: we know what driver and firmware we need .

STEP 3. Purge the package bcmwl-kernel-source (it’s probably the culprit that broke the system in the first place), install the driver and the firmware, and reboot the machine:

# apt-get purge bcmwl-kernel-source
# apt-get install firmware-b43-installer
# apt-get install linux-firmware
# reboot

STEP 3 RESULT: the necessary driver and firmware are now installed on the machine.

Up tp this point, we did not rely on any specific network management software. Steps 4 and 5 below are  specific to Network Manager; other network management utilities, such as connman, wicd, or wpa_supplicant, would have their own procedures to achieve the same end: connection to a wireless network.

STEP 4. Check if the Wi-Fi is working:

# nmcli dev wifi

STEP 4 RESULT: a list of available wireless networks is displayed. in the terminal

STEP 5. Connect to the desired wireless network:

# nmcli dev wifi connect [SSID] password [PASSWORD] ifname [INTERFACE]

where

  • [SSID] is the name of the wireless network
  • [PASSWORD] is the password to access the network
  • [INTERFACE] the name of wireless network interface (in our case, wlan0)

The actual command would look something like this:

# nmcli dev wifi connect MyWiFi password 1234567890 ifname wlan0

STEP 5 RESULT: we have a working WiFi connection.

STEP 6. Reboot to verify that the connection persists.

# reboot

STEP 6 RESULT: we have a working WiFi connection that persisted over a reboot.

Make Samba servers visible

Many system administrators have grown to love Samba, a piece of Linux software that allows to use Linux machines as file and print servers compatible with Windows networking. There is, however, an annoying problem with Samba machines: they are not automatically discovered on a Windows network (in other words, when a user clicks on the Network icon in File Explorer, Samba machines do not appear on the list, although they are accessible via “manual” addressing). To fix this problem, administrators can use wsdd:

https://github.com/christgau/wsdd

To install wsdd on Debian and derivatives, follow these simple steps.

Before installing, check for the latest version of the package by going to https://pkg.ltec.ch/public/pool/main/w/wsdd/. As of this writing, the latest version available there is wsdd_0.6.1_all.deb, so we will install it on our system

Once you know which version you are about to install, issue these commands from the terminal (assuming you are logged in as root; if not, simply add sudo at the beginning of each command):

wget https://pkg.ltec.ch/public/pool/main/w/wsdd/wsdd_0.6.1_all.deb
dpkg --install wsdd_0.6.1_all.deb
systemctl start wsdd
systemctl enable wsdd
systemctl status wsdd

Assuming everything went well, the last command will produce output that looks like this:

● wsdd.service - Web Services Dynamic Discovery host daemon
   Loaded: loaded (/lib/systemd/system/wsdd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2020-09-28 15:46:16 PDT; 22h ago
 Main PID: 16146 (python3)
    Tasks: 1 (limit: 4915)
   Memory: 7.8M
   CGroup: /system.slice/wsdd.service
           └─16146 python3 /usr/bin/wsdd

Be sure that the Loaded: line contains the word enabled; it indicates that the service you just installed will start again when the entire system restarts.

A few months later…

WSDD can be started with a variety of command-line options. Those options are specified in /etc/wsdd.conf. Here’s what I ended up using based on my local situation:

# command line parameters for wsdd 
WSDD_PARAMS="-i wlan0 -p -4 -w MYWORKGROUP"

-i wlan0 tells WSDD to listen on the wireless interface (my Samba server sits on a wireless network)

-p instructs WSDD to announce the server’s name as is (i.e., without converting it to upper or lower case)

-4 tells WSDD to work with IPv4 addresses only (i.e., not to worry about IPv6)

-w MYWORKGROUP indicates that the server belongs to MYWORKGROUP (obviously, the name of the actual workgroup has been changed to protect the innocent…)

Command-line PHP on QNAP hardware

QNAP network-attached storage devices run a lightweight Linux derivative. It’s not a fully-functional Linux (specifically, it can’t update itself from the command line), but a lot of “Linuxy” things are possible nevertheless. Specifically, it is possible to run PHP from the command line, as long as you take care to either refer to the PHP executable by its full path or add its location to $PATH.

On my HS-210, the PHP executable resides in /mnt/ext/opt/apache/bin. To verify which executable it is, I ran the following command:

/mnt/ext/opt/apache/bin/php -r "echo php_sapi_name();"

which returned

cli

This signifies that the executable is the command-line (CLI) executable rather than the CGI executable.

Battery report on Windows 10

Windows 10 has a command-line feature that generates a report on the condition of the battery. To generate the report, open the command line as administrator and type:

powercfg /batteryreport

The OS will generate the report as a viewable HTML file and output its location to screen:

C:\WINDOWS\system32>powercfg /batteryreport
Battery life report saved to file path 
 C:\WINDOWS\system32\battery-report.html.

Canons of good spin

Dan Dennet’s canons of good spin (heard in Reverse-engineering Religion):

  • It is not a bare-faced lie
  • You have to be able to say it with a straight face
  • It has to relieve skepticism without arousing curiosity
  • It should seem profound

Finding system information on Windows

In practical system administration, it is sometimes necessary to record edition and/or version of Windows along with the product key (for example, before installing a non-Windows OS with the view of using the Windows product key on a different machine). This can be accomplished by using systeminfo and piping its output to findstr:

systeminfo | findstr /B /C:"OS Name" /C:"OS Version"

This will output the requested data fields in a format similar to this:

OS Name:                   Microsoft Windows 10 Home
OS Version:                10.0.14393 N/A Build 14393

To display Windows 8.1 or Windows 10 product key, use wmic:

wmic path softwarelicensingservice get OA3xOriginalProductKey

Needless to say, all of the above has to be done while running the command line interpreter with administrative privileges.

Dealing with a c-state bug

Computers that run Linux (especially newer kernel versions) on Intel Bay Trail family processors are sometimes affected by a c-state bug. It manifests as a random and total freeze of the system. Screen content remains unchanged, but the machine becomes completely unresponsive. I have encountered this on units that run Intel Celeron N2920, but other members of the Bay Trail family can also be affected. Also, the kernel.org page linked to above suggests that the bug exists in kernel versions 3.16-4.2, but I have encountered it on Ubuntu 16.04 (kernel version 4.4) and Ubuntu 16.10 (kernel version 4.8), so this bug, as far as I can see, is still extant.

The freeze happens when the processor receives an instruction to enter an unsupported sleep state. The workaround, therefore, is to tell the kernel to stop giving those instructions to the processor. This is accomplished by editing the grub configuration file.

Open the grub configuration file for editing as root using your favorite editor. For example, assuming you’re using nano and are not logged in as root, you can type this into the terminal:

sudo nano /etc/default/grub

When the file opens, find the line that starts with GRUB_CMDLINE_LINUX_DEFAULT and change it to include intel_idle.max_cstate=1. Typically, after you’re done editing, the line would look like this:

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_idle.max_cstate=1"

The values quiet and splash are usually set by default and should be left in place.

Save the file (Ctrl+o, then Enter), exit (Ctrl+x), and apply the update:

sudo update-grub

Finally, restart the system.

Managing Windows product keys

Windows includes a little-known utility named slmgr (which presumably stands for Software License ManaGeR) that allows the administrator to install and uninstall Windows product keys (may be useful when upgrading). Both installation and uninstallation have to be done from the command line running as Administrator.

Uninstallation is done in two steps. First, the administrator needs to display values associated with the currently installed key:

slmgr /dlv

When this command is complete, Windows shows a message box showing a series of values associated with the currently installed product key, including Activation ID. The Activation ID (a series of numbers, letters, and dashes) is used in the second step:

slmgr /upk [Activation ID goes here]

If everything went well, Windows will show a message box saying Uninstalled product key successfully.

Product key installation is a simpler single-step procedure:

slmgr /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX

The Xs, of course, represent the product key. If everything went well, Windows displays a message box saying Installed product key XXXXX-XXXXX-XXXXX-XXXXX-XXXXX successfully.

To display values returned by slmgr in the console, rather than in a message box, or save them into a text file, use cscript. For example:

cscript slmgr.vbs /dlv
cscript slmgr.vbs /dlv > C:\Users\Public\licinfo.txt

The first command will display output in the console, the second, save it into the specified text file.

Predictors of hard drive failure

From the ever so helpful people at Backblaze:

For the last few years we’ve used the following five SMART stats as a means of helping determine if a drive is going to fail.

Attribute Description
SMART 5 Reallocated Sectors Count
SMART 187 Reported Uncorrectable Errors
SMART 188 Command Timeout
SMART 197 Current Pending Sector Count
SMART 198 Uncorrectable Sector Count

When the RAW value for one of these five attributes is greater than zero, we have a reason to investigate. We also monitor RAID array status, Backblaze Vault array status and other Backblaze internal logs to identify potential drive problems. These tools generally only report exceptions, so on any given day the number of investigations is manageable even though we have nearly 70,000 drives.