All things Raspberry Pi and Time Lapse

Linux + Certification Notes

01/13/12@16:47:38 Location: Home 

1.1 The Shell


Linux OS Components
	Kernel
	Libraries
	Utilities
	User Interface
		command line interface (cli)
		graphical user interface (gui)

History
	Andrew Tanenbaum was a professor who used UNIX source code to teach his students how to write operating systems
	He write minnix after UNIX was closed-source to teach his students. It is a minature clone of UNIX
	Linus Torvalds, a graduate student, got ahold of Andrew's book and decided to write his own operating system.
	The original Linux OS was the kernel, cli, and c++ compiler

The shell
	The shell is the command line interface that you use to communicate with the operating system

Linux shells
	bash
	sh
	ksh
	csh
	tcsh

DOS/WIN 
	current path
	PATH var

Linux
	PATH var

exec will execute the command then exit
./ will execute the command in parallel

uname -a will display all information about the system

su - will configure environment variables as if you logged in as that user

chsh /bin/bash will change the shell to bash if it is installed

NON-LOGIN SHELL	
	~/.bashrc is non-login -- some distro uses it as login shells

LOGIN SHELL
	/etc/profile
	~/.bash_profile
	~/.bash_login
	~/.profile

 01/13/12@17:31:45 Location: Home 

1.2 Help


man sections
        1 commands used by anyone
        2 system functions
        3 library functions
        4 /dev files
        5 file formats and conventions
        6 games
        7 misc
        8 admin utilities - root user
        9 kernel documentation

Man pages are split up into 9 sections
	Title
	Name - name and abstract of what it does
	Synopsis - brief description of command
	Description - How the command works with options
	Author
	Reporting Bugs
	Copyright
	See Also
	Version - program version and revision date

Man is what the command does
Info is detailed and instructional on how to use the command

Info
	n = next node
	p = previous node
	CTRL+s to search
	q = quit
 01/13/12@20:59:16 Location: Home 

1.3 Environment Variables


Variable is like a bucket in the computer
Linux Variables
	User defined - input whatever - do not affect the system
	environment variables - affect the system
		BASH - /bin/bash
		SHELL 
		CPU - i686
		DIPLAY - 0.0- x window display
		ENV - ~./bashrc
		EUID - user id of current user
		HISTFILE - specifies the path to the bash history file
		HISTSIZE - the number of commands to save in history file
		HOME - /home/millerj
		HOST - name of system that you named it
		HOSTNAME - name of system that you name it
		INFODIR - path to systems info system - /usr/local/man
		LOGNAME - user name of current user
		MAIL - current mail - /var/spool/mail/millerj
		MANPATH - path to system man pages
		OLDPWD - path that you were in before you switched
		OSTYPE - type of operating system being run
		PATH - list of directory that are searched when a program is being run
		PS1 - shell prompt to set how it appears
		PWD - current working directory

env - will show all environment variable
set - set shell environment variables
unset - remove an eviroment variable

 01/13/12@21:21:03 Location: Home 

1.4 Aliases


alias - link to a file/command/program
 01/14/12@14:55:54 Location: Home 

1.5 Text Editors


vi is the most widely used text editor

vi has 4 different modes
	command
	command line
	insert
	replace

i goes into insert mode
ii goes into replace mode
	then i goes back to insert mode

e! will revert to the last save point

command mode are entered without :
command line mode are commands entered after the :

dw - delete word + any space that follows
de - delete word but not the space that follows
ctrl+g status line that shows filename, total lines, and current cursor position

/search_term searches forward - n goes to the next - N goes opposide of current direction
?search_term searches backwards - n goes to the next - N goes opposide of current direction

a - appends text after the cursor
A - appends text after the line

C - changes text from the current postion to end of line
cc - changes text of entire line

k - up
j - down
l - right
h - left
0 - beginning of line
 01/14/12@21:02:27 Location: Home 

1.6 Redirection and Piping


Redirection
	stdin(0) - standard in or standard input
		stdin could come from a file, text stream, or keyboard
	stdout(1) - standard output which is the screen as default
	stderr(2) - standard error

	command 1> file1 2>file2
	command 1>file1 2>&1

Piping
	ls -l | tee outfile
	tee splits the stdout and displays it to the screen and writes it to the file

Xargs
	Due to the limit imposed by the linux kernel, the max length of a shell command is 128kb. 

	ls | Xargs rm
	-0 Ignore pace names in files
	-l variable - replace the initial arguemnt of the command with the argument from the stdin
 01/18/12@21:14:22 Location: Home 

1.7 Directories


ls -R list contents recursively
ls -r reverses sort order
ls -d displays only directories
mkdir -p will create directories in the path that do not exist

mv -f overwrites if it exists
mv -i prompts before overwrite
mv -n not overwrite

 01/19/12@10:18:04 Location: Home 

1.8 Files



tail -f interactivly watch the file
file filename will get information about the file

cp -f overwrite any files with the same name
cp -i prompts before overwrite

mv -f overwrite any file with the same name
mv -i prompts before overwrite
mv -n never overwrite

rm -f remove without prompt

shred -n specify the number of times to overwrite - default 25
shred -u deletes the inode
shred -v verbose of shred
shred -z overwrite with 0

lsattr 
	-R recursibely list attributes of directories or their contents
	-V displays the program version
	-a lists all files in directores
	-d list directories like other files, rather than listing their contents
	-v lists the file's version/generation number

 01/19/12@12:41:27 Location: Home 

1.9 Links


Hard link
        points to inode of another file
        cant tell which file is pointer or pointee

Symbolic link
        points to another file
        each file has own inode
        more like the traditional shortcut

