Learn to share

Raspberry Pi: Sound Over HDMI

| Comments

I was fascinated, how much powerful Raspberry pi3 for 35$. Upon attaching my pi3 to TV through HDMI cables, I wanted to send sound over HDMI cable. Below is the the config change, you need to send sound over HDMI cable

1
2
# Force the monitor to HDMI mode so that sound will be sent over HDMI cable
hdmi_drive=2

Compile ELF on Windows: Islxss

| Comments

With recent bash addition on windows, I simply love the hybrid environment. In this post, we will create Linux executuable (islxss) which is compiled on Windows bash. The function of this exectuable (islxss) is to verify, whether I am running inside LXSS or not.

Step-1) Write a c program, which detects whether I am running inside LXSS or not

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <dirent.h>
#include <string.h>

int main() {
        DIR *d;
        struct dirent *de;
        d = opendir("/dev");
        while((de = readdir(d)) != NULL)
                if(!strcmp(de->d_name, "lxss")) {
                        printf("I'm running inside LXSS!\n");
                        closedir(d);
                        return 0;
                }
        closedir(d);
        printf("LXSS not detected\n");
        return 1;
}

Step-2) Compile the code with static flag

1
gcc -static -o islxss islxss.c

Finally, I move islxss executable to /usr/local/bin on my windows and other cloud servers.

Convert Video to Mp4: Ffmpeg

| Comments

This post is a report on how to convert MPEG-2 video CD to mp4 file. Initially, video is MPEG-2 with 4G size.

As a first step, I used ddrescue to convert to iso

1
ddrescue -c 1024 /dev/sr0 disc1.iso disc1.log

To view, the contents of ISO, one way is to use ffmpeg. {ffmpeg -i disc1.iso}

Next, mount the ISO at a mount point and then use ffmpeg to convert to mp4. Since 4GB file has been converted to four 1GB VOB files, we need to concat and then map both video and audio stream

1
2
3
mount disc1.iso /rescue -o loop ro
cd /rescue/VIDEO_TS
ffmpeg -i concat:VTS_01_1.VOB/|VTS_02_2.VOB/|VTS_03_3.VOB/|VTS_04_4.VOB -map 0:v -map 0:a -c:v libx264 -crf 24 -vf yadif -c:a mp3 -b:a 192k ../../disc1.mp4

For more information on the flags:

0:v : It maps all into video stream
0:a : It maps all into audio stream
-c:v : codec for video
-crf : constant rate factor
-vf : video filter
-c:a : codec for audio
-b:a : bit rate for audio

Upon converting, I have a slick version of mp4video with 670MB.

How to Convert Initrd to Initramfs

| Comments

It’s no mystery that we refer initramfs as initrd. But how do you convert initrd to initramfs?

unzip and then loop mount
Archive all files into cpio file
gzip your cpio file

Volume Bitmap

| Comments

What is a volume bitmap?

Volume bitmap is an array of bits that tracks which blocks are in use and which are free.

Let’s interpret couple bitmap log messages

1
2
kernel: EXT4-fs error (device dm-5): ext4_read_block_bitmap: Cannot read block bitmap - block_group = 550, block_bitmap = 18030436
kernel: EXT4-fs (dm-5): delayed block allocation failed for inode 653024 at logical offset 9425 with max blocks 7 with error -5

First line suggests, it encountered an I/O error trying to read block bitmap. Typically this mean, there is either a problem with the connection from the computer/vm/server to the storage or volume is severely corrupted.

Second line suggests, it’s a delayed block allocation failure, which mean it tried to write data to a file, but ext4 couldn’t allocate a block. Also it informs error -5, which is EIO – I/O error [Tip: Do you know, Linux calls will return file handles as positive numbers, and represent errors by returning a negative number)

Now, it’s time for a question (~!~)

-> When a write call occours, does it read bitmap for every call?

No, it’s cached in RAM. It has to be written when blocks are allocated.