Thursday, November 25, 2010

How to setup static IP address on Debian

Let check few pre-requirements we need to obtain from the network admin:
  1. Host name: deby01.dev.local
  2. Ip address: 192.168.10.21
  3. Network: 192.168.10/24
  4. Gateway: 192.168.10.1
  5. DNS Servers: 192.168.10.2 and 192.168.10.3
  6. Local Domains: dev.local, corp.local
Here are few simple steps to give your Debian box static IP address:
  1. Configure hostname:
    echo "deby01" > /etc/hostname
    
  2. Ensure /etc/hosts file properly resolves localhost:
    127.0.0.1       localhost
    # In some circumstance it is not recommended to
    # resolve machine name to local ip address
    #127.0.1.1      deby01.dev.local  deby01
    
  3. Here is content of /etc/network/interfaces
    # The primary network interface
    auto eth0
    iface eth0 inet static
         address 192.168.10.21
         netmask 255.255.255.0
         network 192.168.10.0
         broadcast 192.168.10.255
         gateway 192.168.10.1
    
  4. Resolver configuration file /etc/resolv.conf:
    domain dev.local
    search dev.local dev.local. corp.local.
    nameserver 192.168.10.2
    nameserver 192.168.10.3
    
If you need setup a dynamic ip address with DHCP, take a look here.

How to setup DHCP client on Debian

The Dynamic Host Configuration Protocol (DHCP) is an auto configuration protocol used on IP networks. Before we proceed let assume the hostname we are going to setup is deby01.dev.local.
  1. Configure hostname:
    echo "deby01" > /etc/hostname
    
  2. Ensure hosts file properly resolves localhost:
    127.0.0.1       localhost
    # In some circumstance it is not recommended to
    # resolve machine name to local ip address
    #127.0.1.1      deby01.dev.local  deby01
    
  3. Here is content of /etc/network/interfaces
    # The primary network interface
    allow-hotplug eth0
    iface eth0 inet dhcp
    
    # If you experience issues with obtaining
    # default gateway consider uncomment lines below.
    #       up route add default gw 192.168.10.1
    #       down route del default gw 192.168.10.1
    
  4. Let your dhcp client publish our name (so it can be resolved by name). Ensure the following in file /etc/dhcp/dhcpclient.conf:
    send host-name "deby01";
    
  5. If you experience issues with DNS you can set them manually (file /etc/dhcp/dhcpclient.conf)
    prepend domain-name-servers 8.8.8.8, 8.8.4.4;
    
  6. Reboot in order to changes take effect or issue the following commands:
    ifdown eth0 && ifup eth0
    
  7. Check your dynamically obtained ip address:
    deby01:~# ifconfig eth0 | grep inet
     inet addr:192.168.10.41 ...
    
If you need to setup a static ip address, take a look here.

Wednesday, November 24, 2010

How to Compile a Kernel in Debian

Here you will see how to build Debian deb package for linux kernel source.

Install Tools

First of all install few tools:
apt-get install kernel-package libncurses5-dev fakeroot bzip2 build-essential

Prepare Working Directory

  1. Add users to group src:
    usermod -a -G src user1
    
  2. Ensure group src is the owner of /usr/src:
    chgrp -R src /usr/src
    chmod g+s /usr/src
    chmod -R g+w /usr/src
    

Download Kernel Source

  1. Change your working directory to /usr/src/:
    cd /usr/src
    
  2. Download kernel source from kernel.org:
    wget -c http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.36.tar.bz2
    
  3. Decompress kernel source and create a symbolic link:
    tar xjf linux-2.6.36.tar.bz2
    test -L linux && rm linux 
    ln -s linux-2.6.36 linux
    cd linux
    

Configure Kernel

  1. Let use existing kernel configuration as a start point:
    cp /boot/config-`uname -r` /usr/src/linux/.config
    
  2. Launch kernel configuration tool:
    make menuconfig
    
  3. Start kernel build (this may take from 20 mins to few hours depending on your hardware and number of CPUs):
    time fakeroot make-kpkg -j 2 --initrd --append-to-version=-custom kernel_image kernel_headers
    
  4. Once build finishes you should get two .deb files in parent directory:
    deby01:/usr/src$ ls -l *.deb
    
    linux-headers-2.6.36-custom_2.6.36-custom-10.00.Custom_amd64.deb
    linux-image-2.6.36-custom_2.6.36-custom-10.00.Custom_amd64.deb
    

Install Kernel

  1. Install linux kernel and image deb packages by issuing the following command:
    dpkg -i *.deb
    
  2. Restart your computer:
    shutdown -r now
    
  3. Once it restarts check the kernel version you are using:
    deby01:~$ uname -r
    2.6.36-custom
    
Enjoy your custom kernel.

Tuesday, November 23, 2010

How to quickly reboot you Linux

Here is a quick way to reboot you Linux with kexec command. In debian first install kexec-tools package:
apt-get install kexec-tools
Once installed make your current kernel the one you want to quickly reboot into:
kexec -e
In case you would like disable fast reboot, open file located at /etc/default/kexec and set LOAD_KEXEC to false:

# Defaults for kexec initscript
# sourced by /etc/init.d/kexec and /etc/init.d/kexec-load

# Load a kexec kernel (true/false)
LOAD_KEXEC=true

# Kernel and initrd image
KERNEL_IMAGE="/vmlinuz"
INITRD="/initrd.img"

# If empty, use current /proc/cmdline
APPEND=""

How to get Linux partition UUID

Ext3 file system UUID

tune2fs -l /dev/sda11 | grep UUID
Here is an output:
Filesystem UUID: 0827dce3-d1c0-41b1-bc6f-0d4cfa0a1849

XFS file system UUID

xfs_admin -u /dev/sda13
Here is an output:
UUID = f128170a-1ee4-4b4f-abe7-0acf169bb8ae