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

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

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!