Wednesday, 8 September 2010

Creating Debian USB Installer

Prerequisites:

An already insalled and working linux distribution. My laptop already had Fedora Core 10.

Target OS

Debian Lenny 5.0.1 was used for this purpose. It can be downloaded fromhttp://cdimage.debian.org/debian-cd/5.0.1/i386/bt-dvd/

We also need a different installer kernel and initrd image as we will be installing from USB. In this case hd-image installers will be used. vmlinuz and initrd for hd-image installes can be downloaded from http://http.us.debian.org/debian/dists/lenny/main/installer-i386/current/images/hd-media/. It is very important to have correct installer image for a distribution.

Preparing USB disk:

We will create an ext2 partition with fdisk command. USB disk device name can be found from dmesg command output. Create a single partition on USB disk and make it bootable. All these activities are performed using fdisk commands. So if USB disk is called as /dev/sdb , it will have one partition as /dev/sdb1

Copy the required grub files to USB stick:
mount /dev/sdb1 /mnt
mkdir -p /mnt/boot/grub
cp /boot/grub/* /mnt/boot/grub
Copy the downloaded hd-media installer image and iso files to USB stick:
cp /home/test/Download/{vmlinuz,initrd.gz} /mnt
cp /home/test/debian-501-i386-DVD-1.iso /mnt
Configure and Install Grub:
Edit /mnt/boot/grub/menu.lst to have following contents only.
title USB Installer
root (hd0,0)
kernel /vmlinuz rootdelay=10
initrd /initrd.gz

It is important to have rootdelay option other wise installer will not kick off. This is required because USB flash drives take a bit longer to be prepared.

Now Install the grub bootloader to USB disk.
# grub
grub> device (hd0) /dev/sdb
grub> root (hd0,0)
grub> setup (hd0)
Thats it. Boot the system from USB disk.

Monday, 30 August 2010

Creating Fedora11 USB Installer With Grub

Introduction:

As the new OSes are coming in the market, to test and install these OSes requires DVDs to be created. An efficient method was required, so that DVD burning can be stopped. Since my Laptop can be booted from USB device , so It makes much sense to use USB devices (i.e. USB stick or USB drive) to do the installation. For this purpose and 8GB USB disk was used.

Prerequisites:

An already insalled and working linux distribution. My laptop already had Fedora Core 10.

Target OS.

Fedora-11 was used for this purpose. It can be downloaded from http://download.fedoraproject.org/pub/fedora/linux/releases/11/Fedora/i386/iso/Fedora-11-i386-DVD.iso

In case of Debian we had used different installer kernel and initrd image which had to be downloaded. But in case of Fedora-11 we will use the same Installer and initrd image which is available in its ISO file. For more information on Debian USB installer kernel see Preparing USB disk:

We wil create an ext2 partition with fdisk command. USB disk device name can be found from dmesg command output. Create a single partition on USB disk and make it bootable. All these activities are performed using fdisk commands. So if USB disk is called as /dev/sdb , it will have one partition as /dev/sdb1

Copy the required grub files to USB stick:
mount /dev/sdb1 /mnt
mkdir -p /mnt/boot/grub
cp /boot/grub/* /mnt/boot/grub
Copy the installer image and iso files to USB stick:
mount -o loop Fedora-11-i386-DVD.iso /tmp/image
cp /tmp/image/isolinux/vmlinuz /mnt/vmlinuz-fedora-11
cp /tmp/image/isolinux/initrd.img /mnt/initrd.img-fedora-11
cp -pr /tmp/image/images /mnt
cp Fedora-11-i386-DVD.iso /mnt

Note: vmlinuz and initrd.img files are available at two locations in ISO image. First location is isolinux/ and second is images/pxeboot/ . But kernel and initrd.img are exactly same. So it doesn't matter what files are copied. Also there is additional step of copy in Fedora-11 than in Debian.

Configure and Install Grub:
Edit /mnt/boot/grub/menu.lst to have following contents (or grub.conf).
title USB Fedora-11 Installer
root (hd0,0)
kernel /vmlinuz-fedora-11 rootdelay=10
initrd /initrd.img-fedora-11
It is important to have rootdelay option other wise installer will not kick off. This is required because USB flash drives take a bit longer to be prepared.
Now Install the grub bootloader to USB disk.
# grub
grub> device (hd0) /dev/sdb
grub> root (hd0,0)
grub> setup (hd0)
Thats it. Boot the system from USB disk.

Friday, 6 August 2010

OS Remastering CentOS 5.5 using Kickstart

Introduction

This document will describe How to Create a Linux LiveCD using kickstart method. This is the very fast and convenient method of producing LiveCDs. This method can be used only on RedHat based distribution only e.g. Fedora, CentOS. The Method of producing LiveCDs based on Debian distribution is different and is not described here. A manual procedure of modifying a LiveCD is described in the following link.
OS Remastering CentOS 5.5 using Manual Method

Objective

We will be creating a highly customized CentOS 5.5 Based LiveCD which will have some external third party rpm packages as well.

Software Requirement

1) CentOS 5.5 DVD
This can be downloaded from below link
http://mirror.as29550.net/mirror.centos.org/5.5/isos/i386/CentOS-5.5-i386-bin-DVD.iso
2) Third Party RPM package which is to be installed in Live CD. In this case we are using NTFSProgs package which is not available in CentOS repositories.
http://packages.sw.be/ntfsprogs/ntfsprogs-1.13.1-1.el5.rf.i386.rpm

Procedure Overview

First we will install a regular CentOS 5.5 on a system. This can be done on a VM as well. In this installed machine we will build our LiveCD.

Install the Base System

We installed the CentOS 5.5 using CentOS 5.5 DVD in a VM. We used KVM for this purpose.

First create the Virtual Harddisk using following command. and then run VM and finish OS installation
qemu-img create -f qcow2 /VIRTUAL/QEmu/CentOS/CentOS-5.5-i386.img 10G

kvm -smp 4 -m 2048 -hda /VIRTUAL/QEmu/CentOS/CentOS-5.5-i386.img -cdrom /DATA/Install/ISO/CentOS/CentOS-5.5-i386-bin-DVD.iso -usb -usbdevice tablet -vnc :40 -net nic,macaddr=00:00:00:00:00:01 -net tap,script=
I installed the system with minimum utilities. Only Base and Administration Utilities.

Configure the Base system.
Add a repository for LiveCD tools.
Create a file /etc/yum.repos.d/CentOS-LiveCD.repo with following contents.
# Name: CentOS LiveCD repository
[livecd]
name = CentOS $releasever - LiveCD
baseurl = http://www.nanotechnologies.qc.ca/propos/linux/centos-live/$basearch/live
enabled=1
protect=0
gpgkey = http://www.nanotechnologies.qc.ca/propos/linux/RPM-GPG-KEY-PGuay
Install LiveCD tools.
Run the following command to install the LiveCD tools.
yum install livecd-tools syslinux
This is our full blown running OS on a harddisk. We will be creating the LiveCD in this system. All the following commands henceforth will be carried out in this machine only. Mount cdrom
Run the following command to mount the cdrom.
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
Prepare the directory containing third party tools.
mkdir /root/livecdkickstart_files
Place the files in this above directory which you want to include in your customized LiveCD. In this case we had included following files.
BackupRestore.sh 
command.txt 
isolinux.cfg 
kick.ks 
ntfsprogs-1.13.1-1.el5.rf.i386.rpm 
pcbackup_keys 
README 
root_ssh_config 
ssh 
WindowsPCBackup.sh
In the above listed files kick.ks is the kickstart file which will contain all the instructions for the customization of LIveCD. kick.ks is given at the end of this article.

Following are the contents of isolinux.cfg file
default menu.c32
timeout 100
menu title Welcome to BackupRestore CD ver 1.0 !
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color timeout_msg 0 #ffffffff #00000000
menu color timeout 0 #ffffffff #00000000
menu color cmdline 0 #ffffffff #00000000
menu hidden
menu hiddenrow 5
label linux0
menu label Backup This System
kernel vmlinuz0
append initrd=initrd0.img root=CDLABEL=LiveBackupRestoreCD rootfstype=iso9660 ro liveimg mode=Backup vga=0x314
label linux1
menu label Restore This System
kernel vmlinuz0
append initrd=initrd0.img root=CDLABEL=LiveBackupRestoreCD rootfstype=iso9660 ro liveimg mode=Restore vga=0x314
Create the LiveCD
Once you have required files and kickstart file run the following command to create the LiveCD.
cd /root/livecdkickstart_files
livecd-creator --config=kick.ks --fslabel=LiveBackupRestoreCD
kick.ks file
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use hard drive installation media
#harddrive --dir=/tmp/fedora --partition=sda8
repo --name=cdrom --baseurl=file:///tmp/fedora
# To compose against the current release tree, use the following "repo" (enabled by default)
repo --name=released --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-13&arch=$basearch
# To include updates, use the following "repo" (enabled by default)
repo --name=updates --mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f13&arch=$basearch

# Root password
rootpw --iscrypted $1$x9PSyNru$RR5iKsKjlRpaMBgGrg3a81
# System authorization information
auth  --useshadow  --passalgo=md5
# Use text mode install
text
# System keyboard
keyboard uk
# System language
lang en_GB
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
#logging --level=info
# Reboot after installation
reboot
# System timezone
timezone  Europe/London
# System bootloader configuration
bootloader --location=mbr
# Partition clearing information
clearpart --all  

%post
%end

%packages --nobase
@admin-tools
openssh-server
-PackageKit-yum-plugin
-coolkey
-fedora-release-notes
-finger
-fprintd-pam
-ftp
-gnupg2
-hunspell
-iptstate
-irda-utils
-jwhois
-krb5-workstation
-lftp
-mlocate
-mtr
-nc
-nss_db
-nss_ldap
-pam_krb5
-pam_pkcs11
-pam_smb
-perf
-rdate
-rdist
-rsh
-sos
-sssd
-talk
-tcp_wrappers
-telnet
-time
-tree
-vconfig
-words
-ypbind

%end

Monday, 2 August 2010

OS Remastering CentOS 5.5

Introduction

As part of Backup and Restore , We will be customizing an OS CD for our use. We will be using LiveCD for this purpose. We will be customizing it according to our requirement.

Objective

We will customize the LiveCD so that it will represent two customize menu when this system is booted using this CD. We will be inserting our own script which will execute automatically when system is booted without any login. It will execute the script and reboots the system

Software Requirement

1) CentOS 5.5 DVD
This can be downloaded from below link
http://mirror.as29550.net/mirror.centos.org/5.5/isos/i386/CentOS-5.5-i386-bin-DVD.iso
2) LiveCD
This can downloaded from below link
http://mirror.as29550.net/mirror.centos.org/5.5/isos/i386/CentOS-5.5-i386-LiveCD-Release2.iso

Procedure Overview

First we will install a regular CentOS 5.5 on a system. This can be done on a VM as well. We have used. In this installed machine we will modify our LiveCD. This is necessary to have base system same as that of LiveCD. This is due to the squashfs version incompatibility.

We have to use squashfs-tools in order to modify the LIveCD. But If the version of squashFS used to modify the LiveCD is different from the version inside the LiveCD, then resulting LiveCD will not work. Moreover Some OSes used their own patch to patch the utilities. So it is better to use the same Base OS and Same OS based LiveCD.

Install the Base System
We installed the CentOS 5.5 using CentOS 5.5 DVD in a VM. We used KVM for this purpose.
First create the Virtual Harddisk using following command.
qemu-img create -f qcow2 /VIRTUAL/QEmu/CentOS/CentOS-5.5-i386.img 10G
Run VM and start Install Process.
kvm -smp 4 -m 2048 -hda /VIRTUAL/QEmu/CentOS/CentOS-5.5-i386.img -cdrom /DATA/Install/ISO/CentOS/CentOS-5.5-i386-bin-DVD.iso -usb -usbdevice tablet -vnc :40 -net nic,macaddr=00:00:00:00:00:01 -net tap,script=
I installed the system with minimum utilities. Only Base and Administration Utilities.
Configure the Base system(Newly created VM).
Add a repository for LiveCD tools(inside newly created VM).
Create a file /etc/yum.repos.d/CentOS-LiveCD.repo with following contents.
# Name: CentOS LiveCD repository
[livecd]
name = CentOS $releasever - LiveCD
baseurl = http://www.nanotechnologies.qc.ca/propos/linux/centos-live/$basearch/live
enabled=1
protect=0
gpgkey = http://www.nanotechnologies.qc.ca/propos/linux/RPM-GPG-KEY-PGuay
Install LiveCD tools (inside newly created VM).
Run the following command to install the LiveCD tools.
yum install livecd-tools syslinux
This is our full blown running OS on a harddisk. We will be making the changes to LIveCD in this system. All the following commands henceforth will be carried out in this machine only.
CentOS-5.5-i386.img was a 10GB Image. It is necessary to have sufficient space in order to modify the LiveCD. Installation of Base OS on 10GB disk space is enough. All the following commands are now run on this Base OS i.e. CentOS 5.5 (On this VM machine)

Modify LiveCD
Copy the LiveCD ISO to /root directory(inside newly created VM).
# cd /root
#
# ls
anaconda-ks.cfg  centos5.5-livecd.iso  install.log  install.log.syslog
# mkdir -p live/{isofiles,isomount,osmount}
# mount -o loop centos5.5-livecd.iso live/isomount
# cp -R live/isomount/* live/isofiles
# unsquashfs -dest live/squashfiles live/isofiles/LiveOS/squashfs.img
created 1 files
created 2 directories
created 0 symlinks
created 0 devices
created 0 fifos
#
# mount -o loop,rw live/squashfiles/LiveOS/ext3fs.img live/osmount
# cd live/osmount/
# cd etc/rc3.d
#
# mv S08ip6tables K08ip6tables
# mv S08iptables K08iptables
# mv S11auditd K11auditd
# mv S12syslog K12syslog
# mv S23setroubleshoot K23setroubleshoot
# mv S25bluetooth K25bluetooth
# mv S26acpid K26acpid
# mv S26apmd K26apmd
# mv S56cups K56cups
# mv S80sendmail K80sendmail
# mv S85gpm K85gpm
# mv S90crond K90crond
# mv S90xfs K90xfs
# mv S95anacron K95anacron
# mv S95atd K95atd
# mv S97yum-updatesd K97yum-updatesd
# mv S98avahi-daemon K98avahi-daemon
# mv S99firstboot K99firstboot
# mv S99smartd K99smartd
# mv S26hidd K26hidd
# mv S25pcscd K25pcscd
# mv S08mcstrans K08mcstrans
Once changes have been done. Pack the contents back to the CD.
# cd /root
# umount /root/live/osmount
# rm live/isofiles/LiveOS/squashfs.img
# mksquashfs live/squashfiles/* live/isofiles/LiveOS/squashfs.img -keep-as-directory
Modify isolinux.cfg file. (I used following contents.)
# cd live/isofiles/isolinux/
# cat isolinux.cfg
default menu.c32
timeout 100
menu title Welcome to livecd-kick-201008021533!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color timeout_msg 0 #ffffffff #00000000
menu color timeout 0 #ffffffff #00000000
menu color cmdline 0 #ffffffff #00000000
menu hidden
menu hiddenrow 5
label linux0
  menu label Backup
  kernel vmlinuz0
  append initrd=initrd0.img root=CDLABEL=BackupRestore rootfstype=iso9660 ro quiet liveimg 3
label linux1
  menu label Restore
  kernel vmlinuz0
  append initrd=initrd0.img root=CDLABEL=BackupRestore rootfstype=iso9660 ro quiet liveimg 4
Make ISO
# cd /root/live/isofiles/
# mkisofs -o /root/BackupRestore.iso -b isolinux/isolinux.bin -c isolinux/boot.cat \
-no-emul-boot -boot-load-size 4 -boot-info-table -J -r -hide-rr-moved -V BackupRestore /root/live/isofiles
/root/BackupRestore.iso is the resulting customized LiveCD
Note: Please note -V option in above mkisofs command. The option to -V must be same as that of CDLABEL in isolinux.cfg file.

Sunday, 11 October 2009

Creating Solaris OS VM

Solaris10 U6 virtual machine build up process Host OS used is Ubuntu 8.04 Hardy ( IP: 192.168.1.140)
KVM/Qemu is used as Virtualization software. KVM uses hardware assisted virtualization.
Solaris-10 ISO is needed for the purpose.
Following steps were followed Create the virtual disk on which OS will be installed.
# qemu-img create -f qcow2 Solaris10U6-x86.img
Start the OS installation.
kvm -m 4028 -cdrom /home/testuser/sol-10-u6-ga1-x86-dvd.iso -hda Solaris10U6-x86.img -vnc :14
Note: Above command will start a virtual machine with 4G of RAM (-m 4028) along with a VNC session started at VNC port 14
From another machine or same machine capture the above started VNC session and complete the installation.
kvm -m 2048  -hda Solaris10U6-x86.img -vnc :30 -net nic,macaddr=00:00:00:00:00:11 -net tap,script=
Above command will start machine with the networking provided bridging is in place. Also you may have to configure the network interface on guest machine manually.
if you have previously stopped the installation of Virtual guest, starting it again may give you some error. This is due to the fact that OS image (the harddisk of virtual OS) will now have corrupted OS and loader and virtual guest will attempt to boot from this corrupted image rather than cdrom image. To avoid this , run the following command ( it has an added "boot -d" parameter).
kvm -m 4028 -cdrom /home/testuser/sol-10-u6-ga1-x86-dvd.iso -hda Solaris10U6-x86.img -vnc :14 -boot d
If Solaris-10U6 was used to install as virtual guest. Its grub boot loader will not update the grub.conf correctly. ( This is only in Solaris10-U6)
Boot the virtual machine in single user mode Solaris Failsafe -- the other grub boot option. and run following commands.
# cd /a/boot/grub
# TERM=xterm
# export TERM
# EDITOR=vi
# export EDITOR
Change the following line under the section title Solaris 10 10/08 s10x_u6wos_07b x86
kernel /platform/i86pc/multiboot
to
kernel /platform/i86pc/multiboot kernel/unix
save and reboot Note: You may have to use traditional vi editor commands like h,j,k,l to navigate.

Wednesday, 13 March 2002

Recursive functions (using C)

#include
int npower(int m,int n);
int fact(int x);
void reverse(char str[], int n);
void stack_reverse(char str[],int n);
int main()
{
    int result;
    char str[9] = "abcdefghi";
    result=npower(2,5);
    printf("npower result=%d\n", result);
    result=fact(5);
    printf("factorial result=%d\n", result);
    reverse(str, 9);
    printf("\n");
    stack_reverse(str, 0);
    printf("\n");
    return 0;
}

int fact(int x)
{
    if(x==0)
        return 1;
    x=x*fact(x-1);
    return x;
}

int npower(int m, int n)
{
    int d;
    if (n==0)
        return 2;
    m=m*npower(m, n-1);

    printf("m=%d\n", m);
    return m;

}
void reverse(char str[], int n)
{
    if (n==-1) return;     //This function prints backward as well as
    char x;               // as well as forward. Forward printing is
    x=str[n];             //done by poping up characters from stack.
    printf("%c", x);
    reverse(str, n-1);
    printf("%c", x);
}
void stack_reverse(char str[],int n)
{
    char x;
    if (n > 9) return;     // backward printing is done by
    x = str[n];           // poping up the characters from stack repeatedy.
    stack_reverse(str, n+1);
    printf("%c", x);
}
Compile and output:
$ gcc recurse.c
$ ./a.out
m=4
m=8
m=16
m=32
m=64
npower result=64
factorial result=120
ihgfedcbaabcdefghi
ihgfedcba