Sunday, January 22, 2012

Linux Basic

Creating a bootdisk

A bootdisk is basically a miniature, self-contained Linux system on a floppy diskette. It can perform many of the same functions that a complete full-size Linux system performs. The following material is based on the Bootdisk-HOWTO (see Resources).
Step 1. Bios
All PC systems start the boot process by executing code in ROM (specifically, the BIOS) to load the sector from sector 0, cylinder 0 of the boot drive. The boot drive is usually the first floppy drive (designated A: in DOS and /dev/fd0 in Linux). The BIOS then tries to execute this sector. On most bootable disks, sector 0, cylinder 0 contains either:
  • Code from a boot loader such as LILO, which locates the kernel, loads it, and executes it to start the boot proper
  • The start of an operating system kernel, such as Linux
If a Linux kernel has been raw copied to a diskette, a hard drive, or another media, the first sector of the disk will be the first sector of the Linux kernel itself. This first sector will continue the boot process by loading the rest of the kernel from the boot device.
Step 2. The boot loader
You will use a boot loader like LILO to operate the boot process. It allows the development and production platforms to co-exist on the same hardware and permits switching from one to the other just by rebooting. The LILO boot loader is loaded by the bios. It then loads kernels or the boot sectors of other operating systems. It also provides a simple command line interface to interactively select the item to boot with its options. See Resources for more information on LILO.
Step 3. The kernel
The kernel checks the hardware and mounts the root device and then looks for the init program on the root filesystem and executes it.
Step 4. Init
Init is the parent of all other processes that will run on your Linux OS. It will watch its child processes and start, stop, re-launch them if needed. Init takes all information from /etc/inittab.
Step 5. Inittab
The file /etc/inittab/ refers to scripts named /etc/rc... to do the system setup. It also has entries for the getty tool to handle the login process.
Step 6. The login process
There is one getty available in the inittab file for each console allowed for the users. Getty will launch /bin/login to verify the user password.
Step 7. Creating a new partition
From the LFS-HOWTO (see Resources): Before we can build our new Linux system, we need to have an empty Linux partition on which we can build our new system. If you already have a Linux Native partition available, you can skip this step and the following one. Start the fdisk program (or cfdisk if you prefer that program) with the appropriate hard disk as the option (like /dev/hda if you want to create a new partition on the primary master IDE disk). Create a Linux Native partition, write the partition table, and exit the (c)fdisk program. If you get the message that you need to reboot your system to ensure that the partition table is updated, then please reboot your system now before continuing.
Step 8. Creating an ext2 file system on the new partition
From the LFS-HOWTO (see Resources): To create a new ext2 file system we use the mke2fs command. Give $LFS as the only option, and the file system will be created. From now on I'll refer to this newly created partition as $EMBPART. $EMBPART should be substituted with the partition you have created.
Step 9. Mounting the partition
To access the newly created filesystem, you have to mount it. To do this, create an /mnt/hda? directory and type the following at the shell prompt:
mkdir /mnt/hda?
mount $EMBPART /mnt/hda?

If you created your partition on /dev/hda4 and you mounted it on /mnt/hda4, then you'll need to return to the step where you copied a file to $dollar;EMBPART/usr/sbin, and copy that file to /mnt/hda4/usr/bin. Do this after the last command in Step 14 (Copy the file in $EMBPART/usr/sbin).
Step 10. Populating the filesystem
The root filesystem must contain everything needed to support a full Linux system. We will build a directory structure not that far from the File Hierarchy Standard (see Resources).
Step 11. Directories
The mkdir function in the new mounted filesystem creates the following directories:
/proc
Directory stub required by the proc filesystem
/etc
System configuration file
/sbin
Critical System binaries
/bin
Basic binaries considered part of the system
/lib
Shared Libraries to provide run-time support
/mnt
Mount point for maintenance
/usr
Additional utilities and applications
  • cd /mnt/hda?
  • mkdir bin dev home proc sbin usr boot etc liv mnt root tmp var
  • mkdir -p usr/bin usr/sbin usr/share usr/lib
  • mkdir -p etc/config etc/default etc/init.d etc/rc.boot
  • mkdir -p etc/rc0.d etc/rc1.d etc/rc2.d etc/rc3.d etc/rc4.d etc/rc5.d etc/rc6.d etc/rcS.d
/dev
The dev directory is the stub required to perform devices input / output. Each file in this directory may be created using the mknod function. You may save time by directly copying the required dev entries from your desktop Linux, using the following instruction:
cp -dpR /dev /mnt