Tuesday, October 08, 2019

Compiling the Linux Kernel 5.3.5

In Ubuntu 18.04 we need to install some tools first:

sudo apt install build-essential libncurses5-dev gcc libssl-dev bc flex bison

Then we download and decompress the kernel source code:

wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.3.5.tar.xz

tar xvf linux-5.3.5.tar.xz

After that from inside the decompressed directory we run and do the preferred configuration:

make menuconfig

Other options for the configuration would be "oldconfig" and "xconfig"; for this last one we need QT 4.8 or 5.x.

sudo apt install qt5-default

After saving the configuration we run "make" with the option "-j" with the number of processors to speed up the compilation process:

make -j 8
 or
make -j8

My machine has 2 sockets with 4 cores each (Xeon), cache L1d and L1i of 32K each, L2 of 256K and L3 of 10240K; and a total of 16 GB of RAM
Just running plain "make" it took above 2 hours and 10 mins to finish the compilation. When using the -j8 option it took about 32 minutes.

The uncompressed executable that I got is saved directly in the linux-5.3.5 directory with a size of over a 665 MB with the name of "vmlinux".
The compressed executable kernel image is in arch/x86/boot/ with the name of "bzImage" and a size close to 9 MB.

If wanting to get a compiled kernel in the form of a Debian package we need to copy the configuration file from our running boot directory and into the linux-5.3.5 directory.

cp  /boot/config-4.15.0-65-generic  .config

We need to install the "pkg-config" and the "kernel-package" packages:

sudo  apt  install  pkg-config  kernel-package

And then compile it with the deb-pkg command:

make -j8 deb-pkg

Or doing the following steps:

make-kpkg clean

fakeroot make-kpkg -j8 --initrd --append-to-version=-custom kernel_image kernel_headers

After --append-to-version= you can write any string that helps you identify the kernel, but it must begin with a minus (-) and must not contain whitespace.

And to install the kernel in this case would be:

sudo dpkg -i linux-*.deb



Checking the linux kernel source code for special functions, we use the "grep" command to search for specific text inside the kernel source files:

 grep -iRl "sem_init" .

From the list that we get we can check for that text term:

vim ipc/sem.c

Other examples:

grep -iRl "pthread_create" .
vim tools/usb/testusb.c

grep -iRl "pthread_mutex" .
vim tools/lib/lockdep/include/liblockdep/mutex.h

grep -iRl "= fork(" .
vim tools/lib/subcmd/run-command.c

grep -iRl " signal(" .
vim tools/lib/subcmd/sigchain.c




-------------///

Thursday, August 15, 2019

Reducing the size of a video

Calculate the bitrate you need by dividing 1 GB by the video length in seconds. So, for a video of length 16:40 (1000 seconds), use a bitrate of 1000000 bytes/sec:

ffmpeg -i input.mp4 -b 1000000 output.mp4

Additional options that might be worth considering is setting the Constant Rate Factor, which lowers the average bit rate, but retains better quality. Vary the CRF between around 18 and 24 — the lower, the higher the bitrate.

ffmpeg -i input.mp4 -vcodec libx265 -crf 20 output.mp4

Vary the codec as needed - libx264 may be available if libx265 is not, at the cost of a slightly larger resultant file size.

------------||
Other option is to use the program "Handbrake" for Linux.

Friday, July 19, 2019

How to Install Linux Kernel 4.4 in Ubuntu 18.04

The default kernel line for Ubuntu 18.04 LTS is 4.18
I have a Chromebook ASUS C300 and the sound card is  working fine with kernel 4.4 line but not with 4.18, the 4.4 line corresponds to the Ubuntu 16.04 LTS

So I downloaded from the Ubuntu kernels server
https://kernel.ubuntu.com/~kernel-ppa/mainline/
The latest update in the 4.4 line which at this moment is 4.4.185:

linux-headers-4.4.185-0404185_4.4.185-0404185.201907100448_all.deb
linux-headers-4.4.185-0404185-generic_4.4.185-0404185.201907100448_amd64.deb
linux-image-unsigned-4.4.185-0404185-generic_4.4.185-0404185.201907100448_amd64.deb
linux-modules-4.4.185-0404185-generic_4.4.185-0404185.201907100448_amd64.deb

Then it can be installed with the command:
sudo  dpkg  -i  *.deb

You can see a list of your installed kernels with the following command:
dpkg --list | grep linux-image

I'm keeping only the latest versions of the two official lines, we can remove any older version of the 4.4 or the 4.18 with the command:
sudo apt remove linux-image-4.x.x-xxxxxxx-lowlatency

then
sudo apt autoremove

Then we do:  sudo update-grub

We have to edit our grub file to set the default booting kernel
https://forums.gentoo.org/viewtopic-t-1060880-start-0.html

sudo vim /etc/default/grub

In Grub2 we have two different screens before the selection of the kernel, you can check them hitting the "esc" key before the booting. The numbers begin with 0 for the first selection, 1 for the second, and so on. In my case the grub configuration file has the following values for the default, where the number 1 corresponds to the selection in the first screen and the number 2 correspond to the selection for the second screen before the actual boot:

GRUB_DEFAULT="1>2"

Other necessary changes
GRUB_TIMEOUT=10
and comment out either: 
#GRUB_HIDDEN_TIMEOUT=0
or
#GRUB_TIMEOUT_STYLE=hidden

Save & exit.

Then we have to commit with: sudo update-grub

If for some reason we need a higher kernel version, another solution could be downloading the corresponding driver for our sound card and recompiling it for the new kernel.

UPDATE: Up to the kernel 4.4.220 the sound and mic work fine, I have tested kernels beyond that version and the sound is not working. 
I also tried all this in Ubuntu 20.04 but there were broken dependencies for the kernel 4.4.220

----///

Creating Bootable USB Stick On Linux Using Command Line

dd if=~/home/username/path/to/myfile.iso of=/dev/sdb

dd bs=4M if=/path/to/myfile.iso of=/dev/sdx status=progress oflag=sync


----///