Wednesday, January 26, 2011

Stop Wasting CDs; Install Linux Straight from an ISO

All Linux installers use two files to boot a computer: a kernel and an initial root filesystem—also known as the RAM disk or initrd image. This initrd image contains a set of executables and drivers that are needed to mount the real root filesystem. When the real root filesystem mounts, the initrd is unmounted and its memory is freed. These two files are named differently in different distros—refer to Table 1 for their names.

Table 1: Names of kernel and RAM disk images in some popular distros
Distro Kernel path RAM disk path
Fedora /isolinux/vmlinuz /isolinux/initrd.img
RHEL5/CentOS5 /isolinux/vmlinuz /isolinux/initrd.img
openSUSE /boot/i386/loader/linux /boot/i386/loader/initrd
Mandriva /i586/isolinux/alt0/vmlinuz /i586/isolinux/alt0/all.rdz
Ubuntu /casper/vmlinuz /casper/initrd.gz
Debian /install.386/vmlinuz /isolinux/initrd.img

The first thing you need to do is place the ISO image(s) inside a directory. Some installers are not able to read the ISO images if they are placed inside a directory. So, just to be on the safe side, place them in the root of the file system. The partition on the hard disk holding the ISO files must be formatted with the ext2, ext3 or vfat files system.
In our example, let’s go ahead and do it with an old Fedora 9 ISO image. Follow these steps to begin with:

# mkdir /fedora
# cp /home/Fedora-9-i386-DVD.iso /fedora/fedora9.iso
 
Now extract the kernel and initrd files from the ISO image and place them in the same directory in which you placed the ISO. You can use File Roller, the archive manager for GNOME, to extract the files. Just right click on the ISO and select “Open with File Roller”. It displays the contents of the ISO image. Then navigate to the isolinux directory—in Fedora 9 these two files are placed inside the isolinux directory; it’s often different for other distros, so please refer to Table 1 for the paths. Select the kernel and initrd files, and extract them to the location where your ISO image exists.
The second method is to mount the ISO image and extract the files. Run the following commands to do this:

# mount -o loop /fedora/fedora9.iso /media/iso
# cd /media/iso/isolinux
# cp vmlinuz initrd.img /fedora/
 
I have mounted the ISO image without providing the -t iso9660 option (to specify the type of media as an ISO filesystem). It worked for me. If the above mount command doesn’t work, do add this option along with the rest of the mount command above.
Note: Fedora 10 has introduced a change in the Anaconda installer. So, in addition to the vmlinuz and initrd.gz files, you will also need to copy the images/install.img file, create a directory called /fedora/images, and place the install.img file there.
Now, it’s time to edit the /boot/grub/menu.lst file on the system I’m currently using—Ubuntu 8.10. Note that this is the location of the Grub menu in almost all distros, except for Fedora/Red Hat, where it’s called /boot/grub/grub.conf. Append the following entry there:

title Install Linux
root (hdX,Y)
kernel /distro/Linux_kernel
initrd /distro/Ram_disk
 
In this case…
  1. ‘title’ is the name you want to display in your GRUB menu
  2. ‘root’ is the hard disk partition that contains the ISO image
  3. ‘kernel’ is the Linux kernel
  4. ‘initrd’ is the initial RAM disk image
Likewise, the menu.lst entry for the ISO file looks like what’s shown below:

title Install Fedora 9
root (hd4,0)
kernel /fedora/vmlinuz
initrd /fedora/initrd.img
 
Now you are ready to install your new Linux distro directly from the hard disk without the need for a CD/DVD drive. Reboot your system and select the ‘Install Fedora 9’ entry from your GRUB menu.
Figure 1 shows what the GRUB menu looks like after rebooting my system.

Figure 1: The "Install Fedora 9" GRUB entry

Figure 1: The "Install Fedora 9" GRUB entry

Obviously, I selected the ‘Install Fedora 9’ entry and it has started booting my system with the help of vmlinuz and initrd.img files. The set-up prompts me to choose a language and keyboard layout. Then it prompts me to select the ‘Installation Method’ as shown in Figure 2.
Figure 2: Select "Hard drive" for "Installation Method"
Figure 2: Select "Hard drive" for "Installation Method"

In this screen you need to select the ‘Hard drive’ option and proceed to the next screen. Here, you have to select the appropriate partition and the directory where the installation image exists. In my system, the installation image exists in the /fedora directory of /dev/sda5 partition. This is shown in Figure 3.
Figure 3: Select the partition and the sub-directory where the ISO image resides
Figure 3: Select the partition and the sub-directory where the ISO image resides

After this, it picks up the Anaconda installer of Fedora 9 (or any other installer, as in your case) from the prescribed location, and proceeds with the regular installation procedure just like you’d get if you were installing from a bootable optical media. Follow the steps as you would to install the distro. Figure 4 shows the package installation in action. After that’s done, reboot and you’ll be able to use your newly installed operating system.
Figure 4: Fedora 9 installation in progress
Figure 4: Fedora 9 installation in progress

