%% $Header: /cvsroot/lcdp/lpic/general-linux-1/notes/gl1.notes.tex,v 1.8 2003/06/04 04:40:01 geoffr Exp $ \documentclass[a4paper,10pt,fullpage]{book} %\usepackage{draftcopy} \usepackage{palatino} \usepackage{pifont} \usepackage{pstricks} \usepackage{graphicx} \usepackage{alltt} \usepackage{rotating} \usepackage{rotate} \usepackage{boxedminipage} \setlength{\columnsep}{30mm} \usepackage{epsfig} \newcommand{\cmd}[1]{% \texttt{\$ \textbf{#1 \(\hookleftarrow\)}} } \newcommand{\rootcmd}[1]{% \texttt{\# \textbf{#1 \(\hookleftarrow\)}} } \newcommand{\opt}[1]{% {\bf\texttt{#1}} } %% Use \topic instead of \part \newcounter{topic} \newcommand{\topic}[2]{% \setcounter{topic}{#1}% \part*{\underline{\textsf{Topic \arabic{topic}}}\\[3ex]#2}% \addcontentsline{toc}{part}{\textsf{Topic \arabic{topic}:} #2} } %% Use \objective to replace \chapter \newcounter{objective}[topic] \newcommand{\objective}[2]{% \setcounter{objective}{#1}% \setcounter{chapter}{#1}% \setcounter{section}{0}% %\chapter*{#2}% \chapter*{\underline{\textsf{Objective \arabic{topic}.\arabic{objective}}}% \\[3ex]#2}% \addcontentsline{toc}{chapter}% {\textsf{Objective \arabic{topic}.\arabic{objective}:} #2}% } % \renewcommand{\part[#1]#2{% % % \def\@part[#1]#2{% % \ifnum \c@secnumdepth >-2\relax % \refstepcounter{part}% % \addcontentsline{toc}{part}{\thepart\hspace{1em}#1}% % \else % \addcontentsline{toc}{part}{#1}% % \fi % \markboth{}{}% % {\centering % \interlinepenalty \@M % \normalfont % \ifnum \c@secnumdepth >-2\relax % \huge\bfseries \partname~\thepart % \par % \vskip 20\p@ % \fi % \Huge \bfseries #2\par}% % \@endpart} % \def\@spart#1{% % {\centering % \interlinepenalty \@M % \normalfont % \Huge \bfseries #1\par}% % \@endpart} % \def\@endpart{\vfil\newpage % \if@twoside % \if@openright % \null % \thispagestyle{empty}% % \newpage % \fi % \fi % \if@tempswa % \twocolumn % \fi} %\title{ LPIC General Linux 1 } \title{--- {\huge LPI Certification ---\\[3mm] --- General Linux 1} --- \\[3mm]\Large{\textsf{(Study Notes)} \footnote{Copyright \copyright 2002 Geoffrey Robertson. Permission is granted to make and distribute verbatim copies or modified versions of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation---either version 2 of the License or (at your option) any later version.} \footnote{ {\scriptsize RCS Id = $ $Id: gl1.notes.tex,v 1.8 2003/06/04 04:40:01 geoffr Exp $ $} }}} \author{geoffrey hector robertson \\geoffrey@zip.com.au} %============================================================================= \begin{document}%============================================================= %============================================================================= %----10->|-----20->|-----30->|-----40->|-----50->|-----60->|-----70->|-----80-> \maketitle % \begin{abstract} % The % \end{abstract} \tableofcontents %\noindent %****************************************************************************** %****************************************************************************** \topic{101}{Hardware \& Architecture} %****************************************************************************** %****************************************************************************** %****************************************************************************** \objective{1}{Configure Fundamental BIOS Settings} %============================================================================== \section{Overview} \label{sec:over101.1} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to configure fundamental system hardware by making the correct settings in the system BIOS. This objective includes a proper understanding of BIOS configuration issues such as the use of LBA on IDE hard disks larger than 1024 cylinders, enabling or disabling integrated peripherals, as well as configuring systems with (or without) external peripherals such as keyboards. It also includes the correct setting for IRQ, DMA and I/O addresses for all BIOS administrated ports and settings for error handling. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} /proc/ioports /proc/interrupts /proc/dma /proc/pci \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} Large Disk HOWTO by Andries Brouwer \begin{alltt} http://www.linuxdoc.org/HOWTO/Large-Disk-HOWTO.html \end{alltt} %============================================================================== \newpage \section{Notes} \label{sec:notes101.1} %============================================================================== \section{Lab} \label{sec:lab101.1} %============================================================================== \section{Questions} \label{sec:questions101.1} %****************************************************************************** \objective{3}{Configure Modem and Sound cards} %============================================================================== \section{Overview} \label{sec:over101.3} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Ensure devices meet compatibility requirements (particularly that the modem is NOT a win-modem), verify that both the modem and sound card are using unique and correct IRQ's, I/O, and DMA addresses, if the sound card is PnP install and run sndconfig and isapnp, configure modem for outbound dial-up, configure modem for outbound PPP | SLIP | CSLIP connection, set serial port for 115.2 Kbps %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes101.3} %============================================================================== \newpage \section{\textsf{LAB 1:} Setting Up a Shell Dialup Service} \label{sec:101.3_lab_shell} When you have completed this exercise you will be able to dial into a shell account on a remote host. %------------------------------------------------------------------------------ \subsection{Inbound Shell Login - Server} \begin{enumerate} \item Edit \texttt{/etc/inittab} to automatically spawn \texttt{mgetty}. \begin{alltt} \cmd{tail -1 /etc/inittab} T0:2345:respawn:/sbin/mgetty -x0 -s 57600 -D ttyS0 \end{alltt} (Change ttyS0 to whatever device your modem is connected to) \item Connect the modem and phone line. \item Run \rootcmd{telinit q} to reread \texttt{/etc/inittab} \item Check that the modem's \textsf{DTR} indicator is on. \item Check \texttt{mgetty} is there: \begin{alltt} \cmd{ps aux |grep mgetty} root ...... /sbin/mgetty -x0 -s 57600 ttyS0 \end{alltt} \end{enumerate} %------------------------------------------------------------------------------ \subsection{Outbound Shell login - Client} This exercise uses the \textsf{minicom} terminal program. To get help at any time press \textsf{Control-C Z}. \begin{enumerate} \item Run \rootcmd{minicom -s} (as root) and setup the serial port to the desired \texttt{tty} and linespeed. \item Give normal users access to the modem device. \item Run minicom as a normal user. Once the modem has initialised typing \texttt{AT} at the minicom terminal will prompt the modem to return \texttt{OK}: \begin{alltt} AT \(\hookleftarrow\) OK _ \end{alltt} and dial your server: \begin{alltt} OK ATDT12345678 \end{alltt} \item When the modem answers and trains, you should be presented with a login prompt. Login as you normally would. \item Logging out will disconnect the modem. \end{enumerate} %============================================================================== \newpage \section{\textsf{LAB 2:} Setting Up a PPP Dialup Service} \label{sec:101.3_lab_ppp} %------------------------------------------------------------------------------ \subsection{Inbound Dialup \texttt{ppp} - Server} \begin{enumerate} \item Edit \texttt{/etc/inittab} to run \texttt{mgetty}. \begin{alltt} \cmd{tail -1 /etc/inittab} T0:2345:respawn:/sbin/mgetty -x0 -s 57600 -D ttyS0 \end{alltt} Change \texttt{ttyS0} to whatever device your modem is connected to. \item Add the following line (if not already there) to \texttt{/etc/modules.conf} \begin{alltt} alias ppp0 ppp\_generic \end{alltt} \item Connect modem and phone line. \item Run \rootcmd{telinit q} to reread \texttt{/etc/inittab} \item Edit \texttt{/etc/mgetty/login.config} and uncomment the line \begin{alltt} /AutoPPP/ - a_ppp /usr/sbin/pppd auth -chap +pap login debug \end{alltt} \item Edit the file \texttt{/etc/ppp/options} and uncomment or add the lines: \begin{alltt} asyncmap 0 #auth crtscts lock modem -detach proxyarp \end{alltt} \item Edit the file \texttt{/etc/ppp/options.ttyS0} and uncomment or add the line: \begin{alltt} 192.168.0.253:192.168.0.10 \end{alltt} The format of this line is \texttt{Server IP:Client IP}. Note that these addresses should be on the same network as your server unless you are prepared to setup routing for a new network. However, they should not clash with previously allocated IP addresses. \item Edit \texttt{/etc/ppp/pap-secrets} and add: \begin{alltt} #user interface password allowed-ip-addresses * * \end{alltt} This line says: Let user \verb++ with password \verb++ use any ppp interface with any IP address. The username and passwd can be anything you like and do not have to be in \texttt{/etc/passwd}. You will need the username and password pair when you come to set up the client. \end{enumerate} %------------------------------------------------------------------------------ \subsection{Outbound Dialup ppp - Client} NOTE: If your client \& server machines are already connected via a LAN you will probably need to bring down the LAN on your client machine. (Or at least remove any route associated with the LAN from the client). To do this: \texttt{ifconfig eth0 down} Type \cmd{/sbin/route -n} and make sure it looks like the line below before configuring ppp on the client: \begin{alltt} Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 127.0.0.0 * 255.0.0.0 U 0 0 0 lo \end{alltt} Common to both methods: Edit /etc/modules.conf and add the following line: \begin{alltt} alias ppp0 ppp\_generic \end{alltt} \subsubsection{From within X:} \begin{enumerate} \item Run kppp and create an entry for your server, just as you would do for an ISP. The only items that need to be added are: \begin{itemize} \item The telephone number of the server \item The userid you selected in the server pap-secrets file \item The password you selected in the server pap-secrets file \end{itemize} \item Click the Connect button and you should be away!. \end{enumerate} \subsubsection{From a terminal using wvdial:} \begin{enumerate} \item Run \rootcmd{wvdialconf /etc/wvdial.conf}. You should end up with a file called \texttt{/etc/wvdial.conf} that looks something like: \begin{alltt} [Dialer Defaults] Modem = /dev/ttyS0 Baud = 115200 Init1 = ATZ Init2 = ATQ0 V1 E1 S0=0 &C1 &D2 S11=55 +FCLASS=0 ; Phone = ; Username = ; Password = \end{alltt} \item Now edit this file and add the following to the end of the file: \begin{alltt} [Dialer ] Username = username #just as you entered into pap-secrets on the server Password = passwd #just as you entered into pap-secrets on the server Phone = Inherits = Dialer Defaults Stupid mode = 1 New PPPD = 1 \end{alltt} Stupid mode tells wvdial to start pppd as soon as it sees the login prompt and not to log into the server as a normal user first. \item Now you can dial your server by doing the following: \begin{alltt} \cmd{wvdial } \end{alltt} Where \texttt{\textless server-name\textgreater } is the name you gave to the second dialer stanza above. Note that wvdial will add an entry into \texttt{/etc/ppp/pap-secrets} containing the username and password pair automatically. \end{enumerate} %------------------------------------------------------------------------------ \subsection{Adding Automatic DNS setup} You can have the server pass a pair of DNS IP addresses to the client which the client can use to resolve dns queries. If you do this, you should be able to use Windows as a client just like any other ISP. \subsubsection{Server Side:} Add the following line to \texttt{/etc/ppp/options} \begin{alltt} ms-dns ms-dns \end{alltt} The DNS ip addresses should be whatever your server is using (\cmd{cat /etc/resolv.conf} to see). If your server is using the local interface (127.0.0.1) then you should set the address to that of eth0 and make sure that bind is configured to listen on that interface. The following line should be in \texttt{/etc/named.conf} \begin{alltt} listen-on \end{alltt} \subsubsection{Client Side:} Add the following line to \texttt{/etc/ppp/options} \begin{alltt} usepeerdns \end{alltt} Now create a file called \texttt{/etc/ppp/ip-up.local} which contains: \begin{alltt} cp /etc/resolv.conf /etc/ppp/resolv.conf.orig echo "nameserver \$DNS1" > /etc/resolv.conf echo "nameserver \$DNS2" >> /etc/resolv.conf \end{alltt} Create another file called /etc/ppp/ip-down.local which contains: \begin{alltt} cp /etc/ppp/resolv.conf.orig /etc/resolv.conf \end{alltt} Congratulations. You now have a server which behaves just like an ISP! %============================================================================== \section{Questions} \label{sec:questions101.3} %****************************************************************************** \objective{4}{Setup SCSI Devices} %============================================================================== \section{Overview} \label{sec:over101.4} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to configure SCSI devices using the SCSI BIOS as well as the necessary Linux tools. They also should be able to differentiate between the various types of SCSI. This objective includes manipulating the SCSI BIOS to detect used and available SCSI IDs and setting the correct ID number for different devices especially the boot device. It also includes managing the settings in the computer's BIOS to determine the desired boot sequence if both SCSI and IDE drives are used. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} SCSI ID /proc/scsi/ scsi_info \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} %Andrew Eager \label{sec:notes101.4} %------------------------------------------------------------------------------ \subsection{SCSI Devices} \begin{itemize} \item SCSI - Small Computer Systems Interface \item SCSI can support a range of devices \begin{itemize} \item Hard disks \item Tape drives \item Scanners \end{itemize} \item There are many different types of SCSI based on: \begin{itemize} \item \noindent Bus Width \item \noindent Bus Speed \item \noindent Max no of devices \end{itemize} \end{itemize} %------------------------------------------------------------------------------ \subsection{SCSI TYPES} \begin{tabular}{|l|c|c|c|} \hline \textbf{Name}&\textbf{Bus Width}&\textbf{Bus Speed}& \textbf{Max Devices}\\ &\textbf{(bits)}&\textbf{(MB/s)}&\\ \hline \hline SCSI-1& 8 & 5 & 8\\ \hline Fast SCSI& 8& 10& 8\\ \hline Ultra SCSI& 8& 20& 8\\ \hline Ultra2 SCSI& 8& 40& 8\\ \hline Fast Wide SCSI& 16& 20& 16\\ \hline Wide Ultra SCSI& 16& 40& 16\\ \hline Wide Ultra2 SCSI& 16& 80& 16\\ \hline Ultra3 SCSI& 16& 160& 16\\ \hline Ultra320 SCSI& 16& 320& 16\\ \hline \end{tabular} %------------------------------------------------------------------------------ \subsection{SCSI Key Points} \begin{itemize} \item All devices on the SCSI bus are are numbered from 0 to N (7 or 15) \item The SCSI controller is usually numbered 7 or 15 \item The higher the device number, the higher its priority \item To boot from a SCSI disk, it must be device 0 \item The SCSI bus must be terminated at both ends \item SCSI controllers need a kernel module to make them work \end{itemize} %------------------------------------------------------------------------------ \subsection{SCSI Addressing} SCSI devices are addressed according to: \begin{itemize} \item SCSI adapter number (host) \item channel number (bus) \item id number (target) \item lun (lun) \end{itemize} %------------------------------------------------------------------------------ \subsection{SCSI Driver Layers} There are three layers to the SCSI subsystem: \begin{itemize} \item Low level driver - Controller specific \item Mid level driver - SCSI unifying layer \item Upper level driver - Device specific \end{itemize} \epsfig{file=../images/scsi.eps,width=0.9\textwidth} %------------------------------------------------------------------------------ \subsection{SCSI Driver Layers - Example} Consider an SCSI hard disk as an example: \begin{itemize} \item Low level - \texttt{aha1542.o} \item Mid level - \texttt{scsi\_mod.o} \item Upper level - \texttt{sd\_mod} \end{itemize} %------------------------------------------------------------------------------ \subsection{SCSI Upper Level Drivers} These drivers bind themselves to \texttt{/dev} entries. A non exhaustive, but pretty complete list: \begin{itemize} \item Disk driver (magnetic) - \texttt{sd.o} \item Disk driver (optical) - \texttt{sd\_mod.o} \item CDROM driver - \texttt{sr.o} \item Tape drivers - \texttt{st.o} \item Generic drivers - \texttt{sg.o} \end{itemize} %------------------------------------------------------------------------------ \subsection{SCSI \& the Kernel} To get SCSI working, you first need to load the appropriate module for your SCSI controller. For example: \begin{itemize} \item An Adaptec 1542 controller with an attached hard disk you would: \begin{alltt} \rootcmd{insmod aha1542} \end{alltt} \item Then load the mid level driver: \begin{alltt} \rootcmd{insmod scsi\_mod} \end{alltt} \item Finally, load the upper level driver: \begin{alltt} \rootcmd{insmod sd} \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsection{\texttt{/proc/scsi}} To see what devices have been found (at the mid level layer), have a look in the file \texttt{/proc/scsi}: \begin{alltt} \rootcmd{cat /proc/scsi/scsi} Attached devices: Host: scsi0 Channel: 00 Id: 00 Lun: 00 Vendor: CREATIVE Model: CD5233E Rev: 1.00 Type: CD-ROM ANSI SCSI revision: 02 Host: scsi0 Channel: 00 Id: 01 Lun: 00 Vendor: SONY Model: CD-RW CRX145E Rev: 1.0b Type: CD-ROM ANSI SCSI revision: 02 \end{alltt} %============================================================================== \section{Lab} \label{sec:lab101.4} %============================================================================== \section{Questions} \label{sec:questions101.4} %****************************************************************************** \objective{5}{Setup different PC expansion cards} %============================================================================== \section{Overview} \label{sec:over101.5} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to configure various cards for the various expansion slots. They should know the differences between ISA and PCI cards with respect to configuration issues. This objective includes the correct settings of IRQs, DMAs and I/O Ports of the cards, especially to avoid conflicts between devices. It also includes using isapnp if the card is an ISA PnP device. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} /proc/dma /proc/interrupts /proc/ioports /proc/pci pnpdump(8) isapnp(8) lspci(8) \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[Linux Hardware Compatibility HOWTO - Steven Pritchard]: \begin{alltt} http://www.linuxdoc.org/HOWTO/Hardware-HOWTO/index.html \end{alltt} \item[Linux PCI-HOWTO by Michael Will]: \begin{alltt} http://www.linuxdoc.org/HOWTO/PCI-HOWTO.html \end{alltt} \item[Plug-and-Play-HOWTO David S.Lawyer]: \begin{alltt} http://www.linuxdoc.org/HOWTO/Plug-and-Play-HOWTO.html \end{alltt} \end{description} %============================================================================== \newpage \section{Notes} \label{sec:notes101.5} %============================================================================== \section{Lab} \label{sec:lab101.5} %============================================================================== \section{Questions} \label{sec:questions101.5} %****************************************************************************** \objective{6}{Configure Communication Devices} %============================================================================== \section{Overview} \label{sec:over101.6} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to install and configure different internal and external communication devices like modems, ISDN adapters, and DSL switches. This objective includes verification of compatibility requirements (especially important if that modem is a winmodem), necessary hardware settings for internal devices (IRQs, DMAs, I/O ports), and loading and configuring suitable device drivers. It also includes communication device and interface configuration requirements, such as the right serial port for 115.2 Kbps, and the correct modem settings for outbound PPP connection(s). %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} /proc/dma /proc/interrupts /proc/ioports setserial(8) \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[Linmodem-HOWTO by Sean Walbran and Marvin Stodolsky]: \begin{alltt} http://www.linuxdoc.org/HOWTO/Linmodem-HOWTO.html \end{alltt} \item[Modem-HOWTO - David S.Lawyer]: \begin{alltt} http://www.linuxdoc.org/HOWTO/Modem-HOWTO.html \end{alltt} \item[The Winmodems-and-Linux HOWTO by Alexandre J.]: \begin{alltt} http://www.linuxdoc.org/HOWTO/Winmodems-and-Linux-HOWTO.html \end{alltt} \item[Serial HOWTO - David S.Lawyer original by Greg Hankins]: \begin{alltt} http://www.linuxdoc.org/HOWTO/Serial-HOWTO.html \end{alltt} \item[The Linux Winmodem Support Website]: \begin{alltt} http://www.linmodems.org \end{alltt} \end{description} %============================================================================== \newpage \section{Notes} \label{sec:notes101.6} %============================================================================== \section{Lab} \label{sec:lab101.6} %============================================================================== \section{Questions} \label{sec:questions101.6} %****************************************************************************** \objective{7}{Configure USB devices} %============================================================================== \section{Overview} \label{sec:over101.7} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to activate USB support, use and configure different USB devices. This objective includes the correct selection of the USB chipset and the corresponding module. It also includes the knowledge of the basic architecture of the layer model of USB as well as the different modules used in the different layers. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} lspci(8) usb-uhci.o usb-ohci.o /etc/usbmgr/ usbmodules /etc/hotplug \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[The Linux-USB Project ] \begin{alltt} http://www.linux-usb.org: \end{alltt} \item The Linux USB Sub System by Brad Hards, Sigma Bravo Pty. Ltd. \item[Slides] LCDP \texttt{gl1.101.7.slides.tex} \end{description} %============================================================================== \newpage \section{Notes} \label{sec:notes101.7} These notes were prepared by Andrew Eager. \subsection{The Universal Serial Bus} \begin{itemize} \item A serial transmission scheme \item Two versions of USB Version 1 \& Version 2 \item Version \begin{itemize} \item 1 released January 1996 \item supports speeds up to 12MBit/s (8.5Mbit/s in practice) \item supports up to 127 devices connected to the bus \end{itemize} Version 2: \begin{itemize} \item announced 1999 \item supports speeds up to 480Mbit/s \end{itemize} \item Devices can be self or bus powered \end{itemize} %------------------------------------------------------------------------------ \subsection{USB Topology} The system unit contains the host controller and one virtual root hub with at least one (and normally two) USB interfaces. These interfaces can then be connected directly to a USB device or to another HUB. \bigskip \noindent \epsfig{file=../images/topo.eps,width=\textwidth} %------------------------------------------------------------------------------ \subsection{USB Device Driver Layers} The Device drivers used for the USB sub-system are split into two distinct layers: \begin{description} \item [Hardware Layer] - usbcore \& usb-uhci / usb-ohci \item [API Layer] - Application / Product specific \end{description} \bigskip \noindent \epsfig{file=../images/api.eps,width=\textwidth} %------------------------------------------------------------------------------ \subsection{USB Controllers} There are two categories of USB controller: \begin{description} \item [\texttt{usb-uhci}] - For Intel, PIIX4, Via controllers \item [\texttt{usb-ohci}] - For Compaq, iMacs, OPTi, SiS, ALi controllers \end{description} To determine your controller type, examine \texttt{/proc/pci} for a clue: \begin{alltt} [root@Node4] root]\# cat /proc/pci PCI devices found: ......... Bus 0, device 7, function 2: USB Controller: VIA Technologies, Inc. UHCI USB (rev 17). IRQ 10. Master Capable. Latency=32. I/O at 0xe400 [0xe41f]. ......... \end{alltt} The UHCI controllers use a 16 bit IO address: \begin{alltt} I/O at 0xHHHH eg: I/O at 0xe400 \end{alltt} The OHCI controllers use a 32 bit memory address: \begin{alltt} memory at 0xHH000000 eg memory at 0xee000000 \end{alltt} %------------------------------------------------------------------------------ \subsection{USB Modules} Assuming you have a modular kernel, the following modules will be required: \begin{enumerate} \item \texttt{usbcore} - The base usb kernel module \item plus one of the controller specific modules: \begin{itemize} \item \texttt{usb-uhci} - For Intel, PIIX4, Via controllers \item \texttt{usb-ohci} - For Compaq, iMacs, OPTi, SiS, ALi controllers \end{itemize} \end{enumerate} %.............................................................................. \subsubsection{Configuration:} An entry in \texttt{/etc/modules.conf} aliases the specific controller to usb-controller as follows: \begin{alltt} alias usb-controller usb-uhci \end{alltt} %.............................................................................. \subsubsection{Starting up the USB sub-system} To have the usb sub-system startup automatically at boot time, all you need to do is ensure that the above alias line is present in \texttt{/etc/modules.conf}. To startup manually, do the following steps: \begin{enumerate} \item \texttt{insmod usbcore} \item \texttt{insmod usb-uhci} (or usb-ohci) \item mount the \texttt{usbdevfs} filesystem (optional but highly recommended) \end{enumerate} Example: \begin{alltt} [root@Node4] root]\# insmod usbcore Using /lib/modules/2.4.18-4/kernel/drivers/usb/usbcore.o [root@Node4] root]\# insmod usb-uhci Using /lib/modules/2.4.18-4/kernel/drivers/usb/usb-uhci.o [root@Node4] root]\# mount -t usbdevfs usbdevfs /proc/bus/usb \end{alltt} Once this is done, you should see the following entries in /proc/bus/usb: \begin{alltt} [root@Node4] root]\# ls /proc/bus/usb 001 devices drivers \end{alltt} %------------------------------------------------------------------------------ \subsection{USB Interrogation Utilities} %------------------------------------------------------------------------------ \subsubsection{\texttt{lsusb} - A console view of USB devices} Lsusb is a text utility contained in the usbutils package. Use 'rpm -Uvh usbutils.xxx.rpm' to install. \begin{alltt} [root@node4]\# lsusb Bus 001 Device 001: ID 0000:0000 Virtual Hub Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.00 bDeviceClass 9 Hub iProduct 2 USB UHCI Root Hub .......... Bus 001 Device 002: ID 03f0:0601 Hewlett-Packard ScanJet 6300c Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.00 bDeviceClass 0 Interface bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 8 idVendor 0x03f0 Hewlett-Packard idProduct 0x0601 ScanJet 6300c bcdDevice 1.00 iManufacturer 1 iProduct 2 HP ScanJet 6300C iSerial 3 SG9941706SPE ........ Bus 001 Device 003: ID 1189:6000 Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 1.00 bDeviceClass 0 Interface bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 8 idVendor 0x1189 idProduct 0x6000 bcdDevice a.03 iManufacturer 0 iProduct 1 USB Optical Storage Device iSerial 0 \end{alltt} %------------------------------------------------------------------------------ \subsubsection{\texttt{usbview} - An X view of USB devices} \texttt{usbview} is a GUI utility contained in the usbview package. Use \cmd{rpm -Uvh usbview.rpm} to install. \texttt{usbview} parses \texttt{/proc/bus/usb/devices} for connected USB devices. Any device that has a problem will be printed in red. \fbox{\epsfig{file=../images/usbview.eps,width=\textwidth}} %------------------------------------------------------------------------------ \subsection{Hotplugging Usb Devices} When a device is plugged into a USB port, it will automatically register itself with the USB subsystem. The upper API drivers will not however automatically 'insmod' themselves unless the hotplug package has been installed. With the hotplug package installed, an entry in /proc/sys/kernel/hotplug will be created which will contain the name of an executable to be called whenever a new device is detected on the bus. \begin{alltt} \cmd{ls /proc/sys/kernel/hotplug} /sbin/hotplug \end{alltt} For example, when a USB scanner is plugged in, hotplug will automatically load the module \texttt{scanner.o}. The \textsf{xsane} application can then be run directly without any user intervention. \begin{itemize} \item \texttt{/sbin/hotplug} is an executable which is called by the kernel (kernel space to user space interface) \item /etc/hotplug is a directory containing configuration information for hotplug (which drivers to load when a device is plugged in) \end{itemize} %============================================================================== \section{Lab} \label{sec:lab101.7} %============================================================================== \section{Questions} \label{sec:questions101.7} %****************************************************************************** %****************************************************************************** \topic{102}{Linux Installation \& Package Management} %****************************************************************************** %****************************************************************************** %############################################################################## \objective{1}{Design hard disk layout} %############################################################################## %============================================================================== \section{Overview} \label{sec:over102.} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to design a disk partitioning scheme for a Linux system. This objective includes allocating filesystems or swap space to separate partitions or disks, and tailoring the design to the intended use of the system. It also includes placing /boot on a partition that conforms with the BIOS' requirements for booting. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} / (root) filesystem /var filesystem /home filesystem swap space mount points partitions cylinder 1024 \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[Mini-FAQ from Karsten M Self on Linux Partitioning]: \begin{alltt} http://pw1.netcom.com/~kmself/Linux/FAQs/partition.html \end{alltt} \end{description} %============================================================================== \newpage \section{Notes} \label{sec:notes102.} %============================================================================== \section{Lab} \label{sec:lab102.} %============================================================================== \section{Questions} \label{sec:questions102.} %############################################################################## \objective{2}{Install a boot manager} %############################################################################## %============================================================================== \section{Overview} \label{sec:over102.2} %------------------------------------------------------------------------------ \subsection{Weight: [1]} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate should be able to select, install, and configure a boot manager. This objective includes providing alternative boot locations and backup boot options (for example, using a boot floppy). %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} /etc/lilo.conf /boot/grub/grub.conf lilo grub-install MBR superblock first stage boot loader \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[LinuxGazette GRUB Article]: \begin{alltt} http://www.linuxgazette.com/issue64/kohli.html \end{alltt} \item[The Gnu Grub Site]: \begin{alltt} http://www.gnu.org/software/grub/ \end{alltt} \end{description} %============================================================================== \newpage \section{Notes} \label{sec:notes102.2} The notes for this section are based on slides prepared by Andrew Eager. %------------------------------------------------------------------------------ \subsection{Disk Organization} %.............................................................................. \subsubsection{Disk Organization} \begin{itemize} \item A disk is organised into: \begin{itemize} \item Cylinders \item Heads \item Sectors \end{itemize} \item All sectors of Cyl 0, Head 0 are reserved: \end{itemize} Fdisk on a floppy confirms this: \begin{alltt} Disk /dev/fd0: 2 heads, 18 sectors, 80 cylinders Units = cylinders of 36 * 512 bytes Device Start End Blocks /dev/fd0p1 1 1 9 /dev/fd0p2 2 2 18 /dev/fd0p3 3 3 18 /dev/fd0p4 80 80 18 \end{alltt} Note the first partition is smaller than the rest %.............................................................................. \subsubsection{The DOS Boot Process} \begin{itemize} \item A Power On Self Test is performed. \item Control is passed to the boot device \item The first sector on disk is loaded into memory \item The MBR code is executed: \begin{itemize} \item It reads the partition table \item Looks for an active partition \item Loads the boot sector of active partition \item Executes the code in that boot sector \end{itemize} \end{itemize} %.............................................................................. \subsubsection{The Master boot record} \begin{itemize} \item The MBR is the first block (sector) on the disk \item It contains: \begin{itemize} \item Boot Code: 446 bytes \item Partition Table 64 bytes \item MBR Signature 2 bytes (0x55AA) \item TOTAL 512 bytes \end{itemize} \end{itemize} %.............................................................................. \subsubsection{The Master boot record} \begin{tabular}{r|c|} \cline{2-2} \tt 0x000 & \\ & Program code \\ & \\ & \\ \cline{2-2} \tt 0x1BE & Partition table \\ & \\ \cline{2-2} \tt 0x1FE & Magic number (0xAA55) \\ \cline{2-2} \end{tabular} %.............................................................................. \subsubsection{Boot Loaders} A boot loader is a program that is responsible for selecting the operating system to be booted. Once the desired OS is selected for boot, the boot loader must transfer control to it. Typical boot loaders are: \begin{itemize} \item The DOS boot loader. Not interactive \item LILO: An interactive boot loader \item GRUB: An interactive boot loader \item Boot Manager: An interactive boot loader \end{itemize} %------------------------------------------------------------------------------ \subsection{LILO - The Linux Loader} \begin{itemize} \item LILO is a two stage loader: \item Stage 1 is 446 bytes long \& is located in \textit{either} \begin{itemize} \item The MBR (Master boot record. Eg in /dev/hda) \textit{OR} \item The VBR (Volume boot record. Eg in /dev/hda1) \end{itemize} \item Stage 2 is a file (/boot.b) located in /boot it contains the bulk of the lilo functionality \end{itemize} %.............................................................................. \subsubsection{LILO Boot sequence---LILO in the VBR} When LILO is installed in the VBR, it is up to the MBR to transfer control to it. This is normally done by setting the partition where LILO is installed to 'active'. You would use fdisk (either dos or linux) to do this: \fbox{\epsfig{file=../images/lilo2.eps,width=0.9\textwidth}} %.............................................................................. \subsubsection{LILO and the BIOS} LILO uses the BIOS INT13 calls to read the following files: \begin{itemize} \item /boot/boot.b - The second stage loader \item /boot/map - The map file \item All kernels \item The Volume Boot sectors of all OS's it boots \item The boot message if one has been set \end{itemize} %.............................................................................. \subsubsection{Configuring LILO} LILO is entirely configured within the file /etc/lilo.conf. This file contains three areas. \begin{itemize} \item Global Options (eg signon message, delay time etc) \item General 'per operating system' options \item Linux kernel options (Linux only - eg root device, ro etc) \end{itemize} %.............................................................................. \subsubsection{Installing LILO} Once LILO has been configured, it can be installed by running \textbf{/sbin/lilo} as root from the command line. This will do the following: \begin{itemize} \item Make a backup copy of the boot sector (MBR or VBR) \item Create a /boot/map file with the locations of: \begin{itemize} \item /boot/boot.b \item The kernel \item /boot/message \item /boot/chain.b \end{itemize} \item Make a boot sector containing the location of the map file \item Write the boot sector to either the MBR or VBR. \end{itemize} %.............................................................................. \subsubsection{LILO diagnostics} When LILO runs, it prints the word 'L I L O' in the top left hand corner of the screen, one letter at a time: \begin{itemize} \item 'L' - Stage 1 loaded \& running. \item 'LI' - Stage 2 was loaded but could not run \item 'LIL' - Stage 2 was loaded but could not locate the descriptor table \item 'LIL?' - Stage 2 was loaded at an incorrect address \item 'LIL-' - Stage 2 was loaded but descriptor table is corrupt \item 'LILO' - LILO has started up correctly. \end{itemize} %------------------------------------------------------------------------------ \subsection{grub---Grand Unified Bootloader} GRUB operates in a similar manner to LILO. It is a two stage loader that can load stage 1 into either the MBR or VBR. The main differences between LILO and GRUB are: \begin{itemize} \item Stage 2 can be located beyond the 1024 cylinder limit. \item GRUB can boot from network devices using tftp \item GRUB has many more configuration options \item GRUB is effectively a mini shell and can be configured 'on-the-fly' by giving it commands directly at boot time. \end{itemize} %.............................................................................. \subsubsection{Hard Disk Naming Conventions} GRUB uses a different naming convention to that of the rest of the Linux world. In general, the syntax used is: hdN,X where: N is the hard disk number (0 for the first, 1 for the second...) X is the partition number (0 for the first, 1 for the second...) Examples: (hd0,1) refers to the 1st physical drive, 2nd primary partition (hd1,6) refers to the 2nd physical drive, 3rd logical partition (fd0) refers to the floppy drive A file within a partition can be referred to by appending a path to it: EG: (hd0,0)/boot/vmlinuz, refers to the file /boot/vmlinuz on the 1st drive, 1st partition %.............................................................................. \subsubsection{Installing GRUB} Once the configuration file has been created, there are two ways to install GRUB: Option 1: Run grub from the command line: \begin{alltt} [root@cds grub]# /sbin/grub grub> root (hd0,6) grub> setup (hd0) or; grub> setup (hd0,4) \end{alltt} %.............................................................................. \subsubsection{Installing GRUB} Option 2: Use the grub-install command: To install into the MBR: \begin{alltt} [root@cds grub]# grub-install /dev/hda \end{alltt} To install into the VBR: \begin{alltt} [root@cds grub]# grub-install /dev/hda5 \end{alltt} If you have a separate /boot partition, then you need to specify boot directory: \begin{alltt} [root@cds grub]# grub-install --root-directory=/boot /dev/hda5 \end{alltt} %------------------------------------------------------------------------------ \subsection{Sample Installation } The diagram below shows the disk layout used for the sample configuration scripts. \fbox{\epsfig{file=../images/lilo4.eps,height=3in}} %.............................................................................. \subsubsection{LILO configuration} \begin{alltt} # Global configuration options boot=/dev/hda timeout=20 message=/boot/message prompt default=linux vga=normal map=/boot/map install=/boot/boot.b # Per image options other=/dev/hda3 label=WIN98 other=/dev/hda2 label=QNX other=/dev/hda1 label=DOS image=/boot/vmlinuz label=linux root=/dev/hda7 read-only \end{alltt} %.............................................................................. \subsubsection{GRUB configuration} \begin{alltt} default=0 timeout=10 fallback=1 splashimage=(hd0,0)/boot/grub/splash.xpm.gz title RedHat 7.2 root (hd0,4) kernel /vmlinuz ro root=/dev/hda7 initrd /initrd.img title Windows root (hd0,2) makeactive chainloader +1 title QNX root (hd0,1) makeactive chainloader +1 title DOS root (hd0,0) makeactive chainloader +1 \end{alltt} %============================================================================== \section{Lab} \label{sec:lab102.2} %------------------------------------------------------------------------------ \subsection{grub entry for adding Debian} \begin{alltt} default=1 timeout=10 splashimage=(hd0,4)/grub/splash.xpm.gz title Red Hat Linux (2.4.18-3debug) root (hd0,4) kernel /vmlinuz-2.4.18-3debug ro root=/dev/hda7 initrd /initrd-2.4.18-3debug.img title Win ME rootnoverify (hd0,0) chainloader +1 title Debian root (hd0,1) kernel /boot/vmlinuz-2.2.20-idepci ro root=/dev/hda2 \end{alltt} %============================================================================== \section{Questions} \label{sec:questions102.2} %############################################################################## \objective{3}{Make and install programs from source} %############################################################################## %============================================================================== \section{Overview} \label{sec:over102.3} %------------------------------------------------------------------------------ \subsection{Weight: [5]} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to build and install an executable program from source. This objective includes being able to unpack a file of sources. Candidates should be able to make simple customisations to the Makefile, for example changing paths or adding extra include directories. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} gunzip gzip bzip2 tar configure make \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[TBA] \begin{alltt} \end{alltt} \end{description} %============================================================================== \newpage \section{Notes} \label{sec:notes102.3} %------------------------------------------------------------------------------ \subsection{Source Code Distribution} To distribute software in the form of source code a \textsf{source tree} is archived into one file using the tar command and then compressed. The resulting file is called a \textsf{tarball}. Source code may also be distributed using the package management tools of a particular distribution. \begin{description} \item[Debian] apt-get install kernel-source-2.2.27 \item[Redhat] rpm -Uhv at-3.1.8-23.src.rpm \item[Tarball] tdb-1.0.6.tar.gz \end{description} %------------------------------------------------------------------------------ subsection{Steps to Install a package from \textsf{tarball}} \begin{itemize} \item Unpack the \textsf{taball}: \begin{alltt} \cmd{tar zxvf my-prog.tar.gz} \end{alltt} \item Change directory into the source tree: \begin{alltt} \cmd{cd my-prog} \end{alltt} \item Configure the \texttt{Makefile}: \begin{alltt} \cmd{./configure} \end{alltt} \item Make: \begin{alltt} \cmd{make} \end{alltt} \item Install: \begin{alltt} \cmd{su -c 'make install'} \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsection{Installing the trivial database \texttt{tdb}} \subsubsection{Download} Locate and download the \texttt{tarball} \begin{itemize} \item \textsf{googling} for it: \texttt{http://google.com} \item search on \textsf{freshmeat}: \texttt{http://freshmeat.net} \item see if it lives on \textsf{sourceforge}: \texttt{http://www.sf.net} \end{itemize} Download the tarball to a suitable directory such as \texttt{/tmp}. \subsubsection{Unpack} The \textsf{tarball} file is a compressed archived source tree. Most commonly the file will be compressed using either \texttt{gzip} or \texttt{bzip2} \textsf{GNU} \texttt{tar} can uncompress and unpack the archive: \begin{alltt} \cmd{tar zxvf tdb-1.0.6.tar.gz} \end{alltt} or \begin{alltt} \cmd{tar jxvf tdb-1.0.6.tar.bz2} \end{alltt} \subsubsection{\texttt{cd} into the tree} The unpacked \textsf{tarball} creates a source tree. The base of which is the name of the program \begin{alltt} \cmd{ls} tdb-1.0.6 tdb-1.0.6.tar.gz \cmd{cd tdb-1.0.6} \cmd{ls} configure tdb.c tdb.h README INSTALL COPYING ... \end{alltt} \subsubsection{\texttt{cd} into the tree} \small \begin{alltt} \cmd{ls -w 70} acconfig.h install-sh stamp-h.in tdb.h aclocal.m4 ltconfig tdb.3 tdbiterate.c AUTHORS ltmain.sh tdb.c tdb_open.3 ChangeLog Makefile.am tdb_chainlock.3 tdb.spec config.guess Makefile.in tdb_close.3 tdbspeed.c config.h.in missing tdb_delete.3 tdb_store.3 config.sub mkinstalldirs tdbdump.c tdbtest.c configure NEWS tdb_error.3 tdbtool.c configure.in README tdb_exists.3 tdbtorture.c COPYING spinlock.c tdb_fetch.3 tdb_traverse.3 INSTALL spinlock.h tdb_firstkey.3 TODO \end{alltt} \subsubsection{\texttt{./configure}} \small \begin{alltt} \cmd{file configure} configure: Bourne shell script text executable \cmd{head -5 configure} #! /bin/sh # Guess values for system-dependent variables # Create Makefiles. # Generated automatically using autoconf version 2.13 \end{alltt} \subsubsection{\texttt{./configure}} \small \begin{alltt} \cmd{./configure} creating cache ./config.cache checking for a BSD compat install... /usr/bin/install -c checking whether build environment is sane... yes checking whether make sets ${MAKE}... yes checking for working aclocal... found ... creating ./config.status creating Makefile creating config.h \end{alltt} \subsubsection{The \texttt{Makefile}} \small \begin{alltt} SHELL = /bin/sh CC = gcc CFLAGS = -g -O2 prefix = /usr/local includedir = ${prefix}/include ... tdbtool: $(tdbtool_OBJECTS) $(tdbtool_DEPENDENCIES) @rm -f tdbtool $(LINK) $(tdbtool_LDFLAGS) $(tdbtool_OBJECTS) \ $(tdbtool_LDADD) $(LIBS) ... distclean: distclean-am -rm -f config.status \end{alltt} \subsubsection{\texttt{make}} \small \begin{alltt} \cmd{make} /bin/sh ./libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c tdb.c mkdir .libs gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c -fPIC -DPIC tdb.c -o .libs/tdb.lo gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c tdb.c -o tdb.o >/dev/null 2>&1 mv -f .libs/tdb.lo tdb.lo /bin/sh ./libtool --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c spinlock.c ... \end{alltt} \subsubsection{\texttt{make install}} \small \begin{alltt} su -c 'make install' Password: make[1]: Entering directory `/tmp/tdb-1.0.6' /bin/sh ./mkinstalldirs /usr/local/lib /bin/sh ./libtool --mode=install /usr/bin/install -c libtdb.la /usr/local/lib/libtdb.la ... chmod 644 /usr/local/lib/libtdb.a PATH="$PATH:/sbin" ldconfig -n /usr/local/lib \end{alltt} %------------------------------------------------------------------------------ \subsection{Play with the trivial database \texttt{tdb}} The utility \texttt{tdbtool} may be used to have a play with \texttt{tdb}. \begin{itemize} \item Start it and display the help by typing something random: \begin{alltt} \cmd{tdbtool} tdb> ? tdbtool: create dbname : create a database open dbname : open an existing database erase : erase the database dump dumpname : dump the database as strings insert key data : insert a record store key data : store a record (replace) show key : show a record by key delete key : delete a record by key list : print the database hash table and freelist free : print the database freelist 1 | first : print the first record n | next : print the next record q | quit : terminate \(\setminus\)n : repeat 'next' command tdb> \end{alltt} \item Create a database: \begin{alltt} tdb> create test.tdb \end{alltt} \item Add some data: \begin{alltt} tdb> insert 1 thing tdb> insert 2 foo tdb> insert 3 bar tdb> insert 55 whizz \end{alltt} \item Have a look at an entry: \begin{alltt} tdb> show 3 key 2 bytes 3 data 4 bytes [000] 62 61 72 00 bar \end{alltt} \item Experiment. \end{itemize} %============================================================================== \section{Lab} \label{sec:lab102.3} %============================================================================== \section{Questions} \label{sec:questions102.3} %############################################################################## \objective{4}{Manage shared libraries} %############################################################################## %============================================================================== \section{Overview} \label{sec:over102.4} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to determine the shared libraries that executable programs depend on and install them when necessary. Candidates should be able to state where system libraries are kept. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} ldd ldconfig /etc/ld.so.conf LD_LIBRARY_PATH \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[Shared-Library HOWTO] \begin{alltt} http://linuxdocs.org/HOWTOs/Program-Library-HOWTO/ \end{alltt} \end{description} %============================================================================== \newpage \section{Ken Foskey's Notes on Shared Libraries} \label{sec:notes102.4} %------------------------------------------------------------------------------ \subsection{What are they} Shared libraries are code bytes that perform useful tasks for programmers. Consider the operating system itself. It provides services to access the hard disk, the hard disk can be ext2 or reiserfs. You do not change your scripting or programming in any way. The file system and hard disk interface has been isolated from the rest of the programs. Libraries are a similar thing. There are a number of libraries, all performing some functions. For example putting text to the screen (\texttt{libncurses}), to doing complex graphics (\texttt{libpng}). Finally shared libraries reduce memory usage, only one copy of the library is needed in memory no matter how many programs use it, therefore it is very efficient. %------------------------------------------------------------------------------ \subsection{What we need to know about libraries.} From the point of view of users we need to be able to look at a program and determine whether the appropriate libraries are installed for it. Mostly package managers such as RPM and apt takes care of this but it is nice to know more detail. Especially when working with tarballs. What programs are using: Firstly when we are having problems we might want to check what the particular program is calling on, perhaps we might want to update a supporting library. Let us try on the zip command in \texttt{/usr/bin} \begin{alltt} gandalf: /usr/bin \cmd{ldd zip} libc.so.6 => /lib/libc.so.6 (0x40021000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) \end{alltt} The \texttt{ldd} command has told us that it uses \texttt{libc6} (the 'standard' c runtime libraries) and nothing else. More complex, how about the IBM mainframe terminal emulator x3270: \begin{alltt} gandalf: /usr/bin \cmd{ldd x3270} libnsl.so.1 => /lib/libnsl.so.1 (0x40021000) libutil.so.1 => /lib/libutil.so.1 (0x40035000) libXaw.so.7 => /usr/X11R6/lib/libXaw.so.7 (0x40038000) libXmu.so.6 => /usr/X11R6/lib/libXmu.so.6 (0x4008a000) libXt.so.6 => /usr/X11R6/lib/libXt.so.6 (0x4009e000) libSM.so.6 => /usr/X11R6/lib/libSM.so.6 (0x400e9000) libICE.so.6 => /usr/X11R6/lib/libICE.so.6 (0x400f1000) libXext.so.6 => /usr/X11R6/lib/libXext.so.6 (0x40107000) libX11.so.6 => /usr/X11R6/lib/libX11.so.6 (0x40114000) libc.so.6 => /lib/libc.so.6 (0x401ee000) libXpm.so.4 => /usr/X11R6/lib/libXpm.so.4 (0x4030a000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) \end{alltt} You can see that this uses a lot of X windowing libraries. \begin{alltt} ldconfig & /etc/ld.so.conf \end{alltt} Or rather the other way around. \texttt{ldconfig} creates an optimised cache of the libraries in use in the system. It is used every time a new library is installed to update all the various links. \texttt{/etc/ld.so.conf} is a file that lists directories to be scanned. there is two directories implied \texttt{/usr/lib} and \texttt{/lib} that will always be scanned. On my system it contains: \begin{alltt} /usr/X11R6/lib/Xaw3d /usr/X11R6/lib \end{alltt} The tells \texttt{ldconfig} to also scan these directories. running \texttt{ldconfig} simply returns us to the command prompt, you will notice however that the \texttt{ld.so.cache} file has been updated. If you have updated your \texttt{/etc/ld.so.conf} it is worth running \texttt{ldconfig -v} \begin{alltt} gandalf:/etc \rootcmd{ldconfig -v} ldconfig: Can't stat /usr/X11R6/lib/Xaw3d: No such file or directory /usr/X11R6/lib: libxrx.so.6 -> libxrx.so.6.3 libXtst.so.6 -> libXtst.so.6.1 \end{alltt} You will notice that the first directory listed in \texttt{ld.so.conf} was not valid and does not cause an error. Note that the order of directories is very important, the first located shared library will be used. %------------------------------------------------------------------------------ \subsection{\texttt{LD\_LIBRARY\_PATH}} Some time you need to install conflicting libraries onto your system. For example Open Office supplies all its own versions of the shared libraries so that it can perform quality control on the install. It must override the installed versions with its own. The answer is \texttt{LD\_LIBRARY\_PATH}, it makes Linux check the local path before going to the standard path. A scenario that you may use you have discovered a bug in an application but you are using a back version of shared libraries. The support people have asked you to load the most current version of a shared library however this is a production server and you do not want to upgrade everything. You grab the shared library please it in a non-standard area and then use the \texttt{LD\_LIBRARY\_PATH} to make the application find the new version first. If the bug persists then the shared libraries is not an issue, if it disappears then you can leave the \texttt{LD\_LIBRARY\_PATH} as a work around or install the library into your system properly. %------------------------------------------------------------------------------ \subsection{Extra to POMS} From my setup for Open Office: \begin{alltt} LD_PRELOAD=/usr/lib/libfreetype.so.6 \(\backslash\) /usr/local/OpenOffice.org1.0/program/swriter \end{alltt} The \texttt{LD\_PRELOAD} will override the particular library with another regardless of the \texttt{LD\_LIBRARY\_PATH} or the \texttt{ld.so.cache file}. In this case it forces Open Office to use the debian version of libfreetype instead of Open Office version because it has better font drawing that the default. Finally a bit about version numbers: Libraries all have three numbers in the versions. These numbers are: \begin{alltt} current.revision.age \end{alltt} If the age is reset to zero then you cannot use this library to replace with a previous version, if it is non-zero then it can replace a previous version. for more details see autobook section 10.4 library versioning. %============================================================================== \section{Lab} \label{sec:lab102.4} %============================================================================== \section{Questions} \label{sec:questions102.4} \begin{enumerate} \item \begin{enumerate} \item \item \item \item \item \end{enumerate} \item \begin{enumerate} \item \item \item \item \item \end{enumerate} \item Which tool is used to update the \texttt{ld.so.cache file}? \begin{enumerate} \item \texttt{ldconf} \item \texttt{ldconfig} \item \texttt{ldcache} \item \texttt{ldd} \item \texttt{ldupdate} \end{enumerate} \item \begin{enumerate} \item \item \item \item \item \end{enumerate}\end{enumerate} %############################################################################## \objective{5}{Use Debian package management} %############################################################################## \normalsize %============================================================================== \section{Overview} \label{sec:over102.5} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to perform Debian package management.This objective includes being able to use command-line and interactive tools to install, upgrade, or uninstall packages, as well as find packages containing specific files or software (such packages might or might not be installed). This objective also includes being able to obtain package information like version, content, dependencies, package integrity and installation status (whether or not the package is installed). %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} /etc/dpkg/dpkg.cfg /var/lib/dpkg/* /etc/apt/apt.conf /etc/apt/sources.list dpkg dselect dpkg-reconfigure apt-get alien \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[The Debian GNU/Linux FAQ]: \begin{alltt} http://www.debian.org/doc/FAQ/index.html \end{alltt} \item[Quick Reference for Debian GNU/Linux]: \begin{alltt} http://qref.sourceforge.net/ \end{alltt} \item[lcdp slides]: \begin{alltt} gl1.102.5.slides.tex \end{alltt} \end{description} %============================================================================== %\newpage \section{Notes} \label{sec:notes102.5} These notes are based on a presentation given by Jeff Waugh. %% Adapted from a set of slides prepared by Jeff Waugh %------------------------------------------------------------------------------ \subsection{Debian Package Management Overview} \label{sec:deb-overview} The main Debian Package Management tools are: \begin{itemize} \item Basic tool---\texttt{dpkg} \begin{quote} \texttt{dpkg} is the back end for all Debian package management. \end{quote} \item Old Menu System---\texttt{dselect} \begin{quote} \texttt{ncurses} menu system for \texttt{dselect}---bizarre interface. \end{quote} \item The Ultimate Package Tool---\texttt{apt-get} \begin{quote} ``Once you've been spoiled by the apt thing you just can't go back.'' \end{quote} \end{itemize} %------------------------------------------------------------------------------ \subsection{Debian Package Management Tool---\texttt{dpkg}} \label{sec:dpkg} \texttt{dpkg} does basic package management: installation, removal, extraction and building. Does not handle or fulfil dependencies, that's left for higher level software such as apt. %.............................................................................. \subsubsection{\texttt{dpkg} Tasks} \begin{itemize} \item Install a package: \texttt{dpkg -i } \item Remove a package: \texttt{dpkg -r } \item Purge a package: \texttt{dpkg -P } \item Find out which files a package owns: \texttt{dpkg -L } \item Find out which package a file belongs to: \texttt{dpkg -S } \item Extract information from package: \texttt{dpkg -e } \item List contents of package file: \texttt{dpkg -c } \end{itemize} %.............................................................................. \subsubsection{\texttt{/etc/dpkg/dpkg.cfg}} \begin{itemize} \item Configuration file for dpkg(1) \item Each line contains a single option which is exactly the same as a normal command line option for dpkg except for the leading dashes. Hashes for comments. \item See 'man dpkg' or 'dpkg --help' for commands. \item Example: \begin{alltt} # dpkg configuration file # # This file can contain default options for dpkg. # All command line options are allowed. Values can # be specific by putting them after the option, # separated by whitespace and/or an `=' sign. # no-debsig abort-after 2 no-act \end{alltt} \end{itemize} %.............................................................................. \subsubsection{\texttt{/var/lib/dpkg/*}} \begin{itemize} \item Package management status and system files, generally not directly manipulated. \item Most important files: \begin{description} \item [alternatives:] Contains files that define and store configuration for the command alternatives on the system. (Good examples: editor and x-window-manager.) \item [available:] Information about packages available to the system, retrieved from every specified sources. (See also: grep-available.) \item [status:] Information about packages installed on, or removed from your system. \end{description} \end{itemize} %------------------------------------------------------------------------------ \subsection{Debian Package Mgt. Utility---\texttt{apt-get}} %.............................................................................. \subsubsection{\texttt{/etc/apt/apt.conf}} \begin{itemize} \item Configuration files for \texttt{apt(1)}. \item \texttt{apt.conf} used by administrator for unique system configurations. \item Example: Setting apt's HTTP proxy: \begin{alltt} Acquire::http "http://192.168.10.1/"; \end{alltt} \item \texttt{apt.conf.d} managed by software that integrates with apt, such as our examples: \texttt{dpkg-reconfigure} and \texttt{apt-listchanges}. \item See '\texttt{man apt.conf}' for configuration directives and format. \item \texttt{apt-config(1)} is useful for troubleshooting \texttt{apt.conf} problems. \end{itemize} %.............................................................................. \subsubsection{\texttt{/etc/apt/sources.list}} \begin{itemize} \item Administrator-configured list of package repositories used by apt. \item Numerous retrieval methods: file, cdrom, http, ftp, copy, rsh and ssh. \item Many repositories exist for developers, specific software, other distributions, etc. \item Example: \scriptsize \begin{alltt} deb http://mirror.aarnet.edu.au/debian woody main contrib non-free deb file:/mnt/devserver/packages woody main contrib non-free deb http://user:pass@example.com/path distro section section deb ssh://user@example.com/path distro section section \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsection{Debian Package Mgt. Utility---\texttt{deselect}} \begin{itemize} \item Hideous! Ugh! Run for your lives! \item Original frontend to apt/dpkg. \item Subject of many jokes: \begin{quote} ''All package managers feature creep until they're as complicated and horrible as dselect.'' \end{quote} \begin{quote} ''Debian's extensive features provide not only to ability shoot yourself in the foot, but to blow off each toe individually.'' \end{quote} \item Offers more help than apt-get, but is incredibly baroque and hard to use. \end{itemize} %------------------------------------------------------------------------------ \subsection{Debian Package Conversion Utility---\texttt{alien}} %\slidesubheading{\texttt{alien}} \begin{description} \item[Theory]: \begin{quote} ''alien is a program that converts between Redhat rpm, Debian deb, Stampede slp, Slackware tgz, and Solaris pkg file formats. If you want to use a package from another Linux distribution than the one you have installed on your system, you can use alien to convert it to your preferred package format and install it. It also supports LSB packages.'' \end{quote} \item[Reality]: \begin{itemize} \item You are completely bat shit insane, and/or, \item You are using proprietary software. \end{itemize} \end{description} Useful for quick stuff, or pulling apart RPMs and SRPMs without too much hassle. %============================================================================== \section{Lab} \label{sec:lab102.5} %------------------------------------------------------------------------------ \subsection{Exploring \texttt{dkpg}} \label{sec:lab102.5-dpkg} \begin{enumerate} \item List \texttt{/var/lib/dpkg}: \begin{alltt} \cmd{ls /var/lib/dpkg} \end{alltt} \item Have a look at the alternatives directory: \begin{alltt} \cmd{ls /var/lib/dpkg/alternatives} \end{alltt} \item Have a look at an alternative file: \begin{alltt} \cmd{cat /var/lib/dpkg/alternatives/vi} auto /usr/bin/vi vi.1.gz /usr/share/man/man1/vi.1.gz /usr/bin/nvi 30 /usr/share/man/man1/nvi.1.gz /usr/bin/vile 20 /usr/share/man/man1/vile.1.gz /usr/bin/vim 120 /usr/share/man/man1/vim.1.gz /bin/elvis-tiny 10 /usr/share/man/man1/elvis-tiny.1.gz \end{alltt} \item View the \texttt{dpkg} configuration file: \begin{alltt} \cmd{cat /etc/dpkg/dpkg.cfg} \end{alltt} \item Inspect the list of packages available: \begin{alltt} \cmd{less /var/lib/dpkg/available} \end{alltt} \item Look at the package status list: \begin{alltt} \cmd{less /var/lib/dpkg/status} \end{alltt} \end{enumerate} %------------------------------------------------------------------------------ \subsection{Using dkpg} \label{sec:lab102.5-dpkg} Download a few debs to your \texttt{/tmp}: \begin{alltt} \cmd{cd /tmp} \cmd{scp student@foozle:/mnt/floppy/*.deb .} \cmd{ls *.deb} \end{alltt} \begin{enumerate} \item Obtain a debian package and install it: \begin{alltt} \rootcmd{dpkg -i junior-doc_1.15_all.deb} \end{alltt} Note that this package has no dependencies. \item Try to install a package with unmet dependencies: \begin{alltt} \rootcmd{dpkg -i junior-typing_1.1_all.deb} \end{alltt} Note that this install was unsuccessful. \item Check which files a debian package owns: \begin{alltt} \cmd{dpkg -L junior-doc} ... \end{alltt} \item Find out which package a file belongs to: \begin{alltt} \cmd{dpkg -S /usr/share/doc/junior-doc/quickguide} junior-doc: /usr/share/doc/junior-doc/quickguide \end{alltt} \item Extract information from the package: \begin{alltt} \cmd{dpkg -e junior-doc_1.15_all.deb} \end{alltt} \item List the contents of a package: \begin{alltt} \cmd{dpkg -c junior-doc_1.15_all.deb} \end{alltt} \item Remove the package: (Note that -P would purge any configuration files) \begin{alltt} \rootcmd{dpkg -r junior-doc} \end{alltt} \end{enumerate} %------------------------------------------------------------------------------ \subsection{Using the \texttt{apt} package management tool} \label{sec:lab102.5-apt} % NFS mount a Debian cd: % \begin{alltt} % \rootcmd{mkdir /nfs/woody/cd1} % \rootcmd{mount foozle:/export/woody/cd1/ /nfs/woody/cd1} % \end{alltt} \begin{enumerate} \item Update your \texttt{/etc/apt/sources.list} with any CDROMs that you can mount locally. You can use \texttt{apt-cdrom} to do this for you. \begin{alltt} \rootcmd{apt-cdrom add -d /mnt/cdrom} \end{alltt} \item Edit your \texttt{sources.list}: \begin{alltt} \rootcmd{vi /etc/apt/sources.list} \end{alltt} \begin{enumerate} \item Identify any lines you added using \texttt{apt-cdrom}. \item ``Hash out'' any sources that don't currently exist on your system by adding a ``\texttt{\#}'' at the beginning of the line. \item Add any sources that you do have available: \begin{enumerate} \item For locally mounted CDROMS images: \begin{alltt} deb file:/nfs/woody/cd1 woody main \end{alltt} \item For sources available over HTTP locally: \begin{alltt} deb http://192.168.222.254/debian woody main contrib non-free \end{alltt} \item For sources available over HTTP on the Internet: \begin{alltt} deb http://http.us.debian.org/debian woody main contrib non-free \end{alltt} \end{enumerate} \end{enumerate} \item Do an update for \textsf{apt}: \begin{alltt} \rootcmd{apt-get update} \end{alltt} \item Search for a package you might want to install: \begin{alltt} \cmd{apt-cache search junior} \end{alltt} \item View the information about your chosen packege: \begin{alltt} \cmd{apt-cache show junior-typing} \end{alltt} \item Download and install the package and it's dependencies: \begin{alltt} \rootcmd{apt-get install junior-typing} \end{alltt} \end{enumerate} \newpage %============================================================================== \section{Questions} \label{sec:questions102.5} \begin{enumerate} \item Which apt-get parameter updates the database of available packages? \begin{enumerate} \item renew \item upgrade \item update \item reload \item refresh \end{enumerate} \item Which one of the following tools is used to convert packages from one system to another? \begin{enumerate} \item \texttt{alien} \item \texttt{dpkg} \item \texttt{apt} \item \texttt{pkg\_convert} \item \texttt{rpm2deb} \end{enumerate} \item Which tool provides a high-level user friendly interface to Debian package management? \begin{enumerate} \item \texttt{dselect} \item \texttt{apt-get} \item \texttt{dpkg} \item \texttt{kdedpkg} \item \texttt{gnodpkg} \end{enumerate}%(b) \item Which of the following package formats is supported by the \texttt{alien} utility? Select all that apply. \begin{enumerate} \item \texttt{.deb} \item \texttt{.bsd} \item \texttt{.rpm} \item \texttt{.tgz} \item \texttt{.zip} \end{enumerate}%(a), (c), (d) \item Which of the following sources may be not used by the apt-get utility? \begin{enumerate} \item NFS \item IRC \item FTP \item HTTP \item CD-ROM \end{enumerate} \item Which one of these commands removes a Debian package, including its configuration files? \begin{enumerate} \item \texttt{dpkg --remove } \item \texttt{apt-get purge } \item \texttt{dpkg -P } \item \texttt{apt-remove config } \item \texttt{dpkg -e } \end{enumerate} \item Which one of these commands will convert an RPM package to Debian format? \begin{enumerate} \item alien -d package.rpm \item alien -c package \item alien -r package.rpm \item alien -t package.rpm \item alien -d package.deb \end{enumerate} \item A Debian package may be installed with: \begin{enumerate} \item \texttt{dpkg -i } \item \texttt{rpm -i } \item \texttt{apt --install } \item \texttt{rpm --deb } \item \texttt{apt-get -I } \end{enumerate} \end{enumerate} %############################################################################## \objective{6}{Use Red Hat Package Manager (RPM)} %############################################################################## %============================================================================== \section{Overview} \label{sec:over102.6} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to perform package management under Linux distributions that use RPMs for package distribution. This objective includes being able to install, re-install, upgrade, and remove packages, as well as obtain status and version information on packages. This objective also includes obtaining package information such as version, status, dependencies, integrity, and signatures. Candidates should be able to determine what files a package provides, as well as find which package a specific file comes from. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} /etc/rpmrc /usr/lib/rpm/* \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[TBA] \begin{alltt} \end{alltt} \end{description} %============================================================================== \newpage \section{Notes} \label{sec:notes102.6} %.............................................................................. \subsubsection{RPM - RedHat Package Manager} \begin{itemize} \item RPM works with RedHat, Suse \& Mandrake (among others) and can do the following: \begin{itemize} \item Build an RPM package \item Install an RPM package \item Update an already installed RPM package \item Query an RPM package \item Erase an RPM package \item Verify an RPM package. \end{itemize} \end{itemize} %.............................................................................. \subsubsection{RPM Packages} RPM package files consist of a single compressed file much like a tarball. Package files can be sourced from: \begin{itemize} \item Local media (hard disk, cdrom etc) \item An ftp site \item An http site \end{itemize} Packages sourced from local media are specified using just their filename. For example: \begin{itemize} \item \texttt{acroread-4.05-1.i686.rpm} \end{itemize} Packages sourced from ftp or http sites are specified using the following syntax: \begin{itemize} \item \texttt{ftp://USER:PASSWORD@HOST:PORT/path/to/package.rpm} \end{itemize} %.............................................................................. \subsubsection{RPM Filenames} RPM Filenames use a standard naming scheme: \textit{package-version-patch.arch.rpm} package - The name of the package version - The version number patch - patch number of this package arch - The architecture this package is for (i386, i586, i686, alpha, sparc) Example: \begin{alltt} kernel-2.4.9-21.i686.rpm \end{alltt} %------------------------------------------------------------------------------ \subsection{RPM Operating Modes} RPM operations are split up into 4 major modes: \begin{itemize} \item Querying \& Verifying \item Installing, Upgrading or Removing \item Building Packages \item RPM database administration functions \end{itemize} %.............................................................................. \subsubsection{Verifying package Integrity} Having downloaded an rpm from the Internet, the \underline{very first} thing you want to do is verify its integrity. You do this with the -K or --checksig option to rpm: \begin{alltt} \rootcmd{rpm -K kernel-2.4.9-31.i586.rpm} kernel-2.4.9-31.i586.rpm: md5 gpg OK \end{alltt} NOTE: Some packages use PGP to check integrity while others use GnuPG. %.............................................................................. \subsection{Installing, Upgrading \& Removing} Understanding the RPM terminology in relation to Installing, upgrading \& removing rpm packages is essential: \begin{itemize} \item Install - Install a package. Good for Kernels \item Upgrade - Upgrade a package if it's installed, otherwise install the package \item Freshen - Upgrade a package only if it's already installed. \item Erase - Remove a package. \end{itemize} %.............................................................................. \subsubsection{Installing, Upgrading \& Removing - Options} The table below summarises the various options used for package installation, freshening and removal. \begin{tabular}{|c|c|c|} \hline \textbf{{Mode}}& \textbf{{Short option}}& \textbf{{Long option}}\\ \hline \hline Install& \texttt{-i}& \texttt{--install}\\ \hline Upgrade& \texttt{-U}& \texttt{--upgrade}\\ \hline Freshen& \texttt{-F}& \texttt{--freshen}\\ \hline Erase& -e& --erase\\ \hline \end{tabular} %.............................................................................. \subsubsection{Using RPM on the command line} Generally you use rpm in one of the following modes: \begin{itemize} \item \texttt{rpm -i {[}install options{]} package\_file ...} \item \texttt{rpm -U {[}install-options{]} package\_file ...} \item \texttt{rpm -F {[}install-options{]} package\_file ...} \item \texttt{rpm -e {[}erase-options{]} package\_name ...} \end{itemize} Commonly used options are: \begin{description} \item [\opt{-v}] verbose \item [\opt{-h}] print progress hash marks \item [\opt{--force}] Force RPM to overwrite existing packages or files \item [\opt{--nodeps}] Bypass dependency checking \item [\opt{--replacefiles}] Overwrite files owned by other packages \end{description} %.............................................................................. \subsubsection{Example - install option} Install kernel-2.4.18-4 without removing the existing kernel: \begin{alltt} # rpm -q kernel kernel-2.4.9-21 # rpm -ivh kernel-2.4.18-4*.rpm Preparing... ########################### [100%] 1:kernel-2.4.18-4 ########################### [100%] # rpm -q kernel kernel-2.4.18-4 kernel-2.4.9-21 # \end{alltt} %.............................................................................. \subsubsection{Example - Freshen option} Upgrade the existing kernel to kernel-2.4.18-4. % Oh, no! Exactly the one single package you do not want to update. % The example does not match the heading. % Oh, save us all and fix this! \begin{alltt} # rpm -q kernel kernel-2.4.9-21 # rpm -Uvh kernel-2.4.18-4*.rpm Preparing... ########################### [100%] 1:kernel-2.4.18-4 ########################### [100%] # rpm -q kernel kernel-2.4.18-4 # \end{alltt} %.............................................................................. \subsubsection{Example - Upgrade option:} What the upgrade option does will depend on whether or not the package is currently installed. If installed, it will perform a freshen, otherwise it will perform an install: \begin{alltt} # rpm -q gocr package gocr is not installed # rpm -Uvh gocr-0.3.4-1.i386.rpm Preparing... ########################### [100%] 1:gocr-0.3.4-1.rpm ########################### [100%] # rpm -q gocr gocr-0.3.4-1 # rpm -Uvh gocr-0.3.6-1.i386.rpm Preparing... ########################### [100%] 1:gocr-0.3.6-1.rpm ########################### [100%] # rpm -q gocr gocr-0.3.6-1 \end{alltt} %.............................................................................. \subsubsection{Example - Erase option} Remove the package gocr from the system \begin{alltt} # rpm -q gocr gocr-0.3.6-1 # rpm -e gocr # rpm -q gocr # \end{alltt} %.............................................................................. \subsubsection{Querying Packages} RPM can be used to query a package (either installed or not). \begin{alltt} rpm {-q|--query} [select-options] [query-options] \end{alltt} \begin{description} \item [Select options]: Choose what it is you want to query \begin{description} \item [\opt{-a}] Query all installed packages. \item [\opt{-f}] Query package owning FILE. \item [\opt{-p}] Query an (uninstalled) package file \end{description} \item [Query options]: Choose what it is you want to see from the query: \begin{description} \item [\opt{-i}] Show all information about the package \item [\opt{-l}] Show what files are contained in the package \item [\opt{-R}] List packages on which this package depends \end{description} \end{description} %.............................................................................. \subsubsection{Query - Example} Give a list of all packages with kern in their name: \begin{alltt} \$ rpm -qa | grep kern kernelcfg-0.5-5 glibc-kernheaders-2.4-7.14 kernel-2.4.9-21 kernel-source-2.4.18-4 \end{alltt} Show a list of all files in kernel-2.4.9-21 \begin{alltt} \$ rpm -ql kernel-2.4.9-21 /boot/System.map-2.4.9-21 /boot/module-info-2.4.9-21 /boot/vmlinuz-2.4.9-21 .... \end{alltt} Show package which owns /bin/ls: \begin{alltt} \$ rpm -qf /bin/ls \$ fileutils-4.1-10 \end{alltt} %.............................................................................. \subsubsection{Show complete information about the fileutils package:} \begin{alltt} \$ rpm -qi fileutils Name : fileutils Relocations: (not relocateable) Version : 4.1 Vendor: Red Hat, Inc. Release : 10 Build Date: Mon 25 Mar 2002 12:23:22 PM EST Install date: Fri 24 May 2002 02:18:08 PM EST Build Host: daffy.perf.redhat.com Group : Applications/File Source RPM: fileutils-4.1-10.src.rpm Size : 1679468 License: GPL Packager : Red Hat, Inc. Summary : The GNU versions of common file management utilities. Description : The fileutils package includes a number of GNU versions of common and popular file management utilities. Fileutils includes the following tools: chgrp (changes a file's group ownership), chown (changes a file's ownership), chmod (changes a file's permissions), cp (copies files), dd (copies and converts files), df (shows a filesystem's disk usage), dir (gives a brief directory listing), dircolors (the setup program for the color version of the ls command), du (shows disk usage), install (copies files and sets permissions), ln (creates file links), ls (lists directory contents), mkdir (creates directories), mkfifo (creates FIFOs or named pipes), mknod (creates special files), mv (renames files), rm (removes/deletes files), rmdir (removes empty directories), sync (synchronizes memory and disk), touch (changes file timestamps), and vdir (provides long directory listings). \end{alltt} %.............................................................................. \subsubsection{Verifying package files} This option to rpm is used to verify the \underline{files installed} on the system with those from the rpm package file. This is not to be confused with the \textit{integrity} of the package file. The following table lists the characteristics verified: \begin{description} \item [\opt{5}] - The MD5 checksum \item [\opt{S}] - The file size \item [\opt{L}] - Symbolic link \item [\opt{T}] - Modification time \item [\opt{D}] - Device major \& minor number \item [\opt{U}] - User owner \item [\opt{G}] - Group owner \item [\opt{M}] - Permission and/or file type \end{description} %.............................................................................. \subsubsection{Example - Verify package} \begin{alltt} \$ rpm -V setup S.5....T c /etc/bashrc S.5....T c /etc/csh.cshrc S.5....T c /etc/csh.login S.5....T c /etc/host.conf S.5....T c /etc/printcap S.5....T c /etc/profile ..?..... c /etc/securetty .M...... c /etc/shadow \end{alltt} \newpage %============================================================================== \section{Lab} \label{sec:lab102.6} \normalsize Before you begin these exercises, you will need access to the RedHat installation disks or alternatively to an nfs exported copy of these. To mount an nfs copy of these disks, type the following as root: \begin{alltt} \rootcmd{mount foozle:/export/rh73 /nfs/rh73} \end{alltt} Before proceeding the GPG key will have to be imported: \begin{alltt} \rootcmd{gpg --import /nfs/rh73/RPM-GPG-KEY} \end{alltt} Now you can access the RPM directory which contains the complete set of RPM's that came with the RedHat 7.3 distribution CD's: \begin{alltt} \rootcmd{cd /nfs/rh73/RedHat/RPMS} \end{alltt} \subsubsection{Exercises:} \begin{enumerate} \item Have a look at all the packages starting with 'kernel'. Check the integrity of the following two kernel packages. Which one is NOT OK. \begin{alltt} kernel-2.4.18-4.i386.rpm kernel-4.4.18-4.i386.rpm \end{alltt} \item List all packages installed on the system that start with 'kernel'. \item Install the package \texttt{kernel-2.4.18-4}. Once you have done this, repeat step 2 above to confirm that you now have two kernels on your system. \item Now remove the package \texttt{kernel-2.4.18-4}. (Make doubly sure that you specify the kernel version/patch level when removing) \item List the files contained in the kernel package. \item Using the -i option, install the package \texttt{fetchmail-5.9.0-5.i386.rpm}. \item Query which version of fetchmail is installed \item Using the \texttt{-F} option, upgrade the fetchmail package to \texttt{fetchmail-5.9.0-11.i386.rpm} \item Remove the fetchmail package. \item Repeat exercises 6 to 8 above using the \texttt{-U} option to install and upgrade. \item What does the procps package do? What files are contained in the procps package \item What package contains the \texttt{/sbin/fdisk} binary? \item Verify the following packages and explain what has changed in each case: - setup - procps \end{enumerate} \newpage %============================================================================== \section{Questions} \label{sec:questions102.6} \begin{enumerate} \item Which packaging system is used by Red Hat Mandrake and SuSE? \begin{enumerate} \item tgz \item rhi \item rpm \item alien \item deb \end{enumerate} \item If you suspect that the rpm database is corrupted, which of the following might fix it? \begin{enumerate} \item rpm --rebuilddb %correct \item rpm --regendb \item rpm --fixdb \item rpm --unbugger \item rpm --updated \end{enumerate} \item Which methods does RPM support to check package integrity? (Select all that apply.) \begin{enumerate} \item MD5 %correct \item 5DES \item CRC \item PGP %correct \item GnuPG %correct \end{enumerate} \item Which command(s) is/are used to remove an RPM package? \begin{enumerate} \item rpm --remove \item rpm -e %correct \item rpm --uninstall %correct \item rpm -u \item rpm -U \end{enumerate} \item \begin{enumerate} \item \item \item \item \item \end{enumerate} \item \begin{enumerate} \item \item \item \item \item \end{enumerate} \item \begin{enumerate} \item \item \item \item \item \end{enumerate} \item \begin{enumerate} \item \item \item \item \item \end{enumerate} \item \end{enumerate} %****************************************************************************** %****************************************************************************** \topic{103}{GNU \& Unix Commands} %****************************************************************************** %****************************************************************************** % \begin{itemize} % \item {Work on the command line [4]} % \item {Process text streams using filters [7]} % \item {Perform basic file management [2]} % \item {Use streams, pipes, and redirects [3]} % \item {Create, monitor, and kill processes [7]} % \item {Modify process execution priorities [2]} % \item {Search text files using regular expressions [3]} % \item {Perform basic file editing using vi [2]} % \end{itemize} %############################################################################## \objective{1}{Work on the command line} %############################################################################## %============================================================================== \section{Overview} \label{sec:over103.1} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate should be able to Interact with shells and commands using the command line. This includes typing valid commands and command sequences, defining, referencing and exporting environment variables, using command history and editing facilities, invoking commands in the path and outside the path, using command substitution, applying commands recursively through a directory tree and using man to find out about commands. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} . bash echo env exec export man pwd set unset ~/.bash_history ~/.profile \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes103.1} %============================================================================== \section{Lab} \label{sec:lab103.1} %============================================================================== \section{Questions} \label{sec:questions103.1} %############################################################################## \objective{2}{Process text streams using filters} %############################################################################## %============================================================================== \section{Overview} \label{sec:over103.} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate should be able to apply filters to text streams. Tasks include sending text files and output streams through text utility filters to modify the output, and using standard UNIX commands found in the GNU textutils package. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} cat cut expand fmt head join nl od paste pr sed sort split tac tail tr unexpand uniq wc \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes103.} %============================================================================== \section{Lab} \label{sec:lab103.2} %------------------------------------------------------------------------------ \subsection{Text Filter Exercise} \label{sec:filter exercise} %.............................................................................. \subsubsection{First catch some text} Locate a section of text to practice filtering through various filters. For example save the last 12 lines of the GPL license in a temporary file. Edit the file with \texttt{vi} and add some tabs and some extra blank lines. Also duplicate a few lines. Add some carriage returns to the ends of a few lines (in vi do this in edit mode with a Cntl-v Cntl-m. They should show up as \textasciicircum{}Ms in vi). \begin{alltt} \$ locate gpl-lic /usr/share/doc/HTML/en/common/gpl-license ... \$ tail -12 /usr/share/doc/HTML/en/common/gpl-license > \ /tmp/some.txt \$ cd /tmp \end{alltt} %.............................................................................. \subsubsection{The file \texttt{some.txt}} {\scriptsize \begin{alltt} Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989^M Ty Coon, President of Vice^M This General Public License does not permit incorporating your program into This General Public License does not permit incorporating your program into This General Public License does not permit incorporating your program into This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. \end{alltt} } %.............................................................................. \subsubsection{\texttt{cat} the file} Have a look at the man page for \texttt{cat}. \begin{itemize} \item Plain \texttt{cat} the file: \begin{alltt} \$ cat some.txt \end{alltt} \item \texttt{cat} the file with all lines numbered: \begin{alltt} \$ cat -n some.txt \end{alltt} \item \texttt{cat} the file with non-blank lines numbered: \begin{alltt} \$ cat -b some.txt \end{alltt} \item Check to see if there are any non printing characters: \begin{alltt} \$ cat -v some.txt ... , 1 April 1989^M ... \end{alltt}% \item Display any tabs: \begin{alltt} \$ cat -T some.txt ... Ty Coon, ^IPresident ^Iof ^IVice ... \end{alltt} \item Do a \texttt{-vET} all at once: \begin{alltt} \$ cat -A some.txt ... , 1 April 1989^M$ Ty Coon, ^IPresident ^Iof ^IVice^M$ ... \end{alltt} \item Strip out surplus blank lines: \begin{alltt} \$ cat -s some.txt \end{alltt} \end{itemize} %.............................................................................. \subsubsection{\texttt{tac} the file} Have a look at the man page for \texttt{tac}. Try it out. %.............................................................................. \subsubsection{Remove duplicate lines with \texttt{uniq}} Have a look at the man page for \texttt{uniq}. \begin{itemize} \item Plain \texttt{uniq} \begin{alltt} \$ uniq some.txt \end{alltt} \item Show the repetition count: \begin{alltt} \$ uniq -c some.txt \end{alltt} \item Print only the repeated lines: \begin{alltt} \$ uniq -dc some.txt \end{alltt} \end{itemize} %.............................................................................. \subsubsection{Print lines from the beginning of a file with \texttt{head}} Have a look at the man page for \texttt{head}. Try it out on \texttt{gpl-license}. %.............................................................................. \subsubsection{Print lines from the end of a file with \texttt{tail}} Have a look at the man page for \texttt{tail}. \begin{itemize} \item Try it out on \texttt{gpl-license}. \item Try the follow option: \begin{alltt} \$ tail -f /var/log/messages \end{alltt} Create a message in another console to see it work. \end{itemize} %.............................................................................. \subsubsection{Isolate fields with \texttt{cut}} Have a look at the man page for \texttt{cut}. \begin{itemize} \item Use cut to display only the \textsf{gecos} field and the shell field of the \texttt{passwd} file: \begin{alltt} \$ cut -d ":" -f5,7 /etc/passwd \end{alltt} \end{itemize} %.............................................................................. \subsubsection{Format the text with \texttt{fmt}} Have a look at the man page for \texttt{fmt}. \begin{alltt} \$ fmt -w 50 some.txt \$ fmt -t -w 60 some.txt \end{alltt} %.............................................................................. \subsubsection{merge lines of files using \texttt{paste}} Have a look at the man page for \texttt{paste}. Create two files and merge them. \begin{alltt} \$ cat > first one two three four ^D \$ cat > second this that these and those \$ paste first second \end{alltt} %============================================================================== \section{Questions} \label{sec:questions103.2} %############################################################################## \objective{3}{Perform basic file management} %############################################################################## %============================================================================== \section{Overview} \label{sec:over103.3} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate should be able to use the basic UNIX commands to copy, move, and remove files and directories. Tasks include advanced file management operations such as copying multiple files recursively, removing directories recursively, and moving files that meet a wildcard pattern. This includes using simple and advanced wildcard specifications to refer to files, as well as using find to locate and act on files based on type, size, or time. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} cp find mkdir mv ls rm rmdir touch file globbing \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes103.3} %============================================================================== \section{Lab} \label{sec:lab103.3} %============================================================================== \section{Questions} \label{sec:questions103.3} %############################################################################## \objective{4}{Use streams, pipes, and redirects} %############################################################################## %============================================================================== \section{Overview} \label{sec:over103.4} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate should be able to redirect streams and connect them in order to efficiently process textual data. Tasks include redirecting standard input, standard output, and standard error, piping the output of one command to the input of another command, using the output of one command as arguments to another command and sending output to both stdout and a file. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} tee xargs < << > >> | `` \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes103.4} %============================================================================== \section{Lab} \label{sec:lab103.4} %============================================================================== \section{Questions} \label{sec:questions103.4} %############################################################################## \objective{5}{Create, monitor, and kill processes} %############################################################################## %============================================================================== \section{Overview} \label{sec:over103.5} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate should be able to manage processes. This includes knowing how to run jobs in the foreground and background, bring a job from the background to the foreground and vice versa, start a process that will run without being connected to a terminal and signal a program to continue running after logout. Tasks also include monitoring active processes, selecting and sorting processes for display, sending signals to processes, killing processes and identifying and killing X applications that did not terminate after the X session closed. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} & bg fg jobs kill nohup ps top \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes103.5} %------------------------------------------------------------------------------ \subsection{Processes} \begin{itemize} \item A process is an executable loaded in memory. \item Linux is a multitasking operating system and so runs many processes concurrently. \item INIT (PID 1) is the mother of all processes. \item Programms, daemons, shells and commands are all processes. \item The kernel automatically manages processes. \item Normally processes live, execute and die without intervention from users. \end{itemize} %------------------------------------------------------------------------------ \subsection{Process Attributes and Concepts} The kernel starts the first process: \texttt{init} which has \textsf{PID 1} \begin{description} \item[Lifetime:] Each process starts when it's command is executed, and lives till it dies or is killed. \item[Process ID (PID):] Every process has a unique number assigned to it when it is started. \item[User ID and Group ID:] Processes have the privileges associated with the user / group who started them. \item[Parent processes (PPID):] Shell processes are descendants of \textsf{init} and commands run from them are child processes. \item[Environment:] Each process inherits a set of \textit{environmental variables} from it's parent process. \item[Current Working Directory:] Each process starts with a default directory. \end{description} %------------------------------------------------------------------------------ \subsection{Process Monitoring} Processes have to be monitored so as to check their health and use of system resources. \begin{itemize} \item ps \small \begin{alltt} \$ ps aux |grep ssh root 866 0.0 0.3 2676 1268 ? S 07:56 0:00 /usr/sbin/sshd \end{alltt} \item pstree \small \begin{alltt} \$ pstree init-+-alarmd |-apmd |-kdeinit-+-autorun | |-kdeinit---emacs \end{alltt} \item top \small \begin{alltt} \$ top PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND 1792 geoffrey 11 0 8796 8796 7932 S 0.3 2.2 0:01 kdeinit 1590 root 14 0 57512 13M 2572 R 0.1 3.6 0:41 X 2857 geoffrey 14 0 1056 1056 836 R 0.1 0.2 0:01 top \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsection{Process Management} Normally the kernel automatically manages processes. However sometimes processes have to be started, stopped, restarted and killed. \begin{itemize} \item Starting a process: \small \begin{alltt} \# /usr/sbin/httpd ps aux |grep httpd root 2987 0.0 0.4 4512 1584 ? /usr/sbin/httpd apache 3003 0.0 0.4 4656 1672 ? /usr/sbin/httpd \end{alltt} \item Occasionally processes die and have to be restarted. \item Processes may go berserk and have to be killed.\small \begin{alltt} \# kill -9 1234 \end{alltt} \item After configuration changes processes may have to be restarted so as to re-read their configuration files.\small \begin{alltt} \# service xinetd restart Stopping xinetd: [ OK ] Starting xinetd: [ OK ] \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsection{What is multitasking?} Multitasking is used to describe the situation where one processor (CPU) is used to perform multiple tasks concurrently. \begin{itemize} \item Only one task or program is executing instructions on the CPU. \item The CPU must be regularly switched between each program and others. \item This process is known as a \textit{task switch}. \item At each \textit{task switch} the Linux kernel must save the \textit{context} of the CPU. \item The operating system uses the saved context when it switches back to the task the next time it gets some CPU time scheduled to it. \end{itemize} %------------------------------------------------------------------------------ \subsection{Task Scheduling} The total number of slices, when, how often and for how long the CPU is switched is determined by the multitasking algorithm and is handled by a software component within the kernel know as the \textit{task scheduler}. There are three basic types of task scheduling: \begin{description} \item[Nonpreemptive:] A task must relinquish the CPU before a task switch occurs. \item[Preemptive:] The kernel takes away the CPU from a task without notice. \item[Realtime:] Tasks are prioritised. High priority tasks must complete before a task switch. \end{description} %------------------------------------------------------------------------------ \subsection{What is a Process?} The term process is a fundamental abstraction. \begin{itemize} \item Two of the more traditional definitions of a process are: \begin{quote} ``A program in execution.'' \end{quote} \begin{quote} ``A single program running in its own virtual address space'' \end{quote} \item In practice, a process is simply an executable that has been loaded into memory and is either running or ready to run on the system. \end{itemize} %------------------------------------------------------------------------------ \subsection{Process types} Processes under Linux fall into three basic categories: \begin{description} \item[Interactive Process:] An interactive process is a process initiated from (and controlled by) a shell. Interactive processes may be in foreground or background. \\(Example: \texttt{ls, ls \&}) \item[Batch Process:] A batch process is a process that is not associated with a terminal but is submitted to a queue to be executed sequentially. \\(Example \texttt{slocate} started by \texttt{cron}) \item[Daemon Process:] A daemon process is a process that runs in the background until it's required. This kind of processes is usually initiated when Linux boots. \\(Example: \texttt{inetd}, \texttt{lpd}) \end{description} %------------------------------------------------------------------------------ \subsection{Elements associated with a process} For each process running on the system, the kernel needs to keep a list of resources used by that process. Some of these resources include: \begin{itemize} \item tty association (\texttt{tty\_struct}) \item file system (eg current directory \& open files) (\texttt{fs\_struct}, \texttt{files\_struct}) \item memory allocation \texttt{(mm\_struct}) \item Signals received (\texttt{signal\_struct}) \end{itemize} %------------------------------------------------------------------------------ \subsection{Process States} At any given point in time, a process is in one of 5 states: \begin{description} \item[TASK\_RUNNING:] The process is either executing on the CPU or waiting to be executed. \item[TASK\_INTERRUPTIBLE:] The process is sleeping until something becomes true. Raising a hardware interrupt, waiting for a system resource etc are examples of a condition that might wake the process up. If a signal is received by the process (eg KILL -HUP) the process will also be woken up. \item[TASK\_UNINTERRUPTIBLE:] Like the previous state except that delivering a signal will not wake the process up. \item[TASK\_STOPPED:] Process execution has stopped. A process enters this state after receiving a SIGSTOP signal. A debugger may use this to step through a program. \item[TASK\_ZOMBIE:] Process execution has stopped but the kernel has not yet ?cleaned up? the resources allocated to the process. \end{description} %------------------------------------------------------------------------------ \subsection{The Process Family Tree} Every process (with the sole exception of the kernel), must be created by another process. The terms \textit{parent}, \textit{child} and \textit{sibling} (or sometimes \textit{father}, \textit{son} and \textit{brother} in a patriarchal sense) are used to describe the relationships between processes. As an example consider the following line executed from the bash prompt: \begin{alltt} [andy@Node4] andy]\$ ls \& df -h \& \end{alltt} The following relationships are true: \begin{itemize} \item The \texttt{ls} and \texttt{df} processes are both siblings to each other. \item The \texttt{bash} process (ie the shell) is the parent to both \texttt{ls} and \texttt{df}. \item The \texttt{ls} process has \texttt{bash} as its parent. \item The \texttt{df} process has \texttt{bash} as its parent. \end{itemize} %------------------------------------------------------------------------------ \subsection{The Kernel is at the Top of the Family Tree} \begin{itemize} \item When Linux boots, the first thing it does is load the kernel into memory and start executing itself. \item One of the first things it does once execution starts, is to spawn a process called init, which in turn spawns other processes. \item In this sense, the kernel is at the top of the family tree, with only one child process called init. \item Init in turn has many children and probably many grandchildren. \end{itemize} \begin{alltt} Kernel --> Init --> all other processes --> even more processes --> \end{alltt} %------------------------------------------------------------------------------ \subsection{Process IDs} In order for the kernel to keep track of all processes and their descendants, a process ID is assigned to every process running on the system. Process IDs are just numbers and run from 0 to 32767. The number 32767 is the largest signed integer available with a sixteen bit word size and is used to maintain backward compatibility with 16 bit architectures. There are two PIDs (process IDs) that are always the same: \begin{itemize} \item kernel PID is always 0 \item init PID is always 1 \end{itemize} %------------------------------------------------------------------------------ \subsection{Process IDs} Each time a new process is created, a new PID is allocated and is equal to the last PID issued plus one. Once the last PID is reached, the PID wraps back around to zero and the next available PID is used (note that 0 and 1 will never be available). This scheme is a little like the assignment of telephone numbers: When a telephone service is disconnected, rather than just assigning the old telephone number to a new subscriber, the old number remains out of use until all other numbers have been used up. This saves ``wrong numbers'' to the new subscriber from callers who have not yet realised that the old number is no longer connected to the person they were trying to reach. In a similar vein, the kernel does this to minimise ``wrong numbers'' from other processes who have not yet worked out that their intended process no longer exists. This is especially true for Interprocess Communication (IPC) which uses the PID to identify a target process. %------------------------------------------------------------------------------ \subsection{Displaying Process Information} There are three utilities used to display the state of running processes: \begin{itemize} \item \texttt{ps} \item \texttt{pstree} \item \texttt{top} \end{itemize} \begin{itemize} \item The ps command is used to display a ``snapshot'' of all processes running on the system at the time the \texttt{ps} command was executed. \item \texttt{pstree} gives a tree view of the processes. \item The \texttt{top} command is used to display a real-time display of all processes running on the system. Top can also be used in interactive mode to \texttt{kill} or \texttt{renice} (change priority) of a process. \end{itemize} %------------------------------------------------------------------------------ \subsection{Process Monitoring---\texttt{ps}} \begin{quote} \textit{usage:} \texttt{ps [options]} \end{quote} The \texttt{ps} command has a huge number of switches. The switches can be subdivided into two main groups: \begin{itemize} \item Process selection (which processes to display) \item Output control (how and what output should be displayed) \end{itemize} %------------------------------------------------------------------------------ \subsection{\texttt{ps} options} {\scriptsize \begin{alltt} \$ ps ? ERROR: Garbage option. ********* simple selection ********* ********* selection by list ********* -A all processes -C by command name -N negate selection -G by real group ID (supports names) -a all w/ tty except session leaders -U by real user ID (supports names) -d all except session leaders -g by session leader OR by group name -e all processes -p by process ID T all processes on this terminal -s processes in the sessions given a all w/ tty, including other users -t by tty g all, even group leaders! -u by effective user ID (supports names) r only running processes U processes for specified users x processes w/o controlling ttys t by tty *********** output format ********** *********** long options *********** -o,o user-defined -f full --Group --User --pid --cols -j,j job control s signal --group --user --sid --rows -O,O preloaded -o v virtual memory --cumulative --format --deselect -l,l long u user-oriented --sort --tty --forest --version X registers --heading --no-heading ********* misc options ********* -V,V show version L list format codes f ASCII art forest -m,m show threads S children in sum -y change -l format -n,N set namelist file c true command name n numeric WCHAN,UID -w,w wide output e show environment -H process heirarchy \end{alltt} } %------------------------------------------------------------------------------ \subsection{\texttt{ps} options} The switches that need to be known for the purposes of LPIC are as follows: \begin{description} \item[{\bf\texttt{a}}] Display processes for all users \item[{\bf\texttt{txx}}] Display processes within controlling terminal \texttt{txx} \item[{\bf\texttt{u}}] Display user information for the process \item[{\bf\texttt{l}}] Display in long format with detailed information \item[{\bf\texttt{s}}] Display signal information \item[{\bf\texttt{m}}] Display memory information \item[{\bf\texttt{x}}] Display processes without a controlling terminal \item[{\bf\texttt{S}}] Display CPU time and page faults of child processes \item[{\bf\texttt{-C cmd}}] Search for instances of command \texttt{cmd.} \item[{\bf\texttt{-f}}] Forest mode shows process family trees. \item[{\bf\texttt{-w}}] Wide format \end{description} %------------------------------------------------------------------------------ \subsection{\texttt{ps} field names \& their meanings} \begin{description} \item[{\bf\texttt{USER}}] The user who started the process \item[{\bf\texttt{PID}}] The process ID \item[{\bf\texttt{\%CPU}}] Shows the cputime / realtime percentage. \item[{\bf\texttt{\%MEM}}] The fraction of RSS divided by the total size of RAM \item[{\bf\texttt{VSZ}}] Size of virtual memory used by the process \item[{\bf\texttt{RSS}}] Resident set size (Data \& Text segments only) in Kb \item[{\bf\texttt{TTY}}] The TTY associated with this process \item[{\bf\texttt{STAT}}] The current status (DRSTZW$<$ NL) (details next slide) \item[{\bf\texttt{TIME}}] CPU time in MINS:SECS \item[{\bf\texttt{COMMAND}}] The full command line used to start the process \end{description} %------------------------------------------------------------------------------ \subsection{\texttt{ps} Status Field} \small \begin{alltt} \$ ps aux USER PID \%CPU \%MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 1304 72 ? S Mar21 0:19 init \end{alltt} \normalsize \begin{description} \item[{\bf\texttt{D}}] uninterruptible sleep (usually IO) \item[{\bf\texttt{R}}] runnable (on run queue) \item[{\bf\texttt{S}}] sleeping \item[{\bf\texttt{T}}] traced or stopped \item[{\bf\texttt{Z}}] a defunct (``zombie'') process \item[{\bf\texttt{W}}] has no resident pages \item[{\bf\texttt{$<$}}] high-priority process \item[{\bf\texttt{N}}] low-priority task \item[{\bf\texttt{L}}] has pages locked into memory (for real-time and custom IO) \end{description} %------------------------------------------------------------------------------ \subsection{\texttt{ps} Status Field} {\scriptsize \begin{alltt} \$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.2 1384 516 ? S 11:43 0:04 init [5] root 2 0.0 0.0 0 0 ? SW 11:43 0:00 [keventd] root 3 0.0 0.0 0 0 ? SW 11:43 0:00 [kapm-idled] root 5 0.0 0.0 0 0 ? SW 11:43 0:00 [kswapd] root 6 0.0 0.0 0 0 ? SW 11:43 0:00 [kreclaimd] root 7 0.0 0.0 0 0 ? SW 11:43 0:00 [bdflush] root 8 0.0 0.0 0 0 ? SW 11:43 0:00 [kupdated] root 9 0.0 0.0 0 0 ? SW< 11:43 0:00 [mdrecoveryd] root 103 0.0 0.0 0 0 ? SW 11:44 0:00 [kjournald] root 474 0.0 0.2 1444 620 ? S 11:44 0:00 syslogd -m 0 root 479 0.0 0.4 2080 1152 ? S 11:44 0:00 klogd -2 rpc 497 0.0 0.2 1632 708 ? S 11:44 0:00 portmap rpcuser 525 0.0 0.3 1624 796 ? S 11:44 0:00 rpc.statd ntp 735 0.0 0.8 2088 2080 ? SL 11:44 0:00 ntpd -U ntp root 759 0.0 0.3 5784 856 ? S 11:44 0:00 ypbind root 763 0.0 0.3 5784 856 ? S 11:44 0:00 ypbind ..... andy 1176 0.0 0.5 2620 1508 pts/0 S 11:46 0:00 bash root 1343 0.0 0.7 3000 1816 tty1 S 15:21 0:00 ssh node10 andy 1664 0.0 0.3 2824 924 pts/1 R 21:52 0:00 ps -aux \end{alltt} } %------------------------------------------------------------------------------ \subsection{Process Monitoring---\texttt{pstree}} {\scriptsize \begin{alltt} \$ pstree init-+-anacron---run-parts---cfengine |-5*[apache-ssl] |-atd |-bash---startx---xinit-+-X | `-enlightenment-+-E-Clock.epplet | |-E-Cpu.epplet | |-Emix.epplet | |-Eterm---bash-+-abiword---AbiWord | | `-mozilla-bin---moz | |-Eterm---bash---bash | |-Eterm---bash | |-Eterm---bash---gv---gs | |-Eterm---bash---mutt | |-Eterm---bash---emacs-+-ispell | | `-xdvi---gs | |-Eterm---bash---pstree | `-Eterm---bash---man---pager |-cron |-gcache |-6*[getty] |-inetd---nmbd |-junkbuster \end{alltt} } %------------------------------------------------------------------------------ \subsection{\texttt{pstree} options} Three commonly used options for \texttt{pstree}: \begin{description} \item[{\bf\texttt{-a}}] Show command line arguments. \begin{alltt} |-xfs -daemon |-xfstt --port 7101 --daemon --user nobody `-zope-z2 /usr/sbin/zope-z2 `-python /usr/sbin/zope-z2 \end{alltt} \item[{\bf\texttt{-n}}] Sort processes with the same ancestor by PID \item[{\bf\texttt{-p}}] Show PIDs. \begin{alltt} init(1)-+-anacron(27095)---run-parts(27755)---cfengine(27765) |-apache-ssl(27188) |-apache-ssl(27189) \end{alltt} \end{description} %------------------------------------------------------------------------------ \subsection{Process Monitoring---\texttt{top}} The "top" command provides a continuously updated, real-time look at process activity, memory and swap file usage plus CPU activity. It also shows what processes are running and by whom. \begin{itemize} \item Its primary use is as an administration and system information tool. It provides an extension to the functionality of the "ps" command. \item It makes it easy to find an errand process and "kill" that process. It also has an interactive interface whereby options can be passed while the command is actually running. All in all, a very useful tool. \end{itemize} %------------------------------------------------------------------------------ \subsection{\texttt{ top}} \small \begin{verbatim} 9:16am up 13 days, 8:05, 8 users, load average: 0.05, 0.05, 0.00 86 processes: 84 sleeping, 1 running, 1 zombie, 0 stopped CPU states: 2.3% user, 0.7% system, 0.0% nice, 96.8% idle Mem: 900236K av, 546472K used, 353764K free, 0K shrd, 37552K buff Swap: 329324K av, 34784K used, 294540K free 190764K cached PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND 10281 root 16 -10 97952 6452 1584 S < 0 3.9 0.7 56:57 X 12547 geoff 16 0 1728 1728 764 R 0 0.9 0.1 0:01 top 10284 geoff 12 0 3012 2568 1352 S 0 0.7 0.2 50:49 enlight 12173 geoff 10 0 9340 9340 3768 S 0 0.3 1.0 0:11 emacs 12543 geoff 9 0 3328 3328 2072 S 0 0.1 0.3 0:00 Eterm 1 root 9 0 116 72 52 S 0 0.0 0.0 0:19 init 2 root 9 0 0 0 0 SW 0 0.0 0.0 0:01 keventd \end{verbatim} %------------------------------------------------------------------------------ \subsection{top's basic command line options} Note: dashes not required. \begin{description} \item[{\bf\texttt{-b}}] Batch mode. Useful for sending output from top to other programs or to a file. Output is plain text. \item[{\bf\texttt{-d}}] Delay between screen updates. (default 5 seconds) \item[{\bf\texttt{-i}}] Start top ignoring any idle or zombie processes. \item[{\bf\texttt{-p}}] Monitor only processes with given process id. (x20) \item[{\bf\texttt{-q}}] This causes top to refresh without any delay. \item[{\bf\texttt{}}] \item[{\bf\texttt{}}] \item[{\bf\texttt{}}] \item[{\bf\texttt{}}] \end{description} %------------------------------------------------------------------------------ \subsection{\texttt{top}'s upper screen} \small \begin{verbatim} 9:16am up 13 days, 8:05, 8 users, load average: 0.05, 0.05, 0.00 86 processes: 84 sleeping, 1 running, 1 zombie, 0 stopped CPU states: 2.3% user, 0.7% system, 0.0% nice, 96.8% idle Mem: 900236K av, 546472K used, 353764K free, 0K shrd, 37552K buff Swap: 329324K av, 34784K used, 294540K free 190764K cached \end{verbatim} \begin{itemize} \item The current system time: \item The "up time" of the system: \item How many users are logged in. \item The "load average" : the average number of processes ready to run over the last 1,5 and 15 minutes \item "CPU States" shows the percentage of CPU time spent in usermode, system mode and at idle. \item "MEM" shows a complete set of statistics on current memory usage. \item "SWAP" gives us the same details as "MEM" but for the swap space. \end{itemize} %------------------------------------------------------------------------------ \subsection{top's lower screen} \small \begin{verbatim} PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEM TIME COMMAND 10281 root 16 -10 97952 6452 1584 S < 0 3.9 0.7 56:57 X 12547 geoff 16 0 1728 1728 764 R 0 0.9 0.1 0:01 top \end{verbatim} \begin{description} \item[PID] The process ID of each task. \item[USER] The user name of the task's owner. \item[PRI] The priority of the task. \item[NI] The nice value of the task. Negative nice values are higher priority. \item[SIZE] The size of the task's code plus data plus stack space, in kilobytes, is shown here. \item[RSS] The total amount of physical memory used by the task,in kilobytes, is shown here. For ELF processes used library pages are counted here, for a.out processes not. \item[SHARE] The amount of shared memory used by the task is shown in this column. \item[STAT] The state of the task is shown here. The state is either \begin{description} \item[S] sleeping \item[D] uninterruptible sleep \item[R] running \item[Z] zombies \item[T] stopped or trace \end{description} These states are modified by trailing $<$ for a process with negative nice value, N for a process with positive nice value, W for a swapped out process (this does not work correctly for kernel processes). \item[\%CPU] The task's share of the CPU time since the last screen update, expressed as a percentage of total CPU time per processor.\ \item[\%MEM] The task's share of the physical memory. \end{description} %------------------------------------------------------------------------------ \subsection{\texttt{top}: selected interactive commands} \begin{description} \item[\textasciicircum L] Redraw the screen \item[f$\mid$F] Add and remove fields \item[h$\mid$?] Displays a help screen \item[S] Toggle cumulative mode \item[I] Toggle between Irix and Solaris views (SMP-only) \item[k] Kill a task (with any signal) \item[r] Renice a task \item[T] Sort by time / cumulative time \item[s] Set the delay in seconds between updates \item[q] Quit \end{description} %------------------------------------------------------------------------------ \subsection{\texttt{top}'s interactive commands} \begin{description} \item[space] Update display \item[\textasciicircum L] Redraw the screen \item[f$\mid$F] Add and remove fields \item[o$\mid$O] Change order of displayed fields \item[h$\mid$?] Displays a help screen \item[S] Toggle cumulative mode \item[i] Toggle display of idle proceses \item[I] Toggle between Irix and Solaris views (SMP-only) \item[c] Toggle display of command name/line \item[l] Toggle display of load average \item[m] Toggle display of memory information \item[t] Toggle display of summary information \item[k] Kill a task (with any signal) \item[r] Renice a task \item[N] Sort by pid (Numerically) \item[A] Sort by age \item[P] Sort by CPU usage \item[M] Sort by resident memory usage \item[T] Sort by time / cumulative time \item[u] Show only a specific user \item[n$\mid$\#] Set the number of process to show \item[s] Set the delay in seconds between updates \item[W] Write configuration file ~/.toprc \item[q] Quit \end{description} %------------------------------------------------------------------------------ \subsection{\texttt{\~{}\slash .toprc}} \begin{alltt} \$ cat toprc \(\hookleftarrow\) AbcDgHIjklMnoTP|qrsuzyV\{EFWx 2 \end{alltt} %------------------------------------------------------------------------------ \subsection{Killing Processes} %------------------------------------------------------------------------------ \subsection{Job Control} There are three comands and a pretzel used for job control. \begin{itemize} \item \texttt{jobs} \item \texttt{fg} \item \texttt{bg} \item \texttt{\&} \end{itemize} They are bash built-ins: \begin{alltt} \$ type jobs fg bg \(\hookleftarrow\) jobs is a shell builtin fg is a shell builtin bg is a shell builtin \end{alltt} For more information, see the Job Control section of man bash. %------------------------------------------------------------------------------ \subsection{\texttt{\&}--- Direct the shell to execute a command in the background.} Example: \begin{alltt} \$ xeyes \(\hookleftarrow\) \end{alltt} Notice the \texttt{xeyes} process is started in the foreground and you have no prompt. The user is locked out of further interaction with the shell until a process is stopped, terminated or completed. Now start the xeyes process in the background. \begin{alltt} \$ xeyes & \(\hookleftarrow\) [1] 1650 \$ \end{alltt} Two numbers are listed and the prompt is now also displayed waiting for another command. %------------------------------------------------------------------------------ \subsection{Job Control} \begin{alltt} \$ xeyes & \(\hookleftarrow\) [1] 1650 \$ \end{alltt} \begin{itemize} \item The [1] is the programs job id, a unique number for the shell starting from 1. \item The 1650 is the process id (pid), which identifies the process across the entiresystem. \item Either of these numbers can be used to interact with the program through bash. \end{itemize} %------------------------------------------------------------------------------ \subsection{Background Processing} The best candidates for background processing are programs that do not require user input, as these programs will keep on waiting until input is provided. Programs that send their results to standard output (The screen), will do so even if running in the background. If the user is performing another operation, the results may be difficult to interpret. The output from these processes can be redirected to a file. \begin{alltt} \$ wc bigfile > bigfile.wc & \(\hookleftarrow\) [1] 1654 \$ \end{alltt} %------------------------------------------------------------------------------ \subsection{The \texttt{jobs} command} \begin{description} \item [\texttt{\$ jobs \(\hookleftarrow\)}]:\\ Lists all commands stopped, or running in the background. \item [Options]:\\ \texttt{-l} List pid \item [Example]:\\ Start some processes in the background and suspend a foreground process. \begin{alltt} \$ jobs \(\hookleftarrow\) [1]+ Stopped less job_control.txt [2]- Running xeyes & \$ \end{alltt} \end{description} %------------------------------------------------------------------------------ \subsection{The \texttt{fg} command} \begin{description} \item [\texttt{\$ fg \(\hookleftarrow\)}]:\\ Shell built-in used to force a suspended or background process to continue running in the foreground. \item [Example]: \begin{itemize} \item Use the 'jobs' command to find job id. \begin{alltt} \$ jobs \(\hookleftarrow\) [1]+ Stopped less job_control.txt [2]- Running xeyes & \$ \end{alltt} \item Use \texttt{fg} to bring xeyes to foreground. \begin{alltt} \$ fg 2 \(\hookleftarrow\) xeyes \end{alltt} \item A \texttt{\%} used with the job id is equivalent to \texttt{fg 2}. \begin{alltt} \$ \%2 \(\hookleftarrow\) xeyes \end{alltt} \end{itemize} \end{description} %------------------------------------------------------------------------------ \subsection{The \texttt{fg} command} A job can also be referred to by a string that uniquely identifies the beginningof the command line used to start a job. A '\%' can also be used with a unique string. \begin{alltt} \$ fg x \(\hookleftarrow\) xeyes \end{alltt} or \begin{alltt} \$ \%x \(\hookleftarrow\) xeyes \end{alltt} If \texttt{fg} is issued without any argument, the job with the '+' in the job list is brought to the foreground. \begin{alltt} \$ fg \(\hookleftarrow\) xeyes \end{alltt} %------------------------------------------------------------------------------ \subsection{The \texttt{bg} command} \begin{description} \item [\texttt{\$ bg \(\hookleftarrow\)}]:\\ Used to force a suspended process to continue running in the background. \item [Example]:\\ Use the 'jobs' command to find job id. \begin{alltt} \$ jobs \(\hookleftarrow\) [1]- Stopped find -name myfile >myfile.found (wd: /) [2]+ Stopped less job_control.txt [3] Running xeyes & \$ \end{alltt} \end{description} Job 1 shows the 'find' command was started in the foreground and then suspended.To start 'find' in the background, use the 'bg' command or '\%'. \begin{description} \item [Example]: \begin{alltt} \$ bg 1 \(\hookleftarrow\) {\rm or} \$ bg f \(\hookleftarrow\) {\rm or} \$ \%1 \& \(\hookleftarrow\) {\rm or} \$ \%f \& \(\hookleftarrow\) \end{alltt} \end{description} %============================================================================== \section{Lab} \label{sec:lab103.5} %============================================================================== \section{Questions} \label{sec:questions103.5} %############################################################################## \objective{6}{Modify process execution priorities} %############################################################################## %============================================================================== \section{Overview} \label{sec:over103.6} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate should be able to manage process execution priorities. Tasks include running a program with higher or lower priority, determining the priority of a process and changing the priority of a running process. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} nice ps renice top \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes103.6} %============================================================================== \section{Lab} \label{sec:lab103.6} \begin{enumerate} \item This exercise requires a few example processes to play around with, so first we will create a few. \begin{itemize} \item Using the \texttt{vi} editor (for practice) make a file called \texttt{a.c}. \begin{itemize} \item Do not use the arrow keys---use h, j, k and l. \item Do not use the \textsf{Backspace} or \textsf{Delete} keys---use \texttt{x}. \item Be sure you are familiar with the use of \texttt{i}, \texttt{a}, \texttt{o} and \texttt{O} for entering new text. \item For saving and quitting use each of \texttt{ZZ}, \texttt{:w}, \texttt{q:} and \texttt{!}. \item Delete, Yank and Put with \texttt{dd}, \texttt{yy} and \texttt{p}. \item Use \texttt{u} to undo, numerical modifiers (e.g. 5dd) and \texttt{.} to repeat. \end{itemize} \item The file should contain this text: \begin{verbatim} #include int main() { int i = 0; while (1) { system("clear"); printf("Process a: %d\n", i); ++i; } return 0; } \end{verbatim} \item Copy the file \texttt{a.c} to \texttt{b.c} and \texttt{c.c}. \begin{alltt} \$ cp a.c {b,c}.c \(\hookleftarrow\) \end{alltt} \item Edit the \texttt{printf()} calls in files \texttt{b.c} and \texttt{c.c} to refer to \texttt{Process b:} and \texttt{Process c:} respectively. \item Compile the programs: \begin{alltt} \$ gcc a.c -o a; gcc b.c -o b; gcc c.c -o c \(\hookleftarrow\) \end{alltt} \end{itemize} \item Test your three programs. \begin{itemize} \item Start a program running in the background: \begin{alltt} \$ ./a \(\hookleftarrow\) Process a: 400 \end{alltt} \item Suspend the program: \begin{alltt} ^z [1]+ Stopped ./a \end{alltt} \item Kill the job: \begin{alltt} \$ kill %1 \(\hookleftarrow\) \end{alltt} \end{itemize} \item Use \texttt{ps} to view the processes. \begin{itemize} \item Run the processes in the background with differing degrees of niceness: \begin{alltt} \$ ./a& nice ./b& nice -19 ./c& \(\hookleftarrow\) \end{alltt} \item Glance at and absorb the manpage for \texttt{ps}. Note well that some options are preceded by a minus(-) and others are not. For example \texttt{ps a} and \texttt{ps -a} do different things. \item Locate the processes using the \texttt{ps} command; try the \texttt{a}, \texttt{u}, \texttt{x}, and \texttt{f} options separately and in combinations. e.g.: \begin{alltt} \$ ps aux |grep "./a " \(\hookleftarrow\) \end{alltt} \item Kill and restart one of the processes (use the PID not ``123456'': \begin{alltt} \$ kill 123456 \(\hookleftarrow\) \$ ps aux |grep "./a " \(\hookleftarrow\) \$ ./a& \$ ps aux |grep "./a " \(\hookleftarrow\) \end{alltt} \end{itemize} \item Use \texttt{top} to view and modify the processes. \begin{itemize} \item Run \texttt{top} in the foreground: \begin{alltt} \$ top \(\hookleftarrow\) \end{alltt} \item Look at the \texttt{top} help: Press \textsf{h} \item Sort by accumulated time: Press \texttt{T} \item Re-nice a process (Note: Users may only monotonically increase the niceness processes, and (\&\&) they must own the process.): \begin{itemize} \item Press \textsf{r} \item PID to renice: 1234567890 \(\hookleftarrow\) \item Renice PID 1973 to value: 5 \(\hookleftarrow\) \end{itemize} \end{itemize} \item Reniceing from the command line: \begin{itemize} \item After finding it's \textsf{PID}\texttt{renice} one of your processes: \begin{alltt} \$ ps aux |grep "./c " \(\hookleftarrow\) \$ renice +15 1234567890 \end{alltt} \item Re-nice negatively---notice that only the superuser may reduce the niceness of a process. \begin{alltt} \$ renice -10 1234567890 \(\hookleftarrow\) renice: 1234567890: setpriority: Permission denied \$ su -c 'renice -10 1234567890' \(\hookleftarrow\) \end{alltt} \end{itemize} \item Kill off \texttt{./a}, \texttt{./b} and \texttt{./c}. \end{enumerate} %============================================================================== \section{Questions} \label{sec:questions103.6} %############################################################################## \objective{7}{Search text files using regular expressions} %############################################################################## %============================================================================== \section{Overview} \label{sec:over103.7} %------------------------------------------------------------------------------ \subsection{Weight: [3]} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} The candidate should be able to manipulate files and text data using regular expressions. This objective includes creating simple regular expressions containing several notational elements. It also includes using regular expression tools to perform searches through a filesystem or file content. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} grep regexp sed \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} Fun with Regular Expressions by Adrian J. Chung \begin{alltt} http://thelinuxgurus.org/regexp.html \end{alltt} %============================================================================== \newpage \section{Notes} \label{sec:notes103.7} %------------------------------------------------------------------------------ \subsection{\texttt{sed}---stream editor} \label{sec:sed_notes103.7} \normalsize \begin{itemize} \item Example (replace ``teh'' with ``the''): \begin{alltt} \$ sed s/teh/the/g my_file.txt \(\hookleftarrow\) \end{alltt} \item Non-interactive. \item The original file is not touched by \textsf{sed} \item Save the results: \begin{alltt} \$ sed s/teh/the/g old.txt > new.txt\(\hookleftarrow\) \end{alltt} \end{itemize} \subsubsection{Calling \texttt{sed}} \begin{itemize} \item \textsf{sed} one liners: \begin{alltt} \$ sed [opts] 'sed-cmds' input-file(s) \(\hookleftarrow\) \end{alltt} \item \textsf{sed} using a script file: \begin{alltt} \$ sed [opts] -f script-file input-file(s) \(\hookleftarrow\) \end{alltt} \item Script with a \textsf{sed} shebang: \begin{alltt} \$ cat script.sed \(\hookleftarrow\) #!/bin/sed -f ... \end{alltt} \end{itemize} heading{The \texttt{sed} options} \begin{description} \item[-n] No print. The default is to print all lines plus lines selected with the \textsf{p} command. \item[-e] The next command is an edit command; used for multiple edits. \item[-f] \textsf{sed} commands are in a file. \end{description} \subsubsection{Finding text using \texttt{sed}} \begin{itemize} \item Using line numbers: singly or in a range. \item Using Regular Expressions. \end{itemize} Examples: \begin{description} \item[x] Where \textsf{x} is a line number \item[x,y] In a range of lines, from \textsf{x} to \textsf{y} \item[/pattern/] Where \textsf{pattern} is a regex \item[/patern/patern/] Choice of patterns \item[/pattern/,x] Look for the pattern on this line \item[x,/pattern/] Look only at line \textsf{x} for the pattern \item[x,y!] Not lines \textsf{x} to \textsf{y} \end{description} \subsubsection{Basic \textsf{sed} editing commands} \begin{description} \item[p] Print the matched lines \item[=] Display the line number of the file \item[a]\verb+\+ Append the text after the addressed line \item[i]\verb+\+ Insert new text after the addressed line \item[d] Delete addressed lines \item[c] Replace addressed text with new text \item[s] Substitute pattern with replacement pattern \item[r] Read text from another file \item[w] Write text to file \item[q] Quit after first pattern has been matched, or just quit \item[l] Show control characters in their octal ASCII equivalent \item[()] Group a series of commands to be performed only on addressed lines \item[n] Read the next line of text from another file and append it \item[g] Paste the contents of pattern2 into pattern1 \item[y] Translate characters \item[n] Append next input line; this allows pattern matching across two lines \end{description} \subsubsection{\texttt{sed} examples} \begin{itemize} \item Print line 3 only: \begin{alltt} \$ sed -n '3p' foo.txt \(\hookleftarrow\) \end{alltt} \item Print lines 5 through 8: \begin{alltt} \$ sed -n '5,8p' foo.txt \(\hookleftarrow\) \end{alltt} \item Print lines with \textit{Fred} in them: \begin{alltt} \$ sed -n '/fred/p' foo.txt \(\hookleftarrow\) \end{alltt} \item Search for \textit{Fred} only on line 4: \begin{alltt} \$ sed -n '4,/Fred/p' foo.txt \(\hookleftarrow\) \end{alltt} \item Print lines containing \textsf{\$100}: \begin{verbatim} $ sed -n '/\$100/p' foo.txt \end{verbatim}%$ \item Print file 10th line to the last: \begin{alltt} \$ sed -n '1,\$p' \(\hookleftarrow\) \end{alltt} \item Print lines with \textsf{ing}'s in them \begin{alltt} \$ sed -n '/.*ing/p' \(\hookleftarrow\) \end{alltt} \end{itemize} \subsubsection{\texttt{sed} examples} \begin{itemize} \item Print just the line number of a match: \begin{alltt} \$ sed -n '/funny/=' foo.txt \(\hookleftarrow\) 3 \end{alltt} \item Print the line and its number: \begin{alltt} \$ sed -n -e '/fun/p' -e '/fun/=' foo.txt \(\hookleftarrow\) That was funny 3 \end{alltt} \item Appending text: \begin{alltt} \$ cat my.script /funny/p /funny/a\ ha ha ha \$ sed -n -f my.script foo.txt \(\hookleftarrow\) That was funny ha ha ha \end{alltt} \item Substitution: \begin{alltt} \$ sed -n 's/this/that/' foo.file \end{alltt} \end{itemize} \subsubsection{Using a \texttt{sed} script} \begin{itemize} \item Create a script find\_the.sh that will print (append) ``Got One!'' every time it sees the word ``the'' in a file. \begin{verbatim} #!/bin/sed -f /the/ a\ Got one! \end{verbatim} \item Run the script: \begin{alltt} \$ chmod u+x find_the.sh \(\hookleftarrow\) \$ ./find_the.sh owl.pussy.cat.poem \(\hookleftarrow\) "Dear Pig, are you willing to sell for one shilling Your ring?" Said the Piggy, "I will." Got one! So they took it away, and were married next day Got one! By the Turkey who lives on the hill. Got one! \end{alltt} \end{itemize} \newpage \subsubsection{The Owl and the Pussy-Cat} \begin{verse} The Owl and the Pussy-Cat went to sea\\ In a beautiful pea-green boat:\\ They took some honey, and plenty of money\\ Wrapped up in a five-pound note.\\ The Owl looked up to the stars above,\\ And sang to a small guitar,\\ "O lovely Pussy, O Pussy, my love,\\ What a beautiful Pussy you are,\\ You are,\\ You are!\\ What a beautiful Pussy you are!" Pussy said to the Owl, "You elegant fowl,\\ How charmingly sweet you sing!\\ Oh! let us be married; too long we have tarried:\\ But what shall we do for a ring?"\\ They sailed away, for a year and a day,\\ To the land where the bong-tree grows;\\ And there in a wood a Piggy-wig stood,\\ With a ring at the end of his nose,\\ His nose,\\ His nose,\\ With a ring at the end of his nose. "Dear Pig, are you willing to sell for one shilling\\ Your ring?" Said the Piggy, "I will."\\ So they took it away, and were married next day\\ By the Turkey who lives on the hill.\\ They dined on mince and slices of quince,\\ Which they ate with a runcible spoon;\\ And hand in hand on the edge of the sand\\ They danced by the light of the moon,\\ The moon,\\ The moon,\\ They danced by the light of the moon.\\ \end{verse} Edward Lear \subsubsection{Inserting test with \texttt{sed}} \begin{itemize} \item Create a script find\_the.sh that will print (append) ``Got One!'' every time it sees the word ``the'' in a file. \begin{verbatim} #!/bin/sed -f /Owl/ i\ Owl coming up! \end{verbatim} \item Run the script: \begin{alltt} \$ chmod u+x owl.sh \(\hookleftarrow\) \$ ./owl.sh owl.pussy.cat.poem \(\hookleftarrow\) Wrapped up in a five-pound note. Owl coming up! The Owl looked up to the stars above, \end{alltt} \end{itemize} %============================================================================== \section{Lab} \label{sec:lab103.7} Using the poem ``The Owl and the Pussy-cat'' by Edward Lear as a sample text answer the following the steps below. Write down the commands that you use and answer any questions. The text for the poem may be snarfed from the internet by googleing. It's copyright has expired. \begin{enumerate} \item What version of \texttt{sed} are you using? \item Print all the lines containing the word Pussy. \item Print all the lines containing the word the or The. \item Print all the lines starting with a capital p. \item Print lines that don't have the word ``the''. \item Print lines that end in double ticks (``) with or without following punctuation. \item Print lines with four letter words starting with a capital letter. \item Print lines that are preceeded by lines with a capital p in them. \item Save lines with hyphenated words to a file called h\_words.txt \end{enumerate} %============================================================================== \section{Questions} \label{sec:questions103.7} %############################################################################## \objective{8}{Perform basic file editing operations using vi} %############################################################################## %============================================================================== \section{Overview} \label{sec:over103.8} %------------------------------------------------------------------------------ \subsection{Weight: [1]} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate must be able to edit text files using vi. This objective includes vi navigation, basic vi modes, inserting, editing, deleting, copying, and finding text. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} vi /, ? h,j,k,l G, H, L i, c, d, dd, p, o, a ZZ, :w!, :q!, :e! :! \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{itemize} \item \begin{alltt} \$ info text \(\hookleftarrow\) \end{alltt} \item VI Lovers Home Page: Resource listing for using the vi text editor \begin{alltt} http://www.thomer.com/vi/vi.html \end{alltt} \end{itemize} %============================================================================== \newpage \section{Notes} \label{sec:notes103.8} %============================================================================== \section{Lab} \label{sec:lab103.8} %------------------------------------------------------------------------------ \subsection{Vi tour} \label{sec:1.103.8.ex} % This exercise was written by Ken Foley %------------------------------------------------------------------------------ \subsubsection{Note} Should you need a good sized text file to practice editing on, you will almost certainly find a copy of the GPL Liscence on your system. Be sure to deconsecrate the file by renaming before mungeing it. You may locate one thus: \begin{alltt} \$ locate GPL \(\hookleftarrow\) ... /usr/share/doc/netpbm-9.14/GPL_LICENSE.txt /usr/share/doc/cdda2wav-1.10/GPL /usr/share/doc/cdparanoia-alpha9.8/GPL /usr/share/doc/stunnel-3.19/COPYRIGHT.GPL /usr/share/doc/libesmtp-0.8.4/COPYING.GPL ... \end{alltt} Make a scratch copy at a suitable location and open it for editing: \begin{alltt} \$ cp /usr/share/doc/stunnel-3.19/COPYRIGHT.GPL \ \(\hookleftarrow\) /tmp/munged_gpl.txt \(\hookleftarrow\) \$ vi /tmp/munged_gpl.txt \(\hookleftarrow\) \end{alltt} %------------------------------------------------------------------------------ \subsubsection{vi} Vi is the unix editor, simply it is available on just about every Unix installation by default. This is the reason that you have to have a minimum of basic vi skills to allow you to change files when you favourite editor is not available, boot disks have vi due to lack of space. Please note that there are many implementations of vi, the baseline is a very crude editor. This extends to a very extended and powerful VIM editor available on most platforms. I use vim because I am restricted to vi on many of the unix systems I support, rather than trying to 'switch editors' mentally I have vi on every platform I use, including Windows. %------------------------------------------------------------------------------ \subsubsection{vi is a mode editor} Vi is an editor and it is definitely not a friendly editing environment. In fact a random typing of keys of the keyboard can render your text totally unreadable. Vi has been around a long time it was created in an era where editors were modal. The editor can be in three different unrelated states described below. \begin{description} \item[Input mode] This is the mode where you simply type. You characters appear in the text file as you type. \item[Command mode] This is where character take on special significance, for example 'i' for insert 'D' to delete to the end of the line. \item[Line mode] This is the mode when you press a : in command mode, this is where you can type some powerful (and sed like) commands to alter the document. \end{description} Rather than bore you with yet another description I will give you a series of exercises to work through showing each command. In the examples means to press the escape key. This will return you to command mode or cancel an action in other modes. %------------------------------------------------------------------------------ \subsubsection{Inserting text} There are at least three ways to insert text into a document in vi, the following exercises will take you through the basic commands. \begin{description} \item [Exercise 1 - insert] Create a text document, just to get you used to switching in and out of the insert and command mode. \begin{alltt} \$ vi test.txt \(\hookleftarrow\) ithis is the Linux course We want a few lines of txt to work with. \end{alltt} The i inserts text before the cursor. \item [Exercise 2 - open] We want to add some extra text to the document, we want to enter it on the line after the current line, we use the open command by pressing \textsf{o}. \begin{alltt} oI am adding an line after the current line. \end{alltt} \item[Exercise 3 - append] Now I want ot continue adding another sentence on the current line. If I press 'i' I will insert before the full stop, in this case I want to append it after the full stop. \begin{alltt} a I want to add another sentence. \end{alltt} You line should now look like: \begin{alltt} I am adding an line after the current line. I want to add another sentence. \end{alltt} \end{description} %------------------------------------------------------------------------------ \subsubsection{Movement keys \& multiplication} There are a huge number of ways to move around in vi, the arrow keys will not always work . You should be aware of the single character work arounds for these in case your terminal is not set up properly on the box you are 'telnet'ing or 'ssh'ing from or to. \begin{description} \item[h] Left one character * \item[j] Down one line * \item[k] Up one line * \item[l] Left one character * \item[w] Forward one word \item[b] Back one word \item[e] End of current word \item[G] End of file * \item[nG] Goto a particular line * \item[\{] Back one paragraph \item[\}] Forward one paragraph \item[\$] End of current line \item[\textasciicircum] non blank character in line \item[0] Beginning of line (also \verb+|+) \end{description} Ones marked with an asterisk are requierd by POMS, Personally I find word movement is my main tool here. I also use the control keys to scroll screens a far bit. These are listed on the printed cheat sheet. ALL these movement commands can be prefixed by a number to muliply the effect of the movement. To move up 99 lines enter 99k. Note that some vi editor have a status on the bottom line, sometime it will show that you have entered a multiplier, sometimes it is quiet but the results are \_unexpected\_. \begin{description} \item[Exercise 4 - back] In the previous exercise I have forgotten a word after the an I wanted the word 'extra'. I have to go back that position in the line. \texttt{12b} will get me back to the beginning of the word I want to insert before, this is an example of a count followed by a command. Warning on the counts it can repeat most commands whether it makes sense or not at the time. For example enter the following: \begin{alltt} 4iextra \end{alltt} What happened? Why? This is handy with asterisks \texttt{70i*}, try it. \texttt{12b} moves the cursor back 12 words. A word is a sequence of chanracters separated by a space character like a or a Also the punctuation characters or '.', '?', ';' and so on. \item[Exercise 5 - general movement] Edit a large text file on your system. You should be able to do the following with two keystrokes. \begin{itemize} \item Jump to line 6 \item Move 8 character to the right. \item Go to the end of the line \item Go to the beginning of the line. \item Jump to the top of the paragraph in the document (a paragraph is delimitted by blank lines.) \end{itemize} You should be able to do this with one keystroke \begin{itemize} \item Move to the left margin To the end of the line \item Move to the end of the file. \end{itemize} \end{description} %------------------------------------------------------------------------------ \subsubsection{The undo command} The real vi command undo is very very limitted. It does not allow for a lot of recovery. There are two undo commands 'U' and 'u'. The lower case u will undo the last action that you have done. This includes itself so it will cycle through doing and undoing. The upper case U will undo the any change to the current line and restore it back to its original state. Extended vi editors such as vim will allow multiple lower case u undo commands but do not rely on it on an unknow box. To get out of a problem you simply have to quit without with ':q!'. No exercise here, I figure you will find this out without any help. Try both commands. Check the difference. %------------------------------------------------------------------------------ \subsubsection{Deleting changing and copying text} \begin{description} \item[d] Delete * \item[c] Change * \item[x] Delete one character \item[y] Yank (copy text) \end{description} Ones marked with an asterisk are required by POMS, Personally I use single character deletion all the time. I use line deletion all the time. There delete command and yank command can be used with a movement to delete all text within this movement. For example d\$ will delete to the end of the current line, y\$ will yank it into a buffer. Delete will also store the deletion in a buffer to get it back quickly just use paste describe later. To delete or yank a line simply repeat the d or y. To delete a single line use dd, to delete the current line and the next two use 3dd. To yank the next 10 lines use 10yy. Exercise 6 Please your cursor in the middle of a line. Delete from the current position to the beginning of the line with two keystrokes. Delete from the current position to the end of the line. Note that there is a shorthand for d\$ (delete, move to end of line) by using a capital D. Move to the center of a line of text and try it. %============================================================================== \section{Questions} \label{sec:questions103.8} %****************************************************************************** %****************************************************************************** \topic{104}{Devices, Linux Filesystems, Filesystem Hierarchy Standard} %****************************************************************************** %****************************************************************************** % {\Large Old number: (2.4)}\\[2mm] % {\Large Weight: [21]} % \section*{Create partitions and filesystems [3]} % \section*{Maintain the integrity of filesystems [5]} % \section*{Control mounting and unmounting filesystems [3]} % \section*{Managing disk quota [1]} % \section*{Use file permissions to control access to files [3]} % \section*{Manage file ownership [2]} % \section*{Create and change hard and symbolic links [2]} % \section*{Find system files and place files in the correct location [2]} %############################################################################## \objective{1}{Create partitions and filesystems} %############################################################################## %============================================================================== \section{Overview} \label{sec:over104.1} %------------------------------------------------------------------------------ \subsection{Weight: [3]} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to configure disk partitions and then create filesystems on media such as hard disks. This objective includes using various mkfs commands to set up partitions to various filesystems, including ext2, ext3, reiserfs, vfat, and xfs. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} fdisk mkfs \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes104.1} %------------------------------------------------------------------------------ \subsection{Using \texttt{fdisk}} \label{sec:ex.104.1.1} Care must be taken using \texttt{fdisk} as any changes to your disk's partition table will make existing data on the disk unaccessible. There is debate about what the ``\texttt{f}'' in \texttt{fdisk} stands for. %------------------------------------------------------------------------------ \subsubsection{Using \texttt{fdisk} non-destructively on a hard disk} \label{sec:ex.104.1.1.1} \begin{itemize} \item View the partition table for the hard disk: \begin{alltt} \# fdisk -l /dev/hda \(\hookleftarrow\) Disk /dev/hda: 255 heads, 63 sectors, 3648 cylinders Units = cylinders of 16065 * 512 bytes Device Boot Start End Blocks Id System /dev/hda1 * 1 768 6168928+ c Win95 FAT32 (LBA) /dev/hda2 769 3648 23133600 5 Extended /dev/hda5 769 780 96358+ 83 Linux \end{alltt} \item Print the size of a partition in blocks (30G disk): \begin{alltt} \# fdisk -s /dev/hda \(\hookleftarrow\) 29302560 \# fdisk -s /dev/hda5 \(\hookleftarrow\) 96358 \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsubsection{Using \texttt{fdisk} on a diskette} \label{sec:ex.104.1.1.2} Warning: it makes no sense to use \texttt{fdisk} on a floppy---this is just an exercise. \begin{itemize} \item Format the floppy disk: \begin{alltt} \# fdformat /dev/fd0 \(\hookleftarrow\) \end{alltt} \item Start fdisk using the floppy diskette: \begin{alltt} \# fdisk /dev/hda \(\hookleftarrow\) \end{alltt} \item Look at the menu: \begin{alltt} Command (m for help): m \(\hookleftarrow\) \end{alltt} \item Print the partition table: \begin{alltt} Command (m for help): p \(\hookleftarrow\) Disk /dev/fd0: 2 heads, 18 sectors, 80 cylinders Units = cylinders of 36 * 512 bytes Device Boot Start End Blocks Id System \end{alltt} \item Use \textsf{n} for new and construct this partition table: \begin{alltt} Device Boot Start End Blocks Id System /dev/fd0p1 * 1 20 351 1 FAT12 /dev/fd0p2 21 25 90 83 Linux /dev/fd0p3 26 80 990 5 Extended /dev/fd0p5 26 30 81 83 Linux /dev/fd0p6 31 70 711 83 Linux /dev/fd0p7 71 80 171 83 Linux \end{alltt} \item List the partition types: \begin{alltt} Command (m for help): l \(\hookleftarrow\) \end{alltt} \item Change the first partition to type 1: \begin{alltt} Command (m for help): t \(\hookleftarrow\) \end{alltt} \item Toggle the bootable flag on the first partition: \begin{alltt} Command (m for help): a \(\hookleftarrow\) \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsubsection{Using \texttt{cfdisk}} \label{sec:ex.104.1.1.3} \texttt{cfdisk} is reputably more user friendly than \texttt{fdisk}. There are some partition adjustments that may require \texttt{cfdisk}. Have a look at your floppy diskette partitions: \begin{alltt} \# cfdisk /dev/fd0 \(\hookleftarrow\) \end{alltt} %------------------------------------------------------------------------------ \subsubsection{Using \texttt{sfdisk}} \label{sec:ex.104.1.1.3} \texttt{sfdisk} is interactive partition editor. Have a look at your floppy diskette partitions: \begin{alltt} \# sfdisk /dev/fd0 \(\hookleftarrow\) \end{alltt} You may wish to \textsf{Cntl-C} out of this program if you wish not to edit the partition table. %------------------------------------------------------------------------------ \subsubsection{Using \texttt{GNU parted}} \label{sec:ex.104.1.1.3} \texttt{parted} is a partition editor that can resize partitions. \begin{itemize} \item Have a look at your floppy diskette partitions: \begin{alltt} \# parted /dev/fd0 \(\hookleftarrow\) \end{alltt} \item Check the menu: \begin{alltt} (parted) p \(\hookleftarrow\) \end{alltt} \item Experiment on you partitioned floppy. \end{itemize} %============================================================================== \section{Lab} \label{sec:lab104.1} %============================================================================== \section{Questions} \label{sec:questions104.1} %############################################################################## \objective{2}{Maintain the integrity of filesystems} %############################################################################## %============================================================================== \section{Overview} \label{sec:over104.2} %------------------------------------------------------------------------------ \subsection{Weight: [3]} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to verify the integrity of filesystems, monitor free space and inodes, and repair simple filesystem problems. This objective includes the commands required to maintain a standard filesystem, as well as the extra data associated with a journaling filesystem. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} du df fsck e2fsck mke2fs debugfs dumpe2fs tune2fs \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes104.2} %------------------------------------------------------------------------------ \subsection{Summary of Commands} \begin{tabular}{|c|l|} \hline \textit{Command} & \textit{Function}\\ \hline du & Display disk usage\\ \hline df & Display disk space free\\ \hline fsck & Check Filesystem\\ \hline e2fsck & Check an ext2 Filesystem\\ \hline mke2fs & Create an ext2 Filesystem\\ \hline debugfs & Debug an ext2 Filesystem\\ \hline dumpe2fs & Dump Filesystem information\\ \hline tune2fs & Adjust parameters on ext2 Filesystem\\ \hline \end{tabular} %------------------------------------------------------------------------------ \subsection{\texttt{du} - Disk Usage} \begin{itemize} \item du shows \textit{disk usage} \item du can work with subdirectories or an entire disk \item Usage is: \texttt{du [options] [directory]} \end{itemize} %------------------------------------------------------------------------------ \subsection{Options to du} \begin{tabular}{|c|l|} \hline \textit{Option} & \textit{Function}\\ \hline -a & Show counts for all files \& directories\\ \hline -b & Display size in bytes\\ \hline -c & Print total for all arguments after processing\\ \hline -h & Print in \textit{human readable} form\\ \hline -k & Show size in Kilobytes\\ \hline -m & Display size in Megabytes\\ \hline -s & Display a summary for each argument\\ \hline -x & Skip directories containing other filesystems\\ \hline \end{tabular} %------------------------------------------------------------------------------ \subsection{\texttt{df} - Disk Free} \begin{itemize} \item df shows disk space used \& available \item Default is to display all filesystems \item Usage is: \texttt{df [options] [directory]} \end{itemize} %------------------------------------------------------------------------------ \subsection{Options to df} \begin{tabular}{|l|l|} \hline \textit{Option} & \textit{Function}\\ \hline -a & Show counts for all filesystems\\ \hline -t \textit{fs type} & Limit listing to \textit{fs type}\\ \hline -h & Print in \textit{human readable} form\\ \hline -k & Show size in Kilobytes\\ \hline -m & Display size in Megabytes\\ \hline -i & Display inode information\\ \hline -l & Limit listing to local filesystems\\ \hline -x \textit{fs type} & Exclude \textit{fs type} from listing\\ \hline \end{tabular} %------------------------------------------------------------------------------ \subsection{\texttt{fsck} - Check and repair a Linux file system} \begin{itemize} \item fsck is used to check and optionally repair a one or more Linux file systems. \item filesys can be a device name (e.g. /dev/hdc1, /dev/sdb2), a mount point (e.g. /, /usr, /home), or an ext2 label. \item fsck will try to run filesystems on different physical drives in parallel to reduce total amount time to check all of the filesystems. \item fsck makes 5 passes on the filesystem: \begin{itemize} \item Pass 1: Check inodes, blocks \& sizes \item Pass 2: Check directory structure \item Pass 3: Check directory connectivity \item Pass 4: Check reference counts \item Pass 5: Check group summary information \end{itemize} \end{itemize} %------------------------------------------------------------------------------ \subsection{fsck Options} \begin{tabular}{|l|l|} \hline \textit{Option} & \textit{Function}\\ \hline -p & Automatically repair without prompting\\ \hline -n & Don't make changes to filesystem\\ \hline -y & Assume yes to all questions\\ \hline -f & Force check even if fs is clean\\ \hline -r & Interactively prompt for changes\\ \hline -v & Be verbose\\ \hline -A & Check all filesystems in \texttt{/etc/fstab}\\ \hline -C & Display a progress bar\\ \hline -N & Don't execute, show what would be done\\ \hline \end{tabular} %------------------------------------------------------------------------------ \subsection{fsck error codes} When fsck completes, it will return a value (\texttt{\$?}) as follows: \begin{tabular}{|l|l|} \hline \textit{Code} & \textit{Meaning}\\ \hline 0 & No errors\\ \hline 1 & Errors found \& corrected\\ \hline 2 & System should be rebooted\\ \hline 4 & Filesystem error left uncorrected\\ \hline 8 & Operational error\\ \hline 16 & Usage or syntax error\\ \hline 128 & Shared library error\\ \hline \end{tabular} %------------------------------------------------------------------------------ \subsection{\texttt{e2fsck} - Check a Linux ext2 FS} \begin{itemize} \item e2fsck is used to check a Linux second extended file system (e2fs) \item e2fsck also supports ext2 filesystems countaining a journal, which are also sometimes known as ext3 filesystems. \item e2fsck operates in a similar manner to fsck (see man page) \end{itemize} %------------------------------------------------------------------------------ \subsection{\texttt{mke2fs} - Create a Linux ext2 filesystem} \begin{itemize} \item mke2fs is used to create an ext2 filesystem \item mke2fs takes a device special file as its argument \item mkfs.ext2 is the same as mke2fs \item To make an ext3 filesystem, you first make an ext2 filesystem and then add a journal to it using tune2fs or use the \texttt{-j} option to mke2fs \item Usage is: \texttt{mke2fs [options] device} \end{itemize} %------------------------------------------------------------------------------ \subsection{mke2fs Options} \begin{tabular}{|l|l|} \hline \textit{Option} & \textit{Use}\\ \hline -V & Be verbose\\ \hline -b \textit{blocksize} & Make blocks \textit{blocksize} bytes\\ \hline -c & Check for bad blocks on device\\ \hline -i \textit{bytes per inode} & Create an inode for each \textit{bytes per inode}\\ \hline -j & Create a journal (ext3)\\ \hline -L \textit{label} & Set the volume label\\ \hline -N \textit{inodes} & Create the fs with specified number of inodes\\ \hline -n & Show what would be done (don't actually create fs)\\ \hline \end{tabular} %------------------------------------------------------------------------------ \subsection{\texttt{debugfs} - Ext2 filesystem debugger} \begin{itemize} \item debugfs is a file system debugger \item It can be used to examine and change the state of an ext2 file system. \item debugfs is an interactive debugger. It understands a number of commands: \begin{description} \item[cat filespec] Dump the contents of the inode filespec to stdout. \item[cd filespec] Change the current working directory to filespec. \item[chroot filespec] Change the root directory to be the directory file spec. \item[close] Close the currently open file system. \item[quit] Exit debugfs. \end{description} \end{itemize} %------------------------------------------------------------------------------ \subsection{\texttt{dumpe2fs} - Dump filesystem information} \begin{itemize} \item dumpe2fs prints the super block and blocks group information for the filesystem present on device \item Usage is: \texttt{dumpe2fs [options] device} \item Common options are: \begin{tabular}{|l|l|} \hline \textit{Option} & \textit{Use}\\ \hline -b & Display badblocks on device\\ \hline -h & Display superblock information\\ \hline \end{tabular} \end{itemize} %------------------------------------------------------------------------------ \subsection{\texttt{tune2fs} - Adjust filesystem parameters on ext2 fs} \begin{itemize} \item tune2fs adjusts tunable filesystem parameters on a Linux ext2 filesystem. \item tune2fs can be used to add a journal to an ext2 filesystem. \item Usage is: \texttt{tune2fs [options] device} \end{itemize} %------------------------------------------------------------------------------ \subsection{tune2fs - Common options} \begin{tabular}{|l|l|} \hline \textit{Option} & \textit{Use}\\ \hline -c \textit{max-mounts} & Set no of mounts before fsck is forced\\ \hline -g \textit{group} & Set the group who can use reserved blocks\\ \hline -j & Add a journal to the filesystem\\ \hline -L \textit{label} & Set the volume label\\ \hline -r \textit{blocks} & Set the number of reserved blocks\\ \hline \end{tabular} %============================================================================== \section{Lab} \label{sec:lab104.2} %============================================================================== \section{Questions} \label{sec:questions104.2} %############################################################################## \objective{3}{Control mounting and unmounting filesystem} %############################################################################## %============================================================================== \section{Overview} \label{sec:over104.3} %------------------------------------------------------------------------------ \subsection{Weight: [3]} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to configure the mounting of a filesystem. This objective includes the ability to manually mount and unmount filesystems, configure filesystem mounting on bootup, and configure user mountable removeable filesystems such as tape drives, floppies, and CDs. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} /etc/fstab mount umount \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes104.3} %============================================================================== \section{Lab} \label{sec:lab104.3} %============================================================================== \section{Questions} \label{sec:questions104.3} %############################################################################## \objective{4}{Managing Disk Quota} %############################################################################## %============================================================================== \section{Overview} \label{sec:over104.4} %------------------------------------------------------------------------------ \subsection{Weight: [3]} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to manage disk quotas for users. This objective includes setting up a disk quota for a filesystem, editing, checking, and generating user quota reports. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} quota edquota repquota quotao \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[TBA] \begin{alltt} \end{alltt} \end{description} %============================================================================== \section{Notes} \label{sec:notes.quota.114.3} Section prepared by Pia Smith To acheive a general understanding of quotas. In particular the functions of each command, keeping in mind quotas are set on a per-filesystem basis. %------------------------------------------------------------------------------ \subsection{Enabling Quotas} \label{sec:enable} In order to use quotas they must first be enabled. To do this there are a few steps: \begin{enumerate} \item Firstly add the userquota and grpquota options to the relevant filesystems in \texttt{/etc/fstab}, as shown: \begin{alltt} /dev/hda2 /home ext3 defaults,usrquota,grpquota 1 2 \end{alltt} \item Then create the quota.user and quota.group files at the top of the filesystem, in this case, /home. Ensure that only root can read these files, like so: \begin{alltt} fehung:~# touch /home/quota.user /home/quota.group fehung:~# chmod 600 /home/quota.user /home/quota.group \end{alltt} \item We then initialise the \texttt{quota.*} files as databases by running \texttt{quotacheck}. \begin{alltt} fehung:/home# quotacheck -augv Cannot get exact used space... Results might be inaccurate. quotacheck: Scanning /dev/hda2 [/home] done quotacheck: Checked 143 directories and 689 files \end{alltt} \item Confirm that the databases have actually been initialised by making sure that the quota.* files are larger than 0. \item Run quotaon to enable the quota system: \begin{alltt} fehung:/home# quotaon -a \end{alltt} \item There are two further things to ensure quota is turned on when boots, and that the database is checked regularly: \begin{enumerate} \item To ensure quota is turned on upon system boot, add the following to the system's initialisation script (/etc/rc.d/rc.sysinit or similar): \begin{alltt} if [ -x /sbin/quotacheck ] then echo "Checking quotas." /sbin/quotacheck -auvg echo "Done." fi if [ -x /sbin/quotaon ] then echo "Enabling quotas." /sbin/quotaon -avug fi \end{alltt} \item To ensure that the databases are checked regularly, add a script to one of the crontab system directories, (such as /etc/cron.weekly/) to run quotacheck: \begin{alltt} #!/bin/bash /sbin/quotacheck -auvg \end{alltt} or a job in crontab to acheive the same thing. \end{enumerate} \end{enumerate} The filesystem (in this case /home) is now ready to accept quotas on a per user or group basis. %------------------------------------------------------------------------------ \subsection{Quota Limits} \label{sec:limits} There are five types of quota limits that can be enforced: \begin{description} \item[Per-user hard limit] this is the absolute maximum of a users allocated space, once reached the user cannot write anything else to the filesystem, and the currently worked upon file if saved is truncated and useless. The user doesn't lose what is in the current shell, so they can free up some space and then save the file. \item[Per-group hard limit] this is the absolute maximum of a groups allocated space, once reached the group cannot write anything else to the filesystem, and the currently worked upon file if saved is truncated and useless. Users in the group don't lose what is in the current shell, so they can free up some space and then save the file. \item[Per-user soft limit] an abstract limit enforced on users that is less than the hard limit, and once reached, the user enters the grace period. After the soft limit has been reached the user starts getting warnings printed on the terminal that the quota has been exceeded. \item[Per-group soft limit] an abstract limit enforced on groups that is less than the hard limit, and once reached, the group enters the grace period. After the soft limit has been reached the group starts getting warnings printed on the terminal that the quota has been exceeded. \item[Grace Period] Once a soft limit has been reached the user/group enters the grace period which is an abstract time before the hard limit is enforced, regardless of whether the hard limit is reached (assuming the user doesn't get their quota down below the soft limit in that time). \end{description} %------------------------------------------------------------------------------ \subsection{Setting up and configuring quotas.} \label{sec:quota config} The next move is to edit the quota reference for each user. We can get around this with scripts, but essentially this is not nice :) We can actually edit the quota of a typical user on our system and then copy the attributes of that users quota to other users, as follows: \begin{alltt} fehung:/home/greebo# edquota greebo \end{alltt} This edits the quota for user greebo, in this file we change the soft and hard limits to whatever we choose, example: \begin{alltt} Disk quotas for user greebo (uid 1000): Filesystem blocks soft hard inodes soft hard /dev/hda2 538 29000 30000 689 0 0 \end{alltt} The first first soft and hard values are relevant to blocks and the second to inodes, here the user has a block soft and hard limit but no limit on inodes used. We can then attribqute these settings to the rest of the users on our system like so: \begin{verbatim} fehung:/home/greebo# edquota -p greebo $(awk -F: '$3 > \ 999 { print $1 }' /etc/passwd) \end{verbatim}%$ and can confirm this worked by running \texttt{edquota } to see whether the new settings copied across. We can only modify the grace limit system wide. We do this by running \texttt{edquota -tu}, and changing the value. %------------------------------------------------------------------------------ \subsection{Quota commands} \label{sec:} %.............................................................................. \subsubsection{\texttt{quota(1)}} \texttt{quota(1)} is used to display quotas on users and groups, using the -u switch for users and -g switch for groups: \begin{alltt} fehung:/home\rootcmd{quota -uv greebo} Disk quotas for user greebo (uid 1000): Filesystem blocks quota limit grace files quota limit grace /dev/hda2 538 29000 30000 689 0 0 \end{alltt} \subsubsection{\texttt{quotaon(1)}} \texttt{quotaon(1)} turns on the quota system, quotaoff turns it off. Easy! \subsubsection{\texttt{repquota(1)}} \texttt{repquota(1)} reports on the status on quotas. Common options are as follows: \begin{alltt} -a reports on all quotas -g reports on group quotas -u reports on user quotas -v verbose mode \end{alltt} Examples: \begin{alltt} \rootcmd{repquota -v /home} \end{alltt} or \begin{alltt} \rootcmd{repquota -a} \end{alltt} %============================================================================== \section{Lab} \label{sec:lab104.4} %============================================================================== \section{Questions} \label{sec:questions104.4} %############################################################################## \objective{5}{Use file permissions to control access to files} %############################################################################## %============================================================================== \section{Overview} \label{sec:over104.5} %------------------------------------------------------------------------------ \subsection{Weight: [5]} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to control file access through permissions. This objective includes access permissions on regular and special files as well as directories. Also included are access modes such as suid, sgid, and the sticky bit, the use of the group field to grant file access to workgroups, the immutable flag, and the default file creation mode. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} chmod umask chattr \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes104.5} Notes for slide presentation: \texttt{gl1.104.5.slides.tex} \\ \textit{Prepared by Andrew Eager} %.............................................................................. \subsection{File Permissions} \begin{itemize} \item An access control mechanism \item Based on relation between file \& user \item Analogy: \begin{itemize} \item Documents receive classification \item Employees receive clearance \item Access to a particular document is determined by the documents classification and the employees clearance \end{itemize} \end{itemize} \begin{itemize} \item A file has 3 modes of access: \begin{itemize} \item Read (r) - Can view the file \item Write (w) - Can change the file \item Execute (x) - Can run the file (program) \end{itemize} \end{itemize} \begin{itemize} \item A file can be accessed by 3 different types of people: \begin{itemize} \item The file owner or user (u) \item A member of the files group (g) \item Anyone else or others (o) \end{itemize} \end{itemize} \subsection{Directory Permissions} \begin{itemize} \item Directories are treated in the same way as files \item They have an associated owner \item They have an associated group \item The permissions do slightly different things \begin{itemize} \item Read (r) - Can view the contents of directory (ls) \item Write (w) - Can add, delete, rename files \item Execute (x) - Can 'cd' into the directory and open files in it or its subdirectories \end{itemize} \end{itemize} %------------------------------------------------------------------------------ \subsection{USERS \& GROUPS} \begin{itemize} \item A user is any one person (one \& only one) \item A group consists of one or more users \item A user may be a member of more than one group \end{itemize} \noindent \fbox{\epsfig{file=../images/groups.eps,width=\textwidth}} %------------------------------------------------------------------------------ \subsection{\texttt{ls -l} is your friend} All of the file's attributes can be examined using the \texttt{ls -l} command: \begin{alltt} \small \cmd{ls -l rubbles*} -rwxrw---x 1 barney flinstones 16345 Nov15 08:45 rubbles.txt \end{alltt} \noindent \fbox{\epsfig{file=../images/perms.eps,width=\textwidth}} %------------------------------------------------------------------------------ \subsection{Numeric Equivalents} \begin{itemize} \item Each of the permission bits are bitmapped as follows: \end{itemize} \noindent \fbox{\epsfig{file=../images/filebits.eps,width=\textwidth}} %.............................................................................. \subsection{Change Permissions with \texttt{chmod}} \begin{itemize} \item chmod is used to change file permissions \item Permissions can be specified: \begin{itemize} \item In absolute form - Use octal specification \item Surgically - Use who/how/what specification \end{itemize} \end{itemize} %.............................................................................. \subsubsection{\texttt{chmod} - Octal specification} When using an octal specification, you must set the permissions for each of the user, group and other in one go: \begin{alltt} \$ chmod 0543 test.txt \$ ls -l test.txt -r-xr---wx 1 andy andy ... test.txt \end{alltt} %.............................................................................. \subsubsection{\texttt{chmod} - \underline{who}/how/what specification} Who may be one of: \begin{description} \item [\opt{u}] - The file's owner (user) \item [\opt{g}] - The file's group \item [\opt{o}] - Other users (world) \item [\opt{a}] - All three of them \end{description} %.............................................................................. \subsubsection{\texttt{chmod} - who/\underline{how}/what specification} How may be one of: \begin{description} \item [\opt{+}] - Add permission, existing unaffected \item [\opt{-}] - Remove permission, existing unaffected \item [\opt{=}] - Set permission, existing replaced \end{description} %.............................................................................. \subsubsection{\texttt{chmod} - who/how/\underline{what} specification} What may be one of: \begin{description} \item [\opt{r}] - Read permission \item [\opt{w}] - Write permission \item [\opt{x}] - Execute permission \end{description} %.............................................................................. \subsection{\texttt{chmod} - what specification} \subsection{Some examples:} Add execute permission for the file's owner (and leave everything else) \begin{alltt} \rootcmd{chmod u+x file.txt} \end{alltt} Remove write permission from group and others (and leave everything else) \begin{alltt} \rootcmd{chmod go-w file.txt} \end{alltt} Set the file to read only for everyone (kills existing permissions) \begin{alltt} \rootcmd{chmod a=r file.txt} \end{alltt} %.............................................................................. \subsection{Permission Defaults: \texttt{umask}} \begin{itemize} \item When a file is created, the system needs to know what permissions to assign to the newly created file. This is done using \texttt{umask}. \item You set the bits in umask that you \textit{don't} want set on any newly created file. \item A newly created file will \textit{never} have the execute bit set, regardless of the value of \texttt{umask}. \item For example, a \texttt{umask} of 0022 will ensure that write access is not granted to group and others. \end{itemize} \begin{alltt} \$ umask 0022 \$ touch test.txt \$ ls -l test.txt -rw-r--r-- 1 andy andy ... test.txt \end{alltt} %.............................................................................. \subsection{\textsf{SUID} Setuid bit (4000)} The setuid bit is represented by a 'S' in the user/executable field in the file permissions if the file is not executable or by an '\texttt{s}' in that field if the file is executable: \begin{alltt} -rwSrw-rw- --> Setuid bit set, not executable -rwsrw-rw- --> Setuid bit set, executable \end{alltt} The setuid bit is only used for files: %.............................................................................. \subsubsection{Files:} The user executing the file gains the privileges of the file's owner for the duration of that process' run life. For example, a program owned by root with the setuid bit set \texttt{(setuid root)} when run by a normal user will gain root privileges for the purposes of that process. It changes the effective user. One exception: Setuid is ignored if the executable file is a script (security) %.............................................................................. \subsubsection{Directories:} The setuid bit is ignored completely on directories and does SFA %.............................................................................. \subsubsection{Setuid bit - Example} \begin{alltt} \$ ls -l hexdump -rwxr-xr-x 1 root root ... hexdump \$ ls -l /dev/hda1 brw-rw---- 1 root disk ... /dev/hda1 \$ hexdump -n 10 /dev/hda1 hexdump: /dev/hda1: Permission denied \textit{# chmod 4755 hexdump} \textit{# ls -l hexdump} \textit{-rwsr-xr-x 1 root root ... hexdump} \$ hexdump -n 10 /dev/hda1 0000000 ace9 4100 4a50 5726 1a4e \end{alltt} %------------------------------------------------------------------------------ \subsection{\textsf{SGID} Setgid bit (2000)} The setgid bit is represented by a '\texttt{S}' in the group/executable field in the file permissions if the file is not executable or by a 's' in that field if the file is executable: \begin{alltt} -rw-rwSrw- --> Setgid bit set, not executable -rw-rwsrw- --> Setgid bit set, executable \end{alltt} %.............................................................................. \subsubsection{Setgid bit - Example} \begin{alltt} \$ ls -l hexdump -rwxr-xr-x 1 root root ... hexdump \$ ls -l /dev/hda1 brw-rw---- 1 root disk ... /dev/hda1 \$ hexdump -n 10 /dev/hda1 hexdump: /dev/hda1: Permission denied \textit{# chmod 2755 hexdump} \textit{# ls -l hexdump} \textit{-rwxr-sr-x 1 root root ... hexdump} \$ hexdump -n 10 /dev/hda1 hexdump: /dev/hda1: Permission denied \end{alltt} %.............................................................................. \subsubsection{Setgid bit - Example} \begin{alltt} \textit{# chgrp disk hexdump} \textit{# ls -l hexdump} \textit{-rwxr-sr-x 1 root disk .... hexdump} \$ hexdump -n 10 /dev/hda1 0000000 ace9 4100 4a50 5726 1a4e \end{alltt} %------------------------------------------------------------------------------ \subsection{Sticky bit (1000)} The sticky bit is represented by a 'T' in the others/executable field in the file permissions if the file is not executable or by a 't' in that fied if the file is executable: \begin{alltt} -rw-rw-rwT --> Sticky bit set, not executable -rw-rw-rwt --> Sticky bit set, executable \end{alltt} %.............................................................................. \subsubsection{Sticky bit (1000)} The sticky bit takes on a different meaning for files \& directories: \begin{description} \item[Files] Keep programs in swap even after execution. (Historical, not really useful but maintained for backward comparability) \item[Directories] Files in a directory with the sticky bit set can not be deleted by anyone other than: \begin{itemize} \item The owner of the file \item The owner of the directory \item The root user \end{itemize} \end{description} %.............................................................................. \subsubsection{Sticky bit Example} \begin{alltt} [andy@Node4] tmp]\$ ls -ld /tmp drwxrwxrwt 27 root root ... /tmp [andy@Node4] tmp]\$ ls -l andy-temp -rw-rw-rw- 1 andy andy ... andy-temp \textit{[patsy@Node4] tmp]\$ cat andy-temp} \textit{This is Andy's file} \textit{[patsy@Node4] tmp]\$ rm andy-temp} \textit{rm: cannot unlink `andy-temp': Operation not permitted} [andy@Node4] tmp]\$ rm andy-temp [andy@Node4] tmp]\$ \end{alltt} \newpage %------------------------------------------------------------------------------ \subsection{Ken Caldwell's Summary: Use file permissions to control access to files} \label{sec:notes104.5.summary} Linux is a multi user operating system and therefore needs to provide a system whereby the users can control access to their files. All users are given a unique User IDentification number (UID) and are assigned to at least one group(of users). Each group is identified by a Group IDentification number (GID). Frequently users are assigned to a group containing only one member (themselves) as their primary group. The system administrator can add a user to other groups such as may be convenient for example "sales", "engineering", "finance" or "management" Not all "users" of the system are natural people others such as bin, daemon, lp, fetchmail and nobody also exist. About file access permissions Any file created by a user will be owned by that user and belong to the current group of that user. That is to say the file will be tagged with its creator's UID and GID. The file will also be tagged with its (default) permissions according to the umask of its creator. The permissions pertaining to an ordinary file are the permission to Read the file, the permission to edit or delete the file (Write) and the permission to eXecute the file. These permissions are specified for: 1 The file's owner (ie the User who created the file) 2 Members of the Group associated with the file. (as determined by the GID) 3 all Others Permissions are shown in the long format output of the ls command as a nine character string such as, for example, rwxr-x--x. The first three characters represent the permissions of the User who created the file. In this case permission to Read, Write and eXecute the file. Members of the Group have Read and eXecute permission while Others have only eXecute permission. Permissions can also be expressed as an octal number with one digit for the user, one for the group and one for the others. Read permission is given a value of 4, write permission a value of 2 and execute permission a value of 1. In our previous example the file could be described as having the permissions 751. Permissions are interpreted slightly differently when applied to directories. The read permission is interpreted to mean the ability to list the directory. The write permission is interpreted to mean the ability to write files to, or delete files from, the directory. The execute permission allows a user to cd to that directory or to include it in a path to a directory to which you wish to change. The initial permissions of a file upon creation are determined by subtracting the user's umask from 777. The default umask is usually 002 on systems where users have their own exclusive group or 022 otherwise. In the former case files will be created with rwxrwxr-x permissions and in the latter case rwxr-xr-x. The permissions of a file may be altered by the file's owner by means of the chmod command. The chmod command is invoked as: \$ chmod (required change) filename The bit in brackets can be either the octal value of the new permissions e.g. 644 or a string made up of three elements. The first element is one or more of u, g, o or a standing for User, Group, Others or All. The second element is +, - or = meaning add the designated access, remove the designated access or set exact access specified. The third element is the access type ie one or more of r,w or x. There are three further access modes which we haven't discussed so far. They are SUID, SGID and the sticky bit. These are also expressed as an octal digit, 4 for SUID, 2 for SGID and 1 for the "sticky bit". Thus an executable file which we have previously described as having permissions 775 could more exactly be described as having permissions 0755. If the file was SUID the description would be 4755. Again the meanings are different for ordinary files and directories. An executable file with the SUID bit set runs with the UID of the file owner instead of inheriting the UID of the parent process. Similarly for the SGID bit. The "sticky bit" has no meaning on Linux systems when applied to ordinary files. If the "sticky bit" is set on a directory then only the owner of a file may delete it from that directory even if the directory is world writeable. This is most often seen on the /tmp directory. If the SGID bit is set on a directory then all files created in that directory will be assigned the GID of the directory rather than the GID of the user. Another way of creating files with a desired GID is to change the user's GID with the newgrp command. \newpage %============================================================================== \section{Lab} \label{sec:lab104.5} %------------------------------------------------------------------------------ \subsection{File Permissions Exercises} %.............................................................................. \subsubsection{File permissions \& the root user} \begin{enumerate} \item Log into the system as root and make sure you are in root's home directory: \begin{alltt} \rootcmd{cd /root} \end{alltt} \item Create a new file called test.txt using touch: \begin{alltt} \rootcmd{touch test.txt} \end{alltt} \item Remove all permissions of test.txt using chmod: \begin{alltt} \rootcmd{chmod 0000 test.txt} \end{alltt} \item Now write something to test.txt: \begin{alltt} \rootcmd{cat > test.txt} \end{alltt} \item This is root writing to a file without any permissions! Can you read this? \begin{alltt} \# \end{alltt} \item Now try to read the file: \begin{alltt} \rootcmd{cat test.txt} \end{alltt} \item Have a look at the owner, group and permissions of test.txt using ls -l: \begin{alltt} \rootcmd{ls -l test.txt} \end{alltt} \end{enumerate} %.............................................................................. \subsubsection{File permissions \& a normal user} \begin{enumerate} \item Log out from root and log back in as a normal user. \item Try repeating the exercise above as a normal user. \item Change the permissions of test.txt to write only: \cmd{chmod 0200 test.txt (or chmod u=w test.txt)} \item Now try writing something to the file: \begin{alltt} \cmd{cat > test.txt} \end{alltt} \item This is a user writing to a file with only write permissions! Can you read this? \begin{alltt} \$ \end{alltt} \item What do you see when you try to read the file ? \begin{alltt} \cmd{cat test.txt} \end{alltt} \item Have a look at what permissions are set for the file: \begin{alltt} \cmd{ls -l test.txt} \end{alltt} \item Now add read permissions to the file: \begin{alltt} \cmd{chmod u+r test.txt} \end{alltt} \item Look again at what permissions are set for the file: \begin{alltt} \cmd{ls -l test.txt} \end{alltt} \item Can you read the file now? \end{enumerate} %.............................................................................. \subsubsection{Umask exercises} \begin{enumerate} \item Log in as a normal user. \item Have a look to see what your umask is set to: \begin{alltt} \cmd{umask} \end{alltt} Umask = \item Touch a file and have a look at the resulting permissions: \begin{alltt} \cmd{touch test.txt} \cmd{ls -l test.txt} \cmd{rm test.txt} \end{alltt} Record the permissions: \item Now set your umask to 0000 and try the same again: \begin{alltt} \cmd{umask 0000} \cmd{touch test.txt} \cmd{ls -l test.txt} \cmd{rm test.txt} \end{alltt} Record the permissions: \item Now set your umask to 0777 and try the same again: \cmd{umask 0777} \cmd{touch test.txt} \cmd{ls -l test.txt} \cmd{rm test.txt} Record the permissions: \item What do you notice about umask and the execute permission bit? \end{enumerate} %------------------------------------------------------------------------------ \subsection{SUID \& GUID Exercises} \subsubsection{NOTE:} These exercises involve jumping in and out of super user mode. You may want to do these exercises under X with two shells open on the same desktop. Open one shell as a normal user and the other as a superuser. \begin{enumerate} \item Copy the file \texttt{/usr/bin/hexdump} to \texttt{~/bin/mydump}: \begin{alltt} \cmd{cp -a /usr/bin/hexdump ~/bin/mydump} \end{alltt} \item As root, change directory to your normal user home directory and change owner and group to root: \begin{alltt} \rootcmd{chown root:root mydump} \end{alltt} \item Now try to dump the first 10 bytes on \texttt{/dev/hda}. What part of the disk are you looking at? \begin{alltt} \cmd{mydump -n 10 /dev/hda} \end{alltt} \item As root, set the UID bit on the file and have a look at the new permissions: \begin{alltt} \rootcmd{chmod u+s mydump} \rootcmd{ls -l mydump} \end{alltt} \item Try dumping the first 10 bytes on \texttt{/dev/hda} \item As root remove the SUID from the file and set the SGID bit: (could do this as two commands if you feel better). \begin{alltt} \rootcmd{chmod u-s,g+s mydump} \rootcmd{ls -l mydump} \end{alltt} \item Try dumping the first 10 bytes on \texttt{/dev/hda} \item Have a look at the group owner for \texttt{/dev/hda} and change the group owner of myfile to the same group: \begin{alltt} \rootcmd{ls -l /dev/hda} brw-rw---- 1 root disk 3, 0 Apr 12 00:25 /dev/hda \rootcmd{chgrp disk mydump} \end{alltt} \item Try dumping the first 10 bytes on /dev/hda \item Clean up after yourself! Remove the file mydump. \end{enumerate} %----------------------------------------------------------------------------- \subsection{Stickey Bit Exercises} Note: For this exercise, you will need two normal user logins. Create any additional logins as follows: \begin{alltt} \rootcmd{ls -l} \rootcmd{adduser user-name} \rootcmd{mkdir /home/user-name} \rootcmd{passwd user-name} \end{alltt} \begin{enumerate} \item As root, Make a world read/writable /mytmp directory. \begin{alltt} \rootcmd{ls -l} \rootcmd{umask 0000} \rootcmd{mkdir /mytmp} \rootcmd{ls -ld /mytmp} drwxrwxrwx 2 root root 4096 Sep 4 12:01 mytmp/ \end{alltt} \item As User A, touch a file in /mytmp: \begin{alltt} [user-A]\cmd{touch /mytmp/user-a-file.txt} \end{alltt} \item Have a look at the permissions for the file: \begin{alltt} [user-A]\cmd{ls -l /mytmp} \end{alltt} \item Log in as user B and try to remove the file in /mytmp: \begin{alltt} [user-B]\cmd{rm /mytmp/user-a-file.txt} \end{alltt} \item What happened when user-B tried to delete the file. Were you ultimately able to delete the file even after the warning ? \item As root, set the sticky bit on the directory \texttt{/mytmp}: \begin{alltt} \rootcmd{chmod u+t /mytmp} \end{alltt} \item Repeat the above from step 2 onwards. \item Remove the \texttt{/mytmp} directory and its contents: \begin{alltt} \rootcmd{rm -r /mytmp} \end{alltt} \end{enumerate} \newpage %============================================================================== \section{Questions} \label{sec:questions104.5} %############################################################################## \objective{6}{Manage file ownership} %############################################################################## %============================================================================== \section{Overview} \label{sec:over104.6} %------------------------------------------------------------------------------ \subsection{Weight: [1]} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to control user and group ownership of files. This objective includes the ability to change the user and group owner of a file as well as the default group owner for new files. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} chmod chown chgrp \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes104.6} %------------------------------------------------------------------------------ \subsection{Change File Ownership with \texttt{chown}} \textit{by Andrew Eager} \begin{itemize} \item A file's owner can be changed using chown: \end{itemize} \begin{alltt} # ls -l rubble.txt -rw-rw-r-- 1 \textbf{barney} flinstones ... rubble.txt # chown fred rubble.txt # ls -l rubble.txt -rw-rw-r-- 1 \textbf{fred} flinstones ... rubble.txt \end{alltt} \begin{itemize} \item A file's owner \& group can also be changed using chown: \end{itemize} \begin{alltt} # ls -l rubble.txt -rw-rw-r-- 1 \textbf{barney flinstones} ... rubble.txt # chown fred:flinfolks rubble.txt # ls -l rubble.txt -rw-rw-r-- 1 \textbf{fred flinfolks} ... rubble.txt \end{alltt} %------------------------------------------------------------------------------ \subsection{Change File Group Ownership with \texttt{chgrp}} \begin{itemize} \item To change only the group use chgrp: \end{itemize} \begin{alltt} \# ls -l rubble.txt -rw-rw-r-- 1 barney \textbf{flinstones} ... rubble.txt \# chgrp flinfolks rubble.txt \# ls -l rubble.txt -rw-rw-r-- 1 barney \textbf{flinfolks} ... rubble.txt \end{alltt} %------------------------------------------------------------------------------ \subsection{Summary: Managing File Ownership} \label{sec:104.6.1.re} \textit{by Ken Caldwell} The UID and/or the GID of a file may be changed by the file's owner by means of the chown command. man chown for all the options but typically invoked as: \begin{alltt} \cmd{chown newowner:newgroup filename} \end{alltt} or: \begin{alltt} \cmd{chown 314:42 filename} \end{alltt} \texttt{chgrp} is similar but may only be used to change the group. %============================================================================== \section{Lab} \label{sec:lab104.6} %============================================================================== \section{Questions} \label{sec:questions104.6} %############################################################################## \objective{7}{Create and change hard and symbolic links} %############################################################################## %============================================================================== \section{Overview} \label{sec:over104.7} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be able to create and manage hard and symbolic links to a file. This objective includes the ability to create and identify links, copy files through links, and use linked files to support system administration tasks. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} ln \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes104.7} %------------------------------------------------------------------------------ \subsection{\texttt{ln} --- link} A \textit{link} is a pseudofile that creates a shortcut to the original file located elsewere on the filesystem. \begin{description} \item [Symbolic links] \item [Hard links] \end{description} %------------------------------------------------------------------------------ \subsection{Linux files and \textit{inodes}} In creating a file with a command such as: \begin{alltt} \$ cat -n "Hello" > foo \end{alltt} \begin{enumerate} \item An \textit{inode} number in the superblock is allocated to the file \item The files inode is populated with information \item A directory entry (Hard link) is made in a directory file \item The file's data is written to a place on the disk pointed to by the \textit{inode} \end{enumerate} %------------------------------------------------------------------------------ \subsection{Linux files and \textit{inodes}} \fbox{\epsfig{file=../images/links2.fig.eps,width=\textwidth}} %------------------------------------------------------------------------------ \subsection{The \textit{inode} information} \begin{itemize} \item Some of the information contained in a file's inode can be displayed with the \texttt{ls} command:% {\small% \begin{alltt} \cmd{ls -il foo} 2723514 -rw-r--r-- 2 geoff geoff 16 Mar 22 09:38 /tmp/foo \end{alltt}} \item A more complete view of inode information may be had with \texttt{stat}: {\small \begin{alltt} \cmd{stat foo} File: "/tmp/foo" Size: 5 Blocks: 2 IO Block: 4096 Regular File Device: 802h/2050d Inode: 2723514 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/geoffrey) Gid: ( 1000/geoffrey) Access: Fri Mar 22 08:25:00 2002 Modify: Fri Mar 22 09:38:19 2002 Change: Fri Mar 22 09:52:26 2002 \end{alltt}} \end{itemize} %------------------------------------------------------------------------------ \subsection{\textit{Hard links} are directory entries} \begin{itemize} \item A file may have one or more \textit{hard links} to it. Additional \textit{hard links} are made with the \texttt{ln} command: {\small %\scriptsize \begin{alltt} \cmd{ln foo bar} \cmd{ls -il foo bar} 2723514 -rw-r--r-- 2 geoff geoff 5 Mar 22 09:38 bar 2723514 -rw-r--r-- 2 geoff geoff 5 Mar 22 09:38 foo \end{alltt} } \item there is only one file on the disk \item it has one inode \item it has two names (hard links) \end{itemize} \vfill %------------------------------------------------------------------------------ \subsection{Hard links are directory entries} \ \fbox{\epsfig{file=../images/links3.fig.eps,width=\textwidth}} %------------------------------------------------------------------------------ \subsection{\texttt{foo} a.k.a. \texttt{bar}} \begin{itemize} \item One \textsf{inode} one set of permissions: \begin{alltt} \cmd{chmod 640 foo} \cmd{ls -l foo bar} -rw-r----- 2 geoff geoff 5 Mar 22 09:38 bar -rw-r----- 2 geoff geoff 5 Mar 22 09:38 foo \end{alltt} \item Same contents: \begin{alltt} \cmd{echo "Hello there!" > bar} \cmd{head foo bar} ==> foo <== Hello there! ==> bar <== Hello there! \end{alltt} \item Same contents: \begin{alltt} \cmd{diff foo bar} \$ \end{alltt} \item Same \textsf{inode}: \begin{alltt} \cmd{ls -il foo bar} 2723514 -rw-r----- 12 geoff geoff 5 Mar 22 09:38 bar 2723514 -rw-r----- 12 geoff geoff 5 Mar 22 09:38 foo \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsection{Hard link constraints} \begin{itemize} \item Hard links are confined within the volume: \begin{alltt} \cmd{ln foo ~/fred} ln: creating hard link `/home/geoffrey/fred' to `foo': Invalid cross-device link \end{alltt} \item Directories may not have multiple hard links: \begin{alltt} \cmd{ln /tmp doh} ln: `/tmp': hard link not allowed for directory \end{alltt} \item \texttt{ln} declines to clobber unless forced: \begin{alltt} \cmd{ln foo bar} ln: `bar': File exists \cmd{ln -f foo bar} \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsection{Symbolic links} %------------------------------------------------------------------------------ \subsection{A \textit{symbolic link} is a file that points to another} \fbox{\epsfig{file=../images/links4.fig.eps,width=\textwidth}} %============================================================================== \section{Lab} \label{sec:lab104.7} \subsection{Make some files and directories} \emph{These directories and files are just examples to experiment with. Follow the steps.} \begin{enumerate} \item change to you home directory -- \verb+$ cd + %$ \item check where you are -- \verb+$ pwd + %$ \item make a new directory -- \verb+$ mkdir test.dir+ %$ \item change to the new directory -- \verb+$ cd test.dir+%$ \item check where you are -- \verb+$ pwd + %$ \item check what's there -- \verb+$ ls + %$ \item make an empty file -- \verb+$ touch a.file+%$ \item make a hard link to the a.file -- \verb+$ ln a.file b.file+%$ \item make a soft link to the a.file -- \verb+$ ln -s a.file c.file+%$ \item check what's there (the a includes hidden files) -- \verb+$ ls -al+ %$ \item make a subdirectory -- \verb+$ mkdir sub.dir+%$ \item make a soft link to the subdirectory -- \verb+$ ln -s sub.dir ln.dir+%$ \item take a look (the i shows the inode numbers) -- \verb+$ ls -li+%$ \\ Your list should look something like this: \end{enumerate} {\scriptsize \begin{alltt} [geoffrey@freckle text.dir]\cmd{ls -li} total 1 454378 -rw-rw-r-- 2 geoffrey geoffrey 0 Sep 1 14:35 a.file 454378 -rw-rw-r-- 2 geoffrey geoffrey 0 Sep 1 14:35 b.file 454379 lrwxrwxrwx 1 geoffrey geoffrey 6 Sep 1 14:37 c.file -> a.file 454380 -rw-rw-r-- 1 geoffrey geoffrey 0 Sep 1 14:44 d.file 454381 lrwxrwxrwx 1 geoffrey geoffrey 7 Sep 1 15:04 ln.dir -> sub.dir 456433 drwxrwxr-x 2 geoffrey geoffrey 1024 Sep 1 14:35 sub.dir \end{alltt} } \subsection{Hard and soft links} \emph{Note that \texttt{a.file} and \texttt{b.file} have the same \textsf{inode} number, this indicates that the two names represent the same file. But \texttt{c.file} is an alias to that file with two names} {\scriptsize \begin{alltt} 454378 -rw-rw-r-- 2 geoffrey geoffrey 0 Sep 1 14:35 a.file 454378 -rw-rw-r-- 2 geoffrey geoffrey 0 Sep 1 14:35 b.file 454379 lrwxrwxrwx 1 geoffrey geoffrey 6 Sep 1 14:37 c.file -> a.file \end{alltt} } The following should show you that they they are the same file. \begin{enumerate} \item add some text into \verb+a.file+ \\\verb+$ echo "this is going into the in a.file" >> a.file+ \item look in a.file \verb+$ cat a.file+ ... the text went in? \item look at the \verb+c.file+ -- \verb+$ cat c.file+ -- it's a soft link to \verb+a.file+ \item nuke the \verb+a.file+ -- \verb+$ rm a.file+ \item take another look at the \verb+c.file+ -- \verb+$ cat c.file+ nothing to link to now \item but what about the \verb+b.file+ -- \verb+$ cat b.file+ \end{enumerate} %============================================================================== \section{Questions} \label{sec:questions104.7} %############################################################################## \objective{8}{Find system files and place files in the correct location} %############################################################################## %============================================================================== \section{Overview} \label{sec:over104.8} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidates should be thouroughly familiar with the Filesystem Hierarchy Standard, including typical file locations and directory classifications. This objective includes the ability to find files and commands on a Linux system. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} find locate slocate updatedb whereis which /etc/updatedb.conf \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes104.8} %------------------------------------------------------------------------------ \subsection{Ken Foskey's Summary: Using \texttt{find}} \label{sec:104.8.1.re} :vi tw=72 ...heading ... The find command. The find command is one of the fundamental tools of Unix. It is a tool that is constantly rediscovered as you perform more and more complex operations with it. The man page of this simple tool is 555 lines long. The most basic use of find is: find -name "$<$mask$>$" To find a missing file somewhere in you home directory find ~ -name missing.file where ~ is shorthand for your home directory. You can also use masks like "*.txt.gz" but you must put it in quotes. Why do you have to put it in quotes? ...pause for discussion from floor... When you use an * in a bash command line it is interpreted as a file expansion and it is looked for in the current directory and if it does exist it is substituted before the command is sent to find. If it is not found then your shell may generate an error message (for example csh, I think). ... page ... According to the man page 'find - search for files in a directory hierachy' This is true but you can also find directories as well, like the filesystems . First we will start with some basic options: Doing options: -print list the filename (default, never really use it). -exec run a command -ok run a command after prompting for confirmation. -ls list file like `ls -dils`, is a lot of file information. Advanced doing options, I am sure you will use these one day: -prune don't descend past this directory. -printf Print a filename based on format like C printf. -print0 print but end with a null character. -fprintf print a format string to a filename, (scripting??) -fprint print filenames to a file. -fls ls to a file Options on what entries we select: Most of these options take a number, +number, -number. A little explanation is required first. picking one option, -atime: -atime 2 Will pick any file accessed two days ago. -atime -2 Will pick any file access more than two days ago -atime +2 Will pick any file accessed in the last day. ** file date and time Some basic stuff based on the file details itself. -atime n files on access date -ctime n files on creation date (note chmod mucks this up) -mtime n files on modification date -anewer n files on access date based on another file. -cnewer n files on creation date based on another file. -newer n files on modification date based on another file. example: delete all files older than 7 days in the /data directory who have a .A extension. % .... pause to get suggestions from floor... % .... lecturers note solution is find /data -name "*.A" -ctime -7 -exec % rm {} \; ... Write the solution here. %%%%% _______________________________________________________________ A script may run a command and then 'touch' a tag file to give a timestamp when it was run. assume that the last thing a script does is touch modification.tag in the /parms directory. Write a command line that lists all details of files modified in the /apps/source/ directory based on this tag file. .... pause to get suggestions from floor... .... lecturers note solution is find /data -mnewer /parms/modification.tag -ls.... Write solution here. % ---------------------------------------------------------------- There is also a amin, cmin and mmin version of the above. ** Owner and group. One problem with the Unix authenticification system, when you delete a userid you end up with magic numbers on a directory listing. It is handy to be able to change the ownership on all files from the exiting staff member to the new person working on those projects. -nouser users numeric id does not have and entry in /etc/passwd -nogroup group numeric id does not have an entry in /etc/group -uid n User by number -user name User by name -gid n Group by number -group name Group by name I recently converted from Redhat to Debian. I installed a new harddisk and mounted the old one as /mnt/old1. I notice that when I do ls -al I get a username of 500 in the directory listing. Change all the occurences of 500 to the username of ken. .... lecturers note solution is AS ROOT \begin{verbatim} find /mnt/old1 -uid 500 -exec chown ken {} \;.... \end{verbatim} Write solution here \hrule ** Inode number and links You have a directory listing, the hard link count is greater than 1. ... lecturers note wait and ask class how we know this .... You have no idea where the other hard link is and you want to locate the other version to see what impact a change may have. -inode n ... lecturers note, I have no idea how to do this .... Write solution here ------------------------------------------------------- Advanced options on what entries we select: -iregex Use regex rather than standard file masks. Options on how we go through the directories: -xdev don't go into other file systems. \newpage %------------------------------------------------------------------------------ \subsection{Andrew Eager's Summary: Using \texttt{locate}, \texttt{updatedb} and \texttt{slocate}} \label{sec:104.8.2.re} SLOCATE - Secure Locate LOCATE - Normal Locate (Normally symlinked to slocate) Slocate is used to find files on the system without actually having to search the entire directory tree. A database of all files on the system is created and is then used by slocate to reveal the files actual location. It is important to note that slocate may return a result which is no longer valid since the directory structure may have been modified since the slocate database was last created. For example, you create a file called poobar.txt, create the slocate database and then remove poobar.txt. Slocate will still return poobar.txt?s original location until the slocate database is recreated. Slocate can be used in two modes: \begin{itemize} \item Search mode:- To locate an actual file within the database \item Database creation mode:- To build the database \end{itemize} \subsubsection{Search usage:} \begin{alltt} slocate [-qi] [-d ] [-r ] ... \end{alltt} \begin{description} \item[\texttt{-q}] Quiet mode. Suppress error messages. \item[\texttt{-i}] \underline{Does a case insensitive search.} \item[\texttt{-d}] \underline{Specify a database to use.} \item[\texttt{-r}] Pass a regular expression instead of a search string. \end{description} \subsubsection{Examples:} \begin{description} \item[\texttt{locate ls}] \begin{alltt} \$ locate ls \(\hookleftarrow\) ... /etc/X11/xkb/symbols/xfree68/ataritt /etc/X11/xkb/symbols/xfree68/amiga /etc/alternatives/tclsh ... \end{alltt} \item[\texttt{locate -r "/ls\$"}] \begin{alltt} \$ locate -r "/ls\$" \(\hookleftarrow\) /home/geoffrey/tafe/mos/compress/ls /usr/lib/bitchx/help/8_Scripts/ls /bin/ls \end{alltt} \end{description} The above example illustrates the need for a \textsf{regex} option to \texttt{locate}. In the first example there will be lots of hits. In the second there is only one (the actual \texttt{ls} command). As well as searching for a file in the database, \texttt{locate} can also build the search database. \subsubsection{Database Creation Usage:} As well as searching for a file in the database, slocate can also build the search database. \begin{description} \item[\texttt{-u}] \underline{Create slocate database starting at path \texttt{/}.} \item[\texttt{-U $<$dir$>$}] \underline{Create slocate database starting at path $$.} \item[\texttt{-c}] \underline{Parse original GNU Locate's \texttt{/etc/updatedb.conf}} \item[\texttt{-e $<$dir1...$>$}] \underline{Exclude directories from the slocate database when using the -u or -U options.} \item[\texttt{-f $<$fs...$>$}] Exclude file system types from the slocate database \item[-l] Security level. 0--$>$ security off, 1--$>$ security on \item[\texttt{-q}] Quiet mode. Error messages are suppressed. \item[\texttt{-o $<$file$>$}] \underline{Specify the name of the database file to create} \item[\texttt{-v}] Be verbose \end{description} \subsubsection{Examples} \begin{itemize} \item Create a database for all directories under \texttt{/usr} and place the resulting database file into \texttt{slocate.db} in andy's home directory. \begin{alltt} \# slocate -U /usr -o /home/andy/slocate.db \(\hookleftarrow\) \end{alltt} \item Create a database for all directories under /usr, excluding directories under /usr/man and place the resulting database file into slocate.db in andy?s home directory. \begin{alltt} \# slocate -U /usr -e /usr/man -o /home/andy/slocate.db \(\hookleftarrow\) \end{alltt} \end{itemize} \subsubsection{Update \texttt{slocate} database---\texttt{update}} \texttt{updatedb} is simply a link to slocate that implies the -u option. (Excerpt from the man page:- man updatedb) \small \begin{alltt} \$ ls -l `which updatedb` \(\hookleftarrow\) lrwxrwxrwx 1 root root 7 Mar 27 10:44 /usr/bin/updatedb -> slocate* \end{alltt} \normalsize \texttt{updatedb} is typically executed periodically via \textsf{cron}. \subsubsection{\texttt{/etc/updatedb.conf}} \begin{itemize} \item The \texttt{updatedb} (or \texttt{slocate}) tool can use a configuration file to decide which directories and file systems are included when the database is created. This file is normally located in \texttt{/etc/updatedb.conf} \item The following is a list of keywords that are recognised by updatedb (slocate) and their equivalent command line options \begin{description} \item[\texttt{PRUNEFS}] \texttt{$<$fs\_type1 fs\_type2...$>$} - Option \texttt{-f} \item[\texttt{PRUNEPATHS}] \texttt{$<$dir1 dir2 dir3...$>$} - Opion \texttt{-e} \end{description} \item Example \texttt{updatedb.conf} \begin{alltt} PRUNEFS="devpts NFS nfs afs proc smbfs autofs auto iso9660" PRUNEPATHS="/tmp /usr/tmp /var/tmp /afs /net? export PRUNEFS export PRUNEPATHS \end{alltt} \end{itemize} \subsubsection{\texttt{slocate} Exercises} \begin{enumerate} \item Create an \texttt{slocate} database in your home directory including all directories from \texttt{/} down. \item Using the database created in step 1, locate all files with \texttt{rm} in the filename \item Using the database created in step 1, locate the executable file \texttt{rm} using a regex. (ie \texttt{/some/path/rm}) \item Create an slocate database in your home directory include all directories from \texttt{/} down but excluding the \texttt{/bin} directory. \item Repeat (2) and (3) above. Do you notice anything different ? \item After backing up your existing \texttt{/etc/updatedb.conf}, say \begin{alltt} \# cp /etc/updatedb.conf /etc/updatedb.conf.orig \(\hookleftarrow\) \end{alltt} edit \texttt{/etc/updatedb.conf} to perform the same actions as in step (4). \item When you have finished this exercise restore your original \texttt{/etc/updatedb.conf}. \end{enumerate} %============================================================================== \section{Lab} \label{sec:lab104.8} %============================================================================== \section{Questions} \label{sec:questions104.8} %****************************************************************************** %****************************************************************************** \topic{110}{X} %****************************************************************************** %****************************************************************************** %############################################################################## \objective{1}{Install \& Configure XFree86} %############################################################################## %============================================================================== \section{Overview} \label{sec:over110.1} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate should be able to configure and install X and an X font server. This objective includes verifying that the video card and monitor are supported by an X server, as well as customizing and tuning X for the videocard and monitor. It also includes installing an X font server, installing fonts, and configuring X to use the font server (may require a manual edit of /etc/X11/XF86Config in the "Files" section) %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} XF86Setup xf86config xvidtune /etc/X11/XF86Config .Xresources \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{X Window System} \label{sec:notes110.1} %------------------------------------------------------------------------------ \subsection{The Linux Desktop GUI} \begin{itemize} \item On Linux, the graphical desktop is controlled by 4 different types of software: \begin{itemize} \item The X server - hardware interface \item A window manager - windows, icons etc \item Desktop manager - file manager, control panel etc. \item The application itself (the x-client) \end{itemize} \item Only the X server \& X-client are mandatory \end{itemize} %------------------------------------------------------------------------------ \subsection{Window Managers} \begin{itemize} \item Some window managers are: \begin{itemize} \item twm - Tab Window Manager - very light weight \item AfterStep - Light resource usage \item Blackbox - Fast \& simple \item Enlightenment - Resource intensive \item FVWM - Not so popular anymore \item IceWM - Emulates OS/2 \& windows \item Sawfish - default for Gnome \item Window Maker \end{itemize} \end{itemize} %------------------------------------------------------------------------------ \subsection{Desktop Environments} \begin{itemize} \item The two most popular Linux Desktops are: \begin{itemize} \item KDE \item Gnome \end{itemize} \end{itemize} %------------------------------------------------------------------------------ \subsection{Starting X} \begin{itemize} \item The X server is an executable called 'X' \item Usually a link: \begin{alltt} \$ ls -l `which X` lrwxrwxrwx ... /usr/bin/X11/X -> XFree86 \end{alltt} \item You can start X in several ways: \begin{itemize} \item X directly - (not very useful) \item xinit - X \& one X-term client \item startx - X \& desktop (KDE or Gnome) \end{itemize} \end{itemize} %------------------------------------------------------------------------------ \subsection{X Server Screen references} When X starts, it associates itself with a \textit{display \& screen}. The syntax for this is: \texttt{ ':display.screen'} \begin{itemize} \item Display is 0 for the first X server, 1 for the next etc. \item Screen is 0 for the first screen connected to a multihead video card or multiple video cards \item The default for display \& screen are both 0 \end{itemize} Example: \texttt{ :0.1} The second screen (head) on X server 0 \texttt{ :1.0 or :1} The first screen on the second X server %------------------------------------------------------------------------------ \subsection{Starting X directly} The syntax for X is: \begin{alltt} \texttt{X [:display.screen] [options]} \end{alltt} \subsubsection{Examples:} \begin{itemize} \item Start X on display 0, screen 0: \begin{alltt} \cmd{X} \end{alltt} \item Start X on display 1, screen 1: \begin{alltt} \cmd{X :1} \end{alltt} \item Start X on display 1, screen 1: \begin{alltt} \cmd{X :1.1} \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsection{Starting X using xinit} The syntax for xinit is: \begin{alltt} \texttt{xinit [[client] options ] [--[server] [display] options ]} \end{alltt} \subsubsection{Examples:} \begin{itemize} \item Start X and one xterm on display 0, screen 0: \begin{alltt} \cmd{xinit} \end{alltt} Start X and 1 xterm on the second display: \begin{alltt} \cmd{xinit -- :1} \end{alltt} Start X and xcalc on the second display: \begin{alltt} \cmd{xinit /usr/X11R6/bin/xcalc -- :1} \end{alltt} Start X and kde on the second display: \begin{alltt} \cmd{xinit /usr/bin/startkde -- :1} \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsection{Starting X using startx} \begin{itemize} \item startx is a wrapper for X and your favourite desktop \item it has the same syntax as xinit \item On RedHat, default desktop is in \texttt{/etc/sysconfig/desktop} \end{itemize} \subsubsection{Examples:} \begin{itemize} \item Start X and the default desktop on display 0, screen 0 \begin{alltt} \cmd{startx} \end{alltt} \item Start X and desktop on the second display in 16 bit colour \begin{alltt} \cmd{startx -- :1 -depth 16} \end{alltt} \item Start X and the kde desktop on the second display \begin{alltt} \cmd{startx /usr/bin/startkde -- :1} \end{alltt} \end{itemize} %------------------------------------------------------------------------------ \subsection{Running X-clients remotely} \begin{itemize} \item An X-client can be told to direct its output to a given display in one of two ways: \begin{itemize} \item By using the DISPLAY environment variable \item By using the -display option on the command line \end{itemize} \item A remote display is specified using the syntax: \texttt{hostname:display.screen} Example: \texttt{node12.c222:1.0} Refers to the first screen on the second display of host node12.c222 \item Using the -display option \cmd{xcalc -display node12.c222:1.0} \item Using the DISPLAY environment variable \cmd{export DISPLAY=node12.c222:1.0} \cmd{xcalc} \end{itemize} Both methods will run xcalc on the second display of host node12.c222. Note that in the second case, the DISPLAY variable is exported so it will apply to all X-clients started on that terminal. %------------------------------------------------------------------------------ \subsection{Controlling access to the X server} \begin{itemize} \item By default, an X server will only accept connections from clients running on the same host as the server. \item Remote access can be granted using the \texttt{xhost} command \begin{itemize} \item \texttt{xhost + } - Disable access control (any host is OK) \item \texttt{xhost - } - Enable access control (only listed hosts) \item \texttt{xhost +hostname} - Allow hostname to connect \item \texttt{xhost -hostname} - Dissallow hostname from connecting \end{itemize} \item xhost uses host based access control \item xhost must be run on the X server. \end{itemize} %------------------------------------------------------------------------------ \subsection{Testing access to the X server} \begin{itemize} \item As a client, you can see if you have permission to connect to a remote X server by: \begin{itemize} \item Setting \& exporting the DISPLAY variable to the desired X server \item running xhost without any arguments \end{itemize} \item Example:- See if node12.c222 is available to us for display \cmd{export DISPLAY=node12.c222:1.0} \cmd{xhost} \texttt{xhost: unable to open display "node12.c222:.0"} \end{itemize} %------------------------------------------------------------------------------ \subsection{The X server} \begin{itemize} \item There are two versions of the X server: \item X version 3: \begin{itemize} \item Uses the configuration file \texttt{/etc/X11/XF86Config} \item Has different X executables for different cards \end{itemize} \item X version 4: \begin{itemize} \item Uses the configuration file \texttt{/etc/X11/XF86Config-4} \item Has only one executable for all video cards (XFree86) \end{itemize} \item To tell which version you are running do the following: Example: \cmd{ls -l `which X`} \begin{alltt} lrwxrwxrwx .... /usr/bin/X11/X -> XF86_SVGA \end{alltt} Using X version 3 on an SVGA card \cmd{ls -l `which X`} \begin{alltt} lwxrwxrwx .... /usr/bin/X11/X -> XFree86 \end{alltt} Using X version 4. \end{itemize} %------------------------------------------------------------------------------ \subsection{Version 3 drivers} The version 3 drivers are specific to a particular card type. Some of the more common drivers are: \begin{itemize} \item XF86\_3DL - 3D Labs video cards \item XF86\_8514 - 8514 video cards \item XF86\_AGX - AGX video cards \item XF86\_FB - Generic frame buffer device for non-specific cards \item XF86\_Mach64 - ATI Mach 64 video cards \item XF86\_S3 - S3 based video cards \item XF86\_S3V - S3 virge video cards \item XF86\_SVGA - VESA Super VGA cards \item XF86\_VGA16 - 16 colour VGA cards \end{itemize} %------------------------------------------------------------------------------ \subsection{The X server} \begin{itemize} \item is the interface to the graphics card \item allows X clients to display information \item can run multiple instances on a single card \item accepts \textbf{local or remote} X-clients \end{itemize} \newpage %============================================================================== \section{Lab} \label{sec:lab110.1} %------------------------------------------------------------------------------ \subsection{X Server - Lab} \subsubsection{General Notes:} \begin{itemize} \item The Gnome desktop X-client is \texttt{/usr/bin/gnome-session} \item The KDE desktop X-client is \texttt{/usr/bin/startkde} \end{itemize} \subsubsection{Exercise:} \begin{enumerate} \item Using \texttt{xinit}, startup the following three X sessions: (You will need 3 'normal user' consoles) \begin{enumerate} \item The KDE desktop on display \texttt{:0} \item The Gnome desktop on display \texttt{:1} \item An Xterm on display \texttt{:2} \end{enumerate} \item Toggle between each of the 3 displays using \texttt{}, \texttt{} and \texttt{}. \item On display 2, (the 3rd display) startup twm in the background followed by a second xterm. \begin{alltt} \cmd{twm &} \cmd{xterm &} \end{alltt} \item On your KDE desktop, open up an xterm and disable access control on that X server: \begin{alltt} \cmd{xhost +} \end{alltt} \item On display 2 in the second xterm, setup the \texttt{DISPLAY} variable to point to your partners X-server running the KDE desktop (display :0): \begin{alltt} \cmd{export DISPLAY=nodeXX.c222:0} \end{alltt} (Where XX is your partner's node number) \item Now on that same terminal, run the xcalc command and confirm that xcalc launches on your partners KDE desktop. \item Again on the same terminal, take a screendump of your partners KDE desktop: \begin{alltt} \cmd{xwd -root >temp} \end{alltt} \item Now move over to the first xterm and restore the screen dump of your partners KDE desktop to your own screen: \begin{alltt} \cmd{xwud -in temp} \end{alltt} \end{enumerate} %============================================================================== \section{Questions} \label{sec:questions110.1} %############################################################################## \objective{2}{Setup a Display Manager} %############################################################################## %============================================================================== \section{Overview} \label{sec:over110.2} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate should be able setup and customize a Display manager. This objective includes turning the display manager on or off and changing the display manager greeting. This objective includes changing default bitplanes for the display manager. It also includes configuring display managers for use by X-stations. This objective covers the display managers XDM (X Display Manger), GDM (Gnome Display Manager) and KDM (KDE Display Manager). %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} /etc/inittab /etc/X11/xdm/* /etc/X11/kdm/* /etc/X11/gdm/* \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} \begin{description} \item[]: \begin{alltt} \end{alltt} \item[]: \end{description} %============================================================================== \newpage \section{Notes} \label{sec:notes110.2} %------------------------------------------------------------------------------ \subsection{Display Managers} \begin{itemize} \item Manages connection to local or remote X sessions \item Similar function to getty \& login \item Different types are: \begin{itemize} \item KDM - KDE Display Manager \item GDM - Gnome Display Manager \item XDM - X Display Manager (base X system) \end{itemize} \end{itemize} %------------------------------------------------------------------------------ \subsection{Life Cycle of a DM} \begin{itemize} \item When a display manager is started, it: \begin{itemize} \item Starts up X servers on each display configured \item Displays a GUI login window \item Authenticates user / password \item Starts selected X-session (KDE, Gnome, Xterm..) \end{itemize} \item When the X-session ends it: \begin{itemize} \item Resets the X server \item Repeats the process above (optional) \end{itemize} \end{itemize} %------------------------------------------------------------------------------ \subsection{Local \& Remote X sessions} \begin{itemize} \item A user logging in through XDM can: \begin{itemize} \item Log into their local system \item Log into another system running XDM \end{itemize} \item For remote logins, XDMCP (X Display Manager Control Protocol) is used \item A remote X login can be established to: \begin{itemize} \item A specific host \item Any available host (broadcast) \item A host chosen from a list \end{itemize} \end{itemize} %------------------------------------------------------------------------------ \subsection{Direct Remote X login - Client Side} \begin{itemize} \item To log into a specific host: \cmd{X [display] -query } Example: \cmd{X :1 -query node10.c222} This will startup an X server on the second display of your local machine. The X session established will run on the host node10.c222 \item This assumes that node10.c222 has allowed access to the client in its xdm-config. \end{itemize} %------------------------------------------------------------------------------ \subsection{Broadcast Remote X login - Client Side} \begin{itemize} \item To log into any host runnig xdm: \cmd{X [display] -broadcast} Example: \cmd{X :1 -broadcast} This will startup an X server on the second display of your local machine. The X session established will run on any host that responds to the broadcast request. \item This assumes that xdm on the server machines have been configured to listen to broadcast requests. \end{itemize} %------------------------------------------------------------------------------ \subsection{Chooser Remote X login - Client Side} \begin{itemize} \item To log into a host by selecting it from a chooser list: \cmd{X [display] -indirect } Example: \cmd{X :1 -indirect foozle.c222} This will startup an X server on the second display of your local machine. A list of hosts available for logon will be generated by foozle.c222. An X session will then be established on the host selected from the list. \item This assumes that xdm on foozle.c222 has been configured to provide clients with a chooser \end{itemize} %------------------------------------------------------------------------------ \subsection{Configuring XDM} \begin{itemize} \item XDM has its configuration files in \texttt{/etc/X11/xdm} \item \texttt{xdm-config} controls xdm functionality \item \texttt{Xaccess} controls which clients can access XDM \item man xdm gives full documentation to both files \end{itemize} %------------------------------------------------------------------------------ \subsection{Configuring Xaccess} \begin{itemize} \item Xaccess has 4 different syntaxes: \begin{itemize} \item \texttt{pattern} - Controls direct \& broadcast access \item \texttt{pattern } - Forwarding of indirect access \item \texttt{pattern CHOOSER BROADCAST} - To use a chooser \item \texttt{pattern CHOOSER } - To use a chooser with a specific list \end{itemize} \end{itemize} %------------------------------------------------------------------------------ \subsection{Xaccess - Direct \& Broadcast} \begin{itemize} \item To control direct and broadcast access to XDM simply specify a list of hosts that are allowed to connect: Example \texttt{/etc/X11/xdm/Xaccess}: \begin{alltt} !badguy.c222 *.c222 \end{alltt} This says allow all hosts in the c222 domain except for the host badguy.c222 to connect to XDM. \end{itemize} %------------------------------------------------------------------------------ \subsection{Xaccess - Providing a chooser} \begin{itemize} \item To have XDM provide a predefined list of available hosts for all indirect requests: Example \texttt{/etc/X11/xdm/Xaccess}: \begin{alltt} admin.c222 CHOOSER BROADCAST *.c222 CHOOSER node1.c222 node2.c222 \end{alltt} This says that admin.c222 will get a list of hosts discovered on the network by using a broadcast to choose from. Anyone else in the c222 domain will get a list with only node1 and node2 in the list. \end{itemize} %------------------------------------------------------------------------------ \subsection{xdm-config - Enabling chooser requests} \begin{itemize} \item In order to use the chooser, the following line needs to be removed from \texttt{/etc/X11/xdm/xdm-config}: \begin{small} \begin{alltt} ! SECURITY: do not listen for XDMCP or Chooser requests ! Comment out this line if you want to manage X terminals with xdm DisplayManager.requestPort: 0 \end{alltt} \end{small} \item Note that a comment in this file starts with a '!'. \end{itemize} %============================================================================== \section{Lab} \label{sec:lab110.2} %============================================================================== \section{Questions} \label{sec:questions110.2} %############################################################################## \objective{4}{Install \& Customize a Window Manager Environment} %############################################################################## %============================================================================== \section{Overview} \label{sec:over110.4} %------------------------------------------------------------------------------ \subsection{Weight: []} %------------------------------------------------------------------------------ \subsection{Statement of Objective:} Candidate should be able to customize a system-wide desktop environment and/or window manager, to demonstrate an understanding of customization procedures for window manager menus and/or desktop panel menus. this objective includes selecting and configuring the desired x-terminal (xterm, rxvt, aterm etc.), verifing and resolving library dependency issues for X applications, exporting X-display to a client workstation. %------------------------------------------------------------------------------ \subsection{Key files, terms, and utilities:} \begin{alltt} .Xdefaults xhost DISPLAY environment variable \end{alltt} %------------------------------------------------------------------------------ \subsection{Resources:} %============================================================================== \newpage \section{Notes} \label{sec:notes110.4} %============================================================================== \section{Lab} \label{sec:lab110.4} %============================================================================== \section{Questions} \label{sec:questions110.4} %****************************************************************************** %\backmatter %****************************************************************************** \appendix %****************************************************************************** \chapter{Debian Install} %****************************************************************************** \chapter{openMosix} \section{Open Mosix} Open Mosix is a collection of software designed for clustering a set of machines. It comprises two parts: \begin{itemize} \item The kernel \item User land utilities \end{itemize} \label{sec:101.3_in} %------------------------------------------------------------------------------ \section{Obtaining packages} The following packages can be obtained from \texttt{www.openmosix.org} \begin{enumerate} \item openmosix-kernel-2.4.18-openmosix4.i386.rpm \item openmosix-tools-0.2.4-1.i386.rpm \end{enumerate} The optional gui viewer for openmosix can be obtained from: \texttt{www.openmosixview.com/download.html} \begin{enumerate} \item openMosixview-1.2-rh73.rpm \end{enumerate} %------------------------------------------------------------------------------ \section{Installing openmosix} For each of the machines in your cluster do the following: \begin{itemize} \item Install kernel: \texttt{\# rpm -ivh openmosix-kernel-2.4.18-openmosix4.i386.rpm} If you are using grub, the installer should update the grub configuration files automatically. If using lilo, you will need to add to \texttt{/etc/lilo.conf} a stanza that looks something like: \begin{alltt} image=/boot/vmlinuz-2.4.18-openmosix4 label=linux-mosix read-only root=/dev/hda7 \end{alltt} Then run \texttt{\# lilo -v} \item Install the tools: \texttt{\# rpm -Uvh openmosix-tools-0.2.4-1.i386.rpm} \item Edit Configuration file: Edit the file /etc/mosix.map to include the nodes in your cluster. For example: \begin{alltt} # MOSIX-# IP number-of-nodes # ======================================= 1 192.168.222.1 16 \end{alltt} This says we have 16 nodes labelled 1 to 16 with IP addresses ranging from 192.168.222.1 to 192.168.222.16 \item Install the GUI (optional) \texttt{\# rpm -Uvh openMosixview-1.2-rh73.rpm} \item Reboot the machine When the machine has rebooted, make sure you are running the openmosix kernel: \begin{alltt} \$ uname -a Linux Node4 2.4.18-openmosix4 #1 ... \end{alltt} \item Run mosmon from the command line and you should see a display of all nodes up in the cluster. \end{itemize} %============================================================================== \section{Testing Openmosix} How you test openmosix will depend upon what configuration of machines you have in your cluster. The two possibilities are: \begin{itemize} \item Machines are all of similar 'grunt' \item Machines have different 'grunt' \end{itemize} If your machines are all of similar CPU speed, the only way to see the performance gain is to test the difference between running two concurrent tasks on your 'home' node vs running them normally. \begin{itemize} \item Create a simple program that exercises the CPU. The simplest way to test openmosix is to run a simple C program called timewaster.c: \begin{verbatim} #include #include #include int main(int argc, char **argv) { int i, j; double val; time_t ts, elapse = 0, prev_elapse; ts = time((time_t *)NULL); for (i = 0; i < 101; i++) { for (j = 0; j < 9999999; j++) val = (double)(j+1) / (double)(i+1); if (!(i%10)) { prev_elapse = elapse; elapse = time((time_t *)NULL) - ts; printf("i=%d, val=%lg, %d s elapsed, %d s since last print\n" , i, val, elapse, elapse-prev_elapse); } } return 0; } \end{verbatim} \item Make the above program: (You don't need a makefile) \texttt{make timewaster.c} \item Open up two consoles and run an instance of timewaster on each console: \texttt{\$ ./timewaster} \item Now try the same test by forcing each instance to run on your home node: \texttt{\$ runhome ./timewaster} \end{itemize} %============================================================================== \section{Summary of Mosix Userland Utilities} The following tools are part of the openmosix-tools package: \begin{alltt} mosctl - OpenMosix system administrator's tools mon [mosmon] - MOSIX load monitor migrate - request migration of a particular process on MOSIX mps - report multicomputer process status mosrun - run a command with particular node-allocation preferences setpe - OpenMosix node configuration showmap - Display current node configuration \end{alltt} Mosrun contains a subsuite of tools to perform various job allocation functions \begin{alltt} mosrun [cpujob] - Tell mosix this is a CPU intensive app mosrun [iojob] - Tell mosix this is an I/O intensive app mosrun [nomig] - Run job with node lock mosrun [runhome] - Run job on home CPU mosrun [runon] - Run job on particular node mosrun [slowdecay] - Apply slow decay to stat algorithms mosrun [fastdecay] - Apply fast decay to stat algorithms mosrun [nodecay] - Apply no decay to stat algorithms \end{alltt} %============================================================================== \section{Setting up the Mosix File System} OpenMosix contains its own network wide file system called mfs. With mfs you have access to the root filesystem of each node in your cluster. To enable mfs, do the following \begin{itemize} \item Make a the directory \texttt{/mfs} \texttt{\#mkdir /mfs} \item Edit \texttt{/etc/fstab} to include the following line: \texttt{mfs\_mnt /mfs mfs dfsa=1 0 0} \item Mount the mfs filesystem \texttt{\#mount /mfs} Now you can move around the root filesystem of any node in your cluster by changing directory to \texttt{/mfs/N} where N is the node number. \end{itemize} %============================================================================== \section{Lab} \label{sec:lab101.3} %============================================================================== \section{Questions} \label{sec:questions101.3} %============================================================================= \end{document}%=============================================================== %============================================================================= %============================================================================= %============================================================================= \setcounter{chapter}{110} \chapter{Administrative Tasks} \label{ch:111.ex} %============================================================================= \setcounter{section}{4} \section{Maintain an effective data backup strategy [3]} %------------------------------------------------------------------------------ \subsection{Backup Overview} Prepared by Grant Parnell \bigskip Decide what data is important and how long you can do without it. \begin{itemize} \item Is this used 24 x 7 or just business hours? \item During business hours how long can you do without it? 4 hours, 30 minutes, 5 minutes? \item How up-to-date is it required to get you running in an emergency? \item Are you backing up for archival or high availability or espionage? \end{itemize} %------------------------------------------------------------------------------ \subsubsection{Examples of Data} \begin{description} \item[Static:] Configurations of running servers. You need these 24x7 but they don't change much. \item[Databases / Transactions - financial \& otherwise:] These are updated frequently and need to balance. Associated with these are logs and duplication and other means of rollback and integrity checking. With databases it's often a good idea to dump them in a good portable format, especially if the inbuilt format is not cross platform or cross version compatible. EG 'mysqldump mydata >mydata.dump' will give you a text file which can be used on most mysql versions and possibly adapted to other database packages. \item[Logs:] People don't tend to read them unless something goes wrong in which case they're valuable. These need to be kept but don't need to be restored in a hurry. \item[Home directories:] This is a mixed bag of everything but some policies could be instated to make the admin's life easier. EG Making specific sub-directories for things and assigning them different backup/restore priorities. Often the existence of a home directory is more important than the rest of the contents as it may make a user unable to login without it. \item[Code repositories:] Programmers should be accustomed to doing regular backups anyway, they often need to revert to an old version to figure out what they broke. Any tools used such as CVS that have a central repository should be backed up almost as often as programmers commit code, at least once a day but they could probably cope with it being missing for half a day. \item[High availability - read only:] Websites frequently used by your clients. They can contain dynamic data but customers don't update it. This sort of scenario lends itself to frequent replication to a backup server. \item[High availability - interactive:] Taking a website again, this one might allow the customer to do such things as place orders. The website maintains some state information to allow building of an order. This is the most difficult, the state information can be stored in a replicated database. In the event of web server failure the other one comes into play and the customer may have to login again but the information is kept. (Otherwise complex designs and expensive hardware can be used to seemlessly migrate the state to the other webserver). \end{description} %------------------------------------------------------------------------------ \subsubsection{Important Linux directories} \footnotesize \begin{verbatim} /var/spool/mail - daily backup /var/lib/mysql - databases - backup the dumps, and possibly the binary. /var/log ? - from "don't care" to "backup daily" /etc - backup config changes /home - be selective, but if you can't backup daily. /home//mail - contains the user's mail folders (may also be 'Mail' or 'Maildir') /home//.ssh - If you login using ssh keys only, this is a must have. /usr/local - locally installed apps & data Application specifics \end{verbatim} \normalsize %------------------------------------------------------------------------------ \subsection{Backup \& Restore methods} %------------------------------------------------------------------------------ \subsubsection{Copy the files to another directory} This is the poor mans backup and does not offer much peace of mind. It does protect against accidental deletion and corruption by users. One advantage is that it can be very quick for things such as log files. You can also keep multiple copies, one for every day of the week for example. See /etc/logrotate.conf. %------------------------------------------------------------------------------ \subsubsection{Backup to a standby partition} This has about the same level of peace of mind as the above. The backup partition can be left un-mounted after the backup. The backup is slower than the above but the restore operation can be quick. See also "Broken Mirror" method below. %------------------------------------------------------------------------------ \subsubsection{Backup to tape} This is probably the most common backup used in the commercial world. It's easy to backup the lot every day provided you have the tape capacity. If you don't, you become more selective as to what to backup. There's a variety of software to do this but there's 3 main basic systems. Tar, cpio and dump. Often commercial software uses these basic systems and provide for labelling and indexing as well as multi-server capability from a simple GUI. The reason for using the basic systems is you can restore from them if you have to. %------------------------------------------------------------------------------ \subsubsection{Backup to standby disk} This can offer peace of mind and a fairly cheap backup for people that don't require 24x7 service. Basically a removable drive bay houses another hard disk of similar capacity and the entire system is backed up. This can be done partition by partition or file by file using dd, cpio or rsync. Additional steps can be taken to ensure that the backup is also bootable. The backup drive should be removed once done and treated like a tape. The disadvantage here is that you most likely will need to power down the system twice for one backup. Alternately, if you have an external USB or fire-wire storage medium it becomes possible to do this without downtime. %------------------------------------------------------------------------------ \subsubsection{Backup to CDROM/DVD} Under Linux (as far as I know) there's no software to directly write data without creating an image first. This means there must be sufficient space available. It would be possible to create a bootable CD with restore software and a compressed filesystem but I haven't seen this. It may be OK if you don't have a large filesystem or you have a DVD writer or you're not backing up everything. %------------------------------------------------------------------------------ \subsubsection{RAID System} Not strictly a backup but a RAID system can protect against hard drive failure by providing redundancy. Data is written simultaneously to 2 or more hard drives and can include parity information. It does not protect against corrupt databases and people removing files. It will corrupt and remove files equally well on all disks. Linux can do RAID in software very well but the ideal is a hardware solution involving hot swapable disks so they can be replaced whilst the system is fully running. A RAID system can mean the difference between going on-site at 3am and saying "Oh dear, we'll replace that first thing in the morning". Just ensure that you do have a replacement readily available and do not have to wait a week. %------------------------------------------------------------------------------ \subsubsection{RAID Tape array} In a similar manner to RAID 5 disks, data is written in parrallel to 5 tape drives which increases throughput and data integrity. %------------------------------------------------------------------------------ \subsubsection{Backup Server} All of the methods discussed so far involve direct transfer from server to backup medium. If you have a number of servers it may not be practical to install backup devices on each. Another way is to remotely access the required medium directly (/dev/rmt0) but arbitration of access can be an issue. An increasingly popular way is to provide a super-server with a huge amount of disk space capable of holding everything required by the other servers. Transfering the data can happen at any time in either a batch or continuous process. A batch would be say backup a whole directory at once whereas a continuous operation might be transmitting log information or database updates. The backup server itself may then employ any one or more methods to perform backups of itself, possibly based on some statistical analysis. An example of this is a system called ADSM which employs RAID arrays, multiple tape drives, a tape robot with barcode reader and intelligent software that tells the operators which tapes are to go off-site and which ones it wants back. It essentially is a huge cache that stores frequently changing data locally and stores old data off-site. %------------------------------------------------------------------------------ \subsubsection{Broken Mirror} If you've got about 100Gb of data on a mirrored pair of disks and only have a 10 minute backup window this may be for you. Basically you bring the system down, unhook one of the mirrors and replace it with another set of drives and bring the system up again. Mirroring starts from scratch during quiet time and should be finished before load picks up again. With the drive set you just un-hooked this can then be loaded into the standby server and backed up to tape over the course of many hours. Some high end servers can perform this operation without downtime as the hooking up can be done using inbuilt hardware or such things as dual-port fire-wire drive bays. All that is required in this case is an application shutdown, sync, dismount, remount, application start type operation. %============================================================================== \subsection{Software} dd - can be used to copy raw disk blocks, even to tape (yuk). eg dd if=/dev/hda1 of=/dev/hdb1 tar - Tape ARchive - you all know how to unpack tgz files, and maybe even create them. Just remove the 'f' option. It also can be an advantage not to use compression as some drives have this built in. Also, a portion of the tape being corrupt can ruin the rest of the data, whereas you can skip corrupt bits and pickup the next file if not compressed. eg tar -c /home cd /tmp; tar -x cpio - cp I/O - Similar capabilities of tar but different methodology. EG find /home | cpio -oB >/dev/tape cd /tmp; cpio -idB int main() { int i = 0; while (1) { system("clear"); printf("Process a: %d\n", i); ++i; } return 0; } \end{verbatim} \item Copy the file \texttt{a.c} to \texttt{b.c} and \texttt{c.c}. \begin{alltt} \$ cp a.c {b,c}.c \(\hookleftarrow\) \end{alltt} \item Edit the \texttt{printf()} calls in files \texttt{b.c} and \texttt{c.c} to refer to \texttt{Process b:} and \texttt{Process c:} respectively. \item Compile the programs: \begin{alltt} \$ gcc a.c -o a; gcc b.c -o b; gcc c.c -o c \(\hookleftarrow\) \end{alltt} \end{itemize} \item Test your three programs. \begin{itemize} \item Start a program running in the background: \begin{alltt} \$ ./a \(\hookleftarrow\) Process a: 400 \end{alltt} \item Suspend the program: \begin{alltt} ^z [1]+ Stopped ./a \end{alltt} \item Kill the job: \begin{alltt} \$ kill %1 \(\hookleftarrow\) \end{alltt} \end{itemize} \item Use \texttt{ps} to view the processes. \begin{itemize} \item Run the processes in the background with differing degrees of niceness: \begin{alltt} \$ ./a& nice ./b& nice -19 ./c& \(\hookleftarrow\) \end{alltt} \item Glance at and absorb the manpage for \texttt{ps}. Note well that some options are preceded by a minus(-) and others are not. For example \texttt{ps a} and \texttt{ps -a} do different things. \item Locate the processes using the \texttt{ps} command; try the \texttt{a}, \texttt{u}, \texttt{x}, and \texttt{f} options separately and in combinations. e.g.: \begin{alltt} \$ ps aux |grep "./a " \(\hookleftarrow\) \end{alltt} \item Kill and restart one of the processes (use the PID not ``123456'': \begin{alltt} \$ kill 123456 \(\hookleftarrow\) \$ ps aux |grep "./a " \(\hookleftarrow\) \$ ./a& \$ ps aux |grep "./a " \(\hookleftarrow\) \end{alltt} \end{itemize} \item Use \texttt{top} to view and modify the processes. \begin{itemize} \item Run \texttt{top} in the foreground: \begin{alltt} \$ top \(\hookleftarrow\) \end{alltt} \item Look at the \texttt{top} help: Press \textsf{h} \item Sort by accumulated time: Press \texttt{T} \item Re-nice a process (Note: Users may only monotonically increase the niceness processes, and (\&\&) they must own the process.): \begin{itemize} \item Press \textsf{r} \item PID to renice: 1234567890 \(\hookleftarrow\) \item Renice PID 1973 to value: 5 \(\hookleftarrow\) \end{itemize} \end{itemize} \item Reniceing from the command line: \begin{itemize} \item After finding it's \textsf{PID}\texttt{renice} one of your processes: \begin{alltt} \$ ps aux |grep "./c " \(\hookleftarrow\) \$ renice +15 1234567890 \end{alltt} \item Re-nice negatively---notice that only the superuser may reduce the niceness of a process. \begin{alltt} \$ renice -10 1234567890 \(\hookleftarrow\) renice: 1234567890: setpriority: Permission denied \$ su -c 'renice -10 1234567890' \(\hookleftarrow\) \end{alltt} \end{itemize} \item Kill off \texttt{./a}, \texttt{./b} and \texttt{./c}. \end{enumerate} \newpage %------------------------------------------------------------------------------ \section{Search text files using regular expressions [3]} \label{sec:103.7.ex} \newpage %------------------------------------------------------------------------------ \section{Perform basic file editing using vi [2]} \label{sec:103.8.ex} %------------------------------------------------------------------------------ \subsection{Introduction to \texttt{vi}} \label{sec:103.8.ex} %------------------------------------------------------------------------------ \subsubsection{Note} Should you need a good sized text file to practice editing on, you will almost certainly find a copy of the GPL Liscence on your system. Be sure to deconsecrate the file by renaming before mungeing it. You may locate one thus: \begin{alltt} \$ locate GPL \(\hookleftarrow\) ... /usr/share/doc/netpbm-9.14/GPL_LICENSE.txt /usr/share/doc/cdda2wav-1.10/GPL /usr/share/doc/cdparanoia-alpha9.8/GPL /usr/share/doc/stunnel-3.19/COPYRIGHT.GPL /usr/share/doc/libesmtp-0.8.4/COPYING.GPL ... \end{alltt} Make a scratch copy at a suitable location and open it for editing: \begin{alltt} \$ cp /usr/share/doc/stunnel-3.19/COPYRIGHT.GPL \ \(\hookleftarrow\) /tmp/munged_gpl.txt \(\hookleftarrow\) \$ vi /tmp/munged_gpl.txt \(\hookleftarrow\) \end{alltt} %------------------------------------------------------------------------------ \subsection{Vi tour} \label{sec:1.103.8.ex} % This exercise was written by Ken Foley %------------------------------------------------------------------------------ \subsubsection{vi} Vi is the unix editor, simply it is available on just about every Unix installation by default. This is the reason that you have to have a minimum of basic vi skills to allow you to change files when you favourite editor is not available, boot disks have vi due to lack of space. Please note that there are many implementations of vi, the baseline is a very crude editor. This extends to a very extended and powerful VIM editor available on most platforms. I use vim because I am restricted to vi on many of the unix systems I support, rather than trying to 'switch editors' mentally I have vi on every platform I use, including Windows. %------------------------------------------------------------------------------ \subsubsection{vi is a mode editor} Vi is an editor and it is definitely not a friendly editing environment. In fact a random typing of keys of the keyboard can render your text totally unreadable. Vi has been around a long time it was created in an era where editors were modal. The editor can be in three different unrelated states described below. \begin{description} \item[Input mode] This is the mode where you simply type. You characters appear in the text file as you type. \item[Command mode] This is where character take on special significance, for example 'i' for insert 'D' to delete to the end of the line. \item[Line mode] This is the mode when you press a : in command mode, this is where you can type some powerful (and sed like) commands to alter the document. \end{description} Rather than bore you with yet another description I will give you a series of exercises to work through showing each command. In the examples means to press the escape key. This will return you to command mode or cancel an action in other modes. %------------------------------------------------------------------------------ \subsubsection{Inserting text} There are at least three ways to insert text into a document in vi, the following exercises will take you through the basic commands. \begin{description} \item [Exercise 1 - insert] Create a text document, just to get you used to switching in and out of the insert and command mode. \begin{alltt} \$ vi test.txt \(\hookleftarrow\) ithis is the Linux course We want a few lines of txt to work with. \end{alltt} The i inserts text before the cursor. \item [Exercise 2 - open] We want to add some extra text to the document, we want to enter it on the line after the current line, we use the open command by pressing \textsf{o}. \begin{alltt} oI am adding an line after the current line. \end{alltt} \item[Exercise 3 - append] Now I want ot continue adding another sentence on the current line. If I press 'i' I will insert before the full stop, in this case I want to append it after the full stop. \begin{alltt} a I want to add another sentence. \end{alltt} You line should now look like: \begin{alltt} I am adding an line after the current line. I want to add another sentence. \end{alltt} \end{description} %------------------------------------------------------------------------------ \subsubsection{Movement keys \& multiplication} There are a huge number of ways to move around in vi, the arrow keys will not always work . You should be aware of the single character work arounds for these in case your terminal is not set up properly on the box you are 'telnet'ing or 'ssh'ing from or to. \begin{description} \item[h] Left one character * \item[j] Down one line * \item[k] Up one line * \item[l] Left one character * \item[w] Forward one word \item[b] Back one word \item[e] End of current word \item[G] End of file * \item[nG] Goto a particular line * \item[\{] Back one paragraph \item[\}] Forward one paragraph \item[\$] End of current line \item[\textasciicircum] First non blank character in line \item[0] Beginning of line (also \verb+|+) \end{description} Ones marked with an asterisk are requierd by POMS, Personally I find word movement is my main tool here. I also use the control keys to scroll screens a far bit. These are listed on the printed cheat sheet. ALL these movement commands can be prefixed by a number to muliply the effect of the movement. To move up 99 lines enter 99k. Note that some vi editor have a status on the bottom line, sometime it will show that you have entered a multiplier, sometimes it is quiet but the results are \_unexpected\_. \begin{description} \item[Exercise 4 - back] In the previous exercise I have forgotten a word after the an I wanted the word 'extra'. I have to go back that position in the line. \texttt{12b} will get me back to the beginning of the word I want to insert before, this is an example of a count followed by a command. Warning on the counts it can repeat most commands whether it makes sense or not at the time. For example enter the following: \begin{alltt} 4iextra \end{alltt} What happened? Why? This is handy with asterisks \texttt{70i*}, try it. \texttt{12b} moves the cursor back 12 words. A word is a sequence of chanracters separated by a space character like a or a Also the punctuation characters or '.', '?', ';' and so on. \item[Exercise 5 - general movement] Edit a large text file on your system. You should be able to do the following with two keystrokes. \begin{itemize} \item Jump to line 6 \item Move 8 character to the right. \item Go to the end of the line \item Go to the beginning of the line. \item Jump to the top of the paragraph in the document (a paragraph is delimitted by blank lines.) \end{itemize} You should be able to do this with one keystroke \begin{itemize} \item Move to the left margin To the end of the line \item Move to the end of the file. \end{itemize} \end{description} %------------------------------------------------------------------------------ \subsubsection{The undo command} The real vi command undo is very very limitted. It does not allow for a lot of recovery. There are two undo commands 'U' and 'u'. The lower case u will undo the last action that you have done. This includes itself so it will cycle through doing and undoing. The upper case U will undo the any change to the current line and restore it back to its original state. Extended vi editors such as vim will allow multiple lower case u undo commands but do not rely on it on an unknow box. To get out of a problem you simply have to quit without with ':q!'. No exercise here, I figure you will find this out without any help. Try both commands. Check the difference. %------------------------------------------------------------------------------ \subsubsection{Deleting changing and copying text} \begin{description} \item[d] Delete * \item[c] Change * \item[x] Delete one character \item[y] Yank (copy text) \end{description} Ones marked with an asterisk are required by POMS, Personally I use single character deletion all the time. I use line deletion all the time. There delete command and yank command can be used with a movement to delete all text within this movement. For example d\$ will delete to the end of the current line, y\$ will yank it into a buffer. Delete will also store the deletion in a buffer to get it back quickly just use paste describe later. To delete or yank a line simply repeat the d or y. To delete a single line use dd, to delete the current line and the next two use 3dd. To yank the next 10 lines use 10yy. Exercise 6 Please your cursor in the middle of a line. Delete from the current position to the beginning of the line with two keystrokes. Delete from the current position to the end of the line. Note that there is a shorthand for d\$ (delete, move to end of line) by using a capital D. Move to the center of a line of text and try it. %============================================================================= %============================================================================= %============================================================================= \part{Questions} %============================================================================= %============================================================================= % \setcounter{chapter}{0} % \chapter{General Linux Part 1 [89]} %============================================================================= \setcounter{section}{102} \section{(1.3) GNU \& Unix Commands [30]} %\newpage %------------------------------------------------------------------------------ \subsection{Work on the command line [4]} \label{sec:1.103.1.q} %\newpage %------------------------------------------------------------------------------ \subsection{Process text streams using filters [7]} \label{sec:1.103.2.q} %\newpage %------------------------------------------------------------------------------ \subsection{Perform basic file management [2]} \label{sec:1.103.3.q} %\newpage %------------------------------------------------------------------------------ \subsection{Use streams, pipes, and redirects [3]} \label{sec:1.103.4.q} %\newpage %------------------------------------------------------------------------------ \subsection{Create, monitor, and kill processes [7]} \label{sec:1.103.5.q} %\newpage %------------------------------------------------------------------------------ \subsection{Modify process execution priorities [2]} \label{sec:1.103.6.q} %\newpage %------------------------------------------------------------------------------ \subsection{Search text files using regular expressions [3]} \label{sec:1.103.7.q} \newpage %------------------------------------------------------------------------------ \subsection{Perform basic file editing using \textsf{vi} [2]} \label{sec:1.103.8.q} \begin{enumerate} \item How do you quit \textsf{vi} without saving? \verb+__________________+ \item In \textsf{vi} command mode what does the \texttt{p} key do? \verb+___________+ \item The \textsf{vi} editor has three modes. Name them: \\[3mm] \verb+______________ ________________ ____________________+ \item In \textsf{vi} insert mode what does the following key sequence do? \\ \texttt{:wq\(\hookleftarrow\)} \verb+_________________________________________+ \item How do you search forward for the next occurrence of the word ``frob'' in \textsf{vi}. \verb+________+ \item What command will delete the next 23 lines of text in \textsf{vi}. \verb+________+ \item Which command inserts text into \textsf{vi} at the current cursor location? \begin{enumerate} \item \texttt{a} \item \texttt{f} \item \texttt{T} \item \texttt{i} \end{enumerate} \item Which way does cursor move when you press each of these keys in \textsf{vi} command mode? \begin{description} \item[k] \verb+_____________+ \item[h] \verb+_____________+ \item[l] \verb+_____________+ \item[j] \verb+_____________+ \end{description} \item In \textsf{vi} command mode what does the \texttt{u} key do? \\[3mm]\verb+____________________________________________________+ \item In the \textsf{vi} editor what does the term ``yank'' mean.? \\[3mm]\verb+____________________________________________________+ \newpage \item What do you type to repeat the last command? \verb+________+ \item In \textsf{vi} command mode to move a line from its current position to three lines dowm the page you would enter: \begin{enumerate} \item \texttt{3dd3lp} \item \texttt{ddk3p} \item \texttt{1dd3p} \item \texttt{dd3kp} \end{enumerate} \item This command moves three lines of text into a \textsf{vi} buffer named \texttt{a}: \begin{enumerate} \item \texttt{"a3dd}%* \item \texttt{a3dd} \item \texttt{"add3} \item \texttt{A5dd} \end{enumerate} \item The G command does what? \verb+_______________________________+ \end{enumerate} %============================================================================= %============================================================================= %============================================================================= \part{Meta} %============================================================================= %============================================================================= % \setcounter{chapter}{} \chapter{Making Slides Using \LaTeX\ } %============================================================================= \setcounter{section}{0} \section{Making a} \begin{itemize} \item Install the acutex package for emacs \item Open a new document: \begin{alltt} \$ emacs my.slides.tex \(\hookleftarrow\) \end{alltt} \item In emacs create a document environment: \textsf{C-C C-E} Enter for the default (document) in the mini buffer. \item For document style enter: \texttt{seminar} \item For options enter: \texttt{a4} \end{itemize} \framebox{ \begin{minipage}[t]{30mm} \begin{itemize} \item aaaaaaa \item dddddddd \item wwww \item cc \end{itemize} \end{minipage}} % \framebox{ \begin{minipage}[t]{50mm} \begin{itemize} \item aaaaaaa \item dddddddd \item wwww \item cc \end{itemize} \end{minipage}} \begin{rotate}{45} blah \end{rotate} \rotr{90}{blah de blah de blah} %============================================================================= \end{document}%=============================================================== %============================================================================= \begin{alltt} \$ \(\hookleftarrow\) \end{alltt} %============================================================================== %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %------------------------------------------------------------------------------ %.............................................................................. %------------------------------------------------------------------------------ \subsection{ Modify process execution priorities [2]} \item \verb+________+ \item \begin{enumerate} \item \texttt{} \item \texttt{} \item \texttt{} \item \texttt{} \end{enumerate} \end{enumerate}