Archive for June, 2010

Downloading and using kernel source on Ubuntu

There may come a time when you need the kernel source code, usually to build kernel headers, compile a module etc. To work with the kernel source once you have it, you’ll want some development tools installed on your server.

sudo aptitude update
sudo aptitude install build-essential

To check the version right on the server. Just run:

root@laptop:~# uname -r
2.6.28-11-generic

Searching for kernel source.

# apt-cache search linux-source
linux-ports-source-2.6.28 - Linux kernel source for version 2.6.28 with Ubuntu patches
linux-source - Linux kernel source with Ubuntu patches
linux-source-2.6.28 - Linux kernel source for version 2.6.28 with Ubuntu patches
SBDavid

The Linux Kernel

When the kernel loads, it immediately initializes and configures the computer’s memory. Next it configures the various hardware attached to the system, including all processors and I/O subsystems, as well as any storage devices. It then looks for the compressed initrd image in a predetermined location in memory, decompresses it, mounts it, and loads all necessary drivers. Next it initializes file system-related virtual devices, such as LVM or software RAID before unmounting the initrd disk image and freeing up all the memory it once occupied.

After the kernel has initialized all the devices on the system, it creates a root device, mounts the root partition read-only, and frees unused memory.

At this point, with the kernel loaded into memory and operational. However, with no user applications to give the user the ability to provide meaningful input to the system, not much can be done with it.

To set up the user environment, the kernel starts the /sbin/init command.

SBDavid

Initial RAM disk image ( initrd )

Initial RAM disk image ( initrd )

Once the second stage boot loader has determined which kernel to boot, it locates the corresponding kernel binary in the /boot/ directory. The proper binary is the /boot/vmlinuz-2.6.x-xx file that corresponds to the boot loader’s settings.

Next the boot loader places the appropriate initial RAM disk image, called an initrd, into memory. The initrd is used by the kernel to load any drivers not compiled into it that are necessary to boot the system. This is particularly important if you have SCSI hard drives or are using the ext3 file system.

Debugging on part(s) of the bash script

Using the set Bash built-in you can run in normal mode those portions of the script of
which you are sure they are without fault, and display debugging information only for troublesome zones.

Say we are not sure what the `uptime` command will do in a script, then we could enclose it in the script like this:

set -x # activate debugging from here
uptime
set +x # stop debugging from here

How to find IPs and IP networks behind each interface

To find the IPs of your network interfaces use ip addr show and to find the IP networks behind each interface use ip route show.

$ ip addr show

1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
2: eth0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
link/ether 00:08:74:22:5c:61 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.2/24 brd 192.168.1.255 scope global eth0
inet 192.168.1.4/24 brd 192.168.1.255 scope global secondary eth0:1

# ip route show

192.168.52.12 dev ppp0 proto kernel scope link src 117.114.119.119
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.1
169.254.0.0/16 dev eth0 scope link metric 1000
default dev ppp0 scope link

« Prev - Next »