Category Archives: Uncategorized

RHCSA’s Prep

At the end of last year, I took a training to prepare for Red Hat Certified System Administrator (RHCSA EX200) exam. Now it’s February and I haven’t taken the exam yet. Even worse, I forgot most of the things I learned during that 3 day training. Well, since I’m being chased to get this exam done ASAP, with a passing grade of course, I think now it’s the best time to start revising the material again. As part as the exam prep, I’m going to post small challenges and solutions.

I found a task of the day posted on CertDepot website, a very good resource to learn about Red Hat exam. So, let’s see if can I even do that. Here is the challenge:

Allowed time: 5 minutes.
Create a new user account called “bob” with password “redhat” and set expiration in one week.

My solution:

# man useradd
# useradd -e 2017-02-26 bob
# passwd bob

Time taken: 2 minutes 26 seconds.

I must admit the solution is not the most elegant, as I had to manually calculate 7th day’s date from today (2017-02-19).

Here’s another alternative solution according to this:

# useradd -e `date -d "7 days" +"%Y-%m-%d"` bob
# passwd bob
    Update:

Another way to set the account expiry date is using chage.

# chage -E `date -d "7 days" +"%Y-%m-%d` bob
# chage -l bob
Last password change					: Feb 19, 2017
Password expires					: May 20, 2017
Password inactive					: never
Account expires						: Feb 26, 2017
Minimum number of days between password change		: 0
Maximum number of days between password change		: 90
Number of days of warning before password expires	: 7

How to toggle between buffers in Vim with vim-airline

First if you haven’t yet heard about vim-airline plugin, and you’re a Vim user, you owe it to yourself to check it out.

By default vim-airline displays the opening buffers on the top part of the window.

So how to navigate between those buffers? Well, according to this, it seems those buffers are for visual only. To navigate between them, we can use :bp for previous buffer, and :bn for next buffer. Alternatively, we can use :ls to list all buffers, then navigate to a particular buffer by running :number (substitute number with an actual number).

However, if you know any better or more elegant ways to switch between the opening buffers, please do share!

How extract 7zip file on Linux

This evening I need to extract a file with .7z extension. Guess what? I don’t know how to do that. I probably don’t even have 7zip program installed on my Fedora machine.

Here’s something to remind myself how to get it working.

First let’s find out what package we need to install:

[root@watamem ~]# dnf search 7zip
Last metadata expiration check: 3:14:50 ago on Thu Oct 20 20:39:30 2016.
================ N/S Matched: 7zip ==================
p7zip-plugins.x86_64 : Additional plugins for p7zip
p7zip.x86_64 : Very high compression ratio file archiver
p7zip-gui.x86_64 : 7zG - 7-Zip GUI version

So, it seems we need to install p7zip.

# dnf install p7zip
...
Installed:
  p7zip.x86_64 16.02-1.fc24 

Okay. What is the command to run? My guess is that there should be one or two file in /usr/bin.

# rpm -ql p7zip | grep bin
/usr/bin/7za

Ah ha, it’s 7za. Now we can check its man page on how to extract file. I don’t have to remind me to type man 7za, do I?

To extract a .7z file with full path use the x function letter. For example:

$ 7za x a_crompressed_file.7za

If you use Debian based system, you probably need to install the same package name (p7zip) using apt or aptitude command instead. The command to extract file should be just the same.

Losing ZFS storage for Docker

I use ZFS as a storage driver for docker engine running on my machine. Today after my machine rebooted from a crash, yes Linux system crashes too, I notice that all my docker images and containers disappeared.

~ ❯❯❯ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
~ ❯❯❯ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

First thing came to my mind was “did I accidentally destroy docker zfs data set last night?”

# zfs list
NAME                                                                                USED  AVAIL  REFER  MOUNTPOINT
tank                                                                               1.52T   239G   120K  /tank
tank/docker                                                                         999M   239G  73.9M  /var/lib/docker

