Random Tech Thoughts

The title above is not random


Debian related

I used Arch Linux and loved it very much before using Mac. But I didn’t take any notes specific for Arch Linux, sorry for Arch. After I use Mac as my desktop machine, I write code on Debian Linux, and I started to appreciate Debian more and more.

Use backports

Add the following line in /etc/apt/sources.list:

deb http://backports.debian.org/debian-backports squeeze-backports main contrib non-free

Add -t squeeze-backports to aptitude when installing software in the backports repository.

Building a custom kernel using make-kpkg

  1. Install kernel-package.
  2. Extrace the kernel source, make menuconfig as usual.
  3. Invoke make-kpkg at the top level of kernel source tree:

    make-kpkg --revision 1 binary

    binary is the build target, use make-kpkg --targets to see a list of targets.

Debian apt-key importing with http proxy

Add the --keyserver-options:

sudo apt-key adv --keyserver-options http-proxy=http://proxy:port \
    --keyserver subkeys.pgp.net --recv 55BE302B

Debian apt using http proxy

Exporting http_proxy environment variable should work. If not, try to add the following line in /etc/apt/apt.conf:

Acquire::http::Proxy "http://proxy:8080";

Send email directly as a mail server

Say you want to configure the system to send out mail directly (so you can use whatever domain name like me@hello.com), you just need to configure you mail server as “internet site”.

By default, Debian installs exim4, run the following command:

sudo dpkg-reconfigure exim4-config

Control start up service

Install sysv-rc-conf which is a nice console application.

Configuring locales

sudo dpkg-reconfigure locales

locale data are stored in a single archieve at /usr/lib/locale/locale-archive.

List files provided by a package

From Debian Linux apt-get package management cheat sheet

dpkg -L {package-name}

Find which package owns a file

Same source as above

dpkg -S {/path/to/file}

Ubuntu related

Change default compiler to GCC 4.4

First install gcc 4.4

aptitude install gcc-4.4

Set it as default compiler:

update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 100
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.6 50
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 100
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 50
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.4 100
update-alternatives --install /usr/bin/cpp cpp-bin /usr/bin/cpp-4.6 50

Getting cpu information

From Is hyper-threading enabled on a Linux system.

Basically, look at the information from cat /proc/cpuinfo. Watch out the following content:

processor : 7
physical id : 9
siblings : 4
cpu cores : 2
  • processor is the logical processor id
  • By counting unique physical id, we know how many CPUs are there
  • cpu cores shows how many cores each CPU has
  • If siblings is larger than cpu cores, then hyper threading is enabled (If we see ht in the flags, it means the CPU supports hyper threading. But whether it can be used depends also on BIOS and the kernel.)

Dealing with nrg (Nero Img)

From Pank’s blog.


mount -o loop,offset=307200 image.nrg /mnt

convert to iso:

dd bs=1k if=image.nrg of=image.iso skip=300

Mount Windows share with Samba

Mount a Windows share on Linux with Samba

To see shares on Windows box:

smbclient -L <windows-box> -U <username>


mount -t smbfs -o username=<username>,password=<password> \\
    //<win-box>/<share> <mount dir>

Use netstat to see all open port

To see open tcp port, use the following command:

sudo netstat -ap --inet
  • -a Show both listening and non-listening sockets.
  • -p Show the PID and name of progarm which each socket belongs.


Creating /dev/ram0 etc. for ramdisk

If there’s no /dev/ram0 etc, use mknod to create the device file

mknod -m 660 /dev/ram0 b 1 1
chown root.disk /dev/ram0

Change ramdisk size

Append paramater to kernel in grub:

kernel /vmlinux ro root=/dev/sda1 quiet ramdisk_size=10485760

Use tmpfs instead

Easier to use than ramdisk because no need to create file system and easy to specify size.

mount -t tmpfs -o size=512m none <mount point>

Mount proc, sys

From Gentoo Handbook

If proc, sys directory is empty, we need mount to populate them

mount -t proc none /proc
mount -t sysfs none /sys

If we just want to remount sys fs to other directory, we’d better use -o bind to remount the /sys directory to the target directory.

/dev directory contains just files, and we can also use bind populate it to another directory.

CPU hotplug

From Linux hotplug a CPU

List of all current CPUs (including offlines)

# cd /sys/devices/system/cpu
# ls -l

/proc/cpuinfo contains only online cpu info.

Logically turn off (offline) cpu#6

# echo 0 > /sys/devices/system/cpu/cpu6/online
# grep "processor" /proc/cpuinfo


From Arch wiki


  • Physical volume (PV) partition on hard disk
  • Volume group (VG) Group of physical volumes that are used as storage volume (as one disk). Think VG as hard drives
  • Logical volume (LV) A “virtual/logic partition” resides in a volume group, composed of physical extent. Think LV as normal partitions.
  • Physical extent (PE) A small part of a disk (usually 4MB) that can be assigned to a logical volume

Physical volume

  • List pvdisplay
  • Create pvcreate /dev/sda1

Volume group

  • List vgdisplay
  • Create and add PV to VG

    vgcreate VolGroup00 /dev/sda1
    vgextend VolGroup00 /dev/sda2

Logical volume

  • List lvdisplay
  • Create
    • Normal LV, access it at /dev/mapper/Volgroup00-lvolhome or /dev/VGname/LVname

      lvcreate -L 10G VolGroup00 -n lvolhome
    • To create LV for swap, -C y to create contiguous partition

      lvcreate -C y -L 10G VolGroup00 -n lvolswap
    • To use all the free space left on a volume group

      lvcreate -l +100%FREE VolGroup00 -n lvolmedia

After creating LV, we can create file system on them and mount it as normal partitions.

Shrink a LV

First shrink file system, then shrink the LV. The following example reduce the LV to 10G. In order to prevent problems, we first resize the FS to 9G, and resize the FS again to take all the available space on the LV.

e2fsck -f /dev/VG/LV
resize2fs /dev/VG/LV 9G
lvreduce -L 10G /dev/VG/LV
resize2fs /dev/VG/LV

Mounting LVM volume

When rescuing a system with LVM volume, we need to first activate LVM volumn (may need to install lvm2 first.)

# modprobe dm-mod (maybe not needed)
# vgscan
# vgchange -ay <volume group>

After that, the volume can be found in /dev/mapper and use mount to mount the partition.

Change max open fd number

From http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/ and with some modification.

The following way will make the change permanent.

  1. Edit /etc/sysctl.conf, add the following line.

    fs.file-max = 65536
  2. Load new values from the sysctl.conf file

    sysctl -p /etc/sysctl.conf

Or use sysctl to make runtime change:

sysctl -w fs.file-max=65536

User level fd limits

Edit /etc/security/limits.conf, add the following lines to control soft/hard open fd limit for specific user:

cyf hard nofile 65536
cyf soft nofile 65536

Change shared memory limitation

Also use sysctl

sysctl -w kernel.shmmax=256000000

Start VMware Workstation VM and run in background from command line

vmrun start <yourvm.vmx> nogui

Disable ASLR

From How to Disable ASLR and Why you Should do it

I wanted this to simplify things when I was developing application repaly.

sysctl -w kernel.randomize_va_space=0

Or use proc file system (from StackOverflow)

echo 0 > /proc/sys/kernel/randomize_va_space