Apr
19
Posted on 19-04-2010

Introduction ~ GRUB is perfect boot loader for Linux/Unix system! GRUB-2 supports several features that are important for every system admin.

* Platform support – GRUB 2 is intended to work across a wider range of architectures.
* Partition tables – GRUB-2 supports MBR partitioning scheme and GUID Partition Table (GPT).
* RAID and LVM – Now GRUB is supports both redundant array of independent disks (RAID) and Logical Volume Manager (LVM).
* File system support – GRUB 2 supports some additional non-Linux file systems, such as Apple’s Hierarchical File System Plus, NTFS  and  ZFS file systems…

* Configuring GRUB 2 –

GRUB 2 configuration file is different from legacy GRUB….

The default location for the GRUB 2 configuration file is /boot/grub/grub.cfg

* Sample GRUB 2 configuration file

root@me:~# cat /boot/grub/grub.cfg

set timeout=10
set default=0

menuentry “Ubuntu, Linux 2.6.31-20-generic” {
set quiet=1
insmod ext2
set root=(hd0,6)
search –no-floppy –fs-uuid –set 7699852c-2a04-4da2-82e8-a69969f16bf2
linux /boot/vmlinuz-2.6.31-20-generic root=UUID=7699852c-2a04-4da2-82e8-a69969f16bf2 ro quiet splash
initrd /boot/initrd.img-2.6.31-20-generic
}

Thanks,
Arun Bagul

(0) Comments    Read More   

Introduction ~

Long back I edited initrd as  old linux (Ubuntu 6.06) box was not able to boot with SCSI hard disk? One of my friend wanted to do the same for other purpose. So got a chance to write article on the same? Let’s start with what is initrd?

What is initrd ?

initrd (Initial Ram Disk) is a temporary file system ( used as /) commonly used in the boot process of the Linux kernel. It is typically used for making preparations before the real root file system can be mounted.

Why someone want to edit/modify initrd ?

I assume that you all are familier with Linux booting process? Once Linux kernel loaded in to memory (RAM) it start init (father/mother of all  process) process. is that true? Let me ask you one question. Before loading actual physical root file system (/) how kernel access /sbin/init script? what is the use by specifying “initrd” file in GRUB ?  hold on!!

Suppose your root partion resides on some SCSI device and driver for this SCSI devices is compiled as a kernel module. Of course this module is required at boot time to have access to the root partion — but it is not in the kernel. Thus the need for an initrd image. Additionally after udev subsystem become common, somebody has to start udev to create device nodes. This is initrd’s duty too.

See the GRUB menu as shown below ~

title        Ubuntu 9.04, kernel 2.6.28-11-generic
kernel        /vmlinuz-2.6.28-11-generic root=/dev/sda3  ro quiet splash
initrd        /initrd.img-2.6.28-11-generic

GRUB loads  kernel and initrd image in to memory(RAM). When kernel boots  it checks for initrd image, and if it exists starts init script that resides on this image. init script is usually written in bash. When init script on initrd image is finished, kernel usually start standard init process ie /sbin/init

Step 1] Copy original initrd image file to temp location  ~

** Create temporary directory and copy initrd file in that temp directory

arunsb@laptop:~$ cp /boot/initrd.img-2.6.28-11-generic  /tmp/

arunsb@laptop:~$ mkdir /tmp/initrd-src

** Now extract “initrd” image –

arunsb@laptop:~$ cd /tmp/initrd-src