It’s still there. At that point I suspected that Docker might no longer use ZFS as its data storage.

~ ❯❯❯ docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 1.12.1
Storage Driver: devicemapper
 Pool Name: docker-253:0-2753561-pool
 Pool Blocksize: 65.54 kB
 Base Device Size: 10.74 GB
 Backing Filesystem: xfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 11.8 MB
 Data Space Total: 107.4 GB
 Data Space Available: 31.79 GB
 Metadata Space Used: 581.6 kB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.147 GB
...

The output information from docker info command confirmed my suspicion. But how do we change the storage back to ZFS instead of devicemapper? According to ZFS storage in practice the only prerequisite to have ZFS as the data storage is having /var/lib/docker as a ZFS dataset.

I was under the impression that tank/docker was mounted to /var/lib/docker. Actually /var/lib/docker directory lived on my local LVM file system (hence devicemapper was the storage driver).

To fix this, I stopped docker service, cleared out /var/lib/docker, and re-mounted the tank/docker dataset.

# systemctl stop docker
# rm -rf /var/lib/docker/*
# mount tank/docker
# systemctl start docker

Let’s see if it’s working again.

docker info
Containers: 6
 Running: 0
 Paused: 0
 Stopped: 6
Images: 18
Server Version: 1.12.1
Storage Driver: zfs
 Zpool: tank
 Zpool Health: ONLINE
 Parent Dataset: tank/docker
 Space Used By Parent: 1047826432
 Space Available: 263167705088
 Parent Quota: no
 Compression: off

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
abiosoft/caddy      latest              af55a59400be        2 days ago          40.69 MB
...

Everything seemed to back to normal. I’m still not sure why tank/docker wasn’t mounted on boot, but I’ll leave it for another day. As for now, I’m quite happy.

Install Hack font on FreeBSD 10

FreeBSD 10 comes with a pkgng package manager which allows to install binary packages faster and easier.

Unfortunately, there is no binary package available for hack-font for FreeBSD 10. What is hack-font? It’s a very good font which looks very good for source code.

Here’s how to install it from source.

Check /usr/ports/x11-fonts to see if there is a directory named hack-font. If not, you might need to download or update the ports first. If you don’t have ports installed at all, do this:

# portsnap fetch
# portsnap extract

If you already have ports install previously, but just need to run the update:

# portsnap fetch update

Then navigate to /usr/ports/x11-fonts/hack-font, run make command as the following:

# cd /usr/ports/x11-fonts/hack-font
# make install clean

That’s it. If you use portmaster command to install package from source, you probably can just run:

# portmaster x11-fonts/hack-font

Enjoy hack-(font)ing!

Puppetserver failed to start after upgrading to 2.5.0

I upraded puppetserver from 2.4.0 to 2.5.0 on a server running Centos 6.8. Then, puppetserver no longer starts.

The log (I think it was puppetsrver-daemon.log) said:

Exception in thread "main" java.lang.IllegalArgumentException: Specified bootstrap config file does not exist: '/etc/puppetlabs/puppetserver/bootstrap.cfg'

As the error reported, /etc/puppetlabs/puppetserver/bootstrap.cfg was not there. The disappearance must have happened during the puppetserver upgrade. I can confirm this by looking at my backup directory and finding the boostrap.cfg file there: /srv/backup/etc/puppetlabs/puppetserver/bootstrap.cfg.

According to this issue #1247, the boostrap.cfg file is broken into 2 files and relocated to a different directories. This issue was raised sometimes in May, and the problem only happened on my server today in August. How is that possible? This should affect more people right? So far, I haven’t seen any one reported it yet.

I need to get puppetserver running again and fast. Here is a quick fix.

Edit /etc/sysconfig/puppetserver, and make change to BOOTSTRAP_CONFIG variable:

#BOOTSTRAP_CONFIG="/etc/puppetlabs/puppetserver/bootstrap.cfg"
BOOTSTRAP_CONFIG="/etc/puppetlabs/puppetserver/services.d/,${INSTALL_DIR}/config/services.d/"

