Setting Timezone in Linux

There are two ways of changing the system timezone in Linux, either you use timedatectl or changing the /etc/localtime symbolic link and pointing it to your chosen timezone at /usr/zoneinfo/

Solution: Using timedatectl

Step 1

Check the available zones first, which in turn will be provided when we set the timezone you’re gonna use for your system.

timedatectl list-timezones

This will show you all available timezone you can set. You can also use /usr/zoneinfo for the list but this one’s a lot easier than checking each folder for approriate zones.

Step 2

Now let’s set your timezone. In my case I’ll use Asia/Manila as my timezone.

timedatectl set-timezone Asia/Manila

Step 3

Once set, you can now verify if your timezone is currently used by your system. You can run either date or timedatectl. Running just timedatectl defaults to timedatectl status, so there’s no need to do it the long way.

Solution 2: Change Symlink of /etc/localtime

If you’ll check were the /etc/localtime is being point to, you’ll see it’s at /usr/share/zoneinfo/[TIME_ZONE]

readlink -f /etc/localtime

Step 1

Root holds owner of the file, and has a 777 permission. So first let’s remove the symlink

sudo rm -rf /etc/localtime

Step 2

Doing the long way to search and confirm for your timezone, and look for it at /usr/share/zoneinfo

You can do a recursive search to make it easier

ls -R /usr/share/zoneinfo

Step 3

Once you know the timezone to set. Now create a symlink:

sudo ln -s /usr/share/zoneinfo/Asia/Manila /etc/localtime

Step 4

Verify if your system is now using your selected timezone:

date

REFERENCES

  1. timedatectl Manual
  2. /etc/localtime Manual

Written with StackEdit.

Raspberry Pi Camera Error: `Failed to create component ‘vc.ril.camera’`

Hardware & Software Info:

  • 5MP Camera Board
  • Raspbian 10 (Buster)
  • Python 3

When using a Python library PiCamera and this error below occured:

mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1)
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 456, in _init_camera
    self._camera = mo.MMALCamera()
  File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 2279, in __init__
    super(MMALCamera, self).__init__()
  File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 633, in __init__
    prefix="Failed to create MMAL component %s" % self.component_type)
  File "/usr/lib/python3/dist-packages/picamera/exc.py", line 184, in mmal_check
    raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Failed to create MMAL component b'vc.ril.camera': Out of memory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "cam.py", line 4, in <module>
    camera = PiCamera()
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 431, in __init__
    self._init_camera(camera_num, stereo_mode, stereo_decimate)
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 460, in _init_camera
    "Camera is not enabled. Try running 'sudo raspi-config' "
picamera.exc.PiCameraError: Camera is not enabled. Try running 'sudo raspi-config' and ensure that the camera has been enabled.

There are two possible issue that which can cause this error to appear.

  1. Your FFC (Flexible Flat Cable) connection to your camera or your board is loose.
  2. You haven’t enabled your camera yet.

Solution: Tighten your loose FFC on your camera and board

Yes, as it says. It won’t be that hard to follow right. 😀

Solution: Enable camera access

Step 1

Open your terminal and execute:

sudo raspi-config

Once executed and you have provided your password, you’ll be greeted by this screen:

┌──────────────────────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├───────────────────────────────┐
│                                                                                                                        │
│                  1 Change User Password Change password for the 'pi' user                                              │
│                  2 Network Options      Configure network settings                                                     │
│                  3 Boot Options         Configure options for start-up                                                 │
│                  4 Localisation Options Set up language and regional settings to match your location                   │
│                  5 Interfacing Options  Configure connections to peripherals                                           │
│                  6 Overclock            Configure overclocking for your Pi                                             │
│                  7 Advanced Options     Configure advanced settings                                                    │
│                  8 Update               Update this tool to the latest version                                         │
│                  9 About raspi-config   Information about this configuration tool                                      │
│                                                                                                                        │
│                                                                                                                        │
│                                                                                                                        │
│                                                                                                                        │
│                                   <Select>                                   <Finish>                                  │
│                                                                                                                        │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Select 5 Interfacing Options

Step 2

Once you have selected 5 Interfacing Options, this screen will show:

┌──────────────────────────────┤ Raspberry Pi Software Configuration Tool (raspi-config) ├───────────────────────────────┐
│                                                                                                                        │
│                    P1 Camera      Enable/Disable connection to the Raspberry Pi Camera                                 │
│                    P2 SSH         Enable/Disable remote command line access to your Pi using SSH                       │
│                    P3 VNC         Enable/Disable graphical remote access to your Pi using RealVNC                      │
│                    P4 SPI         Enable/Disable automatic loading of SPI kernel module                                │
│                    P5 I2C         Enable/Disable automatic loading of I2C kernel module                                │
│                    P6 Serial      Enable/Disable shell and kernel messages on the serial connection                    │
│                    P7 1-Wire      Enable/Disable one-wire interface                                                    │
│                    P8 Remote GPIO Enable/Disable remote access to GPIO pins                                            │
│                                                                                                                        │
│                                                                                                                        │
│                                                                                                                        │
│                                                                                                                        │
│                                                                                                                        │
│                                   <Select>                                   <Back>                                    │
│                                                                                                                        │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘

Select P1 Camera and proceed with the instructions of enabling your camera. After it, go back on the main menu and select <Finish>. You’ll be prompted to restart your board. Go on and restart, then proceed to the next step to test your camera.

Step 3

Execute the command below and see if your board can detect your camera:

vcgencmd get_camera

You should get this output supported=1 detected=1 if not, tighten your FFC on your cam and board.

To test if the camera is working, execute the command below:

raspistill -v -o test.jpg

Once executed, on the same directory you’re in, you should see a file named test.jpg open it and you should see the captured image from your cam.

References

  1. Raspbian Docs:vcgencmd
  2. Raspbian Docs: Camera

Written with StackEdit.

Use Raspberry PI 4 model B as Local Network Private DNS server on Ubuntu

Tested on the following Ubuntu Version

  • Ubuntu 19.10 (eoan)

There’s not much configuration change when configuring Bind 9 on an ARM architecture over an x86 or x64 this steps can be interchangeable except for different Linux distro which places default configuration files on a different folder (e.g CentOS uses /etc/named while Ubuntu uses /etc/bind) or some preset configurations has already been set and default config locations.

Step 1

Install Bind 9 DNS Server, Bind 9 Utilities and Bind 9 Docs

sudo apt install bind9 bind9utils dnsutils bind9-doc

Step 2

Make sure Bind 9 uses only IPv4, add named arguments for IPv4:

sudo vi /etc/default/bind9

Then add -4 on OPTIONS

# run resolvconf?
RESOLVCONF=no

# startup options for the server
OPTIONS="-4 -u bind"

Step 3

After installation we’re gonna remove some preset. First, open /etc/bind/named.conf.options

sudo vi /etc/bind/named.conf.options

Then remove the following line:

listen-on-v6 { any; };

Then add the following inside options { ... };

// Allow dns query on localhost and all host within the subnet
allow-query     { localhost;192.168.1.0/24; };
// Listen on port 53 with any IP or host (This is the default). 
// In case you're using DHCP for your IP 
// or there are not any statically assigned IP for you NS. 
// You can also use your subnet's CIDR.
listen-on port 53 {any;}

Step 4

Now, we’re gonna add Zone configuration and configure each zone files.

sudo vi /etc/bind/named.conf.default-zones

For CentOS/Fedora, the default file can be at /etc/named.conf.local Then add the following line:

zone "1.168.192.in-addr.arpa" {
    type master;
    file "/etc/bind/db.1.168.192";
    allow-update { none; };
};

zone "sample.net" {
    type master;
    file "/etc/bind/db.sample.net";
    allow-update { none; };
};

Step 5

After setting up the zone info, we’ll now proceed at configuring each zone. First create /etc/bind/db.sample.net and add the following:

TTL    604800
@    IN    SOA   ns1.sample.net.    admin.sample.net. (
     6        ; Serial
     604800   ; Refresh
     86400    ; Retry
     2419200  ; Expire
     604800 ) ; Negative Cache TTL
; name servers - NS records
    IN    NS    ns1.sample.net.
; name servers - A records
ns1      IN    A    192.168.1.10
desktop  IN    A    192.168.1.20

Next, create the reverse lookup record, /etc/bind/db.1.168.192

$TTL 604800
@ IN SOA ns1.sample.net. root.sample.net. (
          5     ; Serial
    6048000     ; Refresh
      86400     ; Retry
    2419200     ; Expire
     604800 )   ; Negative Cache TTL
;
@  IN NS ns1.sample.net.
; PTR Records
101    IN    PTR    ns1.sample.net.     ; 192.168.1.10
200    IN    PTR    desktop.sample.net. ; 192.168.1.20

Step 6

After creating DNS record, we’ll have to test the configuration. To check the configuration files for error run named-checkconfig

sudo named-checkconfig

This will output the error and on which specific line the error occurred on your config file. It won’t output any if there are no error on your configurations. For your zone file, we’ll use named-checkzone. This requires you to input the zone name and zone file. In our case, we’ll do the following:

sudo named-checkzone sample.net db.sample.net
sudo named-checkzone 1.192.168.in-addr.arpa db.1.168.192

It will output OK if no issues are found in your zone file/s.

Step 7

When all configurations are set we’ll have to start/restart the bind9 service.

sudo server bind9 start

Step 8

Make sure you have set your new server as the default or primary DNS on you client/s. To check if your client can now query from your DNS, do the following:

# use `@` to query on the specific DNS
# We're using `localhost` since we're inside the DNS
#   if you're on your client, you have to provide the DNS IP
dig ns1.sample.net @localhost
# For reverse lookup
dig -x 192.168.1.200 @localhost

# Don't point to the DNS if you already have configured your
#   client's network interface's DNS, 
#   pointing at your new server
dig ns1.sample.net
dig desktop.sample.net
# For reverse lookup
dig -x 192.168.1.200

