Sunday, September 29, 2019

Extending a Linux Virtuam Machine File System on a FreeNAS zvol.

I have FreeNAS system where I run a Fedora Linux system on a Virtual Machine. I want to increase the size of a file system on the Linux VM. The file system is on a FreeNAS zvol. Assuming that the file system is mounted at /mnt, and the file system is a Linux Extended File System. The steps are as follows to increase the size of the partition.

  1. Increase the zvol via FreeNAS user interface
  2. Resize the partition at the Linux VM. Go to Linux VM, run parted. See transcript below
    
       $ parted /dev/sdc
       (parted) resizepart 1 100%
       (parted) quit
       $
    

  3. Resize the file system on the partition we just resize. Below are the steps
    
       $ e2fsck -f /dev/sdc1
       $ resize2fs /dev/sdc1
    

Saturday, September 28, 2019

Upgrading PostgreSQL Databases Revisited

Once upon a time I had to upgrade a PostgreSQL database after a Fedora Linux upgrade. Today after I upgraded a Fedora Linux 28 host to a Fedora Linux 31, I found out I had to do it again because PostgreSQL services refuses to start due to database files of older format. I took a slightly simpler approach to upgrade the 9.6 PostgreSQL database to a 11.5 one.

  1. Download and install a PostgresSQL 9.6 binary since I have upgraded the host to Fedora 31 and the old binary was gone. For this, instead of building it from source, I took advantage of the Interactive installer from EnterpriseDB. Download the installer and bring it to the Fedora Host:
  2. Running the installer. This is as simple as running the installer from the command line as,
    
    chmod +x ./postgresql-9.6.15-2-linux-x64.run
    sudo ./postgresql-9.6.15-2-linux-x64.run
    

    Following the prompts given by the installer, I installed the binary at /opt/PostgreSQL/9.6/.
  3. Disable and stop the 9.6 version of the database service
    
     sudo systemctl disable postgresql-9.6.service
     sudo systemctl stop postgresql-9.6.service
    

  4. The 11.5 version of the database service should not be running because this is why we are doing this. However, it does not hurt to make sure it is down:
    
    sudo systemctl stop postgresql.service
    

  5. Switch to user postgres
    
    sudo su - postgres
    

  6. Initialize a 11.5 database. Assuming we want the database to reside at directory /mnt/data/postgres/data11, we run version 11.5's initdb:
    
    mkdir /mnt/data/postgres/data11
    initdb /mnt/data/postgres/data11
    

  7. Start the 11.5 service for the initialized 11.5 database using the installed 11.5's binary:
    
    postgres -D /mnt/data/postgres/data11
    

  8. Open another terminal Window, and in the new terminal Window, start the upgrade process using the pg_upgrade . We take a two-step approach.
    1. First check whether everything is OK with the upgrade using the -c option:
      
      sudo pg_upgrade -b /opt/PostgreSQL/9.6/ -B /usr/bin \
        -d /mnt/data/postgres/data96/ -D /mnt/data/postgres/data11 \
        -c
      

    2. If pg_upgrade does not complain, we go ahead with the upgrade
      
      sudo pg_upgrade -b /opt/PostgreSQL/9.6/ -B /usr/bin \
        -d /mnt/data/postgres/data96/ -D /mnt/data/postgres/data11 \
      

  9. Terminate the 11.5 service we ran manually. Just type CTRL-C in the terminal Windows.
  10. In the new terminal Window, make sure the user postgres owns the the database files:
    
    sudo chown -R postgres:postgres /mnt/data/postgres/data11
    

  11. We are now ready to start the 11.5 database service in the system
    
    sudo systemctl start postgresql.service
    

  12. Finally, we may have to do some additional steps as instructed by the output of pg_upgrade, such as reindexing the database, uninstalling the 9.6 database server binaries, and removing the old database files, e.g.,
    
    sudo su - postgres
    psql < reindex_hash.sql
    exit
    sudo /opt/PostgreSQL/9.6/bin/uninstall-postgresql
    

Friday, September 27, 2019

Showing PostgreSQL Database Database Location (Data Directory)

