Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Tuesday, December 25, 2018

ext4 ext4lazyinit

Today I formatted a 3TB hard disk and mounted it with default options. However after mounting it I noticed that it periodically writes about 2 MB data. Initially I thought it was some journal information writing for the files I copied to the disk, but this 2MB data writing was not stopped when I mounted the disk after removing the journal.

Therefore I installed iotop to see what's going on. Aha, I was able to find the culprit immediately.
It was a process called ext4lazyinit.

Apparently when a partition is formatted with ext4, it does not initialize all inode tables in the file system during the file system creation time in order to speed up the process.  When the new file system is mounted, it starts ext4lazyinit process to initialize the inode tables leisurely.
Needless to say, it's really annoying to hear the sound of the disk is being accessed in every second indefinitely.

After searching about this ext4lazyinit process, I found out that all the inode tables can be initialized  passing lazy_itable_init=0 with the -E option when the  filesystem is created. Since I have already copied some files to the disk, I didn't want to reformat it. Therefore I followed another mechanism described in the articles I read. That is mount the partition with init_itable=0 mount option. This will speed up the inode table initialization. (https://www.kernel.org/doc/Documentation/filesystems/ext4.txt)


Sunday, November 25, 2018

How to configure wireless network interface using CLI in Fedora Server

I wanted to use my wireless network adapter on Fedora Server (version 29). Even though there are ways configure it graphically on Fedora Server, I wanted to configure it using only CLI with minimum steps.

When I plugged the adapter to my server, it was shown as wlp0s21f0u4,

ip a command output,

wlp0s21f0u4: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN group default qlen 1000

Therefore I chose wlp0s21f0u4 as my connection name.

Here are the steps I followed,

1. Create a network configuration file in /etc/sysconfig/network-scripts directory. File name: ifcfg-wlp0s21f0u4 (i.e. ifcfg-<connection name>)


Content of the file is,

[root@localhost network-scripts]# cat ifcfg-wlp0s21f0u4
TYPE=Wireless
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=no
NAME=wlp0s21f0u4
ONBOOT=yes
DEVICE=wlp0s21f0u4
ESSID=bla
KEY_MGMT=WPA-PSK
MODE=Managed

The highlighted configuration parameters are important to establish a wireless connection. As you can see the SSID of my wifi network is bla and it uses WPA-PSK security.

2. Create another file to store the wireless key in the same directory. File name: keys-wlp0s21f0u4 (i.e. keys-<connection name>)


Content of the key file is,

[root@localhost network-scripts]# cat keys-wlp0s21f0u4
WPA_PSK=abc123

 As you can see the password is abc123 and it's stored as plain text.

3. Restart NetworkManager,


systemctl restart NetworkManager

4. After a couple of seconds, the network interface should be up,


ip a command output,

wlp0s21f0u4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000

If you encounter issues, you can use journatctl for troubleshooting,

journalctl -xe -u NetworkManager

Tuesday, November 20, 2018

Firewalld rules required to open nfs services

Fedora server edition comes with nfs server installed. However we need to add several rules for firewalld to access nfs service.

firewall-cmd --add-service=rpc-bind
firewall-cmd --add-service=mountd
firewall-cmd --add-port=2049/tcp
firewall-cmd --add-port=2049/udp


Use --permanent option and then --reload option to make the rules persistent and effective. 

Change a network interface to remove it from being the default gateway in Fedora

Sometimes it's required to change a network interface to avoid it from being the default gateway. This can be easily achieved by changing the network interface configuration file.

The only change required is to change the value of DEFROUTE of the configuration file to no

e.g.:
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp3s0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=no
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=no
IPV6_DEFROUTE=no
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=enp3s0
UUID=e73d611-501-33ac-9fd-4946bcfdf8
ONBOOT=yes
AUTOCONNECT_PRIORITY=-999
DEVICE=enp3s0

Permanently disable ipv6 on Fedora

There are several ways to disable ipv6 on Fedora. e.g.: changing sysctl, changing the network configuration file.

However if it's required to disable ipv6 system wide in a reliable way, I prefer to disable it using the kernel parameter method.

I'm using Fedora 29 server edition on an UEFI system.

1.  Add ipv6.disable=1 to GRUB_CMDLINE_LINUX parameter listed in /etc/default/grub file,

[root@localhost ~]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="resume=UUID=aee6d21-c4a6-437-a7c6-d80c98ab9 rhgb quiet ipv6.disable=1"
GRUB_DISABLE_RECOVERY="true"


2. Take a backup of the grub configuration file.

cp /boot/efi/EFI/fedora/grub.cfg /boot/efi/EFI/fedora/grub.cf.bk

3. Generate the grub configuration file,

grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg 

4. Reboot

Update 1: It looks like this method breaks firewalld on fedora 29, Therefore I had to revert the changes.

[root@localhost ~]# systemctl status firewalld -l
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2018-11-20 11:11:07 +0530; 5min ago
     Docs: man:firewalld(1)
 Main PID: 1874 (firewalld)
    Tasks: 2 (limit: 4915)
   Memory: 22.8M
   CGroup: /system.slice/firewalld.service
           └─1874 /usr/bin/python3 /usr/sbin/firewalld --nofork --nopid