ln to link a file
        specify the pointee file then the pointer file
        creates a hard link by default
ln -s to create symbolic link

ls -i lists inode

cp -l creates a hard link
cp -s creates a symbolic link

 01/19/12@13:48:10 Location: Home 

1.10 Filesystem Hierarchy Standard (FHS)


Full documentation at http://www.pathname.com/fhs

/bin contains executable files that are necessary to run Linux
	contains cp, rm, ...
/boot contains bootloader files
/dev contains files that are used to represent hardware in your system
	character oriented - use data sequentially - printer or mouse
	block oriented - use data non-sequentially - hard disk
	/dev/sda is the first hard drive
	/dev/scd0 is the first cd drive
/etc contains all of the files needed to customize your Linux distro
	It also contains configuration files for services
/home is where users can save personal files
/lib contains code libraries that are used by the programs in the /bin directory
/media is used to mount removable devices - suse
/mnt is also used to mount removable devices - fedora
	suse uses it for temporary mounts
/opt containes file for other programs that the user installs
/proc is dynamically created every time it is accessed
	/proc/4381 - number corresponds to the process id number (PID) of currently running process
/root is the home directory for the superuser
/sbin contains system managemnt and system admin files
	fdisk, fsck, ifconfig
/srv where services running on the system save the files
	http, ftp
/sys contains information about the hardware on the system
/tmp contains temporary files
/usr contains application files that are used in the system
/var contains data that constantly changes - logfiles
 01/20/12@14:48:36 Location: Home 

1.11 File Location Utilities


find can be used to search for a particular file
	find (path to search) -name "name of file"
	-user search for files owned by specific user
	-size specified size (size +100kb) (size -100kb)
	-mtime finds files modified before or after specified number of days
	-maxdepth specifies how many levels to search
	-print0 finds filenames with spaces
	-o specifies an "or" when using multiple criteria

locate is also used to find files
	locate has one advantage - indexes files
	runs much faster than find as find searches recursively - locate searches the database that it has built over time
	to install - add package "findutils-locate"
		creates a database in /var/log/locatedb
		updatedb will update the database
		edit how it works in /etc/updatedb.conf
	-c counts the number of entries rather than list them
	-e lists files only after verifying that they exist
	-l limites the number of files listed

which is used to find the full path to a command

whereis returns information about the command
	-b binaries
	-m man pages
	-s source code
	-u lists entries that do not have source code, binary file, and man page locations

type tell you what type of command you are using
	built-in shell command
	external commnad
	alias
	function

hashed - means the location of the command is currently stored in the hash table. Saves time by not having to look through the whole $PATH variable again.

grep - searches through files or folders
	-A number prints a specified number of lines FOLLOWING the matching lines
	-a searches binary files as though they were text files
	-B number prints a specified number of lines BEFORE the matching lines
	-C number prints a specifired number of lines around matching lines (for context)
	-c shows the number of matches of the string
	-e pattern searches for a literal pattern
	-f searches for multiple strings using a file that lists string patterns
	-l shows matching files instead of matching lines
	-m number only shows a specified number of matches for a file
	-n displays the line number of the line containing the term
	-v displays non-matching lines
	--include=file_name searches only files that match a specified string
	--exclude=file_name searches only files that do not match a specified string
	-w searches for whole words only

egrep (grep -E) has the ability to use regular expressions
	^ beginning of line
	$ end of line
	< matches words that begin with the term
	> matches words that end with the term
	[xyz] matches x or y or z
	[3-7] matches 3,4,5,6,7
	[^jkl] match none of j,k,l
	[asdf]+ matches one or more characters in the list
	. matches any single character
	* matches any number of characters
	| matches either of the terms
	 indicates that the character that follows is just text - not metacharacter

fgrep (grep -F) searches for fixed string - does not use regular expressions

Linux saves configuration files in /etc
Linux saves log files in /var

 01/20/12@16:25:16 Location: Home 

2.1 Installation Design


What you need to do to design and impliment a successful deployment
	Needs assessment
		why installing in the first place?
		go talk to people
		what are the goals?
		final results?
		who is affected?
		when is it needed?
		Scale-Resources-Scale has to stay in balance
	Pick a distro
		Server or Workstation?
		Is there support?
		What applications will be required?
	Check hardware and system requirements
		Video? Hard drive space? Correct architecture?
	Plan the file system
		Choose a file system
			ext2 - problem is when it shuts down without correct shutdown
				drive has to be cleaned to maintain data integrity
			ext3 - supports journaling - eliminates ext2 problem
	Plan partitions
		default - /swp - used for virtual memory - now should be 1 to 1.5 times the size of installed RAM
		default - / - root - at least 4GB
		recommended - /boot - at least 100mb to 200mb - has to be in the first sectors
		recommended - /home - provided falut tolerance
		recommended - /opt - installed programs
		recommended - /tmp - 1GB in size - not critical
		recommended - /usr - system utilities - 10GB - 15GB 
		recommended - /var - log files - 10GB
		/etc, /bin, /sbin, /lib, /dev, /proc must be on the same partition
	Select software
		Select only what software is needed
		extra software that is not used can be a security hole that is not necessary
	Specify users and groups
	Gather network information
		Gather information before start installation
		Installation will ask for network infomation
		Decide on domain information
	Select an insallation source
		Options include CD - DVD - Installation Server
		Sit down and install or remote install
 01/21/12@15:27:01 Location: Home 

2.2 Linux Installation


General Install
	Start the install
	Language
	Clock + Time Zone
	Partitions
	Apps + Services
	Root Password
	HOSTNAME
	Network
	Service Config
	Users + Groups
	Hardware
 01/21/12@15:51:10 Location: Home 

