Thursday, 20 September 2012
Screen Sessions Management
Thursday, 14 June 2012
Create Fedora Installer ISO using GRUB
This is just method to produce the Fedora Installer DVDs using the Grub boot loader instead of ISOLINUX.
Software UsedBase OS used, on which Fedora-13 installer was created was , Ubuntu 8.04.3 LTS (hardy). Fedora-13 will be used for which installer will be created using GRUB as boot loader.
Steps PerformedCopy the required files
Copy whole DVD contents
mkdir grubdvdrom mount -o loop /mnt/ISO-IMAGES/Fedora/Fedora-13-i386-DVD.iso /tmp/fedora-13 rsync -avz /tmp/fedora-13/ grubdvdrom/ umount /tmp/fedora-13Copy grub files from Base OS
mkdir grubdvdrom/boot cp -r /boot/grub grubdvdrom/boot cp grubdvdrom/isolinux/{vmlinuz,initrd.img} grubdvdrom/boot cp /usr/lib/grub/x86_64-pc/stage2_eltorito grubdvdrom/boot/grub
Note: Fedora DVDROM contains some hidden files like .treeinfo, which are must in order to recognize local repos for anaconda installer. If these files are not copied then anaconda will go only to internet for repos. There we used rsync to make sure each file has been copied.Also you have to maintain the tree structure of boot/grub as a whole.
Create menu.lst file create or modify grubdvdrom/boot/grub/menu.lst file with following contents. title Fedora-13 Grub ISO Installer kernel /boot/vmlinuz initrd /boot/initrd.imgCreate ISO
cd grubdvdrom mkisofs -o Fedora-13.iso -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -boot-info-table -J -r -hide-rr-moved -V Fedora
Friday, 25 March 2011
Backing up and Restoring Windows using OpenSource Tools
This section show that how to create image of an installed Windows XP and restore it back using Linux utilities. Linux utilities used are 'ntfsclone' and 'dd'. ntfsclone was used as it creates images of ntfs partition efficiently copying only used blocks from disk. dd will copy entire HD image wasting a lot of space. We will create image over the network.
Preparation:
We had used a windows XP system.
A Liveubuntu CD (10.04)and Internet connection.
A destination machine which will recieve the Backup image over the network. SSH server must be installed and running on it.
Backing Steps:
The windows system had single 75 GB partition. Boot the system from Live CD. if network has DHCP server machine will be on the network and may be able to connect to internet as well.
To work remotely , install openssh . This is optional not required.
sudo aptitude install openssh-server
After this optinal step perform following .
Backup NTFS partition to an Image and save it to remote location:
sudo ntfsclone --save-image --output - /dev/sda1 | gzip -c | ssh testuser@192.168.1.203 'cat - > /home/testuser/IMAGES/diskimage.img.gz'
Backup MBR and Partition Information:
First 446 bytes of MBR (sector 0) conatins boot code. We want to copy the boot code only. Next 64 Bytes contains the Partition table. We do not want to copy the partition table because destination disk may be larger in size and thus will have different C/H/S information. We will copy partition information based on sectors only. And in restoring process we will create partition table based on this sector information only. Partitions created with sectors are more accurate rather than cylinders. Thus making exact partitions on new disk with old information will be easier and much accurate.
Copy the Boot code.
sudo dd if=/dev/sda bs=446 count=1 | ssh testuser@192.168.1.203 'dd of=/home/testuser/IMAGES/MBR446.img'
Copy the Partition information using secotrs as unit.
sudo sfdisk -d /dev/sda | ssh testuser@192.168.1.203 'cat - > /home/testuser/IMAGES/partitionInfo.txt'
Opitonally backup fdisk information:
sudo fdisk -u -l | ssh testuser@192.168.1.203 'cat - > /home/testuser/IMAGES/fdisk.txt'
In above commad -u gives sectors rather than cylinders in the output.
Restoring Steps:
Boot the system with LIVE CD. and bring it on the network. It will be by default if network is available and DHCP server is running in network.
Restore MBR:
Restore the Boot code:
ssh testuser@192.168.1.203 'dd if=/home/testuser/IMAGES/MBR446.img' | dd of=/dev/sdb
Create partitions exactly as it were present on old disk.
ssh testuser@192.168.1.203 'cat /home/testuser/IMAGES/partitionInfo.txt' | sfdisk /dev/sdb
Note: We had used the 160GB drive as the restore drive (destination drive). Original drive was 80GB. Both drives were connected to same computer. 80GB drive was /dev/sda and 160GB drive was /dev/sdb.
Restore NTFS partition:
ssh testuser@192.168.1.203 'cat /home/testuser/IMAGES/diskimage.img.gz' | gunzip -c | ntfsclone --restore-image --overwrite /dev/sdb1 -
When the above step is finished, reboot the system with the second drive. (you may disconnect the first drive). If eveything goes fine it will not complain anything not even filesystem check. System may ask for the reboot after first login because it has detected new disk and have installed its driver. Reboot the system when this message appears. Thats it.
Wednesday, 8 September 2010
Creating Debian USB Installer
An already insalled and working linux distribution. My laptop already had Fedora Core 10.
Target OSDebian 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/grubCopy 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 /mntConfigure 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
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/grubCopy 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-11It 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
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
We will be creating a highly customized CentOS 5.5 Based LiveCD which will have some external third party rpm packages as well.
Software Requirement1) 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
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 SystemWe installed the CentOS 5.5 using CentOS 5.5 DVD in a VM. We used KVM for this purpose.
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-PGuayInstall LiveCD tools.
Run the following command to install the LiveCD tools.
yum install livecd-tools syslinuxThis 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/cdromPrepare the directory containing third party tools.
mkdir /root/livecdkickstart_filesPlace 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.shIn 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=0x314Create 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=LiveBackupRestoreCDkick.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
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.
ObjectiveWe 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
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.
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 10GRun 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-PGuayInstall LiveCD tools (inside newly created VM).
Run the following command to install the LiveCD tools.
yum install livecd-tools syslinuxThis 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 K08mcstransOnce 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-directoryModify 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 4Make 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
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.imgStart the OS installation.
kvm -m 4028 -cdrom /home/testuser/sol-10-u6-ga1-x86-dvd.iso -hda Solaris10U6-x86.img -vnc :14Note: 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 dIf 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 EDITORChange 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/unixsave 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)
#includeCompile and output: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); }
$ gcc recurse.c $ ./a.out m=4 m=8 m=16 m=32 m=64 npower result=64 factorial result=120 ihgfedcbaabcdefghi ihgfedcba