Start puppetserver and it is working again (for now).

# service puppetserver start
Starting puppetserver:                                     [  OK  ]

GDM Doesn’t Start on Fedora 23 Beta and VirtualBox

I just finished upgrading Fedora 22 to Fedora 23 Beta and upon rebooting, gdm no longer started. I tried to reinstall the VirtualBox Guest Additions; unfortunately it still didn’t fix.

To cut the story short, someone has given a working tip at this forum. The solution is to downgrade xorg-x11-server-Xorg package.

# dnf --showduplicates --allowerasing --releasever=22 downgrade xorg-x11-server-Xorg
# mount /dev/cdrom /mnt; cd /mnt
# ./VBoxLinuxAdditions.run
# reboot

After rebooting, I was able to login again.

Credit: http://forums.fedoraforum.org/showthread.php?t=306857

Kinetis Design Studio crashes on Kubuntu 14.04

On Kubuntu 14.04, Kinetis Design Studio (KDS) could be started, but when I tried to create a new project, it’d crash with the following message displayed in the terminal:

$ kinetis-design-studio 
java: /build/buildd/gtk2-engines-oxygen-1.4.5/src/animations/oxygencomboboxdata.cpp:87: void Oxygen::ComboBoxData::setButton(GtkWidget*): Assertion `!_button._widget' failed.

KDS is a Eclipse-based IDE. So I suspect the issue is related to Eclipse IDE itself. (I can’t confirm this as I’m not running the Eclipse IDE on this machine. I know I could have just downloaded and test it; but I don’t have time.)

The (error) message above gave us some hints where the problem was originated from. According to this Eclipse bug report1, yes this bug is caused by a bug in gtk2 theme oxygen.

To change the GTK themes on Kubuntu 14.04, open System Settings window by clicking on: K -> Computer -> System Settings. Then under “Common Appearance and Behavior”, click on “Application Appearance”. Look for GTK on left window pane and click on it.

On the right side on GTK – System Settings window, you should be able to select a different theme for GTK2 from the drop down list. In my case, I selected “Raleigh”. Then click on “Apply” button.

kds3

Let’s try to run it and create a new project:

kds4

Voila, it worked! The only downside is that now it makes all applications that depends on GTK2 look ugly. 🙁

Is there anything we can do about it? Well, as it turned out we can actually ask Eclipse based applications to use GTK3 theme instead of GTK2.

$ export SWT_GTK3=1
$ kinetis-design-studio

Here’s KDS running using GTK3 theme:

kds5

(1) Bug 440660 – Several dialogs incompatible with GTK (Oxygen = default theme for Kubuntu)

PF firewall rule for DNS server

A reminder to readers, most of these blog posts are to remind me what I have done or fixed some problems. What works for me may not work for you. Most of the time, they aren’t even the best practice.

Here’s a snippet of the PF firewall rule on my FreeBSD box which acts as a DNS server. Basically, the firewall opens up UDP port 53 to allow LAN access it.

ext_if = "ue0"
...
pass in on $ext_if proto udp from 192.168.1.0/24 to any port 53 keep state

Reference: IPFW rules for DNS Resolvers

R-tip: List installed R packages

> rownames(installed.packages())
 [1] "bitops"     "manipulate" "RCurl"      "rgl"        "rstudio"   
 [6] "scrapeR"    "XML"        "base"       "boot"       "class"     
[11] "cluster"    "codetools"  "compiler"   "datasets"   "foreign"   
[16] "graphics"   "grDevices"  "grid"       "KernSmooth" "lattice"   
[21] "MASS"       "Matrix"     "methods"    "mgcv"       "nlme"      
[26] "nnet"       "parallel"   "rpart"      "spatial"    "splines"   
[31] "stats"      "stats4"     "survival"   "tcltk"      "tools"     
[36] "utils"     
>