1 / 97

Unix Startup

Unix Startup. Guntis Barzdins Girts Folkmanis Juris Krūmiņš. System Lifecycle: Ups & Downs. start_kernel. sleep? (hlt). LILO. shutdown. init. Power on. Power off. Boot. Kernel Init. OS Init. RUN!. Shut down. Boot Terminology. Loader: Program that moves bits from disk (usually)

ifama
Download Presentation

Unix Startup

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unix Startup Guntis Barzdins Girts Folkmanis Juris Krūmiņš

  2. System Lifecycle: Ups & Downs start_kernel sleep? (hlt) LILO shutdown init Poweron Poweroff Boot KernelInit OS Init RUN! Shutdown

  3. Boot Terminology • Loader: • Program that moves bits from disk (usually) to memory and then transfers CPU control to the newly “loaded” bits (executable). • Bootloader / Bootstrap: • Program that loads the “first program” (the kernel). • Boot PROM / PROM Monitor / BIOS: • Persistent code that is “already loaded” on power-up. • Boot Manager: • Program that lets you choose the “first program” to load.

  4. LILO: LInux LOader • A versatile boot manager that supports: • Choice of Linux kernels. • Boot time kernel parameters. • Booting non-Linux kernels. • A variety of configurations. • Characteristics: • Lives in MBR or partition boot sector. • Has no knowledge of filesystem structure so… • Builds a sector “map file” (block map) to find kernel. • /sbin/lilo – “map installer”. • /etc/lilo.conf is lilo configuration file.

  5. boot=/dev/hda map=/boot/map install=/boot/boot.b prompt timeout=50 default=linux image=/boot/vmlinuz-2.2.12-20 label=linux initrd=/boot/initrd-2.2.12-20.img read-only root=/dev/hda1 Example lilo.conf File

  6. LILO v.s. GRUB • LILO • Run LILO to modify mini-bootloader in the MBR • Cannot read file system itself • GRUB • Multistage loader • Can read file-system itself • Parameter passing (runlevel, init) to kernel • Actually hacking – modifies address and name inside kernel for the process to start

  7. Init process (1)

  8. init When the kernel has started itself (has been loaded into memory, has started running, and has initialisedall device drivers and data structures and such), it finishes its own part of the boot process by starting auser level program, init. Thus, init is always the first process (its process number is always 1). The kernel looks for init in a few locations that have beenhistorically used for it, but the proper locationfor it (on a Linux system) is /sbin/init. If the kernel can't find init, it tries to run /bin/sh, and if thatalso fails, the startup of the system fails. When init starts, it finishes the boot process by doing a number of administrative tasks, such as checkingfilesystems, cleaning up /tmp, starting various services, and starting a getty for each terminal and virtualconsole where users should be able to log in (see Chapter 10).

  9. Unix Process Hierarchy [0] /etc/inittab init [1] Daemon e.g. httpd Login shell Child Child Child Grandchild Grandchild

  10. pstree Kernel threads, not real processes Forked processes for network connections

  11. Startup Sequence Power-on Boot loader LILO Load Kernel Create init process Linux hardware rc.sysinit runlevel 0-6 rc.local Ready Initialisation Scripts

  12. Different Unix startup files.. • Unix systems are usually based in the AT&T System III & V or BSD work. • Sun Mircosystems Solaris 2.X (formally SunOS) BSD-ish • DEC OSF/1 is BSD-ish (DEC use to do Ultrix) • IBM AIX (neither ATT or BSD but something else) • HP HP-UX (BSD-ish) • Silicon Graphics, IRIX (ATTish) • SCO (Santa Cruz Operation) PC unix (ATT) • Linux, kernel from Linus Torvalds (BSD-ish for admin, ATT-ish for programming) • Distributions Slackware, Redhat, SuSE, Debian • other free PC Unixs, NetBSD, 386BSD, free BSD

  13. Startup files • How to start other services not in kernel? • BSD mode • /etc/rc, /etc/rc.boot and /etc/rc.local • System V • Startup runlevels • init process and /etc/inittab file • On linux: • 0: shutdown and halt • 1 single-user mode • 2 multiuse mode, no file sharing • 3 full multiuser. • 4 unused • 5 X windows console • 6 shuts down and reboots

  14. Sample BSD Startup Scripts/etc/rc.boot • First rc script to run is /etc/rc.boot • The first two lines set HOME and PATH environment variables • Executes basic system commands during boot • hostname file in /etc for each network interface • enables IP networking on each interface

  15. Sample BSD Startup Scripts/etc/rc.boot (cont.) • Address or hostname of default Internet gateway is read from /etc/defaultrouter • non-local NW connections up prior to more complicated routing in boot process • /usr filesystem read-only for system check to see if /fastboot exists • Yes: system shut down cleanly~ filesystems in consistent state • No: all filesystems listed in /etc/fstab checked in fsck • If disks check cleanly~ rc.boot runs /etc/rc.single

  16. Sample BSD Startup Scripts/etc/rc.single • Commands in /etc/rc.single are executed at boot time even if not using single mode • Remounts / and /usr filesystems read/write • if not remounted~ system not able to come up • Cleans out /etc/mtabfile and adds entries for / and /usr • was previously mounted but not in mtab file because root filesystem not writable • /usr/kvm mounted~ clean up shared library cache

  17. Sample BSD Startup Scripts/etc/rc.single • /etc/utmp file cleaned out • contains user list of current log ins • tzsetup command sets local time zone & status of daylight savings time (kernal is GMT) • loadkeys command sets keyboard mapping • rc.single exits~rc.boot exits • No problems in autoboot mode the next init process is /etc/rc • If problem~single-user (sh process) on console

  18. Sample BSD Startup Scripts/etc/rc • /etc/rc is the main system startup up script in autoboot after rc.boot • if single-user: rc after shell is terminated • if root filesystems not writable~ rerun rc.single • clean up shared library cache • remove /fastboot file • /etc/passwd file edited ~system crashes • vipw and /etc/rc script make sure password file not destroyed at crash

  19. Sample BSD Startup Scripts/etc/rc (cont.) • Enable quotas • /bin/ps -u cleans out the ps database (status of processes) • /etc/nologin created by shutdown to prevent logins during shutdown • executes rc.local script • swapon -a to make use of all swap partitions listed in etc/fstab • expreserve: looks in /tmp to find files that were edited when system went down

  20. Sample BSD Startup Scripts/etc/rc (cont.) • Start standard system daemons (i.e., lpd,inetd, update, uushed)

  21. Sample BSD Startup Scripts/etc/rc.local • /etc/rc.local contains commands for local system • portmap daemon maps RPC (remote procedure call) service numbers to the NW ports of appropriate servers • NIS (NW info service) Domain Name set from /etc/default domain • set subnet mask of all machines interfaces • default route reset~ if no default routing daemon run • list current configuration of NW interfaces on console

  22. Sample BSD Startup Scripts/etc/rc.local (cont.) • All NFS filesystems mounted • named (server for Domain Name system) maps between hostnames and Internet addresses • Client side NFS daemon run (biod) • syslogd: responsible for managing log messages • save kernel core dump in /var/crash/hostname • Image saved on swap partition~ save image to real filesystem • Clean up temporary mail lock files and start sendmail

  23. Sample BSD Startup Scripts/etc/rc.local (cont.) • Make machine NFS Server if filesystems need to be exported • Daemon to support diskless clients • rpc.statd and rpc.lockd manage advisory locks on NFS filesystems • Start automount daemon • 3rd party vendor install scripts • Appletalk protocol stack started • Licensed software add-ons

  24. System V Run Levels • Level 0 – shutdown • Level 1 or S – single-user mode • Level 2 thru 5 – multi-user mode • Level 6 - reboot

  25. Startup Script Directories • /etc/inittab tells init where scripts are • /etc/init.d script directory • /etc/rc2.d link to script directory

  26. Startup files • Understanding /etc/inittab • Label:runlevel:action:process id:5:initdefault: # System initialization. si::sysinit:/etc/rc.d/rc.sysinit l0:0:wait:/etc/rc.d/rc 0 l1:1:wait:/etc/rc.d/rc 1 l2:2:wait:/etc/rc.d/rc 2 l3:3:wait:/etc/rc.d/rc 3 l4:4:wait:/etc/rc.d/rc 4 l5:5:wait:/etc/rc.d/rc 5 l6:6:wait:/etc/rc.d/rc 6

  27. Some Linux inittab action valus

  28. Linux startup - rc.sysinit script • /etc/rc.d/rc.sysinit - does a range of basic tasks including • configures networking • sets host name • checks the root file system for repairs • check root file system quota & turns quotas for groups and users • mount non-root file systems and checks them for repairs • turns on swapping (virtual memory subsystem) • checks and loads modules (drivers) • (see /var/log/messages)

  29. Linux Run Levels • Linux defines 7 run levels • Each run level defines a set of commands that are run to stop and start processes. • The actual commands are held in /etc/init.d directory • The run level directories rc0.d, rc2.d…rc6.d contain links to the actual commands • Each command is prefixed with S or K and a number 00-99 • S prefix means that a process should be started e.g. S10network • K prefix means that a process should be stopped (killed) K70syslog • The numbers determine the order in which the commands are run from lowest first to highest last

  30. Linux Run Levels 0-2 • Runlevel 0 Directory /etc/rc.d/rc0.d • Actually shutdown sequence • Kill all processes • Turn off virtual memory system (i.e. swap partition) • unmounts swap and file systems • Runlevel 1 /etc/rc.d/rc1.d • single user mode • used for maintenance by system administrators when they need sole control of machine, e.g. reconfiguring hardware installing software • Runlevel 2 /etc/rc.d/rc2.d • Multi-user + networking (minus NFS)

  31. Linux Run level 3-6 • Runlevel 3 /etc/rc.d/rc3.d • Default run level • multi-user + NFS • Runlevel 4 /etc/rc.d/rc4.d • not defined ( available for customization) • Runlevel 5 /etc/rc.d/rc5.d • Same as 3 under Redhat this but includes starting X windows • Runlevel 6 /etc/rc.d/rc6.d • reboot • similar to 0 but allow allows option to shutdown (halt) or reboot

  32. Shutdown • shutdown allows... • users to be warned the systems is going down • the contents of disk caches to be written disk • file systems to be marked as having been closed properly ( avoid file system check on next startup) • Access to the shutdown command is restricted (it is in /sbin) • eg shutdown -h now h = halt r = reboot

  33. Init scripts in Gentoo • Named (not numbered) run levels. • Smart dependencies. • Scripts can ‘use’ or ‘depend’ on others. • Start / Stop / Pause. • /etc/runlevels/default/.

  34. Internet Daemon • Daemon inetd started at boot time • Configuration file /etc/inetd.conf • Name, type, protocol, wait-status, uid, server, arguments # ftp stream tcp6 nowait root /usr/sbin/tcpd in.ftpd telnet stream tcp6 nowait root /usr/sbin/tcpd in.telnetd # # Mail is a useful thing... pop3 stream tcp nowait root /etc/mail/popper popper -s imap stream tcp nowait root /etc/mail/imapd imapd

  35. Internet Daemon • When to modify inetd.conf • Disable a service • Add a # at the beginning of the entry • Send hang-up to inetd kill –HUP processid • Enable a service • Change the path • Modify arguments

  36. Extended Internet Daemon • Daemon xinetd • Configuration file /etc/xinetd.conf and /etc/xinetd.d • Attribute/value pair • Diable = yes/no

  37. Setup automatic Mounting /etc/fstab /etc/vfstab # Device Mpoint FStype Opt Dump Pass /dev/sd01sf /new ufs rw 0 2 /dev/da0b none swap sw 0 0

  38. Sample Directory Tree with Mount Points

  39. Mounting and Unmounting File Systems • File Systems mounted with the mount command:mount [options] devicedirectoryFor example:mount –o rw –t ext2 /dev/hda10 /tmp • File systems umounted with the umount command:umount [-f] directoryFor example:umount /tmp • File systems should only be umounted when they are not in use.

  40. /etc/fstab • Configuration file for all partitions known to the system. • Entry format:/dev/device /dir/to/mount fstype parameters fs_freq fs_passnoSample entry:/dev/hda10 /tmp ext2 defaults 1 2 • For entries in /etc/fstab, can run mount command with just mount point:> mount /tmpTo mount all file systems:> mount -a

  41. Scheduling processes - cron • Many aspects of system administration require things to be done on a routine basis • Rotating logs • building help files • checking disk space • checking permissions • Remembering to do thing is error prone • Unix provides scheduling mechanism refereed to as cron. • Cron has two parts • Daemon - crond • table of actions /etc/crontab

  42. Cron • the crond Daemon is started at boot time • the daemon ‘wakes up’ every minute to check its table of actions • if their is something to do -> run command • if nothing to do --> go back to sleep for 1 min • Cron table is a list (time,commnd) pairs. The format is • minute hour day month dayofweek command

  43. Crontab • Commands can be scheduled by • minute (0 59) • Hour ( 0 to 23) • Day of the month (1 - 31) • Month ( 1 to 12) • Day of the week (0=Sunday 6 = sat, or use mon,tues,wed) • Example 01 * * * * commnd2 # hourly at 1 minute past * 1 * * * commnd2 # daily at 1 am 04 1 * * * commands 3 - run at 4 minute past 1 each day * means ‘check every’

  44. Cron • Under Redhat Linux the cron table is used to execute a set of commands in some special directories • /etc/cron.hourly • /etc/cron.daily • contains logrotate, makewhatis,slocate,tmpwatch • /etc/cron.weekly • /etc/cron.monthly • You can add you own commands to the appropriate directory, but remember they need to be ‘batch’ commands as they will run automatically

  45. Crontab Files • Minute 0-59 • Hour 0-23 • Day 1-31 • Month 1-12 • Weekday 0-6 (0=Sunday) • * Matches everything • 1-3 Matches range • 1,5 Matches Series

  46. Examples 15,45 10 * * 1-5 write garth % Hi Garth % get a job 30 2 * * 1 (cd /user/joe/p; make) find /tmp –atime +3 –exec rm –f {} ‘;’ • Output mailed to owner of crontab file

  47. crontab commands • crontab Replace ^C exit • crontab –l List • crontab –e Edit • crontab –l > cronfile • crontab cronfile • cron.allow • cron.deny

  48. Common Uses for CRON • Cleaning the filesystem • Distribution of config files • Rotating log files • Backups

More Related