Linux From Scratch

I got to know Linux From Scratch soon after I bought my desktop machine. My first attampt failed at making gcc to setup the “cross-compile” environment. About four years later I picked it up and finally went through my first pass of building LFS. My destop machine has been running LFS happily since then. Two experiences are briefly note down: 1) break dependency circle with building twice; 2) reconfig kernel and build with additional modules.

Read More

Relocation and Thread Local Storage

The following excellent articles in the past two days taught me a lot about how the loader does relocation for ELF executables and how thread local storage is handled:

Read More

Fix Broken Packages

A server machine failed at upgrading from Ubuntu14.04 to Ubuntu16.04, and many packages are left in half-installed status, even apt is not working. I struggled several days to fix those broken packages, and this post documents some tricks I learnt.

Read More

Start a Process in Suspended State

Under some circumstances, I would like to launch the process, then let other programs attach to it. No matter how fast can I type, it is impossible for me to bind the processes from the very beginning. The solution is let the script to launch the process but suspend it immediately.

#!/bin/bash
$@ &
PID=$!
kill -STOP $PID
echo $PID
wait $PID

The script earns enough time for you to do your operations in another terminal, then to resume the process:

kill -CONT $PID

Note: need to replace $PID with the number printed in the first terminal.

Read More

Delete Lines from Huge Files

With huge files, tasks that as simple as removing first or last several lines could become hard. If you try to open a huge file with vim, the chance is that the system gets stuck struggling to load the huge file into memory. This post has several alternative approaches to delete lines from huge files.

Read More

Tips to Find Predefines for Compilers

Two useful tips from TACC tips regarding compiler macro expanding.

Tip 120:
Want to know what MACROS are predefined by the GCC and Intel compilers? Do

gcc -dM -E - < /dev/null > gcc_defined_macros.txt
icc -dM -E - < /dev/null > icc_defined_macros.txt

The flag -E in the tip is telling the compiler to expand macros.

Tip 69:
Having trouble figuring out how a macro is being expanded? Try pasting the line into a terminal and adding a -E. For example try changing mpicc -DFOO -DBAR -c foo.c into mpicc -DFOO -DBAR -E foo.c > foo.i and look at the foo.i file.

Read More

How to Create Device Node in Kernel Module

Device node is a file-like abstraction in Linux for user to interact with devices. It could map the operations (read, write, fasync etc.) performed on the file to the associated device. Otherwise, user application needs to be executed with privilege to do memory map before using the device, and programer needs to know the physical address.

After reinstall OS, the SD card reader on my laptop stops work again. Because this time I use Linux Mint, which is based on higher version kernel, I encountered more troubles to drive the SD card reader.

Three steps, five errors and solutions are recorded.

Read More

Driver for RTS5227/RTS5229

After reinstall OS, the SD card reader on my laptop stops work again. Because this time I use Linux Mint, which is based on higher version kernel, I encountered more troubles to drive the SD card reader.

Three steps, five errors and solutions are recorded.

Read More