LPIC-1 Junior Level Linux Certification Exam 101 Study Notes.txt - Notepad

LPIC-1 Junior Level Linux Certification Exam 101 Study Notes

My study notes for the LPIC-1 101 Exam.

1.Hardware Settings

HAL - Hardware abstraction layer - imagine that you plugged 3 network cards from different vendors into a server. HAL labels the ethernet cards as eth0, eth1, eth2 regardless of vendor make - it abstracts out data such as brand and make etc. This makes replacing hardware a lot easier eg simply replace eth0.

dbus - dbus is the communication pathway with hardware and software. dbus is the way HAL communicates with things such as the desktop manager (Gnome/KDE) or other hardware eg plug in a usb drive dbus tells the desktop manager that it has found a usb drive, what do you want to do? It won't mention brand.

udev - when hardware is plugged in it is associated with /dev/sda1, /dev/sdb1 etc, created on the fly during boot. When the computer is turned on udev examines hardware assigned to dev/sda1, sdb1 etc (looks at particular information from the device such as serial numbers) and runs udev rules to see if the device can be mounted under a more useful name such as /dev/camera.

/sys or sysfs - the HAL DB is kept here. This is a DB of all devices connected to the computer.
/proc - the kernel keeps running cmds here - stored in RAM when the computer boots, temporary, must be root to access /proc.

lsmod - shows kernel modules.
lspci - shows pci devices.
lsusb - shows usb devices.
Other HW ls commands include lspcmcia, lshal, lshw.

How to insert and remove kernel modules - remember the kernel is the bridge between applications and hardware.

uuid - used to mount particular folders on specific drives eg instead of mouting the root dir on /dev/sda1 it could be mounted on a specific uuid (device ID - a long crazy number which inclues letters).

hot plug - plug in hardware while computer is running eg usb drive.
cold plug - plug in hardware when computer is turned off - eg PCI-E video card, PCI network card.


2.Boot the System

BIOS - know how to change boot device priority in the BIOS.

Bootloader - specifies what to boot, this kernel, this RAM disk etc then actually boots computer. Press esc during bootup to view the bootloader. GRUB (grand unifier boot loader) is the most common, others include lilo. GRUB includes things such as generic, recovery mode and memtest. You can edit GRUB by typing e. The GRUB specifies the uuid or partition - the HD to boot from. It also tells the system what kernel to boot from and where it is located. Quiet and splash can be removed so you can see info during the boot process. initrd (initial RAM disk) located in boot, has tools needed to finish boot process.

Logs - boot logs

init - replaced by upstart. Init is the first process that starts and manages all other processes - pstree.

3.Change Runlevels and Reboot or Shutdown the System

Runlevels 0, 1, 6 are predefined standard run levels.

/etc/inittab - a configuration file, tells init what to do. Sets default run level.

/etc/init.d - contains a series of scripts. Used to control services eg ./sendmail start, ./sendmail status. If you look in /etc you will see different commands for each run level under the following folders - rc.1, rc.2, rc.3 etc. These folders contain link to the scripts in init.d. K = kill process, s = Start process.

init/telinit?

shutdown
Immediate shutdown, no warning - halt, poweroff. These commands directly kill all processes. Can also use init 0.
shutdown "options" "time" - the best way to shutdown.


4.Design Hard Disk Layout

basic desktop

network workstation

server setup

Various directories


5.Install a Boot Manager

/boot/grub/menu.lst OR /boot/grub/grub.cfg (replaces menu.lst) - the Grub config file.
For systems running the new Grub (/boot/grub/grub.cfg) /etc/default/grub is the file you make changes to (similar to the old menu.lst).
After making changes type update-grub to update /boot/grub/grub.cfg.
grub-install /dev/sda - writes grub to MBR (master boot record). Old way?
To backup your MBR use mount to make sure you have the correct hard drive (the one / is mounted on, if it says sda1 then you are after sda).
dd if=/dev/sda of=/home/beare/backup.mbr bs=512 count=1 - use dd to backup /dev/sda (first hard drive) and send it to a file called backup.mbr, bs=512 specifies a block size of 512, count=1 refers to the first block size (the MBR) - IMPORTANT if you leave off count dd will backup the entire drive.
dd if=/home/beare/backup.mbr of=/dev/sda bs=512 count=1 - copies a backed up mbr file into /dev/sda.

6.Manage Shared Libraries

Shared libraries are common files used by different programs stored in memory.

ldd /bin/ls shows what files/libraries ls depends on in order for it to run.

/etc/ld.so.cache holds a cache of all libaray files stored on the computer. Programs look at ld.so.cache to determine if the dependencies they require to run are installed on the computer.

ld.so.conf specifies what location ld.so.cache uses to make up its library - ld.so.conf.d (folder containing .conf files pointing to library files).

To recreate the cache file - ld.so.cache, type ldconfig. When programs install they often run ldconfig to make sure their library dependencies exist.

The LD_LIBRARY_PATH variable can be exported to take priority over other library file locations.


7.Debian Package Management

dpkg
-l or --list = List all installed packages or if you specify a name it shows info on that package. ii means that the package is installed. Also shows version and description.
-L or --listfiles = shows all installed files for a package.
-p or --print-avail = shows more info for packages already installed.
-i or --install = installs program but does not install depedencies.
-r or --remove = removes package
-P or --purge = removes package including config files.
-S or --search = specify a file (full path name) and then it will tell what package it belongs to.
dpkg -l | grep package_name - is a good way to confirm if a package is installed on your system (look for ii, rc = no longer installed).

apt-get
install = installs package including dependencies.
dist-upgrade = update major version.
upgrade - updates packages to most recent version.
remove - removes package.
autoremove - removes package and dependencies
update - downloads repositories - update DB. Then do upgrade.

apt-cache
search = shows any packages that mention the search string
show = provides info on package
depends = shows dependencies that a package has.
rdepends = shows packages that depend on an app eg flashplugin depends on firefox

aptitude
without any expressions launches a gui installer
install
search

/etc/apt/sources.list - lists repositories. You can add your own repositories here.


8.RPM & YUM Package Management

yum
install - installs package
remove - uninstall package
search - find packages
upgrade - looks for updates for installed packages. /etc/yum.repos.d - lists repositories
/etc/yum.conf - yum config file

yumdownloader
Downloads packages.
--resolve - downloads all dependencies for package.

rpm
Doesn't install dependencies.
-i = install
-e = erase
-v = verbose (visual)
-i --nodeps = install packages without dependencies.
-K = checks signatures on package to make sure it's a legitimate package.
-V = verifies package for errors and shows if any files in the package have been modified.
-q = version number
-i = more info
-d = shows where doco files are
-a = searches all installed packages
rpm -qa | grep ssh - good way to check if a package is installed.

rpm2cpio
rpm2cpio thunderbird.rpm > file.cpio - Converts rpm to binary representation of files in there.
less file.cpio - shows what files would come out if it was extracted.
cpio -ivd < file.cpio - extracts files.

Alien
Converts .deb files to rpm.


9.Work on the Command Line

Use ; to string multiple commands on the one line eg echo hello; ls -l; echo Wow
Type env to view all environment variables. Look for PATH. This shows what locations your customised commands will need to be in order for you to use them.
Making variables - these needs to be in uppercase. VARIABLEX=hi_fellas. To export your variable type export VARIABLEX. Now VARIALBEX will appear in env. You can access it by typing echo $VARIABLEX. To remove a variable type unset VARIABLEX. You can also type set instead of export to make a global variable

Type history to show a list of previous commands.
uname -a shows a bunch of info about your system - what OS you are running, 32 or 64 bit, hostname, kernel version, date built.
man -k - searches all man pages for a specific string.
exec runs a command that will close the shell once the command completes.


10.Process Text Streams Using Filters

cat hello.txt - displays contents of hello.txt
cat hello.txt hello2.txt - displays contents of hello.txt and hello2.txt
cat hello.txt hello2.txt > hello3.txt - paste contents of hello.txt and hello2.txt in hello3.txt.
cut -c 2,3,4 heloo.txt - cut characters 2,3 and 4 from every line of heloo.txt
expand file.txt - convert tabs to spaces
fmt hello.txt - strips out all formatting and puts text in one line, specifies character width with -w
head file.txt - by default outputs the first 10 lines of a file. You can change this to any number of lines with -n eg head -n 30 file.txt
od hello.txt - convert file to octal representation. od -c hello.txt shows character representation.
join file1.txt file2.txt - merge two text files based on a common value in field 1.
nl helo.txt - numbers the lines in a file.
paste 1.txt 2.txt - creates output that lines up both files line by line.
pr 1.txt - prepares files for printing, lists page numbers and breaks text into pages.
sed -e 's/pants/dress' file.txt - edit file.txt and replace pants with the word dress. I haven't had much luck getting the -e option to work -i seems to work though.
sort 1.txt - sort alphabetically. sort -r sorts backwards. -R = random sort.
split -l 5 file.txt - splits file into multiple files containing 5 lines each. -b = bytes.
tail -n 15 - by default shows last 10 lines of file, in this example it shows the last 15 lines. tail -f - shows running log of file.
echo test | tr -t test TEST - changes letters from lower to uppercase (and vice versa). -d = delete, -s = squeezes together repeating characters.
unexpand -a file.txt - convert spaces to tabs, -a captures all spaces.
uniq file.txt - only shows unique lines. -c shows how many occurances of the line. -d only shows duplicated lines. -u only shows entries that are not duplicated.
wc file.txt - shows number of lines, words, bytes (characters) in a file. wc -w only shows word count. wc * will list the count of all files.

11.Perform Basic File Management.

cp -r testing/ testing2 - copy folder and its contents.
use rm -rf to recursively delete without prompt. You can use -i to prompt before deletion "are you sure?". -I prompts once when moving more than 3 files at a time.
mkdir and rmdir to make remove dirs.
file - shows file types.
Wildcards (globbing) - * = everything, ? = any single char, ! = not, [ac] = a or c, [a-c] = a,b,c.

find /home/nick/Downloads/ -size +5G - finds all files in Downloads that are greater than 5Gb in size. Use M to specify Mb, use - to indicate less than, use . to search current dir.
find /home/nick/Downloads/ -name "*.avi" - finds all files in Downloads whose filename ends in .avi
You can include -size and -name in the same command. Use -type to find folders or other file types d=directory, l=symlinks, f=file.
Finding files on time stamps.
-ctime -1 - find file changed (eg change name) less than 1 day ago.
-atime +5 - find file accessed (eg cat file) more than 5 days ago.
-mtime -5 - find file modified (eg modify contents) less than 5 days ago.

Archiving
cpio makes an archives from a list of files. You can use ls and find to direct input.
ls | cpio -o > ../archive.cpio
-o creates the archive
cpio -id < ../archive.cpio
-i = input file.
-d = creates folders if required.

dd - copies an entire drive. Use df to check drive names first.
dd if=/dev/sdb of=backup.img - this creates an archive of /dev/sdb and saves it as backup.img
dd writes the entire drive size even if the space hasn't been used. No compression.
if = input file
of = output file
dd if=backup.img of=/dev/sdb - copies the backup back to the drive.

gzip
gzip backup.img
gunzip backup.img.gz

bzip2
bzip2 backup.img
bunzip2 backup.img.bz2
These utilities delete the uncompressed file.

tar
tar cvzf archives.tar.gz sourcedir - creates an archive of the sourcedir
c = create
v = verbose - show on screen what's happening
z = compress using gzip
j = compress using bzip2, .bz
f = file
x = extract
tar xvzf archives.tar.gz - extracts the files/folders.


12.Use Streams, Pipes, and Redirects

stdin - standard input. Direct stdin using <. Eg to run a wordcount on a file named file.txt type wc < file.txt.
stdout - standard output. Direct stdout using >. Eg to output the contents of an ls command to file.txt type ls > file.txt OR ls 1> file.txt You would use ls 2> file.txt to output errors only. Note, use >> to append to the fle rather than overwriting it.
ls error > file.txt 2>&1 - redirects standard error (stderr) to standard output.

xargs - xargs passes standin to another command eg ls | xargs echo - displays the results of ls on the screen.

tee - used to push stdout to the screen and a file. ls | tee result.txt.


13.Create, Monitor, and Kill Processes

ps aux - lists all processes, useful with grep eg ps aux | grep firefox
jobs - lists process numbers.
bg x - process keeps running in background
fg x - bring process to front
nohup comm - process keeps running even after logout.
killall comm - kills all processes with particular name.

top - useful way to manage processes. F or O to select sort by field (eg memory or cpu utilisation), or you can do > or < to select the column to sort by.
Press k to kill a pid. The default kill signal is sigterm 15 (polite). Type 9 to force the program to shut. You can also type kill -9 pid

free - shows total memory, how much is being used, and how much is free. free -m or -g is easier to read (Mb, Gb).

uptime - shows how long the system has been up, what users are logged on, resource load in 1, 5 and 15 min intervals.


14.Process Priorities

Nice refers to process priority. Highest priority -20, lowest 19. The default priority for processes is 10 if you do not specify a number (nice firefox).
nice -15 firefox - creates firefox process with niceness of 15.
nice --19 firefox - creates firefox process with niceness of -19.
renice 20 pid - changes nice level to 20 for target pid.
ps -eo comm,pid,pcpu,user,nice | grep firefox - shows details for particular process.
Only Root can make a process have more priority or go below 0.
pstree - shows process in tree format with parent child process map. Kill the parent process and all child processes will also stop. renice 20 pid - changes nice level to 20 for target pid.
ps -eo comm,pid,pcpu,user,nice | grep firefox - shows details for particular process.
Only Root can make a process have more priority or go below 0.
pstree - shows process in tree format with parent child process map. Kill the parent process and all child processes will also stop.

15.Search Text Files with Regular Expressions

grep x file.txt - find files in current dir that have x in their name. Grep is case sensitive.
grep ^text destination.txt - specifies beginning of line eg textbook.
grep text$ destination.txt - specifies end of line eg context.
grep .text destination.txt - specifies any character and then text.

egrep allows you to string several expressions together (OR = |).
egrep '(book$|^con)' destination.txt - shows all entries that end in book OR start with con.
egrep '(book$|^con)andinclude' destination.txt - does the OR expression and AND expression.
egrep '^([a-z]|[A-Z])andinclude' destination.txt - finds files that start with any character from a-z or A-z AND include "andinclude".

fgrep> - does not include regular expressions like ^ or $. Useful when you want to literally find ^start_with.

sed - streameditor.sed 's/text/dick/' /home/nick/test - Sed will search test for all instances of text and replace them with dick.
You will need to use the -r flag to use regular expressions $, ^ etc. regex = regular expressions.


16.Perform Basic File Editing Operations Using vi

h = left
l = right
j = down
k = up
o = open insert mode on line below.
e = move one word forward
b = move one word backward
i = insert text to left of cursor.
a = insert text to right of cursor.
y = yank (copy) text. yl = yank letter, yw = yank word, yy = yank whole line.
d = cut text. dl = cut letter, dw = cut word, dd = cut line.
c = change text. cl = change letter, cw = change word, cc = remove line.
p = paste
esc = enter command mode
/ = search forwards. There is no space after /wanted. Hit return to initiate the search. n searches forwards, N searches backwards.
? = search backwards. There is no space after ?wanted. Hit return to initiate the search. n searches backwards, N searches forwards.
:w = write to file
:w! = force write
:e = discard changes to file
:e! = force discard changes to file
:wq = save and quit.
ZZ = save and quit.
:w file.txt = save as to file.txt
:q = quit without saving
:q! = quit without saving

17.Create Partitions and Filesystems

Creating a partition
fdisk -l - shows all hard drives connected to the computer (must be root). Partitions 1-4 are primary partitions (suported by default). The extended partition tells the computer where other partitions are 6+. 5 is SWAP. * under boot shows if the partition is bootable. A raw disk will return "doesn't contain a valid partition table".
fdisk /dev/sdb - format drive
m = help
p = to see drive stats (confirm drive)
n = add partition, e for extended or p for primary (1-4), give it a number for partition number and cylinder(1,1), last cylinder by default is ok if you want the whole drive, otherwise you can do +xG if you still want to create a second parition.
t = partition ID - This change a partition's system Id. Type L to see a list of all possible Ids. These Ids correspond to different partition types.
83 = linux partition
51 = windows
c = windows large block size (use this one)
82 = linux swap
w = writes changes (remember to do this at the end to save your changes).

Creating a filesystem - required to mount and use drive. Need to be root.
mkswap /dev/sdb2 - create SWAP filesystem.
swapon /dev/sdb2 - activate SWAP
swapon -s - show SWAP space in use

mkfs -t ext2 /dev/sdb1 - create ext2 filesystem.
Instead of -t you can also do mkfs.xfs, reiserfs or ext2,3 (vfat=Windows). If paritiion already has file system xfs will warn you and you will need to include the -f flag to overwrite.


18.Maintain the Integrity of Filesystems

df - shows disk usage and where the disk is mounted in the filesystem.
-h = prints info in Gb or Mb etc rather than block size.
-T = shows what filesystem the drives are eg ext2, ext3
-i = shows inodes, each file on comp uses an inode.
Even when there are no files on a drive it doesn't mean that there is no usage on the drive. There are inodes and there can also be journaling - both of these take up space.

du - shows how much space files/folders are taking up. Note this shows all child folders of the target dir
-h = displays the information in human readable format eg Mb, Gb
-s or --summarize = summarises the info. For example if you just want to see the size of /home/user1 type du -sh /home/user1
du -h /home/user1 - shows the size of all folders in /home/user1.
You can use du to find the size of a file - du -sh /home/user1/file.txt

fsck /dev/sdb1 - check the integrity of a formatted file system. fsck is a program that runs a different program to check the filesystem. DON'T run this on a mounted filesystem. You may need to boot to a live cd to fsck your / partition.
You can also run fsck -t ext3 /dev/sdb1 OR fsck.ext3 /dev/sdb1. Need to be root.
To check and repair xfs filesystems you need to use xfs_check /dev/sdb1 and xfs_repair /dev/sdb1 to repair.

debugfs /dev/sdb1
-w = makes changes inside debugfs prompt
help = see commands
q = quit
cd = change dir
ls = list files
rm = remove file
lsdel = view deleted files
undel filename.txt = recover deleted files.

dumpe2fs /dev/sdb1 > file.txt - you need to direct stdout to a file (long output). Shows a bunch of information about your drive.

tune2fs -O has_journal /dev/sdb1 - add feature to drive.
tune2fs -O ^has_journal /dev/sdb1 - remove feature from drive.

xfs_info /dev/sdb1 - shows info on xfs filesystem (must be unmounted)
xfs_metadump /dev/sdb1 file.db - creates binary file that you can run xfs_db on.


19.Control Mounting and Unmounting of Filesystems

You need to run fdisk -l to find out what devices are on your computer. Without the dev name eg /dev/sdb1 you wont be able to identify your drive. If you are trying to mount a USB drive it might be worthwhile running lsusb to make sure your drive is detected and to check the size.

Manual mount
mount -t vfat /dev/sdb1 /media/thumb_drive - you will need to be root to mount a filesystem. vfat (W95 FAT32) is the type of filesystem, dev/sdb1 is the device, /media/thumb_drive is where you want to mount it (this folder needs to exist first).
To unmount the drive type umount /dev/sdb1 or umount /media/thumb_drive. Type mount to look at all currently mounted drives.

To mount drives automatically you need to edit /etc/fstab and add your device to this page.
The first field is file system eg /dev/sdb1, next is mount point eg /media/thumb_drive. The third field is what type of filesystem it is, the next is dump (1= saves mounted files upon system shutdown, 0 = don't save), pass is the order in which filesystems are scanned 1 = /, other local filesystems is 2, 0 = removable drives/cd/floppy.
options include things like rw, r (not even root can write), user (any users can mount the filesystem, auto=automatically mount on bootup. Defaults is a good option it includes auto mount on bootup. Noexec prevents people running binaries on the filesystem.


20.Manage Disk Quotas

You will require a program called quota. To add user and group quotas to a drive you will need to first edit the /etc/fstab file. Add usrquota,grpquota to the mounted drives options. You will need to remount the drive after changing the /etc/fstab file, mount -o remount /dev/sdc1
quotaoff /media/mnt - turn off quotas, useful check before adding a quota to determine if there is an existing quota.
quotacheck / - checks to see if quota is on /.
quotacheck -cug /media/mnt - creates user and group quota files for /media/mnt. quotacheck runs on boot up.
If you ls /media/mnt you will see two files - aquota.user and aquota.group. These are binary files that cannot be edited with vi. To edit these files type edquota -u user1 - this will edit the aquota.user file for user1. This shows how many blocks and inodes user1 is using.
soft = users can go over soft limit. They then go into a 1 week by default grace period. They have 7 days to get the data below the soft limit. If they don't reduce within this timelimit they will have no available space. This can be modified using edquota (they are in Kilobytes). 0 equals no limit
hard = users cannot exceed their hard limit - will receive an access denied error.
both of these limits cann apply to inodes (number of files) and blocks (storage space).
quotaon /media/mnt - will constantly update aquota.user and aquota.group.
repquota /media/mnt - generates report on quota usage for all users.
edquota -t - modify the grace period for soft limits
edquota -g groupname - modify soft/hard limits for groupname

21.Manage File Permissions and Ownership

u = owner
g = group
o = others
4 = read
2 = write
1 = execute
+ = add perms
- = remove perms

sudo chown -R loser:nick permissions/ - changes all files and dirs in permissions/ to owner loser and group nick.
sudo chmod -R 470 permissions/ - changes all files and dirs in permissions/ to read access for owner, rwx for group, no permissions for others.
sudo chmod -R o-x /var/www/html/ - removes execute access for others for all folders/files in /var/www/html. Note, web pages need to have +r for others so that people can view them. Scripts will need +x to work for others.
user chgrp or chown :group_name to change group permissions. Note, you need to be root to change the perms of a folder that you are not the owner of.

In order to do a dir listing (ls) or cd to a dir you need to have executable access (x) for that directory.

umask - shows the default permissions for files and dirs that you create. For example a umask of 022, will subtract 022 from 777 to give you perms of 755 for folders and 644 for files (executable bit is stripped for files).
A umask of 002 would give you 775 (777-002) or drwxrwxr-x for a dir.
NOTE: even if you have a low umask it will always strip off executables for files. Also, umask is not global, its only affects the current user.
You can modify your umask by typing umask or editing /etc/profile or .profile.

suid (s) - affects executables - gives owner-execute access for other users.
guid (s) - affects folders and executables. On files it has the same effect as suid except it is based on group. If it is place on a dir then all files created in the dir take on the group ownership regardless of who they are created by.
sticky bit (t) - affects folders - prevents users from deleting files that they do not own.
suid = 4
guid = 2
sticky bit = 1
The number goes in front of the usual ugo permissions eg 4755.
chmod 4755 /usr/bin/backups - sets the suid for the backups script.
chmod 2755 /usr/bin/backups - sets the guid for the backups script.
chmod u+s /usr/bin/backups - sets the suid for the backups script.
chmod g-s /us/bin/backups - removes the guid for the backups script.
chmod o+t /usr/bin/backups - sets the sticky bit for the backups script.


22.Create and Change Hard and Symbolic Links

ls -i - shows inode numbers. Useful for confirming hard links. Hard links link to the same file or inode. Soft links only point to the filename
ln file.txt hardlink.txt - creates a hard link named hardlink.txt that links to file.txt. These files share the same inode number.
ln -s file.txt softlink.txt - creates a soft link.
Note: hard links cannot be linked across different devices. When linking to a file in a different path make sure you specify the whole path.

23.Find System Files and Place Files in the Correct Location

FHS - File Hierarchy Standard
/ = root
/bin = command binaries eg ls, grep etc
/boot = boot loader, GRUB, kernel - normally separate partiton
/dev = devices such as hard drives
/etc = config files
/home = user home dirs - often separate drive
/lib = library files that executables need
/proc = virtual file system created on boot, can config current running system
/root = root user's home dir.
/sbin = system binaries - super user binaries eg fdisk.
/tmp = temp files
/usr = programs installed by users, used by users - usr/bin.
/var = variable files such log files - often on separate parition
/media = removable media.
/mnt = legacy location for removable media.

locate filename - Fast search for a filename, case sensitive, can't be very specific though. Searches whole filesystem. May need to be root because it looks everywhere. /etc/updatedb.conf is the config file for the database, PRUNEPATHS are omitted from being indexed. Need to run updatedb to update your db manually with newly added files. Need to be root to do this. Db usually updates daily.

which ls - shows where a command lives.
whereis ls - shows where a command lives + extra info like man page.