Linux - Geek went Freak!

Linux

Linux: Detecting and adding fan control

I bought a Zotac EI750 HTPC recently. It has very good specs but its fan gets noisy very too often. Ubuntu by default doesn’t detected EI750’ fan. I installed lm-sensors and tried sensors command.

sudo apt-get install lm-sensors
sudo sensors

Sensors listed my CPU thermal sensors correctly but couldn’t find the fans.

acpitz-virtual-0
Adapter: Virtual device
temp1: +27.8°C (crit = +105.0°C)
temp2: +29.8°C (crit = +105.0°C)

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0: +40.0°C (high = +84.0°C, crit = +100.0°C)
Core 0: +36.0°C (high = +84.0°C, crit = +100.0°C)
Core 1: +37.0°C (high = +84.0°C, crit = +100.0°C)
Core 2: +35.0°C (high = +84.0°C, crit = +100.0°C)
Core 3: +38.0°C (high = +84.0°C, crit = +100.0°C)

This means that the driver for the fan is not loaded. I should find what fan my system has and load its driver. So, I executed sensors-detect to see if lm-sensors can find the fan.

sudo sensors-detect

Luckily, it did!!! I have Nuvoton NCT5532D/NCT6779D and the corresponding driver is nct6775.


Found `Nuvoton NCT5532D/NCT6779D Super IO Sensors’ Success!
(address 0xa10, driver `nct6775’)

Driver `nct6775’:
* ISA bus, address 0xa10
Chip `Nuvoton NCT5532D/NCT6779D Super IO Sensors’ (confidence: 9)

Now, its easy! Load nct6775 module.

sudo modprobe nct6775

Sensors should detect your fan now.

sensors


fan1: 0 RPM (min = 0 RPM)
fan2: 2246 RPM (min = 0 RPM)
fan3: 0 RPM (min = 0 RPM)
fan4: 0 RPM (min = 0 RPM)
fan5: 0 RPM (min = 0 RPM)

Bash: reading output of a command line-by-line and storing the fields in an array

Many times in bash, you would want to process output of a command. This involves going through each line of the output of command and perform some actions on it.

You can execute a command from bash script and store its output in a variable using command substitution. This can be done in two ways:

Using Backtick

var=`ps`

Using $()

var=$(ps)

Out of the two, i prefer $() because it is more cleaner and easier to nest commands.

Now that you know how to get the output of a command and store it in a variable, you must be interested in learning how to process the output line-by-line and store the results into an array.

Case 1: Using awk

array=($(ps aux | awk 'NR > 1 {print $2}' | tr '\n' ' '))

Case 2: Using read command

read -r -a array <<<  $(ps | awk 'NR > 1 {print $1}' | tr '\n' ' ')

Case 3: Using while-read combination

declare -a a
i=0
while read d1 _; do
  if [[ $i -ne 0 ]]; then
    let a+=($d1);
  fi
done <<< $(ps)

Add volume to boot2docker

boot2docker is great. It allows us to develop using docker even on Windows PCs. One feature that is totally awesome is its ability to share folders on windows host with boot2docker virtualbox image. This shared folder from windows can then be used as a volume in the docker containers.

The first part is available to you out of the box. boot2docker shares the c:\User directory with the boot2docker virtualbox image and mounts it under /c/. Yay!

You can add this folder or part of it to the docker container as you would with normal folders.

docker run -it -v /c/:/data/ : bash

This will add the whole C:\User under /data in the launched docker container.

Crack and install Modelsim on linux

Note: Piracy is crime. Please don’t use or encourage pirated software. If you would like to evaluate Modelsim, try the evaluation version. If you still haven’t changed your mind, read on :P.

1) Install the required dependencies

2) Download modelsim 10.1c for linux and its corresponding crack.

3) Mount the downloaded modelsim iso and install modelsim.

mkdir /tmp/modelsim/
mount -o loop path-to-iso /tmp/modelsim
cd /tmp/modelsim
./install.linux

Note:Install modelsim under ~/modelsim/ directory. If you choose another location, please make sure you exchange the default location with your preferred location in the steps below.

4) Execute this script to crack modelsim

Comment the first two lines in the generated license.dat

#SERVER xxxx xxxxxxxxxxxx 27001
#VENDOR mgcld D:FEATURE mgc_s mgcld 2020.00 1-jan-2021 999 0 TS_OK

5) Fix libfreetype problem (Only required if you face this problem) Try to start vsim

cd ~/modelsim/modeltech/linux_x86_64/
./vsim

If vsim reports the following error, your distro’s freetype library doesn’t play well with modelsim.

Fatal: Read failure in vlm process (0,0)
Segmentation fault (core dumped)

Use the following script to compile custom freetype

6) Modelsim is ready to use! One last step, add these commands to ~/.bashrc to avoid executing every time you start a new terminal

Linux and Modelsim!!!! Ain’t it fun?

Ubuntu: Compiling ffmpeg from source

Ubuntu uses avconv instead of ffmpeg. It also doesn’t have a package for libswresample. This can be problematic at times. So I resorted to installing ffmpeg from source. You need the following packages to compile ffmpeg from source.

sudo apt-get install yasm pkg-config

Lets clone the ffmpeg repository and compile it.

git clone https://github.com/FFmpeg/FFmpeg.git FFmpeg
cd FFmpeg
./configure --prefix=/usr/local/ffmpeg --enable-shared
make
sudo make install

After the above step successfully completes, ffmpeg should be installed in /usr/local/ffmpeg directory. Since we have installed ffmpeg in non standard location, we have to set PKG_CONFIG_PATH and LD_LIBRARY_PATH correctly. Add these lines at the end of your ~/.bashrc.

export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/ffmpeg/lib/pkgconfig/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/ffmpeg/lib/

Install ffmpeg/avconv dev packages in Ubuntu

In Debian and its derivatives, the dev package for ffmpeg/avconv is split into several sub packages:

  • libavdevice-dev
  • libavformat-dev
  • libavfilter-dev
  • libavcodec-dev
  • libswscale-dev
  • libavutil-dev

This command will install all of them:

sudo apt-get install libavdevice-dev libavformat-dev libavfilter-dev libavcodec-dev libswscale-dev libavutil-dev

FFMPEG: Get duration of video

First you should have the ffmpeg dev packages installed. Follow this post to install the required ffmpeg dev packages.

Step 1: Open a video file using the function avformat_open_input.

Step 2: Get stream information using the function call avformat_find_stream_info.

Step 3: Duration of the video can be obtained from member duration of AVFormatContext.

Make sure you add linker flags -lavformat -lavcodec while you compile it.