Category Archives: HowTo

Changing a User’s Password on FreeBSD

Before getting into how to change a user’s password on FreeBSD, let’s have a quick revision on how that can be done on a Linux system.

As a user we can change the password by typing:

$ passwd
Changing password for user kenno.
Changing password for kenno.
Current password: 
...

Or with a root account, we can change/set the password for another user:

# passwd kenno
Changing password for user kenno.
New password: 
...

How about a FreeBSD? It should be the same way as how it’s done on Linux right? Right? Well, not quite.

On a FreeBSD system, in addition to run the passwd command, we also need to generate the password databases to be “in sync” with the plain text files.

# pwd_mkdb /etc/master.passwd

You can learn more about both passwd and pwd_mkdb, by running:

$ man passwd
$ man pwd_mkdb

Ref: Can’t change user password

How to remove a user password

Sure, you Linux gurus must be laughing at me to see this post. However, this is my 2nd time needing to remove a user’s password and I had to Google for it! So here is just a quick tip to mind your truly:

# passwd -d your_username

In case you’re wondering why I need to remove a password for an account, it’s for my 4 year old daughter who enjoys playing supertuxcart. She wants to have her own user account on a Fedora 24 box without a password.

Ref: https://ask.fedoraproject.org/en/question/47102/how-to-remove-user-password/

Fix corrupted GPT on FreeBSD

One of the disks in my FreeBSD server reported an issue:

Jul 14 18:00:56 nas kernel: GEOM: da0: the primary GPT table is corrupt or invalid.
Jul 14 18:00:56 nas kernel: GEOM: da0: using the secondary instead -- recovery strongly advised.
Jul 14 18:00:56 nas kernel: GEOM: diskid/DISK-67304734999999999999: the primary GPT table is corrupt or invalid.
Jul 14 18:00:56 nas kernel: GEOM: diskid/DISK-67304734999999999999: using the secondary instead -- recovery strongly advised.

To verify it, first I used gdisk command:

root@nas:~ # gdisk /dev/da0
GPT fdisk (gdisk) version 0.8.10

Caution! After loading partitions, the CRC doesn't check out!
Warning! Main partition table CRC mismatch! Loaded backup partition table
instead of main partition table!

Warning! One or more CRCs don't match. You should repair the disk!

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: damaged

****************************************************************************
Caution: Found protective or hybrid MBR and corrupt GPT. Using GPT, but disk
verification and recovery are STRONGLY recommended.
****************************************************************************

Command (? for help): q

An alternative way to verify this is to use gpart command:

root@nas:~ # gpart show da0
=>       34  976773101  da0  GPT  (466G) [CORRUPT]
         34  976773101       - free -  (466G)

I think it’s possible use gdisk to repair the corrupted GPT table, but I tried gpart and it worked:

nas:~ # gpart recover /dev/da0
da0 recovered
root@nas:~ # gpart show da0
=>       34  976773101  da0  GPT  (466G)
         34  976773101       - free -  (466G)

How to convert vdi to qcow2 image

vdi file is a type of disk image used by VirtualBox. qcow2, on the other hand, is the format of disk image used by KVM.

Recently, I want to move some existing virtual machines running on VirtualBox to KVM. To do that I need to convert the disk image from vdi to qcow2. Here’s one way to achieve that:

# qemu-img convert -f vdi -O qcow2 disk.vdi disk.qcow2

Ref: How to convert VirtualBox vid to KVM qcow2

FreeBSD git fatal: Unable to find remote helper for ‘https’

I just found out that git is not fully functional on my FreeBSD (11) box. It was installed from port (using portmaster git). I can clone a repo using SSH key, but not with HTTPS.

I’m not quite sure if it’s always been this way. Here is how to fix it:

1) Reinstall curl

# pkg remove curl
# portmaster curl

2) Reinstall git

# pkg remove git
# portmaster git

Why did I install git from port? Well, ‘cuz there is no binary package for FreeBSD 11 arm, which runs on my Raspberry Pi B+.

Create bootable USB Fedora 24

Every time there is a new release of Linux distro, I need to create a bootable USB. And, I forgot how I did it last time. So, I tried by using the “Startup Disk Creator” program installed on my Ubuntu workstation, only to find out that it didn’t even work.

After a while I remember, it was just a matter of using dd command to copy the ISO image to the USB.

Here is how I did it last time for Fedora 24:

My USB is showed up as /dev/sdx, and the ISO image is: Fedora-Workstation-Live-x86_64-24-1.2.iso.

$ sudo dd if=./Fedora-Workstation-Live-x86_64-24-1.2.iso of=/dev/sdx bs=8M status=progress oflag=direct
[sudo] password for kenno: 
1541406720 bytes (1.5 GB, 1.4 GiB) copied, 648.041 s, 2.4 MB/s 
183+1 records in
183+1 records out
1541406720 bytes (1.5 GB, 1.4 GiB) copied, 650.655 s, 2.4 MB/s

That’s all I had to do. A few words of warning; make sure you double check the name of USB device detected by your counter. In my case, it was /dev/sdc, but I used /dev/sdx as an example.

For more details check out https://fedoraproject.org/wiki/How_to_create_and_use_Live_USB

Installing Pip with Python 3.5 on FreeBSD

Here is a quick note serves as a self-reminder on how to get pip working or installed on FreeBSD 10.3.

# pkg install python35

There is no package for pip, at least at the time of this writing, on FreeBSD. To have it install, run the following command:

# python3.5 -m ensurepip

While you’re at it, you might as well update pip:

# pip3.5 install --upgrade pip

Thanks to this post in the FreeBSD forum: https://forums.freebsd.org/threads/52702/.

How to renew DHCP lease with NetworkManager

Traditionally, we use dhclient to release and renew DHCP lease on Linux. It probably still work with modern Linux distros nowadays. However, most distros come with NetworkManager which provides nmcli command line interface to manage networking. Here’s how to renew DHCP lease using nmcli performing on my machine. Your output when running these commands could be different.

First, let’s list the connections managed by NetworkManager.

# nmcli con
NAME                UUID                                  TYPE            DEVICE     
virbr0              2c2c7c4f-15e9-439b-be1d-e1d0131fb41c  bridge          virbr0     
Wired connection 1  5c9000c5-2635-4b09-90d7-71c3783c6626  802-3-ethernet  enp0s25    
enp0s25             70ee0b94-8341-46ec-953d-f2c3ca34285a  802-3-ethernet  --         
virbr0-nic          aafaa95e-6ced-4ea9-bd4f-7c8d10fb51b6  generic         virbr0-nic 

Let’s find out the current IP associated with enp0s25:

# ip a show enp0s25 | grep 'inet '
    inet 192.168.1.187/24 brd 192.168.1.255 scope global dynamic enp0s25

To renew IP for enp0s25, run these commands by supplying the connection’s name. In my case, it’s “Wired connection 1”:

# nmcli con down id 'Wired connection 1'
# nmcli con up id 'Wired connection 1'

Let’s verify the new IP address:

# ip a show enp0s25 | grep 'inet '
    inet 192.168.1.114/24 brd 192.168.1.255 scope global dynamic enp0s25

Well, if you still see the same IP address, it could just mean that your DHPC server keeps offering the same IP address for your machine.

Credit:
1) http://askubuntu.com/questions/4014/how-do-i-renew-my-dhcp-lease

Docker with OverlayFS on Ubuntu 15.10

As of today, the default storage for Docker on (K)Ubuntu 15.10 is AUFS. I want to switch it to OverlayFS. Personally, I’m still new to Docker, but I did hear that OverlayFS is better than AUFS. You can read more about OverlayFS here.

Anyway, the purpose of this post is how to switch OverlayFS and avoid head-scratching.

On Ubuntu 15.10 (wily), one can start/stop services either using Upstart or systemd. Since I want to get more accustomed to using systemd, I’ve been trying to use it anywhere possible. For example, here’s the command to start docker:

$ sudo systemctl start docker

To verify what storage driver used:

$ docker info 
Containers: 0
Images: 0
Server Version: 1.9.1
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 0
 Dirperm1 Supported: true
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.2.0-19-generic
Operating System: Ubuntu 15.10
CPUs: 4
Total Memory: 7.663 GiB
Name: f9470m

Okay, let’s begin to change the storage driver from AUFS to OverlayFS.

Lots of tutorials online including this one and this one, suggest to provide an option in /etc/default/docker.

DOCKER_OPTS="-s overlay"

or

DOCKER_OPTS="--storage-driver=overlay"

Unfortunately, it didn’t work for me. But when I started docker using upstart command as the following:

$ sudo service docker start

the storage driver has changed to “overlay” correctly!

$ docker info | grep -i driver
WARNING: No swap limit support
Storage Driver: overlay

It took me awhile to figure out that the option provided to /etc/default/docker is only for Upstart.

Well, now I at least know which direction; or questions I should ask Google. Docker has an article explaining how to control docker with systemd. With that, I was able to adapt it to pass an option to systemd docker.service to use OverlayFS.

Here’s how I did it.

First, I ensure that docker is not running.

$ sudo systemctl stop docker

If docker was started with Upstart use ($ sudo service docker stop instead.)

In my case, since I just started running Docker on this machine, I didn’t have any images or useful files. So I took an extra step to remove old AUFS files. You may need to think twice before running the following command. You might lose your important data!

If you’re unsure, don’t run it. You’ve been warned!

$ sudo rm /var/lib/docker -rf

Then create a directory, if not yet exist, /etc/systemd/system/docker.service.d. Create a file, call it whatever you like. I named it overlay.conf with the content:

[Service]
ExecStart=
ExecStart=/usr/bin/docker daemon -H fd:// --storage-driver overlay

Now, start docker service with systemd again:

$ sudo systemctl start docker

We can verify it by running ‘docker info’:

$ docker info
Containers: 0
Images: 0
Server Version: 1.9.1
Storage Driver: overlay
 Backing Filesystem: extfs
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.2.0-19-generic
Operating System: Ubuntu 15.10
CPUs: 4
Total Memory: 7.663 GiB
Name: f9470m

It’s working! Oh, if you’re wondering why I can just run docker command without prefix with sudo; it’s because my user account is docker group.

Happy dockering!

ZFS zpool upgrade

I’m running ZFS on Fedora 23 and I notice that there’re new features which can be enabled in the existing pool.

# zpool status
  pool: tank
 state: ONLINE
status: Some supported features are not enabled on the pool. The pool can
        still be used, but some features are unavailable.
action: Enable all features using 'zpool upgrade'. Once this is done,
        the pool may no longer be accessible by software that does not support
        the features. See zpool-features(5) for details.
  scan: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          raidz1-0  ONLINE       0     0     0
            sdb     ONLINE       0     0     0
            sdc     ONLINE       0     0     0

errors: No known data errors

Get the ZFS version for tank’s pool:

# zpool get version tank
NAME  PROPERTY  VALUE    SOURCE
tank  version   -        default

Huh? I’m not sure why there’s no value set on ZFS running on Linux.

# zpool upgrade
This system supports ZFS pool feature flags.

All pools are formatted using feature flags.


Some supported features are not enabled on the following pools. Once a
feature is enabled the pool may become incompatible with software
that does not support the feature. See zpool-features(5) for details.

POOL  FEATURE
---------------
tank
      filesystem_limits
      large_blocks

Well, let’s upgrade the pool:

# zpool upgrade -a
This system supports ZFS pool feature flags.

Enabled the following features on 'tank':
  filesystem_limits
  large_blocks

It seems to have been successfully upgraded. Let’s verify:

 # zpool status
  pool: tank
 state: ONLINE
  scan: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          raidz1-0  ONLINE       0     0     0
            sdb     ONLINE       0     0     0
            sdc     ONLINE       0     0     0

errors: No known data errors

# zpool get version tank
NAME  PROPERTY  VALUE    SOURCE
tank  version   -        default

Ref: http://freebsd.pro/topic/12/