To show on which file system and directory on which the PostgreSQL Database System stores its databases, we simply run this query:


psql -U postgres -c "show data_directory;"

Thursday, September 26, 2019

Setting up OpenSSH Server on Windows 7 Hosts

Windows 10 has an OpenSSH server feature that we can enable or disable from the Settings UI. Windows 7 however does not have this feature. Since Windows 7, in particular in enterprise environments are still in wide use. This post notes the procedure to install OpenSSH server from the release of the Microsoft's PowerShell development team .

The steps to install the OpenSSH server is straightforward, that is, to follow the team's instructions:


This instruction applies to both 32-bit and 64-bit binaries at its release page. Two problems I encountered are,

Setting up SSH Server Host Key


To run the OpenSSH Server, we ought to set up the host keys for the SSH server. We complete this in two steps:
  1. Create the  C:\ProgramData\ssh directory, i.e., as Administrator issuing command
    
    mkdir C:\ProgramData\ssh
    

  2. Create SSH server host keys, i.e., running the following as Administrator
    
    C:\Program Files\OpenSSH\ssh-keygen.exe -A
    
It is worth nothing that skipping step 1 above results the following error in my case:

PS C:\Program Files\OpenSSH> .\ssh-keygen -A
ssh-keygen: generating new host keys: RSA Could not save your public key in __PROGRAMDATA__\\ssh/ssh_host_rsa_key.temp_file_suffix: No such file or directory
ssh-keygen: generating new host keys: DSA Could not save your public key in __PROGRAMDATA__\\ssh/ssh_host_dsa_key.temp_file_suffix: No such file or directory
ssh-keygen: generating new host keys: ECDSA Could not save your public key in __PROGRAMDATA__\\ssh/ssh_host_ecdsa_key.temp_file_suffix: No such file or directory
ssh-keygen: generating new host keys: ED25519 Could not save your public key in __PROGRAMDATA__\\ssh/ssh_host_ed25519_key.temp_file_suffix: No such file or directory


Correcting Files and Directory Permissions

Another problem is that the following command to start the SSH server failed:

    net start sshd

The error message is,

    The SSHD service is starting. The SSHD service could not be started.

    A system error has occurred.

    System error 1067 has occurred.

    The process terminated unexpectedly.

On a different occasion, I also encounter an error message like,

     Error code 5: Access is denied. (Create File)

It turns out that the directories hosting the OpenSSH server binaries and keys had wrong permissions. Luckily, this is easy to fix thanks to the powershell script provided by the Powershell team. To fix the permission issues, we run the FixHostFilePermissions.ps1 and FixUserFilePermissions.ps1 scripts in the OpenSSH server directory, e.g.,

  1. Open a Windows Command Prompt window or a PowerShell window as Administrator 
  2. Assume that your OpenSSH server binaries are in directory C:\Program Files\OpenSSH, run the following in the Windows Command Prompt window or the PowerShell Window
    
    cd "C:\Program Files\OpenSSH"
    powershell -ExecutionPolicy Bypass -File FixHostFilePermissions.ps1
    powershell -ExecutionPolicy Bypass -File FixUserFilePermissions.ps1
    

Tuesday, September 24, 2019

Jipack.io Complaining about Not Being Able to Locate a Repo

I use a very useful tool jitpack.io to add dependencies directly from Github repositories. I encountered an error in IntelliJ that complains that it cannot resolve the dependencies. Below is an example message:

