Vous êtes sur la page 1sur 32

CS 498 Lecture 1: Installing, Compiling and Configuring Linux Kernel

Jennifer Hou Department of Computer Science University of Illinois at Urbana-Champaign

Outline
Boot sequence How to build a kernel How to configure a network interface How to set up NFS About Project 1

8/30/2005

cs498HOU

Boot Process
Reading: 1. Red Hat Linux 9: Read hat Linux Reference Guide, Chapter 1: Boot process, Init, and Shutdown.

Boot Process
The basic input/output system (BIOS) starts and checks for hardware devices.
Is stored in the computers ROM and described as firmware. Finds the hardware devices (diskette drives, CDROM drives, and hard drives) needed by the boot process. Loads and initiates the boot program stored in the Master Boot Record (MBR, residing in the first sector of the device), and passes control to the boot program.
8/30/2005 cs498HOU 4

A Hard Drives Partition Layout


Partition 4 is used as a placeholder for a potentially large number of logical partitions extended partition. Boot Code (grub) Partition 1 definition (16 bytes) Partition 2 definition Partition 3 definition Partition 4 definition Magic number Partition 1 Partition 2 Partition 3 Partition 4 Partition 5
8/30/2005

(16 bytes) (16 bytes) (16 bytes) (2 bytes) (/dev/hda1 or /boot) (/dev/hda2) (/dev/hda3) (/dev/had4; no filesystem) (/dev/had5) (/dev/had6)
5

Partition 4

cs498HOU

First Stage Boot Loader


Two boot loaders are available: Linux Loader (lilo) and Grand Unified Bootloader (grub) The first-stage boot loader
reads in the partition table and looks for the second-stage boot loader on the partition configured as bootable (/boot partition). Launches the second stage boot loader.
8/30/2005 cs498HOU 6

Second Stage Boot Loader


Presents the user with different OS kernels it has been configured to boot. Finds the kernel image in the /boot directory.
The kernel binary is named /boot/vmlinuz-<kernelversion>

Places the appropriate initial RAM disk image, called an initrd, into memory. The initrd is used by the kernel to load drivers necessary to boot the system. Hands control to the kernel.
8/30/2005 cs498HOU 7

grub.conf
# grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,1) # kernel /vmlinuz-version ro root=/dev/hdb3 Specifies the default boot image will # initrd /initrd-version.img be the first hard entry #boot=/dev/hdb default=0 Grub will wait for 10 seconds for input from timeout=10 the user before continuing to boot. splashimage=(hd0,1)/grub/splash.xpm.gz title Linux Fedora (2.6.5-1.358smp) root (hd0,1) kernel /vmlinuz-2.6.5-1.358smp ro root=LABEL=/ rhgb quiet initrd /initrd-2.6.5-1.358smp.img title Linux Fedora-up (2.6.5-1.358) The root partition is the second partition root (hd0,1) on the first hard drive. kernel /vmlinuz-2.6.5-1.358 ro root=LABEL=/ rhgb quiet initrd /initrd-2.6.5-1.358.img title Windows 2000 rootnoverify (hd0,0) chainloader +1

8/30/2005

cs498HOU

The Kernel
Initializes and configures the computers memory and configures hardware attached to the system (processors, I/O subsystems, and storage devices). Decompresses and mounts initrd to load all necessary drivers. Mounts the root file system in read-only mode and frees any unused memory. Starts the init process by running /sbin/init.
8/30/2005 cs498HOU 9

Initialization Process
Init parses the /etc/inittab file to determine the specifics of what programs to run and at what level.
0 used to halt the system. The system performs an init 0 command and the system is halted. 1 Puts he system into single-user mode. 2 Puts the system into a multiuser mode but does not support networking. 3 Puts the system into the standard full multiuser mode but does not automatically start X. 4 Unused. 5 X11; Puts the system into standard multiuser mode with a graphical (X-based) login.
8/30/2005 cs498HOU 10

Inittab
id:5:initdefault:
Tells the init program what run level to use after a reboot.

si::sysinit:/etc/rc.d/rc.sysinit
Tells the init program to run the rc.sysinit script. Since the second field is empty, the script will run at boot time for all run levels.
8/30/2005 cs498HOU 11

rc.systinit
Setting the path and the hostname, and checking whether networking is activated. Mounting the /proc file system Setting the kernel parameters Setting the system clock Loading keymaps and fonts Starting swapping Initializing the USB controller along with the attached devices. Checking the root file system. Remounting the root file system as read-write. Loading modules as appropriate.
8/30/2005 cs498HOU 12

Inittab (contd)
Starts the /etc/rc.d/rc script with the appropriate run level.
The rc script executes all of the scripts pointed to by the symblic links contained in the directory for that run level. For example, if the run level is 3, the scripts pointed to by the links in /etc/rc.d/rc3.d are run.
8/30/2005 cs498HOU 13

ls K01yum K05saslauthd K10dc_server K10psacct K12dc_client K15httpd K20nfs K24irda K25squid K34yppasswdd K35smb K35vncserver K36lisa K45named K50netdump K50snmpd K50snmptrapd K50tux K50vsftpd K70aep1000 K70bcm5820 K74ntpd

/etc/rc.d/rc3.d
K74ypserv K74ypxfrd K89netplugd K99readahead K99readahead_early S00microcode_ctl S05kudzu S06cpuspeed S08iptables S09isdn S10network S12syslog S13irqbalance S13portmap S14nfslock S18rpcgssd S19rpcidmapd S19rpcsvcgssd S20random S24pcmcia S25netfs S26apmd S28autofs S40smartd S44acpid S55cups S55sshd S56rawdevices S56xinetd S80sendmail S85gpm S87IIim S90crond S90xfs S95anacron S95atd S97messagebus S97rhnsd S99local S99mdmonitor S99mdmpd

All the files here are only symbolic links to the actual scripts that exist in /etc/rc.d/init.d. The system first runs the scripts whose names start with K to kill the associated processes /etc/rc.d/init.d/<command> stop The system runs the scripts whose names start with S to start the processes /etc/rc.d/init.d/<command> start Changing a K name to start with S (e.g., K20nfs S20nfs) makes Linux start the process rather than kill it. 8/30/2005 cs498HOU 14

Inittab (contd)
ca::ctrlaltdel:/sbin/shutdown -t3 -r now Sets the Ctrl+Alt+Delete key combination to indicate a reboot of the system. -t option indicates that the init process waits for 3 seconds after sending the warning message and before sending the kill signal. pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down" pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled" 3:2345:respawn:/sbin/mingetty tty3
Initializes the ttys, provides the login and retrieves the user-input data, and then starts a login process for the user.
8/30/2005 cs498HOU 15

Building the Kernel


Reading: 1.http://www.digitalhermit.com/linux/Kernel-Build-HOWTO.html 2. Red hat Linux 9: Red Hat Linux Customization Guide Appendix A. Building a Custom Kernel.

16

Building the Kernel


cd /usr/src/linux-2.4.20-8 make mrproper (optional but recommended) make xconfig
This command runs a X-based configuration tool that asks you specific question about every kernel configuration.

8/30/2005

cs498HOU

17

Building the Kernel (Contd)


make xconfig
Most kernel features have three compilation options: Y (compiling the option directly into the kernel), N (not compiling the option at all), and M (compiling the option as a kernel module and load it on demand). After saving the selection, the configuration file /user/src/linux-2.4.20-8/.config is created.
8/30/2005 cs498HOU 18

Building the Kernel (Contd)


make dep Creates dependency information, so that the compiler knows each components dependencies and can compile components as appropriate. make clean Cleans up some miscellaneous object files. make bzImage Can customize the title in Makefile Compiles the Linux kernel properly. The result is a kernel file called bzImage and located in /user/src/linux-2.4.20-8/arch/i386/boot make modules Compiles the kernel modules files
8/30/2005 cs498HOU 19

Building the Kernel (Contd)


make modules_install Installs the kernel modules into the directory path /lib/modules/2.4.20-8/kernel/drivers. make install Copies the new kernel and its associated files to /boot directory. Builds a new initrd image and adds new entries to the boot loader configuration file. Use the command ls -l /boot to make sure the initrd-2.4.20-8.img file was created. Confirm that the file /boot/grub/grub.conf contains a title section with the same version as the kernel package just installed

8/30/2005

cs498HOU

20

Configuring the Network Interface

Reading: man pages for ifconfig, route, netstat, ping, traceroute

21

ifconfig
ifconfig interface [options] [address] interface: network interface, e.g., eth0 options: up, down, netmask mask address: IP address Examples for physical host 1 ifconfig eth0 192.168.2.2; ifconfig eth1 192.168.3.1 ifconfig eth0 Ifconfig eth0 netmask 255.255.255.0 192.168.2.2 /sbin/ifup eth0; /sbin/ifdown eth0
8/30/2005 cs498HOU 22

route
route [add | del] [-net | -host] [target] [gw gateway] [[dev] if]
target is the IP address or network address to which the route applies. One special target is the default route --- 0.0.0.0. or default gw gateway

Examples for physical host


route add net 192.168.1.0 eth0 route add net 192.168.2.0 eth0 route add 192.168.3.2 eth0 route add default gw 192.168.3.2
8/30/2005 cs498HOU 23

Making a host to become a router


The Linux kernel configuration parameter to achieve this is named net.ipv4.ip_forward and can be found in the file /etc/sysctl.conf. # Enables packet forwarding net.ipv4.ip_forward=1 This enables packet forwarding only when we reboot at which time Linux will create a file in one of the subdirectories of the /proc filesystem. To activate the feature immediately you have to force Linux to read the /etc/sysctl.conf file with sysctl p Alternatively, echo 0 > /proc/sys/net/ipv4/ip_forward

8/30/2005

cs498HOU

24

netstat
netstat -r displays the kernel routing table in the same way as route does. netstat i displays statistics for the network interfaces currently configured. If the a option is also given, it prints all interfaces present in the kernel, not only those that have been configured currently. netstat supports a set of options to display active or passive sockets. The options t, u, w, and x show active TCP, UDP, RAW, or Unix socket connections. If you provide the a flag in addition, sockets that are waiting for a connection (i.e., listening) are displayed as well.
8/30/2005 cs498HOU 25

Setting up NFS
Reading: 1. Red Hat Linux 9: Red Hat Linux Reference Guide, Chapter 9 NFS 2. Red Hat Linux 9: Red Hat Linux Customization Guide, Chapter16 NFS
26

On the Server Side


The nfs service must be running on the server
/sbin/service nfs status /sbin/service nfs start To start the nfs service at boot time,
/sbin/chkconfig level 345 nfs on

Edit the /etc/exports file


/home flamingo(rw) lion(ro) sal.cs.uiuc.edu(rw) /mnt *.cs.uiuc.edu(rw) /opt 192.168.0.0/28(ro)

Inform the NFS daemon of the configuration change


8/30/2005

/sbin/service nfs reload

cs498HOU

27

On the Client Side


There are three methods:
Mount [-t nfs] server:/path mountpoint
Mount linux.cs.uiuc.edu:/linux/redhat /misc/myredhat mounts the /linux/redhat from linux.cs.uiuc.edu on the client, at /misc/myredhat.

Add a line in /etc/fstab


#device mountpoint fs linux:/linux/redhat /misc/myredhat operations dump fsck nfs ro,soft,timeo=10 0 0

where soft/hard specifies whether the program should stop and wait (hard) for the server to come back if the server is unavailable or if it should report an error (soft). The mount point /myredhat must exist on the client machine. After adding the above line to /etc/fstab on the client, type mount /myredhat at a shell prompt and the mount point will be mounted.
8/30/2005 cs498HOU 28

On the Client Side


Mount NFS using autofs
Autofs uses the automount daemon to manage mount points by only mounting them dynamically when they are accessed. Edit the automounters configuration file, /etc/auto.master.
Each line contains the base automount point (e.g.,/misc), the configuration file for that mount point (e.g., /etc/auto.misc) and a timeout value. /misc /etc/auto.misc --timeout 60
8/30/2005 cs498HOU 29

On the Client Side


Mount NFS using automount
Edit the /etc/auto.misc configuration file.
The file lists specific subdirectories within the mount point (/misc), filesystem type, and files (for each server) to be auto-mounted.
myredhat -ro,soft,intr linux.cs.uiuc.edu:/linux/redhat myfedora -ro,soft,timeo=10 linux.cs.uiuc.edu:/linux/fedora The /misc/myredhat directory will be automounted when accessed.

/sbin/service autofs restart /sbin/service autofs status /sbin/service autofs reload

8/30/2005

cs498HOU

30

About Project 1
Start now if not yet!
Only two sets of keyboards so at most 2 groups can do at the same time.

Use computers in pairs: 1 and 2, 3 and 4, 5 and 6, and so on.


Machine 7 is not currently working. Machine 17-20 are reserved.

Space allocation:
Allocate 10GB to /usr Mount the second disk: /dev/sdb1 during installation or later.
8/30/2005 cs498HOU 31

About Project 1
VMware 4.5.22 is available in the same directory as given in the handout. But it doesnt work in Fedora 4.
Probably Vmware 4.0.5 will not either. So, better stay at Fedora 3 / redhat 9. But up to you.

Demo: sign up a time with me (~15 mins.) Report:


Drop in at my mailbox in the mailroom (SC 1334, east end) and then send me an email letting me know. Or Hand to me in my office hour; Or Send to me in email as pdf file (may not be printed out as you suppose).

Problems?
Post on newsgroup!
8/30/2005 cs498HOU 32

Vous aimerez peut-être aussi