Web-centric help for Linux applications

No Gravatar

I somehow feel that the help documentation in Linux applications does not follow a common help documentation format and they need not be, as different applications may be built on different frameworks and hence, follow different methods to create help. More than the format of help documentation, it is the completeness of information provided and their relevance that is missing. As such, dedicated help documentation package for the application ceases its importance as internet provides much more refined, detailed and latest information with regard to Application in question. Also it will be more difficult to maintain a dedicated help documentation as a separate package than giving a collective reference to sources of help available on the web. This, along with the ability to share these sources among users in social/community networks will result in much more meaningful usage and improvement in this help documentation.

Well, these are just my thoughts, any feedbacks and/or directions in this regard are most welcome.

How to extract an initrd image

No Gravatar

Well, I had this often repeated problem of searching for how to extract an initrd image only to find that it is basically as cpio+gzip archive but, over a period of time forgetting it so that I come back searching for this again:-) Finally, I made up my mind to put in what all it takes to extract an initrd image in Linux and re-packing it after customization (not covered here, as customization depends on the need), here.

Unpacking the initrd image:

1. Create an empty directory /tmp/initrd (this is an example; you are free to use any other directory name) and cd into it, using the following command

mkdir -p /tmp/initrd; cd /tmp/initrd;

(Replace /tmp/initrd with your directory name, if using a different directory name)

2. Extract the initrd image using the following command

gunzip absolute-path-to-initrd-image | cpio -i –make-directories

Now, the contents of the initrd image will be there in /tmp/initrd (or whatever directory you have used). Go ahead and do the necessary changes and you may follow the steps below to re-pack it into an initrd image again.

Packing the (custom) initrd image:

1. Get into the directory where you have extracted the initrd image (/tmp/initrd in this example), using the command

cd /tmp/initrd

(Replace /tmp/initrd with your directory name, if using a different directory name)

2. Pack the initrd image by using the command

find ./ | cpio -H newc -o > /tmp/initrd.cpio && gzip /tmp/initrd.cpio && mv /tmp/initrd.cpio.gz /tmp/initrd.img

(Replace /tmp/initrd with your directory name, if using a different directory name)

This will get you the (re)packed initrd image as /tmp/initrd.img (in this example). Now your custom initrd image is ready.

Creating Linux filesystem images

No Gravatar

I’m sharing the following script which creates a filesystem image of desired size (in kBs) for use in building an installUSB/LiveUSB Pen-drive image or for similar uses. I have written this in my effort to create a installUSB image for Debian-Lenny. Hope it is of some help to somebody:-). You may copy the italicized/quoted text below into a new text file and save it as a shell script (.sh extension). Don’t forget to set its executable bit;-) and also, please don’t forget to leave your comments/feedbacks.

Note: It currently creates images for fat16, fat32, ext2 and ext3 and you should run it as root/superuser (sudo). You can extend this script to generate fs images for other filesystem types as well.

Usage: script-name fs-type output-file required-size-kB
Ex.,; ./mk-hdd-img.sh ext3 myimage.img 600000
This will create a filesytem image called myimage.img of type ext3 and of size ~600MB.

#!/bin/bash

if [ $UID -ne 0 ]; then
echo “You need superuser/root privileges to run this.”
exit 1
fi

if [ $# -ne 3 ]; then
echo “Usage: `basename $0`
exit 2
fi

BLOCK_SIZE=1024
HDD_IMG_NAME=”$2″
IMG_KB_SIZE=$3

make_img ()
{
if [ -e "$HDD_IMG_NAME" ]; then
echo “Failed!”
echo “Image file $HDD_IMG_NAME already exits!!!”
echo “Please remove the image and try again.”
exit 4
fi

dd if=/dev/zero of=$HDD_IMG_NAME bs=$BLOCK_SIZE count=$IMG_KB_SIZE
sync; sleep 2
}

echo “Trying to create HDD image with $1 filesystem…. ”

case “$1″ in
fat16)
make_img;
mkfs.vfat -F 16 “$HDD_IMG_NAME” $IMG_KB_SIZE > /dev/null 2>&1;;
fat32)
make_img;
mkfs.vfat -F 32 “$HDD_IMG_NAME” $IMG_KB_SIZE > /dev/null 2>&1;;
ext2)
make_img;
mkfs.ext2 -F -b $BLOCK_SIZE “$HDD_IMG_NAME” $IMG_KB_SIZE > /dev/null 2>&1;;
ext3)
make_img;
mkfs.ext3 -F -b $BLOCK_SIZE “$HDD_IMG_NAME” $IMG_KB_SIZE > /dev/null 2>&1;;
*)
echo “Failed!”
echo “Filesystem of type $1 is not supported!”
echo “Only fat16, fat32, ext2, ext3 are supported”
exit 3;;
esac

echo “Done.”
exit 0

Mirroring Debian repositories using debmirror

No Gravatar

This is a quick guide for those who want to keep a local repository of Debian packages in their machines/servers either for internal consumption or for setting up a public mirror for Debian (very much encouraged to do so). Copy the following bash/shell script lines to a file say, ‘mirror-debian.sh’ and set its executable bit suitably using chmod command (chmod +x mirror-debian.sh). Ofcourse, you need to install debmirror package as root/sudo using the command, apt-get install debmirror. You may install it using Synaptic package manager also.

#!/bin/bash

DEST_ROOT=”/mnt/repos/mirror”
DEBMIRROR_OPTS=”–ignore-release-gpg –ignore-missing-release –ignore-small-errors –progress –postcleanup –nosource”

debmirror $DEBMIRROR_OPTS \
-h ftp.de.debian.org \
-r debian-security \
-d testing/updates \
-s main,contrib,non-free \
-e http \
-a i386 \
$DEST_ROOT/debian-security && echo “Mirrored ‘Debian-security’ successfully.”

debmirror $DEBMIRROR_OPTS \
-h ftp.de.debian.org \
-r debian \
-d testing \
-s main,contrib,non-free \
-e http \
-a i386 \
$DEST_ROOT/debian && echo “Mirrored ‘Debian’ successfully.”

Note:

1. The script mirrors ‘testing’ tree of Debian distro with sections main, contrib and non-free and the corresponding Debian-security repository.

2. The mirror is done for i386 architecture (Normal PCs and Notebooks). If you need to include other architectures add them to -a i386 lines as comma separated values. Ex., to mirror arm binaries additionally, the line will look like ‘-a i386,arm’.

3. Source code is not mirrored. If you want source code to be mirrored too, remove the argument –nosource from DEBMIRROR_OPTS.

4. The DEST_ROOT should be suitably set to the root of the directory where you intend to keep your mirror. In my case, I have set it to /mnt/repos/mirror/ directory.

5. Once, the mirroring is done, you can modify the /etc/apt/sources.list to use the newly created mirror for getting packages.

6. This script in general, can be adjusted to mirror Ubuntu repositories as well.

CDMA modem as network connectivity medium

No Gravatar

The idea here is to give a ‘how-to’ on setting up a mobile, CDMA based USB modem as an alternate internet connectivity medium in places where LAN, WiFi and / or WiMax are not readily available.

Hardware Requirements:

  1. Linux PC/Notebook/Netbook
  2. CDMA-1x USB Modem (Device being used: Reliance M880)

Software/OS Requirements:

  1. Linux Operating System with “usbserial” and “cdc_acm” device driver modules
  2. “pppd”, “wvdial” applications and their dependencies installed on the System

Setup: The steps followed in setting up this CDMA based connectivity can be split into 3 steps, as follows.

  • Configuring kernel modules for auto-loading at bootup
  • Configuring “wvdial” application for dialup / ppp connection
  • Initializing / starting the connection

Configuring kernel modules for auto-loading at bootup

  • Open a terminal and type the command, ‘sudo bash’. This will prompt you for current, logged-in user password. Enter the password to become super-user
  • Type ‘gedit /etc/modules’ to open the file /etc/modules
  • Add the following entries just after the comments;

    usbserial vendor=0×19d2 product=0xfffd
    cdc_acm


    Vendor and product values may change if you use different CDMA modem. The values given are for Reliance M880 modem. Please use appropriate values in that case. You may get those values from ‘lsusb -v’ command, when the device is connected.
  • Save and close the file
  • Reboot the machine for automatic driver loading to happen

Configuring “wvdial” application for dialup / ppp connection

  • Open a terminaL and type the command, ‘sudo bash’. This will prompt you for current, logged-in user password. Enter the password to become super-user
  • Type ‘gedit /etc/wvdial.conf’ to open the file /etc/wvdial.conf
  • Replace the contents of the file /etc/wvdial.conf with the following;

    [Dialer Defaults]
    Init1 = ATZ
    Init2 = AT+CRM=1
    Modem Type = Analog Modem
    SetVolume = 0
    Baud = 115200
    New PPPD = yes
    Modem = /dev/ttyUSB0
    Carrier Check = no
    Stupid Mode = 1
    ISDN = 0
    Phone = dialing-number
    Username = username
    Password = password

    Please use the appropriate value for Dialing-number, Username and Password. Username and Password will generally be the same for Reliance connection (will be the phone number)
  • Save and close the file

Initializing / starting the connection

  • Open a terminal and type the command, ‘sudo bash’. This will prompt you for current, logged-in user password. Enter the password to become super-user
  • Create a backup copy of the file /etc/resolv.conf as /etc/resolv.conf.bak. Remove all the contents of the file /etc/resolv.conf
  • Run, ‘wvdial’ to start the connection

Note: Once the above steps are properly followed, subsequent operation/usage only requires running the command ‘wvdial’ as sudo/root, with the USB-CDMA modem connected to the Computer.

Linmaya is using WP-Gravatar