Easy enough, right? So, I hope you’ll start using this simple trick to install the newly released GNU/Linux distros and stop worrying about whether you have the required blank optical media. And the additional environmental benefit is less use of non-biodegradable plastic materials (which is what a CD/DVD is made out of).
Source : LFU Magazine.
----------------------
Kuldeep Sharma
!! Enjoy Linux

Sunday, January 23, 2011

Recovery of deleted /etc/passwd File in Linux

In that case you need to recover /etc/passwd file first.
For this you have to following steps,

-Start GRUB on boot (press ESC while booting)
-Press e over (recovery mode)
-Press e over the line beginning with kernel
-Press Space bar and enter "init=/bin/bash"
-Press enter
-Press b
-At command prompt type: "cp /etc/passwd- /etc/passwd"
-reboot to GRUB again
-Press e over (recovery mode)
-Press e over the line beginning with kernel
-Press Space bar and enter "init=/bin/bash"
-Press enter
-Press b
-At command prompt type "mount -o remount,rw /"
-Type "passwd YOURUSERNAMEHERE" (IF you don't know your user 
name type "ls /home" (that is a Lower case L and lower case 
S) for a list of users)
-Enter new password at prompt
-reboot to normal boot.

Hope that helps others like it did me!

### Then to recover /etc/shadow file, Use following command
pwconf

This command will generate /etc/shadow file from /etc/passwd
Enjoy Linux!!

Monday, January 10, 2011

Delete all lines containing a pattern(vi and sed)

sed :


sed (stream editor) is a Unix utility that parses text files and implements a programming language which can apply textual transformations to such files. It reads input files line by line (sequentially), applying the operation which has been specified via the command line (or a sed script), and then outputs the line. It was developed from 1973 to 1974 as a Unix utility by Lee E. McMahon of Bell Labs, and is available today for most operating systems.

How to remove Blank Lines or some line starting from particular pattern.
   Here Suppose I want to remove the Blank Lines and Lines starting with #.
Original File:
[root@gateway ~]# cat a
Default:
# sleep_after_fork 0

#  TAG: max_filedesc
#       The maximum number of open file descriptors.
#
#       WARNING: Changes of this value isn't respected by reconfigure

        command. This value should be changed only if there isn't
#       any active squid process.
#

        NOTE: This option is only supported by system with poll()
#       or epoll(). You can set this value by --with-maxfd during
#       compilation on system whith uses select().
#


        The maximum value for max_filedesc is set by --with-maxfd during
#       compilation.
#
#Default:
 max_filedesc 1024

[root@gateway ~]#


For removing Blank Lines:

[root@gateway ~]# sed '/^$/d' a > b
[root@gateway ~]# cat b
Default:
# sleep_after_fork 0
#  TAG: max_filedesc
#       The maximum number of open file descriptors.
#
#       WARNING: Changes of this value isn't respected by reconfigure
        command. This value should be changed only if there isn't
#       any active squid process.
#
        NOTE: This option is only supported by system with poll()
#       or epoll(). You can set this value by --with-maxfd during
#       compilation on system whith uses select().
#
        The maximum value for max_filedesc is set by --with-maxfd during
#       compilation.
#
#Default:
 max_filedesc 1024
[root@gateway ~]#

Now For removing lines starting with # :


[root@gateway ~]# sed '/^#/d' b > a
[root@gateway ~]# cat a
Default:
        command. This value should be changed only if there isn't
        NOTE: This option is only supported by system with poll()
        The maximum value for max_filedesc is set by --with-maxfd during
 max_filedesc 1024
[root@gateway ~]#


Vim Tips Wiki                           

The ex command g is very useful for acting on lines that match a pattern. You can use it with the d command, to delete all lines that contain a particular pattern, or all lines that do not contain a pattern.
For example, to delete all lines containing "profile" (the first command is optional; it shows the lines that the second command will delete):

 
:g/profile
:g/profile/d
More complex patterns can be used, such as deleting all lines that are empty or that contain only whitespace:

:g/^\s*$/d
To delete all lines that do not contain a pattern, use g!, like this command to delete all lines that are not comment lines in a Vim script:

:g!/^\s*"/d
Note that g! is equivalent to v, so you could also do the above with:

:v/^\s*"/d
The next example shows use of \| ("or") to delete all lines except those that contain "error" or "warn" or "fail" (:help pattern): 
:v/error\|warn\|fail/d
Kuldeep Sharma 

Integrate Jenkins with Azure Key Vault

Jenkins has been one of the most used CI/CD tools. For every tool which we are using in our daily life, it becomes really challenges when ...