Upload
ashlyn-martin
View
220
Download
0
Embed Size (px)
Citation preview
www.ischool.drexel.edu
INFO 320Server Technology I
Week 4
Basic Unix commands
1INFO 320 week 4
www.ischool.drexel.edu
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
2INFO 320 week 4
www.ischool.drexel.edu
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
3INFO 320 week 4
www.ischool.drexel.edu
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
4INFO 320 week 4
www.ischool.drexel.edu
Memory and speed(memtest86+ v2.11)
Type Amount Speed (MB/s)
L1 cache 32 kB 71,079
L2 cache 256 kB 28,057
L3 cache 4096 kB 19,563
RAM (2 GB) 2039 MB 5,213
RAM (6 GB) 6135 MB 8,703
5INFO 320 week 4
www.ischool.drexel.edu
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?
6INFO 320 week 4
www.ischool.drexel.edu
Memory and speed (same test)
Type Amount Speed (MB/s)
L1 cache 8 kB 14,439
L2 cache 512 kB 12,611
L3 cache none -
RAM (1 GB) 1022 MB 797
7INFO 320 week 4
www.ischool.drexel.edu
Booting
From (Frisch, 2002), (Petersen, 2009) and (Rankin, 2009)
8INFO 320 week 4
www.ischool.drexel.edu
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
9INFO 320 week 4
www.ischool.drexel.edu
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
10INFO 320 week 4
www.ischool.drexel.edu
Booting overviewPower onor reboot
ROM
Boot programlilo or GRUB
/sbin/initPID 1
Other OS kernel
Other OSkernel
Kernelvmlinux
Multiuser modeSingle user mode
11INFO 320 week 4
www.ischool.drexel.edu
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)
12INFO 320 week 4
www.ischool.drexel.edu
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
13INFO 320 week 4
www.ischool.drexel.edu
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
14INFO 320 week 4
www.ischool.drexel.edu
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
15INFO 320 week 4
www.ischool.drexel.edu
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)
16INFO 320 week 4
www.ischool.drexel.edu
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
17INFO 320 week 4
www.ischool.drexel.edu
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!18INFO 320 week 4
www.ischool.drexel.edu
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
19INFO 320 week 4
www.ischool.drexel.edu
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
20INFO 320 week 4
www.ischool.drexel.edu
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
21INFO 320 week 4
www.ischool.drexel.edu
Managing Services
22INFO 320 week 4
www.ischool.drexel.edu
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
23INFO 320 week 4
www.ischool.drexel.edu
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
24INFO 320 week 4
www.ischool.drexel.edu
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
25INFO 320 week 4
www.ischool.drexel.edu
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
26INFO 320 week 4
www.ischool.drexel.edu
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
27INFO 320 week 4
www.ischool.drexel.edu
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
28INFO 320 week 4
www.ischool.drexel.edu
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
29INFO 320 week 4
www.ischool.drexel.edu
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
30INFO 320 week 4
www.ischool.drexel.edu
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.
31INFO 320 week 4
www.ischool.drexel.edu
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
32INFO 320 week 4
www.ischool.drexel.edu
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
33INFO 320 week 4
www.ischool.drexel.edu
Users and Groups
34INFO 320 week 4
www.ischool.drexel.edu
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
35INFO 320 week 4
www.ischool.drexel.edu
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
36INFO 320 week 4
www.ischool.drexel.edu
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
37INFO 320 week 4
www.ischool.drexel.edu
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
38INFO 320 week 4
www.ischool.drexel.edu
Permissions
39INFO 320 week 4
www.ischool.drexel.edu
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
40INFO 320 week 4
www.ischool.drexel.edu
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?
41INFO 320 week 4
www.ischool.drexel.edu
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, chmod is used– The value of permissions can be done
numerically (like above) or with code letters
42INFO 320 week 4
www.ischool.drexel.edu
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
43INFO 320 week 4
www.ischool.drexel.edu
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 chown can change the owner and/or group membership of a file– chown glenn:prof filename– Assigns owner=glenn and group=prof to filename
44INFO 320 week 4
www.ischool.drexel.edu
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 = eXtended InterNET Daemon
45INFO 320 week 4
www.ischool.drexel.edu
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
46INFO 320 week 4