Could not find artifact com.github.GumTreeDiff:gumtree:pom:v2.1.1 
in jitpack.io (https://jitpack.io)

I resolve this by following these simple steps.
  1. Open jitpack.io in a Web browser
  2. Enter the Github username and repository name on the site
  3. Locate the error reports and different releases from the Website, e.g., using the gumtree project as an example dependency,
  4. Try different releases by configuring the Maven project with different releases. In this case, version 2.0.0 works.

Monday, September 23, 2019

Windows 10 Complaining Permission Denied for Bind, but Ports Unused

An application on Windows 10 cannot open a TCP port, and the error message is something like

Error:  Permission denied - bind(2) for 127.0.0.1:7334

However, when you attempts to see if any uses the port, you finds nothing, such as,

netstat -abo | find ":7334"

In fact, this error can be the result of the "exclude port range". For instance, we can query the excluded port range on the system using,

netsh interface ipv4 show excludedportrange protocol=tcp
The output can be something like,

Protocol tcp Port Exclusion Ranges

Start Port    End Port
----------    --------
      7248        7347
      7348        7447

* - Administered port exclusions.

From the output we can see that the 7334 tcp port is in the exclusion range, and thus we can not assign it to a process.

Gradle Complaining about JDK not Found

I was attempting to compile a Kotlin project, and encountered the following error:


* What went wrong:

Execution failed for task ':compileKotlin'.

> Kotlin could not find the required JDK tools in the Java installation 'C:\Program Files\Java\jre1.8.0_211' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
The answer to the problem is straightforward is to inform Gradle where the JDK is. Since I am on a Windows host, and the host has had these installed:

C:\>dir "C:\Program Files\Java\"
....

05/14/2019  09:58 AM    <DIR>          .
05/14/2019  09:58 AM    <DIR>          ..
03/04/2019  09:39 PM    <DIR>          jdk-11.0.2
03/04/2019  09:29 PM    <DIR>          jdk1.8.0_201
05/12/2019  08:32 PM    <DIR>          jre1.8.0_211
.....

C:\>

I added the following line to the gradle.properties file, and the problem went away,

org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_201

Thursday, September 19, 2019

Updating Plex Media Server to Latest FreeNAS Plugin on Command Line in Jail

There are two methods to upgrade Plex Media Server in FreeNAS Jail. 
  1. Method 1. Upgrading Plex Media Server to Latest FreeBSD Release. Using this method, you don't have to wait for FreeNAS developers to upgrade Plex Media Server in the plugin repository.
  2. Method 2. Upgrading Plex Media Server to Latest FreeNAS Plugin. 
This post is about Method 2, and documents the steps to upgrade Plex Media Server on Command Line.

  1. Login or open FreeNAS shell
  2. List jails
    
    $ jls
    

    The output looks like the following
    
    $ jls
       JID  IP Address  Hostname     Path
         1              plex         /mnt/Storage/iocage/jails/plex/root
    $
     
  3. Open a shell inside the jail. The command is as follows,
    
    jexec ${JID} csh
    

    In the above, the jail ID (JID) is 1. Since we can only the csh as root, we open a shell inside the jail as follows
    
    $ sudo jexec 1 csh
    
  4. Upgrading the plexmediaserver package. Inside the jail, we do
    
    # pkg upgrade plexmediaserver
    

    If the installed version is already latest, we should observe something similar to the following,
    
    root@plex:/ # pkg upgrade plexmediaserver
    Updating iocage-plugins repository catalogue...
    iocage-plugins repository is up to date.
    All repositories are up to date.
    Checking integrity... done (0 conflicting)
    Your packages are up to date.
    root@plex:/ #
    

    However, if there is a newer version, the upgrade will commerce.

  5. Restart Plex Media Server if it gets upgraded as follows inside the jail,
    
    # service plexmediaserver restart
    


Monday, September 16, 2019

Locate a Command on Windows

We know we can locate a command on Unix-like operating systems like Linux or OS X using the which command, such as,

$ which ls
/bin/ls
$
Can we do the similar on Windows? Yes, we use the where, e.g.,

C:\>where find
C:\Windows\System32\find.exe

C:\>

Saturday, September 14, 2019

Disqus Complaining "Content Security Policy" Error on Jekyll Webite

I was building a website using Jekyll with the Minima theme. Following the instruction of the Minima theme, I set up Disqus to posts on the site by adding the "Disqus shortname" to Jekyll site configuration file _config.yml, such as,


disqus:
    shortname: mysite-short-name

However, the site displays an error message,

We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
When I clicked on the error message, Disqus shows an error message

Content Security Policy error
It turns out that to make Disqus work, we must include a url attribute in the configuration file, i.e., after I added the attribute, the configuration now includes,

url: https://mysite-url-used-for-disqus
disqus:
    shortname: mysite-short-name