2.3 Localization


determines how the system behaves...
LC_CTYPE - character encoding
LC_MESSAGES - configure natural language messages
LC_COLLAGE - defines sorting
LC_NUMERIC - defines number format
LC_MONETARY - defines currency
LC_TIME - configures data/time
LC_PAPER - paper size
LC_NAME - personal name format
LC_ADDRESS - personal address format
LC_TELEPHONE - telephone format
LC_MEASUREMENT - measurement units
LC_ALL - can be used to overwride all other environment variables
LC_LANG - default local for all environment variables
LC_LANGUAGE - cat be used to over ride LC_MESSAGES

language_territory.codeset @modifier
language = ISO 639 - lowercase
territor = ISO 3166 - UPPERCASE

en_US.UTF8

Order of precidence for environment variable
	LC_ALL - if populated it takes precidence
	LC_* - 
	LANG -

locale - will list all local variables
locale charmap
	-a will list all available locals
	-m will showinstalled encoding

iconv -f source -t destination -o outputfile inputfile

 01/25/12@09:25:23 Location: Home 

3.1 Boot and Shutdown


Linux boot process
	BIOS - test system components to make sure they work
		POST - Power On Self Test
		Containes Setup program which are saved on the CMOS chip
		MBR - Master Boot Record
	Bootloader
		Bootloader creates a virtual hard disk - RAM DISK - initrd image
	Kernel
		Kernel is located in the /boot directory
		After linuxrc is done the RAM DISK is destroyed
		Then the real file system is loaded
		init is then run which is located in /etc/initab
		DONE!!
 01/25/12@10:49:28 Location: Home 

3.2 BootLoaders


GRUB is default bootloader on most linux systems
GRUB stands for "Grand Unified Boot Loader"
Used to boot linux or windows
Stages of GRUB
	Stage1
		Stored in MBR
		Points to Stage2
	Stage2
		Stored on Disk
		Loads graphical choice
grub-install device_name (that has the mbr)
grub-install /dev/sda
Configuring GRUB - edit text file
	suse - /boot/grub/menu.lsd
	fedora & others - grub.conf

	-Global
		default option
		timeout
		gfxmenu option - image file for graphical grub menu
	-Menu Section
		title sections - hd#,partition#
		root - where grub root is..
		kernel - location of kernel /boot/linux which is a link to /boot
		initrd - where the initrd image is to create RAM DISK
GRUB root is /boot 

edit GRUB 
	press ESC
	press e to edit
	press o to add new line
	press b to boot

supply kernel options from the GRUB menu

grub.conf changes
#hiddenmenu
password --md5 (encryted password)
	title
		lock	

LILO - linux loader
	At one time this was the default
	LILO is no longer supported
	Much the same as GRUB from end-user perspective

Installing LILO
	enter lilo from command prompt as root
	configure /etc/lili.conf
	2 sections 
	GLOBAL
		menu-scheme=wr:bw:wr:Yr specifies white text on red background, black highlighted text on a white background, a white border on a red background, and an intense yellow title on a red background. Using a capital specifies intense version of that color.
		timeout - set in 1/10 of a second
		lba32 - ignore physical geometry and use logical
		change-rules - change boot time changes
		reset 
		read-only - mount read only, check filesystem, then remount read/write
		prompt
		default
		message
		boot
	Image option
		Image
		label
		append
		vga - specifies text mode to use while booting
		initrd
		root
Have to "reinstall" lilo after changes

 01/27/12@12:42:28 Location: Home 

3.3 Runlevels


Linux Runlevels
	0 - Halt
	1 - Single User mode - no GUI - no networking
	2 - Multi User - no GUI - no networking
	3 - Multi User - no GUI - networking - server use
	4 - UNDEFINED
	5 - Multi User - GUI - networking - desktop use
	6 - Reboot

INIT process - grandparent of all other processes
	configured using /etc/inittab
	identifier:runlevel:action:commnad
	id:5:initdefault - default runlevel is 5
	15:5:wait:/etc/init.d/rc5 
	cat::CTRL+ALT+DEL:/sbin/shutdown -r -t 4 now

init q --or-- init Q have init re-examine the inittab file

Sending options to the kernel at boot time
	init=/bin/bash will skip init and boot directly into bash
	then exec init will start the init process

vga=0x307 sets the monitor to 1280X1024 with 256 colors
acpi enable or disable advanced configuration and power interface (acpi=off/on)
apm enable or disable advanced power management (apm=off/on)

two ways to add kernel options
	1.
	select operating system
	press the a key
	add the kernel boot option

	2.
	select operating system
	press the e key
	select the kernel line
	press the e key
	add the kernel boot options to existing boot options

 01/28/12@18:17:06 Location: Home 

3.4 Init Scripts


Depends on distro
    system V
        red hat - fedora
        /etc/rc.d/
            rc0.d
            through
            rc6.d
        init scripts are in init.d
    BSD
        suse
        /etc/init.d
            rc0.d
            through
            rc6.d

Managing init scripts
    /etc/init.d/script command
    /etc/rc.d/init.d/script command
    commands
        start
        stop
        status
        restart
        reload - re-read config files without stopping service
Important scripts in init directory
    rc - Both - switch between runlevels
    halt - BSD - stop the system
    boot - BSD - run by init process
    boot.local - BSD - run by init process - additional startup commands
    rc.sysinit - System V - similar as boot on BSD
    rc.local - System V - similar to boot.local

Typical BSD boot process
    /etc/init.d/boot - to prepare the system
    /etc/init.d/inittab - to select appropriate runlevel
    /etc/init.d/rc(runlevel).d - runs scripts in this directory
    /etc/init.d/boot.local

Typical System V boot process
    /etc/rc.d/sysinit - to prepare the system
    /etc/inittab - to select appropriate runlevel
    /etc/rc.d/rc(runlevel).d - runs scripts in this directory
    /etc/rc.d/rc.local

How to configure init scripts
    insserv - configure service command to run at sertain runlevel
        INIT INFO
            default-start:35
            required-start:
            should-start
        insserv service-name - to start service
        insserv -r service-name to disable service from running at any runlevel

    chkconfig - almost the same as insserv
    chkconfig -l name-of-service
    chkconfig --list name-of-service (used for System V)
    chkconfig service-name on/off

BSD shortcut
    rcntp status

Changing runlevels runs init just the same as starting the system

 01/28/12@18:36:07 Location: Home 

3.5 System Shutdown


shutdown
	+m - shutdown in certain number of minutes
	hh:mm - time to shutdown
	-now - shutdown immediately
	-h - halt
	-r - reboot
	Without -h or -r the shutdown command doesnt halt but goes to runlevel 1
	after options put message
	-c - cancel shutdown
	-f - fast boot, it skips fsck utility on boot
	-a - use the /etc/shutdown.allow file to shutdown
 01/30/12@10:11:33 Location: Home 

4.1 The X window system


X window system components - all work together to display the GUI
	X server - heart of the X system - networked
		where the server sends the display is determined by the $DISPLAY variable
	Window Manager - all are slightly different
		enlightenment
		sawfish
		fvwm
		kwin
		twm
		wmaker
	Desktop environment
		GNOME
		KDE
	X font server (optional)

Key questions to configure video card and monitor
	Manufacturer
	Model
	Memory
	Max Resolution
	Max Color Depth
	Chipset
	Sync Rate

configuration file for X window manager - /etc/X11/xorg.conf
Use the configuration utilities NOT text editor to edit these files
	YaST - command yast2
	sax - command sax2
	system-config-display
	system-config-keyboard
	system-config-mouse

These are made to run before you have X windows up and running
	xorgconfig - distro independant configuration
	Xorg -configure - automatically configure hardware

After you have X windows up and running
	xorgcfg

Xfree86 configuration
	XFree-86-configure - detect hardware and make proposed configuration file
	xf86config - text based version of XFree-86-configre
	xf86cfg - after already running x

Have to restart x to re-read configuration files
CTRL+ALT+BACKSPACE - kill x and restart x

Configuration of window manager and desktop environment
	Install packages
	Logout and in the login screen select window manager
	If booting into runlevel 3 edit .xinitrc to set default
	If booting into runlevel 5 edit .Xsession or .Xdefaults or .Xclients
 01/30/12@16:08:52 Location: Home 

4.2 Display Managers


Enable or Disable the display the manager
	BSD - /etc/init.d/
	System V - /etc/rc.d/init.d/
		xdm - suse
		gdm - ubuntu /etc/X11/gdm
		kdm - 
			/etc/kde/kdm/kdmrc
			/etc/X11/kdm
Start or Stop display manager
	/etc/init.d/xdm start/stop
	SHORTCUT rcxdm start/stop

Configure xdm /etc/X11/xdm/Xresources
	xlogin*Foreground
	xlogin*Background
	xlogin*greetColor
	xlogin*failColor
	xlogin*login.Font
	xlogin*login.greetFont
	xlogin*login.promptFont
	xlogin*login.FailFont
	xlogin*greeting
	xlogin*namePrompt
	xlogin*fail

change the default color depth for the display manager
	/etc/X11/xdm/Xservers
	:0 local /usr/bin/x-nolisten tcp-bring (-bpp 32)

configure the x terminal
	1. Select a display host - XDMCP port 177
	2. Edit /etc/X11/Xservers
	3. REMOVE -nolisten tcp(xdm or kdm)
	3. edit /etc/X11/gdm/gdm.conf - set DisallowTCP=FALSE (gdm)
	3. SUSE - /etc/sysconfig/display/manager - edit
	4. Open port 177
	5. Edit /etc/X11/Xaccess - add entry for each host or *.mydomain.com
		use !hostname to disallow
 01/30/12@16:53:28 Location: Home 

4.3 Accessibility


Two types of difficulty - keyboard & screen
	Keyboard accessibility
		Sticky keys - lock CTRL or ALT keys to allow for keyboard shortcuts without having to press multiple keys at the same time
		Mouse keys - use keyboard to move the mouse and click buttons
		Slow Keys - incease the time that a user has to press a key before it is recognized - usefull to prevent accidental key presses
		Toggle Keys - sounds an audible alert whenever the caps lock key or num lock key is pressed
		Repeat Keys - extra time to release a key before multiple multiple keystrokes
		Bounce Keys - insert delay between keystrokes
	Display accessiblity
		Orca
			on screen reader
			screen maginifier 
			Braille support
		High contrast
		large print
 02/04/12@21:06:54 Location: Home 

5.1 Red Hat Package Manager (RPM)


Role of a package manager
	Install new packages
	Update existing packages
	Verify Packages
	Manage Installed Packages
	Remove Installed Packages
RPM database stored in /var/lib/rpm
To rebuild/restore the database - rpm -rebuilddb
Package naming convention
	acroread-8.1.3-51.6-i586.rpm
	name-version#-release#-(optional)fc13-arch
Check the package:
	rpm --checksig package_name
Install the package:
	rmp -i package_file_name
	rpm -ihv package_file_name - shows progress bar
	rpm --test to check for dependancies
	rpm --nodeps to ignore dependacies
Uninstall packages
	rpm -e package_name
Update packages
	rpm -U package_file_name
	rpm -Uhv package_file_name - show progress bar
Query packages
	rpm -qx package_name
		-qa - generates list of all installed packages
		-qi - list information about a specific package
		-q --whatrequire - display list of packages that are dependant on this package
		-q --whatprovides - find out what packages provide utility
		-ql - included files included in rpm package
		-q --provides - to see what the package does or provides
		-q --requires - to see functionality it requires
Verify packages that are installed
	rpm -V package_package
	rpm -Va - to check all packages
Error messages 
	S - problem with the size
	M - problem with the mode
	5 - problem with the md5 checksum
	D - problem with revision number
	L - problem with the files symbolic link
	U - problem with the ownership
	G - problem with group 
	T - problem with modification time
	c - specifies a config file
	file - name of file

	...DL... file - dots are OK - letters have a problem
Repair package if it fails verify
	rpm -U --replacepkgs package_name
Convert rpm to files
	rpm2cpio package_name > package_name.cpio

yum is a front-end for rpm - Yellowdog Updater Modified
	install rpm and all dependicies at once
Basic syntax
	yum option command package
	yum list installed - show installed packages
	yum list updates - show updates
	yum list available - list available packages to be installed
	yum list info package_name - list inforation and digital signature
	yum install package_name - install packages
	yum whatprovides - find what packages provide utility
	yum remove package_name - remove packages
	yumdownloader - download but do not install package
configuration files for yum
	/etc/yum.conf - main config files
	/etc/yum.repos.d - configure local repository
 02/05/12@21:16:16 Location: Home 

5.2 Debian Package Manager


package_name-version#-revision#-arch.deb
dpkg - same as rpm
dpkg options action package
	actions
		-i used to install
		--configure to reconfigure an installed package
		-r remove package but leaves config files
		-P removes package and remove config files
		-p displays information about installed package
		-I displays information about a package not installed
		-l [pattern] to list information about pacages that include [pattern]
		-L to list all associated packages with the package
		-S to locate package that owns files
		-C search for packages that were partially installed
	options
		-B to uninstall package and disable any package that relies on the package you are removing
		--ignore-depends install a package without checking for dependancies
		--no-act check for dependancy information without installing/uninstalling
		-G not install package if newer package is already installed
		-E not install if same version of package is already installed
Uses package database (cache)
	apt-cache
		showpkg name - information about package
		stats - number of packages installed and dependancies
		unmet - view missing dependacies
		depends names - view all dependancies 
		pkgnames name - view packages installed with name
apt-get is like yum
	/etc/apt/sources.list
	update - update repository with newer information
	upgrade - install all packages that are newer than installed packages
	install
	remove
	check - check to see if any packages have problems
 02/05/12@21:43:21 Location: Home 

5.3 Shared Libraries


All linux systems can share some code
Shared Libraries - example: open a file
	Not every program needs to know how to open a file, but it is written once, then other programs can call it from the shared library.
	Dynamic library
		not integrated into code of application
		application just knows where to access library
	Static Library
		used when code is compiled
		makes application bigger
		makes the application independant 
name.so - dynamic library
name.a -static library

check program for shared libraries 
	ldd program_name - will check a programs shared libraries
	/etc/ld.so.conf - shows where shared libraries are located
		/lib and /usr/lib are assumed to be shared libraries and are not specified in /etc/ld.so.conf file
Add extra shared libraries
	set LD_LIBRARY_PATH = /path/to/file
	add path to /etc/ld.so.conf
		after adding line run ldconfig
ldconfig -p to view all available shared libaries
ldconfig -v to show information about current system shared libaries
 02/09/12@10:51:36 Location: Home 

6.1 Users and Groups Overview


Users can be local or network located
local 
	/etc/passwd is used for user info
		USER:PASSWD:UID:GID:FULL_NAME:HOME:SHELL
		standard user - used to login to system
		system user - used for services
	/etc/shadow is used for passwords
		USER:PASSWD:LASTMODIFIED(days since jan 1, 1970:MINDAYS:MAXDAYS:WARN:DIS:EXP
		A $ is used to identify the password as encrypted
		! or !! means the account is locked and cannot be used to login
		* means its a system account 
	Do not use text editor if at all possible to edit these file
	pwck - verify that both passwd and shadow file are correct
	pwconv - syncronize passwd and shadow file	
	/etc/groups is used for user groups
		each line is a group
		GROUP:PASSWD:GUID:USER,USER
		some distros(fedora) uses a separate file to store passwd for groups
		/etc/gshadow - group passwords
			GROUP:PASSWD:GROUP_ADMIN:MEMBERS

 02/09/12@11:53:54 Location: Home 

6.2 User Management


Add user account
	useradd options user
		/etc/default/useradd - users defaults
		/etc/login.defs - group id defaults
		/etc/skel - copy these files into new users home directory
		-c specify full name
		-e date when account is disabled
		-f number of days after password change when account is disabled
		-g default group
		-G additional groups
		-M create user without /home/user directory
		-m specifies where /home directory is 
		-n/-N (only REHL/fedora -respectively) disable creating each user as a group
		-p specify password
		-r specify system user
		-s default shell
		-u manually specify user id
	passwd options user
		LK = locked
		PS = unlocked (has password)
		-S displays whether account is locked
		-l manually lock an account
		-u manually unlock an account
		-d removes a user password
		-n sets minimum number of days before password can be changed
		-x sets maximun number of days
		-w sets number of days prior to password change to warn user
		-i sets number of days after to lock account
	usermod options user
		Same options as useradd - except for -m -n -r -
		-l change username
		-L lock user account
		-U unlock user account
	userdel user options
		-r removes home directory when deleting user
 02/09/12@14:39:04 Location: Home 

6.3 Group Management


groupadd options group
	default options in /etc/login.defs
	-g specify group ID
	-p specify password
	-r system group
groupmod options group
	-g to change group id number
	-p to change password
	-n changes name of group
	-A add users to group
	-R remove users from the group
groupdel group - delete group
gpasswd group
	-r removes group password
 02/14/12@14:45:46 Location: Home 

7.1 Disk Partitions


fdisk device_name
	p - will display partitions
	m - view available commands
	n - new partition
	l - to list partition types
	t - change partition type
	q - to exit out of fdisk without saving changes
	w - to write changes and exit
	d - delete partition
partprobe - probe hard drives and send information to kernel without having to reboot

 02/16/12@12:01:33 Location: Home 

7.2 File Systems


After partitioning - have to format
mkfs can be used to make lots of different types of file systems
	mkfs is really just a front end for other commands
	mkfs -t ext3 partition
	mkfs -t ext3 /dev/sdb1
	-b block - blocksize ie: 1024, 2048
	-i bytes-per-inode 
	-j ext3 journal
mkreiserfs partition (same as mkfs -t reiserfs)
mkswap partition
swapon partition - to enable the swap partition
swapoff partition - to disable

 02/16/12@12:29:54 Location: Home 

7.3 Mounting File Systems


mount -t filesystem-type device directory
mount -ro makes it read-only
df - to view mounted drives

/etc/fstab - six fields per line
	device mount-point filesystem mount-options dump order

	mount options - 
		rw - read/write
		ro - read only 
		sync - syncronous
		async - asyncronous
		atime - update inode with last access time
		noatime - do not update inode
		exec - allows executing program from this drive
		noexec - does not allow executing
		auto - will be automatically mounted
		noauto - will not be automatically mounted
		user - allows standard users to mount device
		nouser - does not allow standard users to mount
		default - rw,exec,auto,nouser,async
mount -o loop img dir
 02/16/12@14:59:45 Location: Home 

7.4 File System Maintenance


df - will show snapshot of partitions with free space
	-h - human readable format
	-i - inode information
	-l - only look at locally mounted file systems
du - will show how much space is being used by files and directories
	-c - grand total
	-h - human readable format
	-s - display a total for each metric it observes
lsof - lists open files
	--s - displays the file size
	-u user - only list files owned by specific user
fuser - displays process ID numbers of file or file system specified
	-a - all files including those not being accessed
	-v - display extended information
	-m - specify directory
	-u - append user name to the ID
fsck - front end for a bunch of other utilities - used to check file system
	before you run this you have to unmount the file system
	fsch partition
	without arguments - will check all file system from /etc/fstab
	then after running fsck remount the file system
 02/16/12@15:51:45 Location: Home 

7.5 Disk Quota


Before you can use quotas it has to be installed
Some distros install it by defalut
	check by using rpm -qi quotas
configuring quotas
	1. edit /etc/fstab
		add usrquota and grpquota to enable quota
		reboot
	2. create quota files
		quotacheck -amvug - will scan the disk and see used space
		-a - all mounted files
		-m - forces checks on all disks
		-v - verbose
		-u - checks users
		-g - checks groups
		after running this it will create two files in the filesystem
			aquota.user
			aquota.groups
	3. enable quotas
		guotaon -av
		insserv or chkconfig to specify start on boot
	4. run the quota report to see how much disk usage by user
		repquota -av
	5. define quotas
		edquota -u user
			hard quota - strickly enforced
			soft quota - loosely enforced
			block quotas - control how much space
			inode quotas - control how many files
		edquota -t - to change grace period
		edquota souce-user destination-user
		edquota -g group
	6. repquota -av to generate a new report with the new quotas
 02/19/12@22:12:35 Location: Home 

7.6 Ownership


Linux uses two concepts to define who can do what in the filesystem
	ownership - who owns the file
	permissions - read/write/execute

Two owners of the file - user who created it and that users group

To change ownership - have to be root
	chown user.group file/dir
	chown .users (to change group) file
		-R changes ownership recursively

	chgrp group file

 02/20/12@11:58:18 Location: Home 

7.7 Permissions


mode of the file = the permissions
read = 4
write = 2
execute = 1

chmod 
	chmod entity=permissions file/dir
	chmod u=rw,g=rw,o=r file
	chmod g-w file # turns off write permissions for group
	chmod -R - will apply permissions recursively

umask - default value = 022
	new files mode=644
	new directores mode=755

umaks 027 - changes umask
edit /etc/profile and change umask to make it persistant

Special Permissions
	SUID (4)- Set UserID - only can be applied to binary executable file
		User becomes file's owner while executing file
	SGID (2)- Set GroupID - only can be applied to binary executable file
		User temporarily becomes member of file's owning group
	StickyBit (1)- used for directories
		User can only delete files in directory they own	

	chmod 4750 myfile
 02/20/12@12:47:46 Location: Home 

7.8 Archive and Backup


tar - tape archive

tar -cvf file files - create tar archive
	-c - create archive
	-v - verbose
	-f - name of file
	-j - compress tar archive using bzip2
	-z - compress tar archive using gzip
tar -xvf file.tar location - extract tar archive
	-z - will decompress archive 

cpio - same as tar but have to list files to use (ls) to send to STDIN of cpio
	ls | cpio -ov > backup.cpio
		-o - specify output
		-v - verbose
	cpio -iv < backup.cpio
		-i - extract

dd - same as cp (kinda) - more advanced
	dd if=input of=output
	dd if=/dev/sda of=/root/mbr bs=512 count=1
 02/24/12@22:07:38 Location: Home 

8.1 Device Drivers


Device drivers
	loaded as kernel module
		.ko or .o file extension
		/lib/modules/version/kernel/drivers
		dynamic
	compiled into the kernel
		Less modular

/proc contains information about hardware and software
hardware info in /proc
	cpuinfo
	devices - hardware devices in the system
	dma - list of devices and dma channel
	interrupt - list what devices are assigned what IRQ
	iomen - IO port assigned to hardware
	modules - list of all kernel modules that are loaded and running
	version
	/scsi 
	/bus/devices - usb devices
	/ide

/sys - export information about hardware to running programs
	/sys/block - contains entry for each block device
	/sys/bus - subdirectries for each drive type - scsi ide usb
	/sys/class - all available class information
	/sys/devices - outline hierchy of devices
	/sys/module - subdirectory for each module

lsusb - all usb informaiton
hwinfo - lots of information about system hardware
	-device
lspci - probes pci bus and lists information that it finds
	-k will also list kernel modules that are using a pci device
 02/25/12@10:17:36 Location: Home 

8.2 Kernel Modules


view loaded kernel modules
	lsmod - gets information from /proc/modules and reformats it
	modinfo mod_name - more information than lsmod
generate list of moules dependencies
	depmod -v - text file stored in /lib/modules/version/modules.dep
	insmod /path/to/module_name - does not worry about dependencies
	modprobe modules_name - loads dependencies
		for old hardware add irq= and io=hex options
		every time the system boots it loads these files
			/etc/modprobe.conf - if doesnt exist it loads
			/etc/modprobe.dl
			/etc/modprobe.conf.local - use this for customization
unloading kernel modules
	rmmod module_name - if currently in use wont unload - does not calculate dependencies
	modprobe -r module_name - checks dependencies

 02/25/12@10:35:50 Location: Home 

8.3 Hotplug and Coldplug


coldplug - ram,cpu,expansion cards, hard drives
hotplug - usb,firewire

managing hotplug
	sysfs - virtual filesystem mounted in /sys
	hald - hardware abstraction layer daemon
	d-bus - desktop bus - notiify system of new hardware
	udev - virtual filesystem to create device files dynamically
		/etc/udev - customization text files for udev
 03/05/12@11:39:54 Location: Home 

9.1 Processes


Linux Processes
	Binaries
	Internal shell commands
	Shell Scripts
Types of processes
	user process is usually started when the user executes an application
	daemon (system) process does not provide an application - it provides system service
		usually identified by a "d" at the end - mysqld
Process Identifires
	PID - Process ID
	PPID - Parent Process ID
Forking - the process of creating processes in processes

For each process in top	- dynamic
	PID
	USER
	PR - priority
	NI - nice value
	VIRT - virtual memory used
	RES - Residence size RAM used
	SHR - shared memory
	S - current status 
		D - uninteruptly sleeping
		R - running	
		S - sleeping
		T - traced or stopped
		Z - zombie
	%CPU - 
	%MEM - 
	TIME - total amount of cpu used since it was started
	COMMAND - name as originally executed
ps - current snapshot
	Just ps - process for current shell are displayed PID,TIME,TTY,CMD
	-e - shall all processes on system
		? in TTY column means its a system process
	-f - display more detail
		UID,PPID,C(processor time),STIME(time command was started)
	-l - long format
		F(flags),S(state),PRI(priority),NI(nice value),SZ(size),WCHAN(kernel sleeping value)
 03/05/12@12:31:58 Location: Home 

9.2 Process Management


Run a process in background &
	[1] job ID and PID
	jobs to see background processes
fg - to move a process that is running in background to foreground
	fb jobid
bg - to move a process from the foreground to the background
	CTRL+Z to create a background jobID
	bg jobID
nice - used to launch a process with a custom nice value
	nice -n val command
	range from -20 to 19
	lower values have higher priority	
	regular users can only set 0 to 19
	root is the only one able to set below 0
renice - readjust a running process
	renice value PID
nohup - allows the process to continue running after logging out of the shell

kill -signal PID
	kill signals - default 15
		SIGHUP 1 - restart with same PID
		SIGINT 2 - same as CTRL+C
		SIGKILL 9 - Brute force way of killing process - meat cleaver
		SIGTERM 15 - nicer than 9 - allowing clean-up
killall -signal process_name
 03/05/12@22:10:37 Location: Home 

9.3 Process Management


use 'at' to schedule process to run at some point in the future
Crontrol access to atd
	/etc/at.allow
	/etc/at.deny
How to use atd
	at time
		fixed time
			HH:MM
			noon - midnight - teatime (4pm)
			MMDDYY
		relative time
			now
			now+ time
			today
			tomorrow
	press CTRL+D after at> prompt
	atq to see at jobs 
		normal user - only your at jobs
		root - all users jobs
	atrm job - to remove job

cron daemon
	system jobs
		/etc/cron.hourly (cron.daily)(cron.weekly)(cron.monthly)
		/etc/cron.d - custom entries
		cron runs system jobs as root user
	user jobs
		/var/spool/cron/tabs/username
restrict access to cron	
	/etc/cron.allow - not created by default
	/etc/cron.deny - only default deny is guest
	crontab -l - lists entries
	crontab -r - remove crontab file
 03/08/12@14:48:16 Location: Home 

9.5 Print Management


cups - common unix printing
	cups client - cups server - queue - filder - backend - printer
	cups server is like a web server - port 631
	Printers use different languages
	filter is located in /usr/lib/cups/filter
	backend is located in /usr/lib/cups/backend
	queue is located in /var/spool/cups

Installing and customizing cups
	/etc/cups/cupsd.conf
	directives
		ServerName
		ServerAdmin - email address
		DocumentRoot - /usr/share/doc/packages/cups
		LogLevel - level of detail stored in logs
		MaxCopies - default 100
		MaxJobsPerUser - 
		User - specify name of user cups runs as default lp
		Group - same as user
		MaxClients - default 100
		Browsing - default on to announce availablity
		BrowseAddress - broadcast address default is disabled
		BrowseInterval - default 30 seconds
Need to create user for cups
	stored in /etc/passwd.md5
	has to be called root in sys group
	lppasswd -g(group) -a(name) - used to add user for cups
Configure cups printer
	http://localhost:631
	select Administration
	Authenticate - root user from lppasswd
	Add a printer
		Name, location, description
	Select the device
	Secify the make and model
	Test the printer

enable printer sharing
	cupsctl --share-printers

Managing print jobs
	lpr -P printer file - sent file to printer
	lpc status - view status of printer
	lpq - view print queue
	lpq -a - view all print queue
	lprm - remove print job from queue
Other
	lpstat -t - display information about all cups printer on system
	cancel job_id - to cancel job
	lpoptions -d printer - specify default printer for all users on system
		~/.lpoptions - to override for specific user
			default printer
	lpoptions -l - display current options
	accept printer_name - enable printer queue
	reject printer_name - disable printer queue
	disable printer_name - stops queue from printing
	/usr/bin/enable printer - starts queue 
 03/12/12@21:34:45 Location: Home 

9.5 Time Management


Hardware clock - built into motherboard - OS dependant
	stored in /proc/driver/rtc (real time clock)
	hwclock option
		-a - used to adjust time drifting (add/subtract)
		-r - show current time as hardware clock sees it
		-s - set system clock to what the hardware clock is and sets the timezone according to what the TZ variable is currently
		--set --date=08/30/10 10:15:00 - set date and time of hardware clock
		-w - works in reverse of -s 
System clock - time that the kernel uses
	seconds since Jan 1, 1990
	netdate time_server (outdated)- check time from remote server
		time provider must be running time service (port 37 UDP)

on startup system clock is syncronized to hardware clock
UTC - Univeral Time Cordinated - GMT Greenwich Mean Time
Local time - Mountain time UTC-7

Files where timezone is written to:
	/etc/timezone - ubuntu
	/etc/sysconfig/clock - redhat suse

root is required to change time
	tzselect - will walk through drilling down to what timezone
Or you can change the value of TZ to change for a specific user
	TZ=time_zone; export TZ
	view list of available time zones in /usr/share/zoneinfo
If your distro uses /etc/localtime 
	/etc/localtime is a symbolic link to file in /usr/share/zoneinfo
	ln -s /usr/share/zoneinfo/file /etc/localtime

ntp (network time protocol) cross-platform
	nptd is a time_provider and time_consumer at the same time
	uses port 123
Stratum - define a hierachy of time_provider/time_consumer 
	stratum 1
	stratum 2
	lower number, closer to accurate
Stepping - updates once every 60 sec then once it gets closer 17 min
Slewing - slow down as you get close to make sure it doesnt go beyond the correct time
Insane Time - More than 17min - no synchronization will occur

How to configure ntp - pool.ntp.org
	/etc/ntp.conf
	server ip_address (to get time from)
	Should be two lines (server and localhost)
ntpdate ip_address - (make sure ntpd is not running) to change time
monitor ntp log file /var/log/ntp as ntp starts 
Monitoring ntp
	ntpq 
		-p show information (like top) about ntp
		remote - host currently synchronizing time with
		refid - type of referece source
		st - stratum of host
		when - seconds since last poll
		poll - number of seconds between poll
		reach - time when last update
		delay - roundtrip time measured in milliseconds
	ntptrace - traces source

 03/13/12@16:14:10 Location: MJC 

9.6 Mail Transfer Agent


The mail system on linux is full email
MUA - Mail User Agent
MTA - Mail Transfer Agent
SMTP - Simple Mail Transfer Protocol - Port 25
POP3 - Post Office Protocol - Port 110
	A little older
IMAP - Internet Message Access Protocol - Port 143
	Possible to download entire email or just the header
	Create custom folder to keep mail organized
Linux MTA - all are full mail applications
	sendmail - been around a long time (default) but difficult, single program
		init scripts in /etc/rc.d/init.d/sendmail
	postfix	- still difficult but it is modular
	qmail - not default on any distro - weird licence - built upon security
		QMQP - Quick Mail Queuing Protocol
		QMTP - Quick Mail Transfer Protocol
	exim - single program - easier than sendmail
These can only send, they cannot reveive mail from server. Need imap package
	imap package supports IMAP and POP3
users can view mail from the local MTA from the command line
	/var/spool/mail - holds users mail
Configuring Aliases
	/etc/aliases
		alias_name: email_address or username
	run "newaliases" after editing file
Fordwarding mail 
	The user that the mail was intended for will not receive a copy of the mail if the .forward file is setup
	~/.forward
		user_name
mailq or sendmail -bp to display the mail queue
sendmail -q to deliver all mail
sendmail -bd to start the sendmail daemon
 03/13/12@20:24:14 Location: Home 

9.7 Structured Query Language


Databases => tables => records => fields 
mysql
	-h host
CREATE TABLE name(col1 VARCHAR20, col2 VARCAR20)
INSERT INTO name VALUES(...)

Labsim uses:
	SORT BY (ORDER BY)
	SELECT (location,sales) FROM shirts; (SELECT location, sales FROM shirts)

Comments on: "Linux + Certification Notes" (1)

  1. […] History Andrew Tanenbaum was a professor who used UNIX source code to teach his students […] ubuntu server – WordPress.com Search […]

Comments are closed.

Tag Cloud

%d bloggers like this: