Reference: |
Linux /
LPIC-1ExamTopics
After the exam I would say that 2 weeks is enough if you have knowledge of common configuration of linux computers. I mean not only the simple installation of nowadays distributions but the manual installation steps beginning with creating partitions until configuration the X files. Chapter 1.101.1 Basic Bios properties (exam weight: 1)I/Os:
As important file is here named /proc/pci but this file doesn't exist in my Ubuntu distribution. IRQ 0 Timer Chapter 1.101.5 Installation of PC cards (weight: 3)Important things:
Information about current assignment: /proc/interrupts and /proc/ioports and "lspci -vv" SCSI8-Bit-scsi has three address lines. So we have 2^3=8 IDs. The controller gets ID 7 and devices 0-6. Make clear if you being asked for number of ids or devices. 16-Bit-scsi has four address lines. Controller gets also ID 7. Information files: /proc/scsi/scsi Programs: scsi_info Device names: /dev/scdX scsi cd or dvd device
/dev/srX scsi raw access. That is for burning devices.
/dev/sdXN scsi harddisks, usb and sata devices. N means the partition on this device.
/dev/sgX scsi generic is the deprecated predecessor of /dev/srX
/dev/stX scsi tape device
/dev/nstX Also for tape device but without rewind operation at the end of the job (n=norewind)
Plug and Playwith the program pnpdump we get the configuration and then we write it down into /etc/isapnp.conf i.e. the i/o addresses and interrupts that the pnp card uses. At last we use this properties with program isapnp to activate pnp card. hdparm$ sudo hdparm /dev/hda Password: /dev/hda: multcount = 16 (on) IO_support = 0 (default 16-bit) unmaskirq = 0 (off) using_dma = 1 (on) keepsettings = 0 (off) readonly = 0 (off) readahead = 256 (on) geometry = 65535/16/63, sectors = 117210240, start = 0 hdparm -c1 /dev/hda activates 32-bit i/o support
hdparm -d1 /dev/hda activates dma access for hard disk 1
hdparm -d0 /dev/hda disables dma access for hard disk 1
hdparm -I /dev/hda or hdparm -i /dev/hda returns tecnical hard disk data, geometry, serial and model number. With (-I) directly from hard disk bios.
ModemsHCF Modems are special modem devices for windows os. Therefore they use specific drivers and so they are often not useable under linux. With setserial you can set the speed of the communication with the serial interface. Wrong speed properties lead to wrong communication and many lost characters. USBTo connect usb devices to your computer there exists "hotplug" which is also used for pcmcia, firewire devices. Some distributions use "usbmgr". The kernel modules are called "usb-uhci (Universal Host Controller Interface) for intel and via chipsets and "usb-ohci" (Open Host Controller Interface) for all the other chipsets. Chapter 1.102.1-6
common question from this part:
Chapter 1.102.1 Creation of a partition set for linux/bin /sbin /lib /etc /dev These partitions have to be placed into the root partition. The installation needs at least two partitions: "/" and "swap" partition. Own Partitions are recommended for /var /home /boot # as first partition if boot manager is lilo to solve 1024 cylinder problem FHS (Filesystem Hierarchy Standard)
Combination of one of the first pair with one from the last pair is also possible. "/home" can be declared as "variable shareable". For this reason we have execution files in /bin as well as in /usr/bin. We have to prevent some files like "mount" in /bin or a mount of /usr partition cannot be made because the binary lies in the partition that we want to mount. Chapter 1.102.2 Installation of a boot managerLILO stores the position of kernel and necessary files by means of sector addressing of the hard disk. Therefore lilo has to be reinitialized each time any file has changed a little bit. It is unindependently from naming because lilo does not use inodes to find the file like grub does. Grub uses the common file systems like ext2/3 or reiserfs to get the files. Therefore it is not necessary to reinstall grub into mbr after changing any file in /boot directory. LILO Errorcodes:
first stage was loaded and executed but start of the second stage failed
second stage was loaded but cannot be executed. Maybe /boot/boot.b was moved inside the file system.
second stage was executed but the map file cannot be found
second stage was loaded but the address derives to a invalid point. Maybe because /boot/boot.b was moved.
The description table cannot be read.
all stages were executed successful.
After the bios starts the code in the mbr. Lilo as well as Grub have only a small part in the mbr part. With this small part they load the second part from /boot which loads the kernel into memory. grub-install installs the first stage loader into the mbr and it loads the rest of grub from /boot/grub. That is grub.conf or menu.conf.
INSTALLATION without grub-install with grub console:install (hd1,1)/boot/grub/stage1 d (hd2) (hd1,1)/boot/grub/stage2 p (hd1) (hd1,1)/boot/grub/menu.lst or with #grub grub>root (hd1,1) grub>setup (hd1) This is gonna tell you whether or not the stage files can be found and further information about installation process.
lilo installs lilo data into mbr. That has to be done ALWAYS after changes to /etc/lilo.conf
Important files:
Chapter 1.102.3 Installtion from source packagetar -xzf source.tar.gz or gunzip source.tar.gz; tar xf source.tar ./configure make make install or ./configure && make && make install make clean gzip -d tux.gz gunzip -d tux.gz make both sense because gunzip is often the same file or connected with a symbolic link. The difference recognizes gzip through command line call. "-d" means decompress and is therefore all what gzip needs to know.
With gzip you can also compress a stream of data but not pack files into a package. For this cases we have "tar". Options for "tar":
create file
extract file
use file which is given as parameter
decompress gzip file
decompress bzip2 file
test mode, what means that the file will be tested for errors but returns also a full list of all files in the packages.
To decrompress file with means of pipes use: $bunzip2 src.tar.bz2 | tar -xv - "-" shows tar that STDIN should serve as input file.
Default parameters for "./configure" script is for example "--with-prefix=/usr/local" which means that the installtion path is "/usr/local". Default rules for make files:
deletes all .o files and other temporary files
clean all the data so that we have the origin status as we have right after the tar command. The rule for the source files of the kernel is called "mrproper".
deprecated, because we have often the "configure" script.
handles dependencies
starts the compile process.
starts the installation process.
tries to bring up an already installed version up to date
Chapter 1.102.4 Management of shared librariesshared objects: *.so ldd /bin/echo linux-gate.so.1 => (0xffffe000) libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7e19000) /lib/ld-linux.so.2 (0xb7f5e000) File /etc/ld.so.conf define where the system search for libraries. Some distributions use also files from /etc/ld.so.conf.d/. No prevent searching whole list of pathes it exists an cache. With "ldconfig" you can bring this cache up to date. ldconfig Additionally the variable LD_LIBRARY_PATH gives pathes which will be searched for necessary libraries. Important:
Chapter 1.102.5 Debian package administrationdpkg -i install
dpkg -r or dpkg --remove remove
dpkg -l list of installed packages
dpkg -l 'gnome*' list all installed packages that begins with "gnome"
dpkg -L package shows all files from package
dpkg -S pattern or dpkg --search pattern search for pattern in list of installed files.
dpkg -P package or "--purge" means that all remaining config files will also be deleted.
dpkg -s package or dpkg --status package dpkg -E avoids installation of packages of the same version as the one that is already installed
dpkg -G avoids installation of an older package over one that is newer.
dpkg -R traverses recursively all sub folders and installs all packages .deb that will be found.
apt-get update load recent package list
apt-get upgrade install new versions if any are available.
dselect Menu based install tool.
alien converts .rpm to .deb an vice versa.
Config files:
Important files:
Chapter 1.102.6 RPM-i --install install package
-e --erase erase package
-U --upgrade upgrade package
rpm -i package.rpm --test test mode
--force --nodeps ignores error respectively wrong dependencies
--oldpackage for installation of updates. Option --oldpackage approves installation of old version above newer ones.
-V --verify test package and shows lacking and modified files.
-K --checksig Run some tests before installation as checksum or signature test.
-q --query Show extra information.
-ql List of all files which are installed.
-qc List of all config files which are connected to the package.
-qd Manual pages
-qi Common information about the package.
-qa List of all packages which are installed.
-qf file returns package name which contains the given file
$rpm -qf /usr/bin/passwd shadow-4.0.2-205 If the package will be installed later you can add option "p" to the commands above. "-p packagename" means that the search will not go through installed packages but through files of packagename. -c --configfiles searchs only config files
-d --docfiles searchs only documentation files
-l package --liste package all files which the package contains.
-R --requires searchs only dependencies
-i (with q as -qi, not -i as --install) searchs in the information about the package
--rebuilddb repairs rpm database
Important files:
Chapter 1.103
Configuration of bashIf you start with a login shell bash searchs for the following files in the given order:
The file ~/.bashrc is only for shells which were interactive meaning that they were start during execution of another shell. Chapter 1.103.1 Working on the command line (exam weight:5)Important things:
Here is basic knowledge of bash or sh necessary like variable declaration, variable exporting, usage of history as !-5 or !234. env (run a program in a modified environment)env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...] Set each NAME to VALUE in the environment and run COMMAND.
Chapter 1.103.2 Processing text via filters (exam weight:6)Important things:
cat (returns the content of the given file)cut (cut characters or fields from files)$cut -option file $cut -c5 <file> extracts from each line the fifth character
$cut -c5- <file> extracts from each line the fifth character until the end of the line
$cut -c5-10 <file> extracts fifth until tenth character
$cut -c1,3,5,7 <file> extracts list of given positions
We can also define a delimiter. That is practical for csv files where the delimiter is the ";" character. The delimiter devide a line into parts or better called as fields. To define the delimiter we have option "-d" and the fields we want to see will be defined with "-f". By default is the delimiter the tabulator \t. $cut -d\; -f1,3 file.csv extracts field 1 and 3
expand (transform tab characters into space characters)By default it transform one tab to eight space characters. You can choose how many characters one tab should be with option "-" and then the number of spaces. For example to transform tab to four spaces use: expand -4 main.c "-0" is not possible. To delete tabs from file use "tr". fmtfmt - simple optimal text formatter SYNOPSIS fmt [-DIGITS] [OPTION]... [FILE]... DESCRIPTION Reformat each paragraph in the FILE(s), writing to standard output. If
no FILE or if FILE is ‘-’, read standard input.
Mandatory arguments to long options are mandatory for short options
too.
-c, --crown-margin
preserve indentation of first two lines
-p, --prefix=STRING
reformat only lines beginning with STRING, reattaching the pre‐
fix to reformatted lines
-s, --split-only
split long lines, but do not refill
-t, --tagged-paragraph
indentation of first line different from second
-u, --uniform-spacing
one space between words, two after sentences
-w, --width=WIDTH
maximum line width (default of 75 columns)
--help display this help and exit
--version
output version information and exit
With no FILE, or when FILE is -, read standard input.
head (output the first part of files)-n, --lines=[-]N print the first N lines instead of the first 10; with the leading ‘-’, print all but the last N lines of each file hexdump, hd (ASCII, decimal, hexadecimal, octal dump)$hexdump -C a.avi | head 00000000 52 49 46 46 90 54 de 01 41 56 49 20 4c 49 53 54 |RIFF.T..AVI LIST| 00000010 8c 20 00 00 68 64 72 6c 61 76 69 68 38 00 00 00 |. ..hdrlavih8...| 00000020 57 82 00 00 00 00 00 00 00 00 00 00 10 01 00 00 |W...............| 00000030 84 03 00 00 00 00 00 00 02 00 00 00 00 00 00 00 |................| 00000040 80 02 00 00 e0 01 00 00 00 00 00 00 00 00 00 00 |................| 00000050 00 00 00 00 00 00 00 00 4c 49 53 54 1c 10 00 00 |........LIST....| 00000060 73 74 72 6c 73 74 72 68 38 00 00 00 76 69 64 73 |strlstrh8...vids| 00000070 4d 4a 50 47 00 00 00 00 00 00 00 00 00 00 00 00 |MJPG............| 00000080 e8 03 00 00 12 75 00 00 00 00 00 00 84 03 00 00 |.....u..........| 00000090 5b c4 00 00 10 27 00 00 00 00 00 00 00 00 00 00 |[....'..........| join - join lines of two files on a common field$cat test1 testfield1 testfield2 $ cat test2 testfield1 testfield2fromtest2 $ join test1 test2 testfield1 testfield2 testfield2fromtest2 less (print file content pagewise and possibility to navigate through the content)more (print file content pagewise but you can not navigate through the content)nl (print file lines with their line number) nl -s '.) ' linearerKongruenzGenerator.c | head
1.) #include <stdio.h>
2.) #define OBERGRENZE 10
3.) #define MAX_LOESUNGEN 100
4.) /*
5.) unsigned in ggT(unsigned int a, unsigned int b);
6.) unsigned in euclid(unsigned int a, unsigned int b);
7.) */
8.) unsigned int euclid(unsigned int a, unsigned int b)
paste (merge lines from files)$cat test1 test2 testfield1 testfield2 testfield1 testfield2fromtest2 $ paste test1 test2 testfield1 testfield2 testfield1 testfield2fromtest2 pr - convert text files for printing$cat test1 test2 testfield1 testfield2 testfield1 testfield2fromtest2 converts text content and print it pagewise similar to the following:
2007-02-27 17:57 test1 Page 1 testfield1 testfield2 2007-02-27 17:58 test2 Page 1 testfield1 testfield2fromtest2 sedsed s/./A/ replaces every first occurence of a arbitrary character with a "A".
sed s/\\./A/ replaces every first occurence of a "." with a "A".
sed s/\\/x/ (without use of bash) replaces every first occurence of a "\" with a "x". But the bash replaces "\\" with a "\" because it interprets backslash as an special character. But "sed" needs two backslashes. So we have to give the bash four backslashes. Bash replaces that with "\\" and sed gets its two needed backslashes and can recognize that it should search for a backslash character.
sed s/\\\\/x/ sort (sort text or files)-n (numerical) -f (no difference between lower and capital characters) -r (reverse order) -n -r (reverse numerical order) -c (test if file is sorted and returns errorlevel 1 if not) -u (no double occurence of lines) split (split a file into pieces)Without any parameters "split" creates pieces of 1000 lines. $split -100 logfile.log $ls xaa xab xac xad The logfile was devided into pieces a 100 lines.
$for file in `ls x* | sort`; do cat $file >> newlogfile.log;done takes pieces and stick them again together to a new file.
Let us assume that we have a file of size 3 gigabyte. We want to split this into pieces of size 700 megabyte to burn them onto cds. $split -b 700m filesize3gb.tgz After copying files back to harddisk we can concatenate these files together again with:
$cat filesize3gb* > hugefile.tgz tac (as cat only with reverse order)"tac" prints out the last line first then the second last line and so on. tail (prints end of file)$tail -20 messages shows last 20 lines of file messages
$tail +100 messages shows lines from line 100 until end of file.
$tail +100 -r messages as tac prints out last line and go further with reverse order.
tee (t-piece for output redirecting)If you want to redirect stdout to a file and want to see simultaneous stdout on screen "tee" is the right tool. $du -bc | sort -n | tee bytesorted.log writes output to screen and to file bytesorted.log. If you want to print into multiple files just add parameters to "tee".
touch (creates file)-a change the access time -c if file does not exist it will not be created -m change the modified time tr (replace characters)echo "Hello World" | tr [:upper:] [:lower:] gives "hello world"
tr - translate or delete characters tr [OPTION]... SET1 [SET2] Translate, squeeze, and/or delete characters from standard input, writing to standard output. -c, -C, --complement first complement SET1 -d, --delete delete characters in SET1, do not translate -s, --squeeze-repeats replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character -t, --truncate-set1 first truncate SET1 to length of SET2 --help display this help and exit --version output version information and exit SETs are specified as strings of characters. Most represent themselves. Interpreted sequences are: \NNN character with octal value NNN (1 to 3 octal digits) \\ backslash \a audible BEL \b backspace \f form feed \n new line \r return \t horizontal tab \v vertical tab CHAR1-CHAR2 all characters from CHAR1 to CHAR2 in ascending order [CHAR*] in SET2, copies of CHAR until length of SET1 [CHAR*REPEAT] REPEAT copies of CHAR, REPEAT octal if starting with 0 [:alnum:] all letters and digits [:alpha:] all letters [:blank:] all horizontal whitespace [:cntrl:] all control characters [:digit:] all digits [:graph:] all printable characters, not including space [:lower:] all lower case letters [:print:] all printable characters, including space [:punct:] all punctuation characters [:space:] all horizontal or vertical whitespace [:upper:] all upper case letters [:xdigit:] all hexadecimal digits CHAR all characters which are equivalent to CHAR Translation occurs if -d is not given and both SET1 and SET2 appear. -t may be used only when translating. SET2 is extended to length of SET1 by repeating its last character as necessary. Excess characters of SET2 are ignored. Only [:lower:] and [:upper:] are guaranteed to expand in ascending order; used in SET2 while translat‐ ing, they may only be used in pairs to specify case conversion. -s uses SET1 if not translating nor deleting; else squeezing uses SET2 and occurs after translation or deletion. Example: Replace linefeed with nothing. cat linefeed.txt | tr -d '\012' uniq (do not print lines that occurs twice)wc$wc test.txt 671 4168 26487 test1.txt prints number of lines, words and characters
$wc -c test.txt 26487 $wc -w test.txt 4168 $wc -l test.txt 671 "wc" is able to get its input from stdin, pipe or through parameter. File Globbing (bash replaces * ? and [] with fitting patterns)whereis (search for files)"whereis" starts a search for a particular file or command and returns its full path and if possible its manual sites. xargs (takes a list from stdin and call a command with this list)$find . -name "*.tmp" -print0 | xargs -0 rm searchs for all files with extension .tmp and the list goes to xargs. xargs takes that list and calls rm with the whole list. That means that we have only one call instead of several hundrets if we go through the file list with a loop and calls for every match the "rm" command.
`` (back quotes)$ today=`date` $ echo $today Wed Feb 28 19:58:55 CET 2007 test (to evaluate expressions)if test expression then
fi or you can use the symbolic form of "test" with "[ expression ]": if [ expression ] then # do something fi The spaces inside the brackets are not a coincidence. After [ and before ] you have to place a space character. and also the expressions will be devided with a space character. [ var1 -eq var2 ] [ var1 -ne var2 ] [ var1 -lt var2 ] [ var1 -gt var2 ] [ var1 -le var2 ] [ var1 -ge var2 ] if [ $# -ne 2 ] then echo "You have to give 2 parameters!" fi let (compares integer numbers)As "test" we have a short form for let: (( var1 == var2 )) (( var1 != var2 )) (( var1 < var2 )) (( var1 > var2 )) (( var1 >= var2 )) (( var1 <= var2 )) unexpand (converts spaces to tabs) Convert blanks in each FILE to tabs, writing to standard output. With no FILE, or when FILE is -,
read standard input.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
convert all blanks, instead of just initial blanks
--first-only
convert only leading sequences of blanks (overrides -a)
-t, --tabs=N
have tabs N characters apart instead of 8 (enables -a)
-t, --tabs=LIST
use comma separated LIST of tab positions (enables -a)
Chapter 1.103.3 File management (exam weight:3)Important things:
Command cp (copy)-d (no dereference) copyies links as links and not as their reference content.
-f (force) If destination files can not be opened for writing this parameter leads to removing the file and its new establishment as it exists in the source
-i (interactive) asks each time if a file will be overwritten.
-l (link) does not copy the files physically but as hard links. That implies that the destination must be on the same partition.
-p (preserve attributes) keeps file attributes as owner, access rights and so on.
-R -r (recursive) copyies also subfolders
-s (symlink) same as "-l" but not hard links but symlinks.
-u (update) overwrites existing destination files only if the source file is newer.
-v (verbose) gives more output.
-Rpd or -a copyies recursive, permits rights and does not dereference links. These options are called archiv options and have a short parameter "-a"
Chapter 1.103.4 Using streams, pipes, redirects (exam weight:5)Important things:
$cmd1 | cmd2 cmd1 stdout will be connected via pipe with stdin of cmd2
$cmd1 ; cmd2 first execution of cmd1 then cmd2
$cmd1 && cmd2 first cmd1 and if it returns errorlevel 0 then execution of cmd2 else nothing happens
$cmd1 || cmd2 first cmd1 and if it returns errorlevel unequal to zero then execution of cmd2
$cmd1 & cmd2 cmd1 execution in background then cmd2 in foreground.
$cmd > test.out or cmd 1>test.out stdout to test.out
$cmd >> test.out stdout appended to test.out
$cmd 2>error.log stderr to error.log
$cmd &>output.log or cmd > output.log 2>&1 both stdout and stderr into output.log
$cmd < intput.txt gets stdin from intput.txt
$cmd << EOT input cmd gets input from file input until string EOT occurs.
$cat << EOM | mail user@localhost Subject: Hello <emptyline> Testemail <emptyline> <emptyline> EOM bash option "noclobber"$set -o noclobber $echo Test > test.txt bash: test.txt: cannot overwrite existing file $set +o clubber $echo Test > test.txt $_ Chapter 1.103.5 Creating, monitoring and killing of processes (exam weight:5)Important things:
Command "jobs"shows all processes that are stopped or running in the background. fg <JOBID NOT PID!> takes job with id and continue it in the foreground.
bg <JOBID> takes job with id and continue it in the background.
Command "ps"ps -ef returns snapshot of current processes with enviroment (e) and full formatted output (f)
ps aux returns overview with usage of cpu time and so on.
Command killends the given process. kill <pid> kill %<jobid> kill -9 <pid> sends signal 9 alias SIGKILL to process.
Signals
If a process gets this signal it should end itself.
forces the termination of the process.
used to be as "Hang Up immediately" but nowadays it is used to force process to load its config files again.
kill -HUP <pid> forces process pid to load its config files again.
same as we press <ctrl>+z in the console what has the result in a process that is stopped.
Chapter 1.103.6 Modifying process priorities (exam weight:3)Important things:
nice -n 18 program the higher the number the friendlier you are to other users because you give away cpu time. Value interval goes from -20 to 19 because we have 40 levels and 0 is also one level.
nice -18 <pid> nice -+18 <pid> are the same.
nice --18 <pid> sets priority to -18, what is a very high priority.
Chapter 1.103.7 Searching text files via regular expressions (exam weight:3)Important things:
. arbitrary character
^ begin of a line
$ end of a line.
? 0 or one repetition of previous expression. Expression "?" stands for a arbitrary character that occurs once or none.
+ one or more repetitions of previous expression.
* no or arbitrary repetitions of previous expression.
Chapter 1.103.8 vi basics (exam weight:1)Important things: vi / or ? h,j,k,l G, H, L i, c, d, dd, p, o, a ZZ, :w!, :q!, :e! :! Chapter 1.104
Questions:
Chapter 1.104.1 Creation of partitions and file systemsImportant things:
Partitions IDs
$ls -l $du -a to get file size of individual files
$ls -lr sorts backwards
$du -c gives size of all subfolders and a summary.
#fdisk -l Disk /dev/hda: 60.0 GB, 60011642880 bytes 255 heads, 63 sectors/track, 7296 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
/dev/hda1 1 7166 57560863+ 83 Linux /dev/hda2 7167 7296 1044225 82 Linux swap / Solaris To start partition tool fdisk just give as parameter the hard disk device. fdisk /dev/hda m gives help
a toggle a bootable flag
b edit bsd disklabel
c toggle the DOS compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
n creates new partition. Numbers will be interpreted as absolute cylinder i.e. 150 means that partition ends up with cylinder 150. "+2000M" for size of 2 gb for partition. "fdisk" asks first for the type of the partition i.e. "logical 5 or above" or "primary partiton 1-4". Only four primary partitons can be created. Primary Partitions are defined in the Master Boot Record (MBR). Should it be more than four you have to create an extended partion. In an extended partition you can create further 63 (IDE) or 15 (SCSI) logical partitions. Other operating systems can only be installed into a primary partition. Linux can be installed into both types. Partition types for linux is 83 or 82 (swap).
To define a file system in a partition use mkfs. By default it creates type ext2. Alternatively you can use option -t or use mkfs.reiserfs. For ext3 use mkfs.ext3 or "-t ext3". For windows file system use mkfs.vfat. mkfs -t reiserfs to make a reiser file system.
For swap partitions we have:
If you have forgotten to create space for a swap partition you can create a file as swap "device". dd if=/dev/zero of=/var/swap bs=1024k count=128 creates file /var/swap with size 128mb
chmod 600 /var/swap mkswap /var/swap swapon /var/swap To view all swap devices which are being used: $ cat /proc/swaps Filename Type Size Used Priority /dev/hda2 partition 1044216 101804 -1 Chapter 1.104.2 Maintenance of integrity of the file systems (exam weight: 3)Important things:
From time to time every file system should be tested with fsck or for ext2/3 with program e2fsck. fsck -s (serialize) process file system checks one by one
-A (all) tests all file system of /etc/fstab
-N (no operation/NOOP) tests but does not change anything.
-p (preen) or -a (automatic) (latter is deprecated) tests and repairs automatically.
Chapter 1.104.3 Control of mounting and unmounting of file systemImportant things:
mount /dev/hda5 /mnt/tmp mounts partition hda5 into current filesystem.
mount gives overview of mounted partitions
df -h gives a (human readable) overview of mounted partitions with a table of assigned and free space on these partitions.
To unmount partition from file system use umount /dev/hda5 or umount /mnt/tmp To do this automatically create an entry in /etc/fstab. A line as follows mounts partition 5 to /mnt/tmp at the system start. /dev/hda5 /mnt/tmp ext3 defaults 0 0 Another example: # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 /dev/hda1 / ext3 defaults,errors=remount-ro 0 1 /dev/hda2 none swap sw 0 0 /dev/hdc /media/cdrom0 udf,iso9660 user,noauto 0 0 "defaults" means "rw"+"auto" for automatically mount at boot. The dump column defines for data backup if partition is to be stored or not (1 or 0). The last column gives the order for a system check after a system crash (2-9). Swap partitions get mount point "none" and type "swap" as well as options like "sw" and "prio=42" which defines the priority. The options "usrquota" and "grpquota" are for user quotas. "devpts", "proc", "usbdevfs" are for internal functions. For cd-roms we have "noauto" because the device doesn't contain always medias at the start of the system. "user" means that a normal user can mount the partition what make sense for cdrom devices. Option "user" implies that if a specific user mounts a partition only this user can umount the partion again. Option "users" implies that every user can mount and any other user can umount this partition. "exec" is used to are able to execute programs on cd media. Chapter 1.104.4 Manage disk quotasImportant things:
This starts with entries in "/etc/fstab". In particular the options "usrquota" and "grpquota" are of importance. /etc/fstab: /dev/sda6 /var reiserfs usrquota,grpquota 1 2 mount -o remount /var to mount partition without reboot
quotacheck -avugm checks all partitions with quota options from /etc/fstab
v means verbose
m forces to check a mounted partition
u creates config file aquota.user
g creates file aquota.group in /var/
These files contain information which user has currently how many space allocated.
edquota changes quotas for specific users.
Filessystem blocks soft hard inodes soft hard /dev/sda6 2243 150000 200000 1 0 0 means that user tux has currently 2243 blocks a 1kb allocated. Softlimit is 150mb and hard limit is 200mb. While overstepping the soft limit you have by default seven days remaining to come under this limit. While reaching the hard limit ends every following write access.
quotaon activates user quota limits
repquota shows a report of the current quota status.
quota shows every user his quota status. User root can ask for status of the quota of a specific user with "quota user" .
The limit that reaches first its limit counts. That means that a user cannot write any more if its group limit has been reached although his own limit has not been reached. There must exist two files in the root level of the partition that you want to mount with quota rules. Once "quota.user" and "quota.group" both with rights 600. Chapter 1.104.5 Access control for files with attributesImportant things:
rwxrwxrwx first three are for the owner
second three for the group
last three for all others
Sticky bit means for a directory that its files can only be removed from its owner. That makes sense for /tmp. To be recognized as "t" at the position of "x" from others. For group directories we have SGID (Set Group ID Bit) which appears as "s" instead of "x" at group position. That means that every new file in this directory has the ownership of the group not of the creator. Assigned to a file means that its execution process gets the identity of its group not from the user that execute the file. SUID (Set User ID Bit) appears as "s" at "x" position of the owner. It brings up the execution process under identity of the owner of the file not from the user that execute the file. "S" or "T" means that the execution right is missing. That does not make very sense. To set these sticky bits use a four digit value with chmod:
$ chmod 1100 test ; ls -l test ---x-----T 1 micki micki 0 2007-02-22 17:29 test $ chmod 2100 test ; ls -l test ---x--S--- 1 micki micki 0 2007-02-22 17:29 test $ chmod 4100 test ; ls -l test ---s------ 1 micki micki 0 2007-02-22 17:29 test $ chmod 4400 test ; ls -l test -r-S------ 1 micki micki 0 2007-02-22 17:29 test -r-------- 1 micki micki 134 2006-12-17 16:32 blacklist.txt $ chmod o+w blacklist.txt ; ls -l blacklist.txt -r------w- 1 micki micki 134 2006-12-17 16:32 blacklist.txt $ chmod g+x blacklist.txt ; ls -l blacklist.txt -r----x-w- 1 micki micki 134 2006-12-17 16:32 blacklist.txt $ chmod u+x blacklist.txt ; ls -l blacklist.txt -r-x--x-w- 1 micki micki 134 2006-12-17 16:32 blacklist.txt $ chmod u-r blacklist.txt ; ls -l blacklist.txt ---x--x-w- 1 micki micki 134 2006-12-17 16:32 blacklist.txt $ chmod a+r blacklist.txt ; ls -l blacklist.txt -r-xr-xrw- 1 micki micki 134 2006-12-17 16:32 blacklist.txt chmod 712 blacklist.txt ; ls -l blacklist.txt -rwx--x-w- 1 micki micki 134 2006-12-17 16:32 blacklist.txt UMASK $ umask 0044; touch test; ls -l test;rm test -rw--w--w- 1 micki micki 0 2007-02-22 17:11 test $ umask 0077; touch test; ls -l test;rm test -rw------- 1 micki micki 0 2007-02-22 17:12 test $ umask 0022; touch test; ls -l test;rm test -rw-r--r-- 1 micki micki 0 2007-02-22 17:12 test $ umask 0000; touch test; ls -l test;rm test -rw-rw-rw- 1 micki micki 0 2007-02-22 17:13 test The "x" attribute won't be set while creation whatever value umask has for security reasons.
For directories and its "x" flag use the three digit parameter: $ umask 000; mkdir test; ls -ld test;rmdir test drwxrwxrwx 2 micki micki 4.0K 2007-02-22 17:19 test $ umask 234; mkdir test; ls -ld test;rmdir test dr-xr---wx 2 micki micki 4.0K 2007-02-22 17:20 test $ umask 127; mkdir test; ls -ld test;rmdir test drw-r-x--- 2 micki micki 4.0K 2007-02-22 17:20 test Some special attributes for ext2 file systems for example the immutable bit which can only be set by root. After it was set you cannot delete this file. To set this bit use "chattr": chattr +i importantfile Because "ls -l" does not show this bit you can use "lsattr":
lsattr importantfile Chapter 1.104.6 Manage file ownerImportant things:
After creation of a file, the owner is the current user. Only root is allowed to change its owner with chown user filename A normal user can only change the group definition of a file and this only if he is owner of the file and member of the new group. chgrp users filename.txt Chapter 1.104.7 Creating and changing of hard respectively symbolic linksImportant things:
ln -s destination source creates a symbolic link. A symbolic link can be recognized by "l" in front of the access attributes after command "ls -l" and by showing file name "source -> destination"
To create an hard link we use also ln but without parameter. The destination cannot be an directory only a file. The os saves the content of a file in blocks on the hard disk. Inodes are deriving on this blocks. The inodes contain also additional informations like owner, access attributes, timestamp and so on. The hard link is a file that derives on the inode of the destination file. So the link keeps valid if the file is moved inside the same partition. Hard links are only valid inside the same partiton because each partition has its own inode management. ln source destination ls -li 6153239 -rw-r--r-- 2 micki micki 66K 2007-02-21 10:14 destination 6153239 -rw-r--r-- 2 micki micki 66K 2007-02-21 10:14 source source and destination point both on inode 6153239. If you remove one file the content of the file is not been lost.
$ ls -li blacklist.txt 6153522 -rw-r--r-- 1 micki micki 134 2006-12-17 16:32 blacklist.txt $ ln blacklist.txt hardlink1 $ ls -li blacklist.txt 6153522 -rw-r--r-- 2 micki micki 134 2006-12-17 16:32 blacklist.txt $ ln blacklist.txt hardlink2 $ ls -li blacklist.txt 6153522 -rw-r--r-- 3 micki micki 134 2006-12-17 16:32 blacklist.txt As you see the third column shows the number of names a file or inode has. If you delete one the number decrease but the content of the file keeps unchanged until the last reference or name to this inode has been deleted. The rules for directories are a little bit different. The counter is at least 2 because in every directory itself lies the file with name "." which points at the current directory. With every sub directory the counter increase because each one has the file ".." which points at the father directory.
srwx------ ... amavisd is the socket from AMaViS.
chmod u+rwx,g+rw <filename> and not chmod u+rwx g+rw <filename> chattr a (append only) file cannot be deleted. Only content can be appended.
c (compressed) not supported
i (immutable) File is unchangeable. Cannot be deleted, renamed or changed nor a symlink can be derived to this file.
s (secure deletion) If the file will be deleted the sectors of the hard drive will be filled with random numbers instead of only delete its reference in the file system table.
S (synchronous update) The file will be flushed and not cached by the hard drive cache.
u (undeleteable) Should appear as opposite to "s" but is not supported by the kernel yet.
To set these attributes use: chattr +a <filename> sets attribute "a"
chattr -a <filename> unsets "a"
Chapter 1.104.8 Finding and placing files at the right position in file systemImportant things:
$which ping /bin/ping "which" search for the given file in the search path $PATH.
$whereis ping ping: /bin/ping /usr/share/man/man8/ping.8.gz gives the path independent from value of PATH and additionally the manual file.
$find / -type f -name '*.mp3' searchs for mp3 files from root directory to its sub directories.
$find -type f -iname '*~' -exec rm {} \;
removes temporary files. "-iname" ignores lower and capital character. "{}" will be replaced with the file name that has been found. To find a specific inode and its file you can use "-inum". Without the "\" before ";" the bash would interpret ";" for itself and find would not see it and so the syntax of the exec parameter would be hurted.
$find ~ -mtime 2 finds files that were modified 2 days ago. find gets its time parameter ALWAYS in days!
$find ~ -atime -3 finds files that were accessed in the time period back to 3 days. That is 2 minutes ago, 12 hours ago and also 3*24 hours ago.
$find ~ -atime +3 finds files that were accessed in the past and at least 3 days ago.
means atime means access time so we have also readings that change this timestamp.
mtime means modification time. That is the time when last writing access has occured to the file.
ctime means change time. That is the time when the last changes were made to the file information as access rights, owner and so on.
find / -perm +6000 finds all files that have at least ("+") the rights 6000.
If file names contains spaces we have a problem if we put them through pipe to "xargs". A solution is to define the end of the file as zero character. find / parameter -print0 | xargs -0 command "xargs" has a parameter "-i" to define a pattern that stands for the name "xargs" gets from stdin. That is an advantage if you need the pattern twice for example if you rename the file. xargs -ixxx mv xxx /tmp/rename-xxx < filelist.txt reads the file list from file filelist.txt and substitutes the pattern xxx with the current name from filelist.txt. Between option an pattern must not stand a space character!
$locate pdf searchs in a internal database for file names and its pathes for the given pattern. Possible results are a.pdf or /pdfs/a.doc. The latter one because "pdf" is also part of its path "/pdfs".
Use "updatedb" to update this database. ls -l shows also the type of the file in the first column. The character have the following meaning:
d directory l symlink c character device b block device p fifo s socket Chapter 1.110 X
Chapter 1.110.1 DISPLAY MANAGER: Installation and Configuration of X11 (exam weight:5)Important things: /etc/X11/xorg.conf
XF86Setup
xf86config
xvidtune
.Xresources
Xorg -configure # automatic configuration
xorgcfg # graphical tool
xorgconfig # console tool
Results will be written to /etc/X11/xorg.conf. You activate the X server with "startx" If the screen is a little bit hidden or if you want to change size of the viewed screen use "xvidtune". After you are happy with "xvidtune" this program returns a modeline like: Modline "1280x1024" 166.29 1280 1392 1528 1744 1024 1025 1028 1077 Col1: Name of the mode
Col2: pixel clock (factor between pixel and seconds)
Col3-6: values for horizontal timing
Col7-10: values for vertical timing
The "xorg.conf" file is devided into sections. Each section begins with "Section" and ends with "End Section". The different types of section are the following ones:
The X font server "xfs" serves the font wishes of the X server. The config file is "/etc/X11/xfs.conf" or "/usr/X11R6/lib/X11/fs/config". With an entry as 'FontPath "tcp/192.168.100.1:7000"' in the Files section the X server tries to get the fonts from the specified server. After installing new fonts you have to call "mkfontdir <path>" and "mkfontscal2 <path>" to be able using the fonts. ATTENTION: it does not exist a section "Font"! Chapter 1.110.2 Installation of the display manager (exam weight:3)Important things:
The display manager presents a login dialog and after user login it starts a window manager like KWin (KDE), Metacity (Gnome). The well known display manager are XDM, KDM, GDM. Configuration of the greetings message of login screen lies in "/etc/X11R6/*/Xresources". Inside this files we have values as "Client*Resource: value". For example to start xterm with a given geometry use "XTerm*geometry:90x40". Then xterm will be started each time with "xterm -geometry 90x40". The protocol "XDMCP" (X Display Manager Control Protocol) is for remote access over network. After that you can take an old rusty pc and call the X with "X :0.0 -query <host>" where host is the one that should serve the data. After that you are working on the old pc with X which comes from the host over network. The old pc takes only the input from keyboard and mice and sends it to the host. For that reason the remote host must be a strong processing unit, if it has to process different user over network. XDM/usr/X11R6/bin/gdm (binary) /usr/X11R6/lib/X11/xdm (config file) To allow remote connections you have to uncomment the following line in xdm config file with a "!": DisplayManager.requestPort: 0 !DisplayManager.requestPort: 0 GDMConfig files under "/etc/X11/gdm". defaults.conf custom.conf To adjust these files you can use "gdmsetup". KDMkdmrc (config file under KDE_DIR/share/config/kdm) Chapter 1.110.4 Installation and adjustment of a WINDOW MANAGER (exam weight:5)Important things:
Window Manager:
To adjust these use file "~/.Xdefaults". The syntax is as follows: program.class.resource: value "class" means for example "Geometry" for common properties for window size and window position. xterm*Background: black xterm windows get a black background.
xhost +192.168.0.2 allows host 192.168.0.2 to open windows on the local x server. To derive the output from 192.168.0.2 to the local host start the application with parameter "-display" or set enviroment variable "DISPLAY" as "Host:Xserver.Display"
xeyes -display tux:0.0 start xeyes on screen of host tux.
adjust run levelIn the file "/etc/inittab" we have the entry "id:3:initdefault:" which says that 3 is the default run level. The entry "x:5:respawn:/usr/sbin/kdm" starts kdm in run level 5. "respawn" means that kdm is called again after a crash. MiscellaneousTo modify the message the console shows if it appears as "Ubuntu feisty (development branch) \n \l" you can modify the text inside the file "/etc/issue". |