arunsb@laptop:/tmp/initrd-src$ gzip -dc  /tmp/initrd.img-2.6.28-11-generic  | cpio -id
38791 blocks
arunsb@laptop:/tmp/initrd-src$ ls -l
total 36
drwxr-xr-x 2 arunsb arunsb 4096 2009-07-12 16:32 bin
drwxr-xr-x 3 arunsb arunsb 4096 2009-07-12 16:32 conf
drwxr-xr-x 6 arunsb arunsb 4096 2009-07-12 16:32 etc
-rwxr-xr-x 1 arunsb arunsb 4825 2009-07-12 16:32 init
drwxr-xr-x 5 arunsb arunsb 4096 2009-07-12 16:32 lib
drwxr-xr-x 2 arunsb arunsb 4096 2009-07-12 16:32 sbin
drwxr-xr-x 8 arunsb arunsb 4096 2009-07-12 16:32 scripts
drwxr-xr-x 3 arunsb arunsb 4096 2009-07-12 16:32 usr
arunsb@laptop:/tmp/initrd-src$

** Check how “init” looks like ~

arunsb@laptop:/tmp/initrd-src$ head init
#!/bin/sh

echo “Loading, please wait…”

[ -d /dev ] || mkdir -m 0755 /dev
[ -d /root ] || mkdir -m 0700 /root
[ -d /sys ] || mkdir /sys
[ -d /proc ] || mkdir /proc
[ -d /tmp ] || mkdir /tmp
mkdir -p /var/lock
arunsb@laptop:/tmp/initrd-src$

Step 2] Edit/Modify as per your requirement

Step 3] How to create initrd image  ~

Create initrd image from scratch –

root@laptop:/home/arunsb# mkinitramfs  -v -o  /tmp/initrd-arun-$(uname -r)

root@laptop:/home/arunsb# ls -l /tmp/initrd-arun-2.6.28-11-generic
-rw-r–r– 1 root root 7536506 2009-07-12 17:11 /tmp/initrd-arun-2.6.28-11-generic

root@laptop:/home/arunsb# du -sh /tmp/initrd-arun-2.6.28-11-generic
7.2M    /tmp/initrd-arun-2.6.28-11-generic
root@laptop:/home/arunsb#

mkinitramfs ~ is the tool used to create initrd image. “initrd” image is a gzipped cpio archive.

** After all modifcation create initrd image as shown below…

arunsb@laptop:/tmp/initrd-src$ find . | cpio –quiet –dereference -o -H newc | gzip -9 > /tmp/initrd.img-2.6.28-11-arun
arunsb@laptop:/tmp/initrd-src$ ls -l /tmp/initrd.img-2.6.28-11-arun
-rw-r–r– 1 arunsb arunsb 7505955 2009-07-12 16:56 /tmp/initrd.img-2.6.28-11-arun
arunsb@laptop:/tmp/initrd-src$

* Enjoy !!

Regards,
Arun Bagul

(3) Comments    Read More   
Jul
22
Posted on 22-07-2007
Filed Under (GRUB boot loader) by Arun Bagul

Introduction – GRUB (GRand Unified Bootloader) is the part of GNU project, which was originally designed and implemented by Erich Stefan Boleyn. GRUB is one of the best open source boot loader used to boot Linux operating system. Which can load a wide variety of free operating systems (Linux), as well as proprietary operating systems (like Windows) with chain-loading. LILO(Linux Loader) is another boot loader used in Linux. Now we will start with….

[1] What is Boot Loader? –

Boot Loader is the first software program that runs when a computer start. It is responsible for loading and transferring control to an operating system kernel software (for e.g. Linux kernel). The kernel, then initializes the rest of the operating system. GRUB understands filesystems and kernel executable formats, so you can load an arbitrary operating system the way you like, without recording the physical position of your kernel on the disk. Thus you can load the kernel just by specifying its file name and the drive and partition where the kernel resides.

When booting with GRUB, you can use either a command-line interface or a menu interface Using the command-line interface, you type the drive specification and file name of the kernel manually. In the menu interface, you just select an OS using the arrow keys. The menu is based on a configuration file which you prepare beforehand. While in the menu, you can switch to the command-line mode, and vice-versa. You can even edit menu entries before using them.

root@arunbagul:~# grub –version
grub (GNU GRUB 0.97)
root@arunbagul:~#

GRUB command-line (After booting OS)- just type ‘grub’ on bash command promt # for grub command-line.

root@arunbagul:~# grub
[ Minimal BASH-like line editing is supported. For
the first word, TAB lists possible command
completions. Anywhere else TAB lists the possible
completions of a device/filename. ]

grub>

* Possible GRUB command (just type TAB on grub command-line)

grub>

Possible commands are: blocklist boot cat chainloader clear cmp color configfile debug device displayapm displaymem dump embed find fstest geometry halt he
lp hide impsprobe initrd install ioprobe kernel lock makeactive map md5crypt module modulenounzip pager partnew parttype password pause print quit quiet rea
d reboot root rootnoverify savedefault serial setkey setup terminal terminfo testload testvbe unhide uppermem vbeprobe

grub>

[2] How to get help about any command line –

grub> help root
root: root [DEVICE [HDBIAS]]
Set the current “root device” to the device DEVICE, then attempt
to mount it to get the partition size (for passing the partition
descriptor in `ES:ESI’, used by some chain-loaded bootloaders),
the BSD drive-type (for booting BSD kernels using their native
boot format), and correctly determine the PC partition where a
BSD sub-partition is located. The optional HDBIAS parameter is a
number to tell a BSD kernel how many BIOS drive numbers are on
controllers before the current one. For example, if there is an
IDE disk and a SCSI disk, and your FreeBSD root partition is on
the SCSI disk, then use a `1′ for HDBIAS.
rootnoverify: rootnoverify [DEVICE [HDBIAS]]
Similar to `root’, but don’t attempt to mount the partition. This
is useful for when an OS is outside of the area of the disk that
GRUB can read, but setting the correct root device is still
desired. Note that the items mentioned in `root’ which derived
from attempting the mount will NOT work correctly.

grub> quit

root@arunbagul:~#

** Syntax and naming convention used in GRUB –

The device syntax used in GRUB is a bit different from normal syntax. First of all, GRUB requires that the device name be enclosed with “(” and “)“.
For example :-

(fd0)
(hd0,1)
(hd1,3)

Here “fd” means floppy disk, “hd” means Hard Disk. (fd0)- means first floppy drive , (hd0,1) – means first Hard Disk and first partition of first Hard Disk. and (hd1,3) – means 2nd Hard Disk and 3rd partition of 3rd Hard Disk. How to use GRUB command-line to boot system, please refer below…

NOTE – Drive number and Partition number start from zero(0). Use “tab” to see possible Drive, Partitions no etc.

[3] How to boot operating systems –

GRUB has two distinct boot methods.

a) Load an operating system directly,
b) Chain-loader –
load another boot loader which then will load an operating system.

GRUB support Multiboot. Linux/Unix like OS can be directly loaded, while other OS which are not supported like Windows can be loaded by using “Chain-loader” method.

Step(1)- Set root/boot drive –

* During GRUB menu you can select grub command-line by pressing “c” and to edit GRUB menu you can press “e“…

