1 / 71

Lecture 3: Unix installation&startup

Lecture 3: Unix installation&startup. Guntis Barzdins Girts Folkmanis Juris Krumins. Mājas Darbs #1.

gamma
Télécharger la présentation

Lecture 3: Unix installation&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. Lecture 3: Unix installation&startup Guntis Barzdins Girts Folkmanis Juris Krumins

  2. Mājas Darbs #1 A. Izvēlēties iespēju robežās no citiem atšķirīgu *nix distribūciju, to patstāvīgi instalēt un īsumā aprakstīt galvenos soļus, grūtības un tml. Instalācijas procesa ekranattēlu iegūšanai ieteicams lietot VirtualBox, Vmware vai citu emulatoru. B. Instalētajā *nix versijā panākt lai darbojas C kompilātors; tajā uzrakstīt, nokompilēt un palaist vienkāršu "Sveika, pasaule!" programmiņu. C. (Neobligātā daļa atzīmes 10 iegūšanai): nodemonstrēt buffer overflow ielaušanos datorā (Unix shell piekļuvi vai kādas programmas izpildi) caur jūsu "Sveika, pasaule!" programmiņu, kas satur scanf vai līdzīgu nedrošu C bibliotēkas funkciju. Pašu ielaušanos veikt tikai programmas ievadā, bez ievainojamās programmas "pašuzlaušanas".

  3. Praktiskas lietas • Video lekcijas – padziļinātai izpratnei (angliski) • Kristaps Džonsons • http://students.mii.lu.lv/Lekcijas/OperetajsistemaUNIX/ • Mājasdarba C-daļai skatīt • 11stack1.mov (no 24-46 min) • 12stack2.mov (no sākuma)

  4. Ieteicamās virtualiācijas vides majas darbam • VirtualPC (Win) • VMWare (Win, Mac) • VirtualBox (Sun, Oracle) • Parallels (Mac) • KVM (Linux)

  5. Linux Distributions • Debian GNU/Linux (Xandros, Knopix,...) • a free operating system that provides almost 4000 software packages for six architectures (Intel, Motorola, Alpha, SPARC, PowerPC, ARM) and is developed entirely by volunteers over the Internet • Fedora/RedHat • a Red-Hat-sponsored and community-supported open source project. The goal of The Fedora Project is to work with the Linux community to build a complete, general purpose operating system exclusively from free software. Development will be done in a public forum • Mandrake Linux • a friendly Linux Operating System which specializes in ease-of-use for both servers and the home/office. It is freely available in many languages throughout the world • Slackware • a long running Linux distribution that descends from the SLS Distribution • SuSE Linux • an extremely popular distro that features excellent documentation, thousands of applications on a DVD/CD-ROM set • Gentoo Linux • an optimized GNU/Linux distribution featuring 5 different pgcc-optimized builds, including Intel Pentium, Pentium Pro/II/III and AMD K6 optimized

  6. BSD Versions • FreeBSD - Focusing on features and ease of use • Darwin (OS X) - Focusing on the desktop and multimedia with use of the Apple's Aqua Interface • NetBSD - Focusing on portability • OpenBSD - Focusing on security

  7. Citi brīvi pieejami Unix • Solaris • x64/x86 • SPARC • Minix

  8. Unix Instalacijano CD/DVD

  9. Installing NetBSD The main menu of the installation program

  10. Installing NetBSD Choosing the partitioning scheme

  11. Installing NetBSD fdisk

  12. Installing NetBSD Installing the boot selector

  13. Installing NetBSD The disklabel editor

  14. System startup

  15. System initialization • Overview of the PC Boot Process • When a PC is powered on, the BIOS (Basic Input-OutputSystem) runs first, followed by a boot loader and finally the operating system initialization routine.

  16. System initialization • The BIOS • When power is initially applied tothe computer this triggers the RESET pin on the processor. This causes the processor to read frommemory location 0xFFFFFFF0 and begin executing the code located there. This address is mapped to theRead-Only Memory (ROM) containing the BIOS. The BIOS must poll the hardware and set up anenvironment capable of booting the operating system. BIOS functionality can be broken into three areas:Power On Self Test (POST), Setup and Boot. • The last action of the BIOS is to execute the 19h interrupt, which loads the first sector of the firstboot device. Since this is the location of the boot loader, execution of the 19h interrupt transfers control tothe boot loader.

  17. Hard Drive Construction • Master Boot Record (MBR) Track 0, Sector 1 (512bytes): • Number of partitions and their location (max 4 primary partitions or 3 primary + 1 Extended + 12 Logical) • Pointer to partition with bootloader struct master_boot_record { char bootinst[446]; /* space to hold actual boot code */ char parts[4 * sizeof (structfdisk_partition_table)]; ushort signature; /* set to 0xAA55 to indicate PC MBR format */ };

  18. System initialization • The Boot Loader • Once the BIOS loads the first sector of the boot device into RAM, the boot loader begins execution.In the case of a hard drive, this first sector is referred to as the Master Boot Record (MBR). The MBRcontains the partition table describing the partitions defined on the hard drive. It also contains a program,the boot loader, which will load the first sector of the partition marked as active into RAM and execute it. • The size of the MBR is limited to one sector on disk or 512 bytes, since it is located within the first sectorof the drive at cylinder 0, head 0, sector 1. • Typicallyboot loaders have been highly integrated with the operating system that they support. This integration cutsdown on the operations a boot loader must perform, making a 512 byte boot loader feasible. When morefunctionality is required, a multi-stage boot loader may be used. • A multi-stage boot loader provides more function and flexibility by working around the 512 bytesize limitation. Rather than consisting of a single program which loads the operating system directly,multi-stage boot loaders divide their functionality into a number of smaller programs that eachsuccessively load one another.

  19. Boot Block The system’s primary disk unit contains a boot block that contains the bootstrapping program that loads the OS to memory. This program is invoked by the computer’s minimal bootstrap program in ROM. This boot block is often called the Master Boot Record (MBR). Different operating systems treat the MBR in very different ways. Some are flexible enough to install a boot loader in the MBR, so that the disk can contain different OS in different disk partitions. The loader for each OS is then stored at the beginning of its own partition. Examples: Windows NT/2000/xp boot loader, Linux lilo and grub. A “bootable” disk is one on which a boot block has been installed.

  20. How computer startup? • Booting is a bootstrapping process that starts operating systems when the user turns on a computer system • A boot sequence is the set of operations the computer performs when it is switched on that load an operating system

  21. Booting sequence • Tern on • CPU jump to address of BIOS (0xFFFF0) • BIOS runs POST (Power-On Self Test) • Find bootale devices • Loads and execute boot sector form MBR • Load OS

  22. BIOS (Basic Input/Output System) • BIOS refers to the software code run by a computer when first powered on • The primary function of BIOS is code program embedded on a chip that recognises and controls various devices that make up the computer. BIOS on board BIOS on screen

  23. Boot loader

  24. MBR(Master Boot Record) • OS is booted from a hard disk, where the Master Boot Record (MBR) contains the primary boot loader • The MBR is a 512-byte sector, located in the first sector on the disk (sector 1 of cylinder 0, head 0) • After the MBR is loaded into RAM, the BIOS yields control to it.

  25. MBR(Master Boot Record)

  26. MBR(Master Boot Record) • The first 446 bytes are the primary boot loader, which contains both executable code and error message text • The next sixty-four bytes are the partition table, which contains a record for each of four partitions • The MBR ends with two bytes that are defined as the magic number (0xAA55). The magic number serves as a validation check of the MBR

  27. Extracting the MBR • To see the contents of MBR, use this command: • # dd if=/dev/hda of=mbr.bin bs=512 count=1 • # od -xa mbr.bin **The dd command, which needs to be run from root, reads the first 512 bytes from /dev/hda (the first Integrated Drive Electronics, or IDE drive) and writes them to the mbr.bin file. **The od command prints the binary file in hex and ASCII formats.

  28. Boot loader • Boot loader could be more aptly called the kernel loader. The task at this stage is to load the Linux kernel • Optional, initial RAM disk • GRUB and LILO are the most popular Linux boot loader.

  29. Other boot loader (Several OS) • bootman • GRUB • LILO • NTLDR • XOSL • BootX • loadlin • Gujin • Boot Camp • Syslinux • GAG

  30. GRUB: GRand Unified Bootloader • GRUB is an operating system independant boot loader • A multiboot software packet from GNU • Flexible command line interface • File system access • Support multiple executable format • Support diskless system • Download OS from network • Etc.

  31. GRUB boot process • The BIOS finds a bootable device (hard disk) and transfers control to the master boot record • The MBR contains GRUB stage 1. Given the small size of the MBR, Stage 1 just load the next stage of GRUB • GRUB Stage 1.5 is located in the first 30 kilobytes of hard disk immediately following the MBR. Stage 1.5 loads Stage 2. • GRUB Stage 2 receives control, and displays to the user the GRUB boot menu (where the user can manually specify the boot parameters). • GRUB loads the user-selected (or default) kernel into memory and passes control on to the kernel.

  32. Example GRUB config file

  33. LILO: LInux LOader • Not depend on a specific file system • Can boot from harddisk and floppy • Up to 16 different images • Must change LILO when kernel image file or config file is changed

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

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

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

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

  38. LILO interface • Once LILO has successfully loaded, you will see a LILO prompt. • You may let LILO time out (after 10 seconds), which will boot the default Linux partition. • Second, you can press the TAB key, which will list a selection of operating systems to boot from. For example we would get "Linux" and "WindowsXP" as our options. • Typing either of these will load up that OS.

  39. GRUB (GRand Unix Bootloader)

  40. Grub interface

  41. Kernel is loaded into memory GRUB also passes “kernel command line” (255bytes) to the loaded Linux kernel

  42. 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 # initrd /initrd-version.img #boot=/dev/hdb default=0 timeout=10 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) root (hd0,1) 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 Specifies the default boot image will be the first hard entry Grub will wait for 10 seconds for input from the user before continuing to boot. The root partition is the second partition on the first hard drive.

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

  44. Changing runlevel at boot time • LILO: append the runlevel to the bootcommand : • LILO: linux 3 or • LILO: linux 5 • GRUB: press the `e' key to edit the boot configuration • append therunlevel to the end of the boot command as shown: • kernel /vmlinuz ro root=/dev/hda1 5

  45. Kernel starts the init process Kernel passes desired runlevel to the init pocess as argument If runlevel not specified, then

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

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

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

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

  50. HD identification Partition identification: • IDE drives • dev/hda • dev/hdb • ... • SCSI • dev/sda • dev/sdb • ... Note that /dev is not a real directory for accessing the contents of disks – it is rather a naming space for all hardware devices (and their drivers) present in the system, including keyboard, screen etc. The contents of disks is made available in other part of root / hierarchy. • brw-rw---- 1 root disk 3, 0 May 5 1998 hda • brw-rw---- 1 root disk 8, 0 May 5 1998 sda

More Related