References

  1. MIT Bind Config
  2. ISC: Bind 9 Documentation
  3. ISC: Bind 9.14 named.conf Docs

Written with StackEdit.

Install PlatformIO Binaries in Ubuntu Linux

Step 1 (Optional)

Before doing this step, make sure you already have installed Python’s distutils . To do this, run the command below:

sudo apt-get install python3-distutils

Step 2

Get and run the installer:

python3 -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/develop/scripts/get-platformio.py)"

Step 3

Create symbolic links to /usr/local/bin

sudo ln -s ~/.platformio/penv/bin/platformio /usr/local/bin/platformio
sudo ln -s ~/.platformio/penv/bin/pio /usr/local/bin/pio
sudo ln -s ~/.platformio/penv/bin/piodebuggdb /usr/local/bin/piodebuggdb

Note: After this, you can now use PlatformIO plugin in Clion without hiccups

References

  1. PlatformIO Utility Installation

Written with StackEdit.

Enable Wifi on Raspbian Using WPA Supplicant

Step 1

Edit your wpa_supplication config file.

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf 

Step 2

Then copy and paste the configurations below and edit the SSID and WIFI PASSWORD.

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=PH

network={
    ssid="[SSID]"
    psk="[WIFI PASSWORD]"
    scan_ssid=1
    proto=RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP
    auth_alg=OPEN
}

Note: Double check your own Wifi settings and change the network configuration as you see fit. See WPA Supplicant Config Documentation for details. Also use iwlist [NET INTERFACE] scan to get more infor on your Wifi settings

Note on Hidden SSID: If you’re using hidden SSID for your Wifi hotspot, make sure to use scan_ssid=1 This uses probe request specific to your hidden SSID, and has a high latency.

Step 3

After setting the WPA Supplicant configurations. Restart your network manager with:

sudo service networking restart

Note: If restarting your network manager doesn’t connect you to wifi. Restart your board.

References

  1. WPA Supplicant Configuration Documentation

Written with StackEdit.

Enable SSH on Raspbian OS without Desktop UI (Headless)

Step 1

Whichever storage you’re using for your Raspbian OS either SD Card, SSD, or HDD; remove it from your board and mount the storage to your computer. Look for the boot partition and push an empty file with a filename ssh

Step 2

Put your storage back in the board and start your Raspberry Pi.

Step 3

Connect to your Raspberry Pi with SSH ssh [USERNAME]@[YOUR PI IP OR DOMAIN HERE]

Note: The default username and password for Raspbian is pi for username and raspberry as password, in case you didn’t add a new user or you didn’t change it.

REFERENCES

  1. Raspberry Pi Documentation: SSH Remote Access
  2. Raspberry Pi Documentation: Linux User Management

Written with StackEdit.

Fix Hive `SemanticException [Error 10035]: Column repeated in partitioning columns`

While creating a new table with partition and you got this error:

SemanticException [Error 10035]: Column repeated in partitioning columns

You have redundantly included a column to be partitioned on your create table clause.

Say we want to create a user table partitioned by lastname the following create statement will generate the above error:

CREATE TABLE `user` (
  `firstname` STRING,
  `lastname` STRING,
  `age` INT
)
PARTITIONED BY (lastname STRING);

Moving of Columns to Partioned By Clause

To fix this, we need to remove the declaration of lastname column from the create table clause.

CREATE TABLE `user` (
  `firstname` STRING,
  `age` INT
)
PARTITIONED BY (`lastname` STRING);

More Verbose Error Message On Hive

Most of the time it’s hard to find what goes wrong with your Hive script. Hive’s using Log4J as it’s logging library and defaults to INFO and DRFA as its appender. The default log file can be found at /tmp/<user name>/hive.log. To get a more verbose ouput on errors you have to change Hive’s configuration hive.root.logger to ERROR and CONSOLE as appender. You can do this in three ways:

Hive CLI or Beeline

set hive.root.logger=WARN,console

Command Parameter

hive --hiveconf hive.root.logger=WARN,console

Hive Configuration File

Locate your hive configuration folder, and add the following config on your hive-site.xml.

<property>
  <name>hive.root.logger</name>
  <value>WARN,console</value>
</property>

Show Free and Used Memory in Linux

The free comman can be used to show the free and used memory on both RAM and Swap files.

Sample Usage

List Free and Used Memory in Either Kilobytes, Megabytes or Gigabytes

Kilobytes

free -k
# or
free -kilo

Megabytes

free -m
#
free --mega

Gigabytes

free -g
# or
free --giga

Show List in Human Readable Format

free -h
# or
free --human

Display the List of Block Devices in Linux (e.g. Hard Disk, CD-ROM, Flash Drive)

When you want to find out the list of block devices in your computer, you can use lsblk.

Sample Usage

List block devices

lsblk

List all block devices

lsblk

List all SCSI devices

Please take note of the capital ‘S’

lsblk -S

Specifically list column

You can get all the available columns by running lsblk -h.

lsblk -o NAME,TYPE,MODEL

References