grub> root (hd0,
Possible partitions are:
Partition num: 0, Filesystem type unknown, partition type 0x7
Partition num: 1, Filesystem type unknown, partition type 0x7
Partition num: 2, Filesystem type is ext2fs, partition type 0x83
Partition num: 4, Filesystem type is ext2fs, partition type 0x83
Partition num: 5, Filesystem type is ext2fs, partition type 0x83
Partition num: 6, Filesystem type unknown, partition type 0x82
Partition num: 7, Filesystem type is ext2fs, partition type 0x83

grub> root (hd0,2)

grub> cat /grub/menu.lst

…..

* use this file to find out which will be your possible root partition..

grub> cat /
Possible files are: lost+found System.map-2.6.22-14-generic abi-2.6.22-14-generic config-2.6.22-14-generic initrd.img-2.6.22-14-generic.bak memtest86+.bin
vmlinuz-2.6.22-14-generic initrd.img-2.6.22-14-generic grub System.map-2.6.22-14-xen vmlinuz-2.6.22-14-xen config-2.6.22-14-xen xen-3.1.gz initrd.img-2.6.22
-14-xen initrd.img-2.6.22-14-xen.bak

Step(2) – Load kernel (don’t forget to mention your root partion ie /)-

grub> kernel /vmlinuz-2.6.22-14-generic root=/dev/sda5 ro quite splash

grub>

Step(3) How to load ‘initrd’ –

grub> initrd /initrd.img-2.6.22-14-generic

Step(4) Just Boot your OS –

grub> boot

*** That’s it to boot your system from GRUB command line!

[4] How Boot unsupported operating systems(OS) by using ‘chain-loader’ method-

Normally, the boot loader is embedded in the boot sector of the partition on which the operating system is installed. Use ‘rootnoverify’ command for setting the correct root device. this command don’t attempt to mount that partition.

Step(1) Set GRUB’s root device to the partition –

grub> rootnoverify (hd0,0)

Step(2) Set the active flag in the partition using ‘makeactive’ command –

grub> makeactive

Step(3) Load the boot loader with the command chainloader-

grub> chainloader +1

Step(4) Just Boot your OS –

grub> boot

* “+1” indicates that GRUB should read one sector from the start of the partition.

[5] How to read any file from GRUB command-line –

* you can easily find out which is the root partition (/) by looking the directory structure!!

grub> root (hd0,4)

grub> cat /
Possible files are: lost+found var boot home media usr etc cdrom bin dev initrd lib mnt opt proc root sbin srv sys tmp initrd.img vmlinuz home2 initrd.img.
old vmlinuz.old

grub> cat /etc/fstab
# /etc/fstab: static file system information.
#
#<file system> <mount point> <type> <options> <dump> <pass>
proc /proc proc defaults 0 0
/dev/sda5 / ext3 defaults,errors=remount-ro 0 1
/dev/sda3 /boot ext3 defaults 0 2
/dev/sda8 /home ext3 defaults 0 2
/dev/sda6 /usr ext3 defaults 0 2

grub>

[6] How to Boot DOS/Windows from 2nd Hard Disk –

If you have installed DOS (or Windows) on a non-first hard disk, you have to use the disk swapping technique, because that OS cannot boot from any disks but the first one. Use “map” command. This performs a virtual swap between your first and second hard drive.

grub> map (hd0) (hd1)
grub>
grub> map (hd1) (hd0)
grub>

NOTE: This is effective only if DOS (or Windows) uses BIOS to access the swapped disks. If that OS uses a special driver for the disks, this probably
won’t work.

** Another problem arises if you installed more than one set of DOS/Windows onto one disk, because they could be confused if there are more than one primary partitions for DOS/Windows. Certainly you should avoid doing this, but there is a solution if you do want to do so. Use the partition hiding/unhiding technique. If GRUB hides a DOS/Windows partition, DOS/Windows will ignore the partition. If GRUB unhides a DOS/Windows partition, DOS/Windows will detect the partition.

grub> help hide
hide: hide PARTITION
Hide PARTITION by setting the “hidden” bit in its partition type code.

grub> root (hd0,
Possible partitions are:
Partition num: 0, Filesystem type unknown, partition type 0x7
Partition num: 1, Filesystem type unknown, partition type 0x7
Partition num: 2, Filesystem type is ext2fs, partition type 0x83
Partition num: 4, Filesystem type is ext2fs, partition type 0x83
Partition num: 5, Filesystem type is ext2fs, partition type 0x83
Partition num: 6, Filesystem type unknown, partition type 0x82
Partition num: 7, Filesystem type is ext2fs, partition type 0x83

grub> hide (hd0,2)

grub> root (hd0,
Possible partitions are:
Partition num: 0, Filesystem type unknown, partition type 0x7
Partition num: 1, Filesystem type unknown, partition type 0x7
Partition num: 2, Filesystem type unknown, partition type 0x93
Partition num: 4, Filesystem type is ext2fs, partition type 0x83
Partition num: 5, Filesystem type is ext2fs, partition type 0x83
Partition num: 6, Filesystem type unknown, partition type 0x82
Partition num: 7, Filesystem type is ext2fs, partition type 0x83

grub>

grub> help unhide
unhide: unhide PARTITION
Unhide PARTITION by clearing the “hidden” bit in its partition type code.

grub>

For example … see below

grub> unhide (hd0,0)
grub> hide (hd0,3)
grub> rootnoverify (hd0,0)
grub> chainloader +1
grub> makeactive
grub> boot

Thank you,

Arun Bagul

(0) Comments    Read More   

Introduction – In many systems, User has to enter root password to enter in to “single user mode“. On Ubuntu/Debian system, you have to enter root password while entering into single user mode.

What to do if you loss or forgot root password ?

method(1) Use bootable CD – This is the last options to reset root password on your system. Infact if you have set GRUB password and you have loss root as well as GRUB password then only you need to go for this method. Otherwise go with second method…

method(2) Single user mode and bypass root password – You can reset root password even if your system require root password to enter in to single user mode. GRUB will help you to bypass , and will not ask you for root password.

This is as simple editing the preferred boot line in your GRUB boot loader menu at boot time…

  • Reboot the system, and when you are at the selection prompt(GRUB menu), highlight the line for Linux and press ‘e’.
  • This will take you to another screen, where you should select the entry that begins with “kernel” and press “e” again….
  • Append "single" to the end of that line (without the quotes and give space)
  • If your system requires you to enter your root password to log into single-user mode, then append init=/bin/bash after “single“. Hit “Enter” to save the changes.
  • Press “b” to boot into Single User mode.
  • Once the system finishes booting, you will be logged in as root. Use passwd and choose a new password for root.
  • Type reboot to reboot the system, and you can login with the new password you just selected.

Original Line –

/vmlinuz-2.6.22-14-generic root=/dev/sda5 ro quiet splash

Modify as –

/vmlinuz-2.6.22-14-generic root=/dev/sda5 ro quiet splash single init=/bin/bash


Thank you,

Arun Bagul

(0) Comments    Read More   
Feb
07
Posted on 07-02-2007
Filed Under (GRUB boot loader) by Arun Bagul

Introduction –

Why Ubuntu does not provide GRUB splash image as background for GRUB selection menu?. Really I don’t know but, today we will learn how to do it.

root@arunbagul:~# apt-get install grub-splashimages
Reading package lists… Done
Building dependency tree

….
root@arunbagul:~#

Once you install “grub-splashimages” you will get grub splash image installed on your Ubuntu system in “/boot/grub/splashimages” directory.

root@arunbagul:/boot/grub/splashimages# update-grub
Searching for GRUB installation directory … found: /boot/grub
Searching for default file … found: /boot/grub/default
Testing for an existing GRUB menu.lst file … found: /boot/grub/menu.lst
Searching for splash image … none found, skipping …

…….
Updating /boot/grub/menu.lst … done

root@arunbagul:/boot/grub/splashimages#

update-grub is a program used to generate the menu.lst file used by the grub bootloader. It works by looking in /boot for all files which start with “vmlinuz-“. They will be treated as kernels, and grub menu entries will be created for each. It will also create the initial menu.lst if none exists, after prompting the user. It will also add initrd lines for ramdisk images found with the same version as kernels found. e.g. /boot/vmlinuz-2.4.5 and /boot/initrd-2.4.5 will cause a line of “initrd=/boot/initrd-2.4.5 or similar to be added for the kernel entry in the menu.lst. After update-grub has been run for the first time, the user is required to edit the generated menu.lst.
Cheers,
Arun Bagul

(0) Comments    Read More   

www.flickr.com
arunbagul's photos More of arunbagul's photos
Get Adobe Flash player
-->