460 likes | 603 Views
INFO 320 Server Technology I. Week 4 Basic Unix commands. Overview. Now we’re focusing more on practical concerns about how Linux/UNIX works Booting Managing Services Users and Groups Permissions But first a brief digression about scheduling and memory speeds. Installation addendum.
E N D
INFO 320Server Technology I Week 4 Basic Unix commands INFO 320 week 4
Overview Now we’re focusing more on practical concerns about how Linux/UNIX works Booting Managing Services Users and Groups Permissions But first a brief digression about scheduling and memory speeds INFO 320 week 4
Installation addendum I recently got a new system, and was very good to set it up right Make sure the system works out of the box Test RAM and hard disk – no errors Install one component at a time, and check for errors for each before adding the next In doing so, I found a surprising increase in RAM speed just from doing an upgrade INFO 320 week 4
Memory and speed Recall that a major part of an OS’s job is to manage processes, and where they run As a refinement of the earlier slide about memory speeds, here are examples of speed to access various levels of memory They are for a 2.132 GHz four-core Intel Xeon E5506 processor with 4 MB cache and DDR3 800 MHz RAM, before and after a 4 GB RAM upgrade INFO 320 week 4
Memory and speed(memtest86+ v2.11) INFO 320 week 4
Memory and speed In contrast, a 2002-era 2 GHz (1993 MHz) Pentium 4 processor with 1 GB of RAM (200-266 MHz DDR SDRAM) got the results on the next slide (same test) So how much of a factor is CPU clock speed in system performance? Is 800 MHz RAM four times faster than 200 MHz RAM? Why or why not? INFO 320 week 4
Memory and speed (same test) INFO 320 week 4
Booting From (Frisch, 2002), (Petersen, 2009) and (Rankin, 2009) INFO 320 week 4
Bootstrapping The process of bringing a computer to life and preparing it for use is formally known as bootstrapping As in ‘picking yourself up by your bootstraps’ This is usually abbreviated to booting We won’t go into huge detail, but an overview of the process is in order INFO 320 week 4
Booting overview Power on (or command to reboot) ROM finds boot device, loads boot program Boot program loads kernel into memory Kernel makes sure hardware is happy, runs init program INFO 320 week 4
Booting overview INFO 320 week 4
Start booting The process of booting varies from one flavor of UNIX/Linux to another, and is also hardware-dependent We’ll focus on Linux on PC’s Booting starts with permanent instructions executed when the system powers up Their location can be called ROM, ROS, firmware, or CMOS/nvram (a list of terms is at the end of these notes) INFO 320 week 4
Booting Several kinds of devices could be used for booting (examples?) The ROM (BIOS) program chooses in which order they are checked It finds the boot device, loads the boot program, and hands control to it On PC’s, ROM loads the master boot program from the master boot record (MBR), at the start of the C: drive INFO 320 week 4
Master boot programs On a Windows system, the master boot program could be a simple DOS program On Linux systems, lilo or GRUB can be the master boot program Then based on input from the user, it knows which kernel to boot GRUB’s configuration file is at /boot/grub/menu.lst INFO 320 week 4
GRUB If you want to change the GRUB configuration use the tool update-grub instead of editing the config file For more GRUB information install sudo apt-get install grub-doc Can use the HTML reader w3m w3m /usr/share/doc/grub-doc/html/grub.html INFO 320 week 4
Booting The boot program loads the kernel into memory (RAM), and passes control to it The boot program also checks RAM, looks for key peripherals, might detect new devices The kernel has many names, unix (System V), vmunix (BSD), hp-ux (HP-UX), vmlinux or vmlinuz (Linux) INFO 320 week 4
Kernel In Linux the kernel is now modular*, to accommodate all the different kinds of file systems, RAID, encryption, etc. possible The initrd (initialized RAM disk) file is loaded with the kernel It decompressed initramfs, which is a RAM filesystem for the kernel to use until it mounts the disk-based root filesystem * It was ‘monolithic’- just load everything right away INFO 320 week 4
Booting Then the kernel has control It initializes itself, runs hardware diagnostics, installs drivers, might test the CPU Then the kernel runs the first program, init Init is usually* PID 1, found in /sbin/init It is the parent of all other Unix processes and shells Init controls if the system will be booted into multiuser mode or single user mode * Try ps –ef and see for yourself! INFO 320 week 4
Multiuser mode The normal boot process goes into multiuser mode Init verifies the integrity of the filesystems using the fsck utility Mount local disks Designate paging areas Clean up filesystems – check quotas, save recovery files, delete /tmp files INFO 320 week 4
Multiuser mode Start server daemons for printing, email, cron jobs, etc. Start networking daemons, mount remote disks Enable user logins with agetty process These are accomplished via a lot of services scripts (next section) Now a user can log into the system INFO 320 week 4
Single user mode Single user mode (also called service mode or maintenance mode) is used for exclusive access to the system Often for admin or maintenance functions Could enter it if file system problems occur that fsck can’t fix Init runs a Bourne shell (/bin/sh) as root user; often has limited filesystems loaded INFO 320 week 4
Managing Services INFO 320 week 4
Services The init daemon manages the startup of services in most traditional System V-based UNIX systems Ubuntu has recently switched to a tool called Upstart for the same purpose To understand their role, we need to look at run levels INFO 320 week 4
Run Levels Services are set up in different run levels from 0 to 6 Runlevel 0 powerdown state, ready to shut off Runlevel 1 single user mode Runlevel 2 normal multiuser mode Runlevels 3 to 5 are other multiuser modes Runlevel 6 shutdown and reboot state Runlevel s or S, single user mode INFO 320 week 4
Run Levels There are other special purpose run levels, such as a, b, c, and q To see your current run level try who -r The default run level for Ubuntu is 2, per /etc/inittab (not used in Desktop) The telinit utility can be used to change run level interactively INFO 320 week 4
Run Levels Other key service resources include: The /etc/init.d directory has startup scripts for every service Most accept start or stop as arguments Directories /etc/rc0.d through /etc/rc6.d have init scripts for each runlevel These scripts Start, Kill (stop), or Disable (ignore) each service in numeric order INFO 320 week 4
Run Levels The directory /etc/rcS.d has startup scripts that are applied before going to a particular run level So a typical startup would run Init looks to inittab to find the desired run level (let’s say 2) Then run the S (start) flagged services in /etc/rcS.d Then run the services in /etc/rc2.d INFO 320 week 4
Run Levels The init daemon keeps running in case there’s a change in run level Services can be manually started or stopped by commanding their scripts sudo /etc/init.d/networking start sudo /etc/init.d/networking stop Use no argument (e.g. start, stop) to see the available ones INFO 320 week 4
xinetd A legacy program for starting and stopping Internet services is xinetd (eXtended InterNET Daemon) The services it controls are in the directory /etc/xinetd.d All are disabled by default; enable them by editing their config file, e.g. /etc/xinetd.d/echo Then reload xinetd to activate themsudo service xinetd reload INFO 320 week 4
Upstart Upstart was designed to handle interactive running and stopping of services, beyond what the run level concept can do Init only changes services when you boot, reboot, or change run level But some services, like networking, could change during a session INFO 320 week 4
Upstart Upstart is event-driven Actions (such as starting or stopping services) can be taken based on events that occur Events could include startup, shutdown, changing runlevel, plugging in a network cable, removing a flash drive, etc. INFO 320 week 4
Upstart Upstart scripts are in /etc/event.d Get a list of all Upstart jobs with sudo initctl list The default Upstart runlevel is in /etc/event.d/rc-default Look for the command telinit 2 Replaces the inittab file INFO 320 week 4
Rebooting and shutting down The boot command can be used to manually reboot, or use reboot The –s qualifier can boot into single user mode boot -s To shut down from a command line use halt or shutdown The latter has many configuration options INFO 320 week 4
Users and Groups INFO 320 week 4
Users Ok, now we have a running system, we need to define users, and assign them to groups In the Desktop GNOME interface, users and groups are managed from System > Administration > Users and Groups INFO 320 week 4
Users From the command line add a user with sudo adduser <username> To set or reset a password use sudo passwd <username> Remove a user with deluser sudo deluser <username> It can also remove their files and home directory, or remove them from a group INFO 320 week 4
Groups The addgroup command creates a new group sudo addgroup <groupname> Conversely, delgroup removes a group sudo delgroup <groupname> The group must have no users for whom it is their primary group INFO 320 week 4
Other stray commands The who command tells who is logged into the system For keyword-based help, use man –k keyword Or apropos keyword If you can’t find a command, use whereis whereis commandname INFO 320 week 4
Permissions INFO 320 week 4
Permissions Permissions apply to files, directories, and links Their basis is the right to read, write, and execute Read is only that Write includes create, modify or delete Execute is in the sense of running a script or application INFO 320 week 4
Permissions In a full listing (ls –l) the permissions for each entry are shown In order, they pertain to the User, their Group members, and Other (anyone else) For each of those categories, read (r), write (w) and execute (x) So what does rwxr-xr-- mean? What’s wrong with r-xrwxrwx? INFO 320 week 4
Changing permissions The read, write, and execute can be given numeric values of 4, 2, and 1 respectively and are added for each type of user So the example rwxr-xr-- becomes what numbers? To change permissions, chmodis used The value of permissions can be done numerically (like above) or with code letters INFO 320 week 4
Changing permissions The numeric format might look like chmod 751 filename Whereas the text format might say chmod u+rw filename Meaning the user (u) adds (+) read and write (rw) permissions to filename Before the operator, u g o a mean user, group, other, or all users A plus operator adds permissions, - removes them INFO 320 week 4
Files and ownership Files have group membership By default it’s the group of their creator chgrp can be used to modify the group associated with them Also chowncan change the owner and/or group membership of a file chown glenn:prof filename Assigns owner=glenn and group=prof to filename INFO 320 week 4
Terms CMOS = complementary metal oxide semiconductor GRUB = GNU GRand Unified Bootloader lilo = Linux Loader MBR = master boot record, sector 0 on C: drive Nvram = non-volatile random access memory RAM = random access memory ROM = read only memory ROS = read only storage xinetd = eXtendedInterNET Daemon INFO 320 week 4
References The Official Ubuntu Book, by Benjamin Mako Hill et al, Prentice Hall 2007. ISBN 0132354136 Index of Ubuntu community HowTo pageshttps://help.ubuntu.com/community/TitleIndex INFO 320 week 4