Nov 20 11:11:06 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
Nov 20 11:11:07 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
Nov 20 11:11:07 localhost.localdomain firewalld[1874]: WARNING: ip6tables not usable, disabling IPv6 firewall.
Nov 20 11:11:07 localhost.localdomain firewalld[1874]: ERROR: UNKNOWN_ERROR: 'ip6tables' backend does not exist
Nov 20 11:11:08 localhost.localdomain firewalld[1874]: ERROR: COMMAND_FAILED: UNKNOWN_ERROR: 'ip6tables' backend does not exist
Nov 20 11:11:08 localhost.localdomain firewalld[1874]: ERROR: '/usr/sbin/iptables-restore -w -n' failed: iptables-restore v1.8.0 (legacy): goto 'PRE_FedoraServer' is not a chain
                                                      
                                                       Error occurred at line: 2
                                                       Try `iptables-restore -h' or 'iptables-restore --help' for more information.
Nov 20 11:11:08 localhost.localdomain firewalld[1874]: ERROR: COMMAND_FAILED: '/usr/sbin/iptables-restore -w -n' failed: iptables-restore v1.8.0 (legacy): goto 'PRE_FedoraServer' is not a chain
                                                      
                                                       Error occurred at line: 2
                                                       Try `iptables-restore -h' or 'iptables-restore --help' for more information.




Install and Configure hd-idle on Fedora

hd-idle is a useful program if you want to spin down hard disks after a defined time period.
It is available in fedora repositories. Therefore you can install it using dnf command,

dnf install hd-idle

systemd unit file is available in below path,

/usr/lib/systemd/system/hd-idle.service

The configuration file is available in below path,

/etc/sysconfig/hd-idle

man page of hd-idle (man hd-idle) describes the usage of hd-idle program. It has capability to define a default idle time for all the disks and define idle time for disks individually.

The default log file path is,

/var/log/hd-idle/hd-idle.log

All the informatiion about this utility can be found here,

http://hd-idle.sourceforge.net/

Saturday, July 14, 2018

Fix some errors appeared in rtorrent

After a fresh installation and configuration of rtorrent and rutorrent, below errors were appeared.

  • unpack plugin: rtorrent user can't access 'unrar' program.
  • rTorrent user can't access external program (sox)

To fix those, I had to install the missing programs,

In Ubuntu,

apt-get install unrar-free
apt-get install sox


Tuesday, July 10, 2018

Create your own OVH Server availability checker

Recently I came to know that OVH has a line of storage specific "So You Start"  (SyS) ARM based servers. I have been using a Kimsufi server, but some of these SyS servers are cheaper than the Kimsufi server I have been using. Also the storage available in SyS servers is larger than what I get from the Kimsufi Server for a slightly higher price. Therefore I decided to try a SyS ARM server (ARM-2T/1801armada01)

Unfortunately SyS ARM servers are not always available to order, specially the cheapest servers. I was refreshing their page regularly to order a server, but soon I understood that's not practical. I didn't see they become available in the web page even though I tried many times for several days.

Then I decided to automate the check so that I can order a server whenever they are available.

Fortunately OVH offers a REST API to communicate with their servers and services. It's easier to check the availability of a server sending a http request to their API. Using a bunch of commands, the availability can be checked using a one line Linux command.

Just checking the availability is not enough. There should be a way to notify the availability. I could setup a script to send the availability to an email easily, but I don't read emails often. The best way of doing that is to push a message to my mobile. I found a free service called pushme (pushme.jagcesar.se) which can be used to push a message to my mobile. It also use a REST API, so I can send a message as a http POST request to pushme servers. Then pushme forwards the message to the app installed in the mobile via iCloud.

I created a simple shell script to read the server code as an argument and used it to check the availability of that server type using the OVH REST API. If a server is available, it sends a message to pushme using pushme REST API.

Then the script was scheduled to run for every 5 minutes using a cron job so that I'll get a notification whenever a server is available.

I also created another script to send a test message in every day morning to verify that the availability checker mechanism works.

After a day of implementing this, I was able to purchase the server I wanted. :)
Hope this might help you to find a server as well.
 
Avaiability Checker. It worked!

Screenshot of the notifications I received about 1801armada01 availability

But note that pushme works only with Apple. you will need another message sender if you use Android. Also this is a very simple and lazy way of doing this. No errors are checked in the script and only happy path is considered.

Here are the shell scripts and crons I used,

server_checker.sh

#!/bin/bash

server_code=$1
pushmeapi_token='replace_this_with_your_pushmeapi_token'

availability_count=`curl -s "https://www.ovh.com/engine/api/dedicated/server/availabilities?country=eu&hardware=$server_code" | json_pp | grep availability | grep -v unavailable | wc -l`

if [ $availability_count -gt 0 ]; then
 curl -d "title=found a $server_code&token=$pushmeapi_token" -X POST  https://pushmeapi.jagcesar.se
fi



ping_sender.sh

#!/bin/bash

pushmeapi_token='replace_this_with_your_pushmeapi_token'

curl -d "title=test message&token=$pushmeapi_token" -X POST  https://pushmeapi.jagcesar.se



Cron Jobs

*/5 * * * * /home/seedbox/server_checker.sh 1801sk13
*/5 * * * * /home/seedbox/server_checker.sh 1801armada01
30 5 * * * /home/seedbox/ping_sender.sh


You can find out the server code from either their web page (look at the source of the web page) or using their API.

Examples:

In https://www.soyoustart.com/us/server-storage/ page, when you click ARM-2T, the server code is there at the end of the URL as 1801armada01

below command will provide the list of ARM server types,

curl -s "https://www.ovh.com/engine/api/dedicated/server/availabilities?country=eu" | json_pp | grep hardware | grep -v , | sort | uniq | grep armada

below command will provide the list of kimsufi server types,

curl -s "https://www.ovh.com/engine/api/dedicated/server/availabilities?country=eu" | json_pp | grep hardware | grep -v , | sort | uniq | grep sk



Anyway, here is a list of machine types of kimsufi servers and SyS ARM servers,

Kimsufi Servers

France
KS-1    1801sk12
KS-2    1801sk13
KS-3    1801sk14
KS-4    1801sk15
KS-5    1801sk16
KS-6    1801sk17
KS-7    1801sk18
KS-8    1801sk19
KS-9    1801sk20
KS-10    1801sk21
KS-11    1801sk22
KS-12    1801sk23

Canada
KS-1    1804sk12
KS-2    1804sk13
KS-3    1804sk14
KS-4    1804sk15
KS-5    1804sk16
KS-6    1804sk17
KS-7    1804sk18
KS-8    1804sk19
KS-9    1804sk20
KS-10    1804sk21
KS-11    1804sk22
KS-12    1804sk23

Sys ARM servers

France
ARM-2T    1801armada01
ARM-4T    1801armada02
ARM-6T    1801armada03

Canada
ARM-2T    1804armada01
ARM-4T    1804armada02
ARM-6T    1804armada03

Tuesday, July 3, 2018

Document viewer Evince in Fedora does not print page borders? Here is a solution!

Well, this is not a workaround or a solution available in Evince, but this is a general solution which can be used when the usual GUI applications does not have some features. 

Today I was trying to print some lecture slides using "Document Viewer" also known as "Evince" running on my Fedora laptop. I was trying to print several pages in one output page. (4 lecture slides should be printed on a single page)

Once I got the output, I realized that it does not add a border to source pages printed on a single output page. I couldn't find an option in Evince to get that done.

Fortunately I came across about the Unix/Linux lp command which uses CUPS. (Common UNIX Printing System)
Using that I was able to get what I wanted printed precisely.

Here are the steps,

1. Find out the status of the printers you have configured in the system,

lpstat -a

This will list down all the printers you have configured in your machine. Use the preferred printer as the destination of the lp command using -d option. (see the next step)

2. Use lp command to get the job done

lp -d HP-LaserJet-400 -o sides=two-sided-short-edge -o number-up=4 -o pagesize=A4 -o landscape -o page-border=single -o fit-to-page -o number-up-layout=lrtb my_document.pdf

As you can see, we can pass multiple options to lp command including the page-border which I couldn't find in Evince. You can find the explanations of each option in lp man page.

Another great option of lp is that you can send multiple files to printer.
e.g.: if you want to print all the files which have file names starting from "bla_" then you can pass bla_* to lp command so that all of them will be printed one by one.

Saturday, March 10, 2018

How to create SSH tunnel and use it for web browsing

Command

ssh -D 12345 -C -q -N <username>@<ip or FQDN> -p 23456

Explanation

-D ssh will act as a SOCKS server for the given port
-C Compress data
-q quiet mode. warning and diagnostic messages will be suppressed
-N Do not execute a remote command.  just forwarding ports.
<username>@<ip or FQDN> Connection string to SSH server
-p SSH server port. (if it's usual port 22, you can ignore this parameter)

In addition to above options you can use -f option to push ssh command to background

Executing above command will create a SSH tunnel which supports SOCKS protocol.

How to configure Firefox to use the SSH tunnel 

Go to proxy settings and use localhost as "SOCKS Host" and the port you used for the tunnel as the Port (see the screenshot below)

How to configure Firefox to forward DNS queries to the SSH tunnel

Use "Proxy DNS when using SOCKS v5" in proxy settings or set "network.proxy.socks_remote_dns" to "true" via about:config to get DNS queries resolved via the tunnel. Otherwise the browser will use DNS server configured in your network interface or ISP's DNS servers.


Proxy Settings in Firefox

How to disable WebRTC in Firefox

Important: Please read http://swapoff.blogspot.com/2018/08/avoid-webrtc-leak-if-you-use-browser.html for instructions to disable WebRTC.

Thursday, December 28, 2017

avrdude: stk500_recv(): programmer is not responding error


For the first time, I have started to play with Arduino. I bought an Arduino Pro mini and FT232RL USB to Serial Adaptor Module to connect it to PC for programming.

So I plugged it to my Fedora PC, Started the IDE, configured everything correctly and tried to program it.

Instead of success what I got was annoying error "avrdude: stk500_recv(): programmer is not responding error". After doing about an hour of investigations, I was still unable to find a clue.

Then I decided to plug the FT232RL module to an on-board USB port instead of the USB port I used in the front panel. Surprise!!! It worked!!!.

So the issue was with the USB port in the front panel.


Tl;DR:
Use on-board USB ports. Do not use front panel USB ports to program Arduino.

Sunday, December 3, 2017

How to install and configure Kodi on Linux to use NFS and MySQL

Plex and Kodi are very popular media player software. Both of these software have pros and cons in various aspects such as open source vs closed source, free vs paid, server end transcoding vs client end transcoding etc.

When it comes to configurations, Plex is easier to configure than Kodi. However if you are a Linux user, configuring Kodi is not difficult. Actually it is easier than what I thought.

My use case is sharing media files across a LAN. An Espressobin works as the centralized headless media source, a Fedora desktop and an Android Tab as the Kodi clients.

I chose NFS to share the files and MySQL to share the Libraries.

1. Install and configure NFS server on the NAS


I'm using Armbian on my Espressobin, hence the package management tool is apt-get. 

apt-get install nfs-kernel-server

Then I have configured /etc/exports file which is the configuration file for NFS server to share the directory where my media files are.

Methods of configuring this file is explained in Kodi Wiki in detailed manner.
http://kodi.wiki/view/NFS#NFS_sharing_from_Linux

I used option one where all UIDs connected to the NFS server are mapped to UID 65534 (i.e. user nobody)

Content of my /etc/exports file,

root@espressobin:~# cat /etc/exports  | grep -v '#'
/mnt/kodi_test 192.168.8.0/24(rw,all_squash,insecure)


Then I executed exportfs -ra command to refresh the NFS shares.

At this point, the NFS share has been successfully configured.

 

2. Install and configure MySQL server on the NAS


The steps required for this are well documented in the Kodi Wiki,
http://kodi.wiki/view/MySQL/Setting_up_MySQL

In brief the steps are,
  • Install MySQL server,
apt-get install mysql-server

  • Change Bind Address,
Change bind-address in /etc/mysql/mysql.conf.d/mysqld.cnf file

  • Restart MySQL Server,
service mysql restart

  • Execute SQLs to create and configure required database user in MySQL server,
mysql -u root -p

CREATE USER 'kodi' IDENTIFIED BY 'kodi';
GRANT ALL ON *.* TO 'kodi';
flush privileges;


Now I have finished configuring the server side. I have installed and configured NFS and MySQL on my NAS. Now it's time to configure client side. So I installed Kodi on my Fedora desktop.

3. Use MySQL in Kodi


Even though I have created MySQL server and the required MYSQL users on the NAS, Kodi runs on my Desktop must be configured to use the MySQL server.

For that I need to create a XML file called advancedsettings.xml and put it to a directory in each Kodi clients. The directory location is OS specific and the correct location is documented here,
http://kodi.wiki/view/Userdata#Location_of_the_userdata_folder

So I have created my advancedsettings.xml in ~/.kodi/userdata/  in my Fedora desktop machine.

[user@localhost userdata]$ pwd
/home/user/.kodi/userdata


[user@localhost userdata]$ cat advancedsettings.xml
<advancedsettings>
  <videodatabase>
    <type>mysql</type>
    <host>192.168.8.102</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </videodatabase>
  <musicdatabase>
    <type>mysql</type>
    <host>192.168.8.102</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </musicdatabase>
  <videolibrary>
    <importwatchedstate>true</importwatchedstate>
    <importresumepoint>true</importresumepoint>
  </videolibrary>
</advancedsettings>


4. Use NFS share in Kodi


I started Kodi on the Fedora desktop and added the NFS share as the media source.

Instruction on adding a shared source is documented here,
http://kodi.wiki/view/Adding_video_sources#Adding_Remote_sources

In brief the steps are,
  • Click on the settings icon
  • Click on Media Settings
  • Click on Library
  • Select  Videos from "Manage Sources"
  • Click on Add Videos
  • Then Click on Browse from "Add Video Source" window
  • Choose Network File System (NFS) option from the drop down

That's it. the Espressobin NAS has been configured,
  • to share content via NFS to Kodi running on devices connected to my LAN
  • to maintain a centralized Kodi library in MySQL server running on the same NAS.

Was that difficult? I don't think so.

Monday, October 16, 2017

LineageOS on Galaxy Tab 2 7 AKA P3113

A few days a go I wanted to install an application from google play store on my Galaxy Tab 2 7 Tab. The device had an old stock Android version (Jelly Beans) and it refused to install the application as the application required a newer version of Android OS.

Then I remembered Cyanogenmod which was very popular a few years ago. It could install a new Android version on my tab. After searching about the project I learnt that it was shutdown last year. Fortunately it has been reborn as "LineageOS".

I decided to install LineageOS on my tab. I used my Fedora desktop to upload and flash the required software. The process was straightforward and it's well documented in LineageOS wiki pages.

The OS is still delivered as nightly builds, but I haven't experienced any issues with it so far. The build is as stable as a standard stable release.

You can install Google applications (Open GApps) after just installing the OS. Those applications are not bundled with the OS due to licensing restrictions. Applications such as Google Play Store are available with Open GApps.

After installing the OS, I have tried several applications such as Google Chrome and YouTube. The results are amazing. I'm experiencing smooth scrolls, quality video play, etc. LineageOS offers a way better experience than the old Android stock OS on the Galaxy Tab 2 7.

I think this is the best thing happened to my Tab. I should have done this a long time ago.

Saturday, October 7, 2017

Modify Atheros AR9271 USB WiFi Adapter to add heat sinks

Today I received  Atheros AR9271 USB WiFi Adapter which I ordered from AliExpress. I ordered it after a thorough google search about Linux friendly WiFi adapters. As I expected it started to work on my Fedora desktop machine out of the box.

However I noticed that the adapter heats a little when I touched it after a few minutes. I was curious to see what caused the heat. So I decided to dissemble it. Disassembling the plastic enclosure of the adapter was not difficult. Sliding a piece of thin plastic or metal between the two pieces of the enclosure would open it.

The adapter actually uses a WiFi module. The chip was covered with a small metal sheet to handle the heat. The metal sheet was covered by a sticker which has the information of the module. (See the photo below)

Atheros AR9271 USB WiFi Adapter
WiFi Module

Hmm Nothing special. Oh wait is that a LED in the module? It is. There is a LED and it lights up when the adapter is turned on. It blinks when there is a data transfer. The enclosure does not have any hole above it so the light is not visible unless you disassemble it.

At that moment I decided to modify the USB enclosure. A simple small hole drilled through the top piece of the plastic enclosure would do the job. Hmm.. Why shouldn't you hack it further to add a heat sink?  Yes, It was a perfect crazy idea to ruin the enclosure. Also it may be a overkill to add a heat-sink for that small USB gadget. but I was already bored and looking for a job something like that. So I decided to modify the top piece of the enclosure to mount a heat-sink.

I didn't have a heat sink which matches with the size of the metal sheet. Nothing stops doing crazy things, Fortunately I had 2 small heat sinks which could cover the metal sheet.

First I drilled the top piece of the enclosure for the LED. Then I drilled the top piece multiple times using a small bit so that it could help to remove a rectangle piece from the enclosure. I used a small hand file to smooth the edges after that.

After I verified the rectangle space is good enough for the heat-sinks, I assembled the plastic enclosure. Then I mounted the two heat sinks on the metal sheet through the rectangular space I cut on the top of the enclosure.

The end result? Yes, it looks funny, but I like it.

Atheros AR9271 USB WiFi Adapter
Modified USB WiFi Adapter

Atheros AR9271 USB WiFi Adapter
The Modified Adapter in use

Saturday, February 4, 2017

Flash BeagleBone (Black Rev C) eMMC with Debian Jessie IoT


  • Download the latest image,

wget https://debian.beagleboard.org/images/bone-debian-8.6-iot-armhf-2016-12-09-4gb.img.xz

  • Then write the image in to your SD card,

xzcat bone-debian-8.6-iot-armhf-2016-12-09-4gb.img.xz | sudo dd of=/dev/sdc
sync

  • After the image is written to the SD card, mount the rootfs partition.
  • Then change directory to boot directory
  • vi uEnv.txt file and find below lines,

##enable Generic eMMC Flasher:
##make sure, these tools are installed: dosfstools rsync
#cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh

  • uncomment below line, save and exit

cmdline=init=/opt/scripts/tools/eMMC/init-eMMC-flasher-v3.sh


  • Enter the SD card in to the Beaglebone and connect the power. The OS will be flashed in to the eMMC for about 20 minutes and then all the LEDs will be turned off.
  • Remove the power code, then remove the SD card and connect the power again.

Saturday, January 28, 2017

SD card benchmarking on raspberry pi

I have been reading about various SBCs (Single Board computers) to find a suitable one to build a NAS. While doing that, I remembered I own a Raspberry Pi 1 Model B SBC. Therefore I decided to try a torrent client on the raspberry pi to find out the capabilities of my old raspberry pi.

So, I used the latest raspbian lite image (2017-01-11-raspbian-jessie-lite.img) which is a nice headless distro suitable for my experiment on a Class 10 SD card ( Kingston 32GB SDHC SDC10G2/32GB).

Then I installed the transmission client daemon as the torrent client and added a private torrent which had a good healthy swarm. I left the torrent client keep running for a while and noticed that the download speed goes down to 0 time to time. I thought this was due to the behavior of the peers. however after observing the client for a while I understood it happened time to time with a pattern.

Then I used iostat command (comes with the sysstat package) to monitor the I/O behavior and found out that the I/O Wait goes about 100% when the download speed goes to 0. So there is a relationship between the write performance and the periodic download speed drops.

Therefore I decided to benchmark the write performance on the raspberry pi. The intention was just to study the performance of the write performance of the OS (VFS + File system ) and the raspberry pi hardware combination, not the SD card performance.

The tests were done using iozone tool with different test scenarios. Each scenario was tested for a 1000MB file with 25MB, 50 MB and 100MB record sizes.


File System
Disk Scheduling Algorithm
Ext4 with journal
noop
Ext4 without journal
noop
Ext4 with journal
deadline
Ext4 without journal
deadline
Ext4 with journal
cfq
Ext4 without journal
cfq


Then I plotted the read,write,random read and random write results using gnuplot.

According to the results,

  • write graphs shows that the raspberry pi can handle about 10000 KB write rate. There was no significant variance in the rate with the record size.
  • random write graph shows that the raspberry pi can handle 9000 KB write rate. It also shows that the higher rates can be achieved setting the higher record sizes.
  • read and random read graphs show that the raspberry pi can handle about 18000 KB read/random read rate. There was no significant variance in the rate with the record size. 

Therefore even though the SD card is class 10, that will not give you the actual SD card performance due to bottlenecks in Raspberry pi.


Write
Write 

Random Write
Random Write
Read
Read
Random Read
Random Read
This is how I prepared the SD card for the tests,

Prepare the SD card for raspberry pi

First write the raspbian image on to the SD card using dd command,

dd if=2017-01-11-raspbian-jessie-lite.img of=/dev/sdx

Then we need to create two partitions with and without ext4 journal for this experiment. However when raspberry pi boots at first time, it expands the file system automatically to consume all the free disk space in the SD card. In order to avoid that we should disable that feature.

For that, mount the SD card and edit cmdline.txt file located in the boot partition and remove the highlighted portion from the boot parameters.

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet init=/usr/lib/raspi-config/init_resize.sh


Create 2 partitions for tests

Insert the SD card in to the raspberry pi and boot it. Now we are able to create the two partitions we want on the SD card.


root@raspberrypi:~# fdisk /dev/mmcblk0

Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p
Disk /dev/mmcblk0: 29 GiB, 31104958464 bytes, 60751872 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x244b8248

Device         Boot  Start     End Sectors  Size Id Type
/dev/mmcblk0p1        8192  137215  129024   63M  c W95 FAT32 (LBA)
/dev/mmcblk0p2      137216 2715647 2578432  1.2G 83 Linux


Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): e
Partition number (3,4, default 3): 
First sector (2048-60751871, default 2048): 2715648
Last sector, +sectors or +size{K,M,G,T,P} (2715648-60751871, default 60751871): 

Created a new partition 3 of type 'Extended' and of size 27.7 GiB.

Command (m for help): p
Disk /dev/mmcblk0: 29 GiB, 31104958464 bytes, 60751872 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x244b8248

Device         Boot   Start      End  Sectors  Size Id Type
/dev/mmcblk0p1         8192   137215   129024   63M  c W95 FAT32 (LBA)
/dev/mmcblk0p2       137216  2715647  2578432  1.2G 83 Linux
/dev/mmcblk0p3      2715648 60751871 58036224 27.7G  5 Extended


Command (m for help): n
Partition type
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 5
First sector (2717696-60751871, default 2717696): 
Last sector, +sectors or +size{K,M,G,T,P} (2717696-60751871, default 60751871): +14G

Created a new partition 5 of type 'Linux' and of size 14 GiB.

Command (m for help): p
Disk /dev/mmcblk0: 29 GiB, 31104958464 bytes, 60751872 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x244b8248

Device         Boot   Start      End  Sectors  Size Id Type
/dev/mmcblk0p1         8192   137215   129024   63M  c W95 FAT32 (LBA)
/dev/mmcblk0p2       137216  2715647  2578432  1.2G 83 Linux
/dev/mmcblk0p3      2715648 60751871 58036224 27.7G  5 Extended
/dev/mmcblk0p5      2717696 32077823 29360128   14G 83 Linux


Command (m for help): n
Partition type
   p   primary (2 primary, 1 extended, 1 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 6
First sector (32079872-60751871, default 32079872): 
Last sector, +sectors or +size{K,M,G,T,P} (32079872-60751871, default 60751871): 

Created a new partition 6 of type 'Linux' and of size 13.7 GiB.

Command (m for help): p
Disk /dev/mmcblk0: 29 GiB, 31104958464 bytes, 60751872 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x244b8248

Device         Boot    Start      End  Sectors  Size Id Type
/dev/mmcblk0p1          8192   137215   129024   63M  c W95 FAT32 (LBA)
/dev/mmcblk0p2        137216  2715647  2578432  1.2G 83 Linux
/dev/mmcblk0p3       2715648 60751871 58036224 27.7G  5 Extended
/dev/mmcblk0p5       2717696 32077823 29360128   14G 83 Linux
/dev/mmcblk0p6      32079872 60751871 28672000 13.7G 83 Linux


Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: Device or resource busy

The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8).


root@raspberrypi:~# partprobe /dev/mmcblk0

root@raspberrypi:~# lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0   29G  0 disk 
├─mmcblk0p1 179:1    0   63M  0 part /boot
├─mmcblk0p2 179:2    0  1.2G  0 part /
├─mmcblk0p3 179:3    0  512B  0 part 
├─mmcblk0p5 179:5    0   14G  0 part 

└─mmcblk0p6 179:6    0 13.7G  0 part 


Create file systems on the partitions

Create a ext4 file system without a journal,

root@raspberrypi:~# mkfs.ext4 -O ^has_journal /dev/mmcblk0p5
mke2fs 1.42.12 (29-Aug-2014)
Discarding device blocks: done                            
Creating filesystem with 3670016 4k blocks and 917504 inodes
Filesystem UUID: 70fbac8c-4b68-4f53-aacb-12c2f84022ba
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done                            
Writing inode tables: done                            
Writing superblocks and filesystem accounting information: done

Create another ext4 file system with default options,

root@raspberrypi:~# mkfs.ext4  /dev/mmcblk0p6
mke2fs 1.42.12 (29-Aug-2014)
Discarding device blocks: done                            
Creating filesystem with 3584000 4k blocks and 897600 inodes
Filesystem UUID: 3d5c4292-3aa6-49c8-a0e9-4fa7f0d484e3
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 


Then mount the partitions,

mkdir /no_journal /with_journal

root@raspberrypi:~# cat /etc/fstab 
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
/dev/mmcblk0p5  /no_journal     ext4    defaults,noatime  0       0
/dev/mmcblk0p6  /with_journal   ext4    defaults,noatime  0       0

root@raspberrypi:~# mount -a



iozone utilitiy

Download iozone source code and compile it to build the tool.

wget http://www.iozone.org/src/current/iozone3_465.tar


Note: I changed  MAXBUFFERSIZE constant defined in the iozone.c file in order to have larger record sizes. by default it supports only for 16MB record sizes.

References,

Friday, January 13, 2017

Things I did after installing Fedora 24

Removed evolution application since I don't use it.


dnf remove evolution

Configure RPMFusion repo


wget https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-24.noarch.rpm
rpm -ivh rpmfusion-free-release-24.noarch.rpm 

Upgrade the system


dnf upgrade

Install Intel Linux graphic drivers


wget https://download.01.org/gfx/fedora/24/x86_64/intel-graphics-update-tool-2.0.3-24.intel20163.x86_64.rpm
rpm -ivh intel-graphics-update-tool-2.0.3-24.intel20163.x86_64.rpm 
Run intel-graphics-update-tool command as root and install the Intel drivers

Install VLC and configure hardware acceleration


Read the instructions here,
http://swapoff.blogspot.com/2017/01/how-to-enable-hardware-acceleration-in.html


Install Google Chrome


rpm -ivh google-chrome-stable_current_x86_64.rpm 
warning: google-chrome-stable_current_x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 7fac5991: NOKEYerror: Failed dependencies: lsb >= 4.0 is needed by google-chrome-stable-55.0.2883.87-1.x86_64

Install redhat-lsb as well if you receive above error when you try to install Google Chrome.
dnf provides lsb
dnf install redhat-lsb

Install Gnome Tweak Tool and configure it to show files on Desktop


dnf install gnome-tweak-tool

Disable dnf-makecache service


systemctl status dnf-makecache.service
systemctl status dnf-makecache.timer
More information is avaiable here,
http://swapoff.blogspot.com/2015/09/disable-automatic-package-metadata.html

Wednesday, January 11, 2017

How to enable hardware acceleration in VLC running on Fedora 24

I used to use VLC hardware acceleration (http://swapoff.blogspot.com/2014/12/install-libva-intel-driver-to-get-hw.html) because it's a cool thing to have when you play HD videos. Recently I noticed that my CPU is heavily utilized when I played HD videos even though I was under the impression that the hardware acceleration was working. The methods I tried to find out whether the hardware acceleration was working or not gave positive results, but the CPU utilization was telling a different story.

Therefore I tried to understand what was actually happening.

After doing some google searches I landed on a VLC forum thread which describes this was due to the behavior in the FFmpeg library. (https://forum.videolan.org/viewtopic.php?t=134770) According to the information shared in that thread, the library does not support multithreading with hardware acceleration. But VLC set 0 which is auto for the number of threads for FFmpeg.

Therefore changing this value to 1 should work. We can change the value by selecting,  
Tools -> Preferences -> Input/Codecs -> Show Settings All -> Input codecs -> Video codecs -> FFmpeg and set the value of the parameter "Threads" to 1

After setting this value to 1 and restarting the VLC, I tried to play several 720p videos. It actually worked. The CPU utilization was well under 10%.

However when I tried to play a 1080i Blue-Ray video, a nasty thing happened. It triggered a bug in the kernel and crashed the system.

details of the crash from journalctl,

Jan 10 02:31:17 localhost.localdomain kernel: BUG: unable to handle kernel NULL pointer dereference at           (null)
Jan 10 02:31:17 localhost.localdomain kernel: IP: [<ffffffffc019d58d>] gen6_ppgtt_insert_entries+0x14d/0x1d0 [i915]
Jan 10 02:31:17 localhost.localdomain kernel: PGD 0
Jan 10 02:31:17 localhost.localdomain kernel: Oops: 0000 [#1] SMP
Jan 10 02:31:17 localhost.localdomain kernel: Modules linked in: uas usb_storage fuse xt_CHECKSUM ipt_MASQUERADE nf_nat_masquerade_ipv4 tun ip6t_REJECT nf_reject_ipv6 xt_con
Jan 10 02:31:17 localhost.localdomain kernel:  intel_rapl_perf snd_hda_core snd_hwdep snd_seq snd_seq_device snd_pcm joydev i2c_i801 mei_me i2c_smbus snd_timer snd mei shpch
Jan 10 02:31:17 localhost.localdomain kernel: CPU: 3 PID: 2740 Comm: vlc Not tainted 4.8.15-200.fc24.x86_64 #1
Jan 10 02:31:17 localhost.localdomain kernel: Hardware name: ASUS All Series/H97M-E, BIOS 2302 02/09/2015
Jan 10 02:31:17 localhost.localdomain kernel: task: ffff91804f7f1e80 task.stack: ffff91801e340000
Jan 10 02:31:17 localhost.localdomain kernel: RIP: 0010:[<ffffffffc019d58d>]  [<ffffffffc019d58d>] gen6_ppgtt_insert_entries+0x14d/0x1d0 [i915]
Jan 10 02:31:17 localhost.localdomain kernel: RSP: 0018:ffff91801e3439d8  EFLAGS: 00010246
Jan 10 02:31:17 localhost.localdomain kernel: RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffff91808be44000
Jan 10 02:31:17 localhost.localdomain kernel: RDX: ffff91801de7aae0 RSI: ffff918088b01000 RDI: 000000038cc4d000
Jan 10 02:31:17 localhost.localdomain kernel: RBP: ffff91801e343a28 R08: 0000000000000000 R09: ffff91808be44000
Jan 10 02:31:17 localhost.localdomain kernel: R10: 0000000000000000 R11: ffff918088a20000 R12: ffff918088b01ffc
Jan 10 02:31:17 localhost.localdomain kernel: R13: 0000000000000000 R14: ffff91801de7aae0 R15: 0000000000000000
Jan 10 02:31:17 localhost.localdomain kernel: FS:  00007f8b0882a700(0000) GS:ffff91809fb80000(0000) knlGS:0000000000000000
Jan 10 02:31:17 localhost.localdomain kernel: CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
Jan 10 02:31:17 localhost.localdomain kernel: CR2: 00007fe765248000 CR3: 00000003b4c1a000 CR4: 00000000001406e0
Jan 10 02:31:17 localhost.localdomain kernel: Stack:
Jan 10 02:31:17 localhost.localdomain kernel:  ffff91804f7f1e80 0000000000000200 ffff91808be44000 0000100000000001
Jan 10 02:31:17 localhost.localdomain kernel:  000000038cc4d000 0000000000000000 ffff91801dd0ac00 0000000000000002
Jan 10 02:31:17 localhost.localdomain kernel:  0000000000000001 ffff9180487dba80 ffff91801e343a60 ffffffffc019ee60
Jan 10 02:31:17 localhost.localdomain kernel: Call Trace:
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffc019ee60>] aliasing_gtt_bind_vma+0x90/0xe0 [i915]
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffc01a3e8e>] i915_vma_bind+0xce/0x180 [i915]
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffc01aa4fb>] i915_gem_object_do_pin+0x86b/0xa60 [i915]
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffc01aa71d>] i915_gem_object_pin+0x2d/0x30 [i915]
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffc0198acf>] i915_gem_execbuffer_reserve_vma.isra.20+0x9f/0x180 [i915]
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffc0198f3b>] i915_gem_execbuffer_reserve.isra.21+0x38b/0x3b0 [i915]
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffc019a1d8>] i915_gem_do_execbuffer.isra.24+0x6b8/0x1200 [i915]
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffc019b944>] i915_gem_execbuffer2+0x104/0x260 [i915]
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffc00cbfa0>] drm_ioctl+0x200/0x4f0 [drm]
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffc019b840>] ? i915_gem_execbuffer+0x330/0x330 [i915]
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffb0264cc3>] do_vfs_ioctl+0xa3/0x5f0
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffb0265289>] SyS_ioctl+0x79/0x90
Jan 10 02:31:17 localhost.localdomain kernel:  [<ffffffffb0803b72>] entry_SYSCALL_64_fastpath+0x1a/0xa4
Jan 10 02:31:17 localhost.localdomain kernel: Code: 5f 5d c3 c7 45 cc 00 00 00 00 31 db 48 c7 45 d0 00 00 00 00 45 31 f6 e9 2a ff ff ff 8b 45 b8 48 8b 4d c0 48 8b 84 c1 c8 0
Jan 10 02:31:17 localhost.localdomain kernel: RIP  [<ffffffffc019d58d>] gen6_ppgtt_insert_entries+0x14d/0x1d0 [i915]


Then I have found a bug report (https://bugs.freedesktop.org/show_bug.cgi?id=98760) which was reported for this particular issue. Fortunately it had a workaround mentioned to fix the issue. The workaround is to downgrade the
libvdpau-va-gl installation.

First, find out the available versions of libvdpau-va-gl,
dnf --showduplicates list libvdpau-va-gl

Then remove the existing libvdpau-va-gl installation,
dnf remove libvdpau-va-gl

Then install the previous version of libvdpau-va-gl,
dnf install libvdpau-va-gl-0.3.6-1.fc24.x86_64

Finally I was able to get hardware acceleration in VLC worked for both 720p and 1080i HD videos.

Saturday, August 20, 2016

How to enable serial console on LS-VL

Why do need to connect to your linkstation via a serial console?
  1. You can see the actual messages the linkstation prints when it is booted
  2. You can log in to the linkstation without using the network interface
  3. Just for fun :)
What do you need?
  1. Patience
  2. soldering skills
  3. a serial cable. (I have a cheap PL2303HX USB to TTL serial cable ordered from ebay)

If you are a amateur to soldering, my recommendation is do not try this.

Main board modifications


First you need to disassemble the linkstation and remove the main board. Then you have to connect four points in the main board as shown in the picture. These four holes can be found between the processor and the SATA connector.
This is where you need patience and soldering skills. It's bit difficult task to connect the holes using small wires.


Serial Header


The serial header can be found near the SATA connector as shown in the picture. You can solder a pin header so that you can easily plug a serial cable.




Once the main board and serial header are modified, you can plug a serial cable and use the screen program to view the console.

I used PL2303HX USB to TTL serial cable and didn't attach the power cable (red color) to the serial header. The white color cable connected to TxD pin, The green color cable connected to RxD pin  and the black color cable connected to the GND pin

screen command I used,

screen /dev/ttyUSB0 115200

console output,



If you need to find u-boot output messages, you can do another modification to the main board. However this is extremely difficult. You shouldn't attempt to do this unless you have good experience in SMD soldering.
The modification is, remove R60 and solder it on space allocated for R59.

I almost screwed up my main board trying to moving R60 to R59. It took hours to make things worked.
You have been warned!!!


Console output with u-boot messages, 




References: