SlideShare a Scribd company logo
1 of 91
Linux File System
Chapter 2
2.1. Objectives:
 The UNIX file system
 Typical UNIX directory structure
 Directory and file handling commands
 Making hard and soft (symbolic) links
 Specifying multiple filenames
 Quotes
 File and directory permissions
 Inspecting file content
 Finding files
 Finding text in files
 Sorting files
 File compression and backup
 Handling removable media
2.2 The UNIX Filesystem
 Every item such as configuration information, temporary
files , user data etc that can be stored in a UNIX
filesystem belongs to one of four types:
2.2 The UNIX Filesystem…
1. Ordinary files
Ordinary files can contain text, data, or program
information.
Files cannot contain other files or directories.
Unlike other operating systems, UNIX filenames are
not broken into a name part and an extension part
(although extensions are still frequently used as a
means to classify files).
Instead they can contain any keyboard character
except for '/' and be up to 256 characters long (note
however that characters such as *,?,# and & have
special meaning in most shells and should not
therefore be used in filenames).
2.2 The UNIX Filesystem…
2. Directory Files
Directories are containers or folders that hold files, and
other directories.
3. Device Files
To provide applications with easy access to hardware
devices, UNIX allows them to be used in much the
same way as ordinary files.
There are two types of devices in UNIX:
 block-oriented devices which transfer data in blocks
(e.g. hard disks) and
 character-oriented devices that transfer data on a
byte-by-byte basis (e.g. modems and dumb terminals).
2.2 The UNIX Filesystem…
4. Links
A link is a pointer to another file.
There are two types of links:
 A hard link to a file is indistinguishable from the
file itself.
 A soft link (or symbolic link) provides an indirect
pointer or shortcut to a file.
 A soft link is implemented as a directory file entry
containing a pathname.
2.3 Typical UNIX Directory
Structure
 The UNIX filesystem is laid out as a hierarchical tree
structure which is anchored at a special top-level directory
known as the root (designated by a slash '/').
 Because of the tree structure, a directory can have many
child directories, but only one parent directory.
 Fig. 2.1 illustrates this layout.
Fig. 2.1: Part of a typical UNIX filesystem
tree
 To specify a location in the directory hierarchy, we must specify
a path through the tree.
 The path to a location can be defined by an absolute path from
the root /, or as a relative path from the current working
directory.
 To specify a path, each directory along the route from the
source to the destination must be included in the path, with each
directory in the sequence being separated by a slash.
 To help with the specification of relative paths, UNIX provides
the shorthand "." for the current directory and ".." for the parent
directory.
 For example, the absolute path to the directory "play"
is /home/will/play, while the relative path to this directory from
"zeb" is ../will/play.
 Fig. 2.2 shows some typical directories you will find on UNIX
systems and briefly describes their contents.
 Note that although these subdirectories appear as part of a
seamless logical filesystem, they do not need be present on the
same hard disk device; some may even be located on a remote
machine and accessed across a network.
 When you log into UNIX, your current working
directory is your user home directory.
 You can refer to your home directory at any time as
"~" and the home directory of other users as
"~<login>".
 So ~will/play is another way for user jane to specify
an absolute path to the directory /home/will/play.
 User will may refer to the directory as ~/play.
2.4 Directory and File Handling
Commands
 pwd (print [current] working directory)
 pwd displays the full absolute path to the your current
location in the filesystem. So
$ pwd
/usr/bin
implies that /usr/bin is the current working directory.
 ls (list directory)
 ls lists the contents of a directory. If no target
directory is given, then the contents of the current
working directory are displayed. So, if the current
working directory is /,
 $ ls
bin dev home mnt share usr var
boot etc lib proc sbin tmp vol
 Actually, ls doesn't show you all the entries in a
directory.
 Files and directories that begin with a dot (.) are
hidden (this includes the directories '.' and '..' which
are always present).
 The reason for this is that files that begin with a .
usually contain important configuration information
and should not be changed under normal
circumstances. If you want to see all files, ls supports
the -a option:
 $ ls -a
 Even this listing is not that helpful - there are no hints
to properties such as the size, type and ownership of
files, just their names.
 To see more detailed information, use the -l option
(long listing), which can be combined with the -
a option as follows:
2.3. Each line of the output looks like this:
 where:
 type is a single character which is either 'd' (directory), '-'
(ordinary file), 'l' (symbolic link), 'b' (block-oriented device) or 'c'
(character-oriented device).
 permissions is a set of characters describing access rights.
There are 9 permission characters, describing 3 access types
given to 3 user categories. The three access types are read ('r'),
write ('w') and execute ('x'), and the three users categories are
the user who owns the file, users in the group that the file
belongs to and other users (the general public). An 'r', 'w' or 'x'
character means the corresponding permission is present; a '-'
means it is absent.
 links refers to the number of filesystem links pointing to the
file/directory (see the discussion on hard/soft links in the next
section).
 owner is usually the user who created the file or directory.
 group denotes a collection of users who are allowed to access
the file according to the group access rights specified in the
permissions field.
 size is the length of a file, or the number of bytes used by the
 ls supports more options. To find out what they are,
type:
 $ man ls
 man is the online UNIX user manual, and you can use it
to get help with commands and find out about what
options are supported.
 It has quite a terse style which is often not that helpful,
so some users prefer to use the (non-
standard) info utility if it is installed:
 $ info ls
cd (change [current working] directory)
 $ cd path
changes your current working directory to path (which
can be an absolute or a relative path). One of the most
common relative paths to use is '..' (i.e. the parent
directory of the current directory).
 Used without any target directory
 $ cd
 resets your current working directory to your home
directory (useful if you get lost).
 If you change into a directory and you subsequently
want to return to your original directory, use
 $ cd -
 mkdir (make directory)
$ mkdir directory
 creates a subdirectory called directory in the current
working directory. You can only create subdirectories in
a directory if you have write permission on that
directory.
 rmdir (remove directory)
 $ rmdir directory
 removes the subdirectory directory from the current
working directory.
 You can only remove subdirectories if they are
completely empty (i.e. of all entries besides the '.' and
'..' directories).
 cp (copy)
 cp is used to make copies of files or entire directories. To
copy files, use:
 $ cp source-file(s) destination
 where source-file(s) and destination specify the source
and destination of the copy respectively. The behavior
of cp depends on whether the destination is a file or a
directory. If the destination is a file, only one source file is
allowed and cp makes a new file called destination that
has the same contents as the source file. If the destination
is a directory, many source files can be specified, each of
which will be copied into the destination directory.
 To copy entire directories (including their contents), use a recursive copy:
 $ cp -rd source-directories destination-directory
 mv (move/rename)
 mv is used to rename files/directories and/or move them
from one directory into another. Exactly one source and
one destination must be specified:
 $ mv source destination
 If destination is an existing directory, the new name
for source (whether it be a file or a directory)
will be destination/source.
 If source and destination are both files, source is
renamed destination.
 N.B.: if destination is an existing file it will be destroyed
and overwritten by source (you can use the -i option if you
would like to be asked for confirmation before a file is
overwritten in this way).
 rm (remove/delete)
 $ rm target-file(s)
 removes the specified files. Unlike other operating systems, it is
almost impossible to recover a deleted file unless you have a
backup (there is no recycle bin!) so use this command with care.
If you would like to be asked before files are deleted, use the -
i option:
 $ rm -i myfile
rm: remove 'myfile'?
 rm can also be used to delete directories (along with all of their
contents, including any subdirectories they contain).
 To do this, use the -r option. To avoid rm from asking any
questions or giving errors (e.g. if the file doesn't exist) you use
the -f (force) option. Extreme care needs to be taken when using
this option - consider what would happen if a system
administrator was trying to delete user will's home directory and
accidentally typed:
 $ rm -rf / home/will
(instead of rm -rf /home/will).
 cat (catenate/type)
 $ cat target-file(s)
 displays the contents of target-file(s) on the screen, one
after the other. You can also use it to create files from
keyboard input as follows (> is the output redirection
operator, which will be discussed in the next chapter):
$ cat > hello.txt
hello world!
[ctrl-d]
$ ls hello.txt
hello.txt
$ cat hello.txt
hello world!
$
 more and less (catenate with pause)
 $ more target-file(s)
 displays the contents of target-file(s) on the screen,
pausing at the end of each screenfull and asking the user
to press a key (useful for long files).
 It also incorporates a searching facility (press '/' and then
type a phrase that you want to look for).
 You can also use more to break up the output of
commands that produce more than one screenfull of
output as follows (| is the pipe operator, which will be
discussed in the next chapter):
 $ ls -l | more
 less is just like more, except that it has a few extra
features (such as allowing users to scroll backwards
and forwards through the displayed file).
 less not a standard utility, however and may not be
present on all UNIX systems.
2.5 Making Hard and Soft
(Symbolic) Links
 Direct (hard) and indirect (soft or symbolic) links from
one file or directory to another can be created using
the ln command.
 $ ln filename linkname
 creates another directory entry
for filename called linkname (i.e. linkname is a hard link).
 Both directory entries appear identical (and both now
have a link count of 2).
 If either filename or linkname is modified, the change will
be reflected in the other file (since they are in fact just two
different directory entries pointing to the same file).
 $ ln -s filename linkname
 creates a shortcut called linkname (i.e. linkname is a
soft link). The shortcut appears as an entry with a
special type ('l'):
 $ ln -s hello.txt bye.txt
$ ls -l bye.txt
lrwxrwxrwx 1 will finance 13 bye.txt -> hello.txt
$
 The link count of the source file remains unaffected.
 Notice that the permission bits on a symbolic link are not
used (always appearing as rwxrwxrwx).
 Instead the permissions on the link are determined by the
permissions on the target (hello.txt in this case).
 Note that you can create a symbolic link to a file that
doesn't exist, but not a hard link.
 Another difference between the two is that you can
create symbolic links across different physical disk
devices or partitions, but hard links are restricted to
the same disk partition.
 Finally, most current UNIX implementations do not allow
hard links to point to directories.
2.6 Specifying multiple filenames
 Multiple filenames can be specified using special
pattern-matching characters. The rules are:
 '?' matches any single character in that position in the
filename.
 '*' matches zero or more characters in the filename. A
'*' on its own will match all files. '*.*' matches all files
with contains a '.'.
 Characters enclosed in square brackets ('[' and ']') will
match any filename that has one of those characters in
that position.
 A list of comma separated strings enclosed in curly
braces ("{" and "}") will be expanded as a Cartesian
 For example:
 ??? matches all three-character filenames.
 ?ell? matches any five-character filenames with 'ell' in
the middle.
 he* matches any filename beginning with 'he'.
 [m-z]*[a-l] matches any filename that begins with a letter
from 'm' to 'z' and ends in a letter from 'a' to 'l'.
 {/usr,}{/bin,/lib}/file expands to /usr/bin/file /usr/lib/file
/bin/file and /lib/file.
 Note that the UNIX shell performs these expansions
(including any filename matching) on a command's
arguments before the command is executed.
2.7 Quotes
 As we have seen, certain special characters (e.g. '*', '-','{' etc.)
are interpreted in a special way by the shell.
 In order to pass arguments that use these characters to
commands directly (i.e. without filename expansion etc.), we
need to use special quoting characters.
 There are three levels of quoting that you can try:
 Try inserting a '' in front of the special character.
 Use double quotes (") around arguments to prevent most
expansions.
 Use single forward quotes (') around arguments to prevent all
expansions.
 There is a fourth type of quoting in UNIX. Single backward
quotes (`) are used to pass the output of some command as an
input argument to another.
 For example:
2.8. File and Directory Permissions
 As we have seen earlier, every file or directory on a UNIX
system has three types of permissions, describing what
operations can be performed on it by various categories of
users.
 The permissions are read (r), write (w) and execute (x), and
the three categories of users are user/owner (u), group (g)
and others (o).
 Because files and directories are different entities, the
interpretation of the permissions assigned to each differs
slightly, as shown in Fig 2.4.
 File and directory permissions can only be modified by their
owners, or by the superuser (root), by using
the chmod system utility.
 chmod (change [file or directory] mode)
 $ chmod options files
 chmod accepts options in two forms.
 Firstly, permissions may be specified as a sequence of 3
octal digits (octal is like decimal except that the digit range is
0 to 7 instead of 0 to 9).
 Each octal digit represents the access permissions for the
user/owner, group and others respectively.
 The mappings of permissions onto their corresponding octal
digits is as follows:
 For example the command:
 $ chmod 600 private.txt
 sets the permissions on private.txt to rw------- (i.e. only the
owner can read and write to the file).
 Permissions may be specified symbolically, using
symbols u (user), g (group), o (other), a (all), r (read), w (write)
, x (execute), + (add permission), - (take away permission)
and = (assign permission).
 For example, the command:
 $ chmod ug=rw,o-rw,a-x *.txt
 sets the permissions on all files ending in *.txt to:
rw-rw---- (i.e. the owner and users in the file's group can read and
write to the file, while the general public do not have any sort of
access).
 chmod also supports a -R option which can be used to
recursively modify file permissions, e.g.
 $ chmod -R go+r play
 will grant group and other read rights to the
directory play and all of the files and directories
within play.
 chgrp (change group)
 $ chgrp group files
 can be used to change the group that a file or directory
belongs to.
 It also supports a -R option.
2.9. Inspecting File Content
 Besides cat, there are several other useful utilities for investigating
the contents of files:
 file filename(s)
 file analyzes a file's contents for you and reports a high-level
description of what type of file it appears to be:
 $ file myprog.c letter.txt webpage.html
myprog.c: C program text
letter.txt: English text
webpage.html: HTML document text
 file can identify a wide range of files but sometimes gets
understandably confused (e.g. when trying to automatically detect the
difference between C++ and Java code).
 head, tail filename
 head and tail display the first and last few lines in a file
respectively. You can specify the number of lines as an option,
e.g.
 $ tail -20 messages.txt
$ head -5 messages.txt
 tail includes a useful -f option that can be used to continuously
monitor the last few lines of a (possibly changing) file. This can
be used to monitor log files, for example:
 $ tail -f /var/log/messages
 continuously outputs the latest additions to the system log file.
 objdump options binaryfile
 objdump can be used to disassemble binary files - that is it can show
the machine language instructions which make up compiled
application programs and system utilities.
 od options filename (octal dump)
 od can be used to displays the contents of a binary or text file in a
variety of formats, e.g.
 $ cat hello.txt
hello world
$ od -c hello.txt
0000000 h e l l o w o r l d n
0000014
$ od -x hello.txt
0000000 6865 6c6c 6f20 776f 726c 640a
0000014
 There are also several other useful content inspectors
that are non-standard (in terms of availability on UNIX
systems) but are nevertheless in widespread use. They
are summarised in Fig. 2.5.

2.8. Finding Files
 There are at least three ways to find files when you don't know their exact
location:
 find
 If you have a rough idea of the directory tree the file might be in, you can
use find:
 $ find directory -name targetfile -print
 find will look for a file called targetfile in any part of the directory tree rooted
at directory.
 targetfile can include wildcard characters. For example:
 $ find /home -name "*.txt" -print 2>/dev/null
 will search all user directories for any file ending in ".txt" and output any
matching files (with a full absolute or relative path). Here the quotes (") are
necessary to avoid filename expansion, while the 2>/dev/null suppresses
error messages (arising from errors such as not being able to read the
contents of directories for which the user does not have the right
permissions).
 find can in fact do a lot more than just finding files by name.
It can find files by type (e.g. -type f for files, -type d for
directories), by permissions (e.g. -perm o=r for all files and
directories that can be read by others), by size (-size) etc.
 You can also execute commands on the files you find. For
example,
 $ find . -name "*.txt" -exec wc -l '{}' ';'
 counts the number of lines in every text file in and below the
current directory. The '{}' is replaced by the name of each file
found and the ';' ends the -exec clause.
 For more information about find and its abilities, use man
find and/or info find.
 which (sometimes also called whence) command
 If you can execute an application program or system
utility by typing its name at the shell prompt, you can
use which to find out where it is stored on disk. For
example:
 $ which ls
/bin/ls
 locate string
 find can take a long time to execute if you are searching a large
filespace (e.g. searching from / downwards). The locate command
provides a much faster way of locating all files whose names match a
particular search string. For example:
 $ locate ".txt"
 will find all filenames in the filesystem that contain ".txt" anywhere in
their full paths.
 One disadvantage of locate is it stores all filenames on the system in an
index that is usually updated only once a day. This means locate will not
find files that have been created very recently.
 It may also report filenames as being present even though the file has
just been deleted.
 Unlike find, locate cannot track down files on the basis of their
permissions, size and so on.
2.11. Finding Text in Files
 grep (General Regular Expression Print)
 $ grep options pattern files
 grep searches the named files (or standard input if no files are named) for
lines that match a given pattern. The default behaviour of grep is to print out
the matching lines. For example:
 $ grep hello *.txt
 searches all text files in the current directory for lines containing "hello".
Some of the more useful options that grep provides are:
-c (print a count of the number of lines that match), -i (ignore case), -v (print
out the lines that don't match the pattern) and -n (printout the line number
before printing the matching line). So
 $ grep -vi hello *.txt
 searches all text files in the current directory for lines that do not contain
any form of the word hello (e.g. Hello, HELLO, or hELlO).
 If you want to search all files in an entire directory tree for a particular pattern,
you can combine grep with find using backward single quotes to pass the
output from find into grep. So
 $ grep hello `find . -name "*.txt" -print`
 will search all text files in the directory tree rooted at the current directory for
lines containing the word "hello".
 The patterns that grep uses are actually a special type of pattern known
as regular expressions. Just like arithmetic expressions, regular
expressions are made up of basic sub expressions combined by operators.
 The most fundamental expression is a regular expression that matches a
single character. Most characters, including all letters and digits, are regular
expressions that match themselves. Any other character with special
meaning may be quoted by preceding it with a backslash (). A list of
characters enclosed by '[' and ']' matches any single character in that list; if
the first character of the list is the caret `^', then it matches any character not
in the list. A range of characters can be specified using
 a dash (-) between the first and last items in the list. So [0-9] matches
any digit and [^a-z] matches any character that is not a letter.
 The caret `^' and the dollar sign `$' are special characters that
match the beginning and end of a line respectively. The dot '.'
matches any character. So
 $ grep ^..[l-z]$ hello.txt
 matches any line in hello.txt that contains a three character sequence
that ends with a lowercase letter from l to z.
 egrep (extended grep) is a variant of grep that supports more
sophisticated regular expressions. Here two regular expressions may
be joined by the operator `|'; the resulting regular expression matches
any string matching either subexpression. Brackets '(' and ')' may be
used for grouping regular expressions. In addition, a regular
expression may be followed by one of several repetition operators:
 `?' means the preceding item is optional (matched at most once).
`*' means the preceding item will be matched zero or more times.
`+' means the preceding item will be matched one or more times.
`{N}' means the preceding item is matched exactly N times.
`{N,}' means the preceding item is matched N or more times.
`{N,M}' means the preceding item is matched at least N times, but
not more than M times.
 For example, if egrep was given the regular expression
 '(^[0-9]{1,5}[a-zA-Z ]+$)|none'
 it would match any line that either:
 begins with a number up to five digits long, followed by a sequence of
one or more letters or spaces, or
 contains the word none
 You can read more about regular expressions on
the grep and egrep manual pages.
 Note that UNIX systems also usually support
another grep variant called fgrep (fixed grep)
which simply looks for a fixed string inside a file
(but this facility is largely redundant).
2.12. Sorting files
 There are two facilities that are useful for sorting files in UNIX:
 sort filenames
 sort sorts lines contained in a group of files alphabetically (or if the -
n option is specified numerically). The sorted output is displayed on
the screen, and may be stored in another file by redirecting the
output. So
 $ sort input1.txt input2.txt > output.txt
 outputs the sorted concatenation of files input1.txt and input2.txt to
the file output.txt.
 uniq filename
 uniq removes duplicate adjacent lines from a file.
 This facility is very useful when combined with sort:
 $ sort input.txt | uniq > output.txt
2.13. File Compression and Backup
 UNIX systems usually support a number of utilities for backing
up and compressing files. The most useful are:
 tar (tape archiver)
 tar backs up entire directories and files onto a tape device or (more
commonly) into a single disk file known as an archive.
 An archive is a file that contains other files plus information about
them, such as their filename, owner, timestamps, and access
permissions.
 tar does not perform any compression by default.
 To create a disk file tar archive, use
 $ tar -cvf archivename filenames
 where archivename will usually have a .tar extension. Here
the c option means create, v means verbose (output filenames
as they are archived), and f means file.
 To list the contents of a tar archive, use:
$ tar -tvf archivename
 To restore files from a tar archive, use
$ tar -xvf archivename
 cpio
 cpio is another facility for creating and reading archives.
 Unlike tar, cpio doesn't automatically archive the contents of directories.
 So it's common to combine cpio with find when creating an archive:
$ find . -print -depth | cpio -ov -Htar > archivename
 This will take all the files in the current directory and the
directories below and place them in an archive called archivename.
 The -depth option controls the order in which the filenames are
produced and is recommended to prevent problems with directory
permissions when doing a restore. The -o option creates the archive,
the -v option prints the names of the files archived as they are added
and the -H option specifies an archive format type (in this case it
creates a tar archive).
 Another common archive type is crc, a portable format with a
checksum for error control.
 To list the contents of a cpio archive, use
$ cpio -tv < archivename
 To restore files, use:
$ cpio -idv < archivename
 Here the -d option will create directories as necessary.
 To force cpio to extract files on top of files of the same name
that already exist (and have the same or later modification
time), use the -u option.
 Compress and gzip
 compress and gzip are utilities for compressing and decompressing
individual files (which may be or may not be archive files).
 To compress files, use:
$ compress filename
or
$ gzip filename
 In each case, filename will be deleted and replaced by a
compressed file called filename.Z or filename.gz.
 To reverse the compression process, use:
$ compress -d filename
or
$ gzip -d filename
2.14. Handling Removable Media
(e.g. floppy disks)
 UNIX supports tools for accessing removable media such as CDROMs and
floppy disks.
 mount, umount
 The mount command serves to attach the filesystem found on some device to
the filesystem tree.
 Conversely, the umount command will detach it again (it is very important to
remember to do this when removing the floppy or CDROM).
 The file /etc/fstab contains a list of devices and the points at which they will
be attached to the main filesystem:
 $ cat /etc/fstab
/dev/fd0 /mnt/floppy auto rw,user,noauto 0 0
/dev/hdc /mnt/cdrom iso9660 ro,user,noauto 0 0
 In this case, the mount point for the floppy drive is /mnt/floppy and the mount
point for the CDROM is /mnt/cdrom.
 To access a floppy we can use:
$ mount /mnt/floppy
 Then you can do:
$ cd /mnt/floppy
$ ls (etc...)
 To force all changed data to be written back to the floppy and
to detach the floppy disk from the filesystem, we use:
$ umount /mnt/floppy
RAIDS
 Outline:
 RAID 0
 RAID 1
 RAID 5
 RAID 10
 Performance
 Storage space
 Fault tolerant
What is RAID?
 Stands for Redundant Array of Independent Disks.
 It’s a technology that enables greater levels of
performance, reliability and/or large volumes when
dealing with data.
 How?? By concurrent use of two or more ‘hard disk
drives’.
 How Exactly?? Mirroring, Stripping (of data) and
Error correction techniques combined with multiple
disk arrays give you the reliability and performance.
RAID flavors
 Commonly used ones:
1. RAID 0
2. RAID 1
3. RAID 5
4. RAID 10
 Other types used…but rarely: RAID
2,3,4,6,50……
RAID 0
a. RAID 0 is block-level data striping
b. No parity or mirroring
c. It splits data among two or more disks.
d. Provides best performance.
e. Lack of data redundancy means there is no
fail over support (no fault tolerance)with
this configuration.
f. In the diagram to the right, the odd blocks
are written to disk 0 and the even blocks to
disk 1 such that A1, A2, A3, A4, … would
be the order of blocks read if read
sequentially from the beginning.
g. Used in read only NFS systems and gaming
systems.
RAID 0 …
 Storage space used is all the disks’ space combined.
 The probability of failure increases with increase in the number
of disks.
 The more hard drives we have, the faster RAID 0 becomes.
 The fragments are written to their respective disks
simultaneously on the same sector.
 This allows smaller sections of the entire chunk of data to be read
off the drive in parallel, hence best performance.
RAID 1
•RAID1 is ‘data mirroring’.
•Two copies of the data are held on
two physical disks, and the data is
always identical.
• Twice as many disks are required to
store the same data when compared
to RAID 0.
•Array continues to operate so long
as at least one drive is functioning.
RAID 1 …
Performance:
 If we use independent disk controllers for each disk,
then we can increase the read or write speeds by doing
operations in parallel.
 Storage space used is half the discs’ space combined
and the other half is used as a backup.
RAID 5
• RAID 5 is an ideal combination
of good performance, good fault
tolerance and high capacity and
storage efficiency.
• An arrangement of parity and
CRC to help rebuilding drive data
in case of disk failures.
• “Distributed Parity” is the key
word here.
RAID 5
 MTBF is slightly better than RAID 0. This is because failure of one
disk is not quite a harm. We need more time if 2 or more disks fail.
 Performance is also as good as RAID 0
 We can read and write parallel blocks of data.
 One of the drawbacks is that the write involves heavy parity
calculations by the RAID controller. Write operations are slower
compared to RAID 0.
 Pretty useful for general purpose uses where ‘read’s’ are more
frequent than ‘write’s’.
RAID 10
a. Striping and mirroring
b. Combines RAID 1 and RAID 0.
c. Which means having the pleasure
of both - good performance and
good failover handling.
d. Also called ‘Nested RAID’.
Implementations
Software based RAID:
 Software implementations are provided by many Operating
Systems.
 A software layer sits above the disk device drivers and
provides an abstraction layer between the logical
drives(RAIDs) and physical drives.
 Server's processor is used to run the RAID software.
 Used for simpler configurations like RAID0 and RAID1.
Implementations …
Hardware based RAID:
 A hardware implementation of
RAID requires at least a special-
purpose RAID controller.
 On a desktop system this may be
built into the motherboard.
 Processor is not used for RAID
calculations as a separate
controller present.
A PCI-bus-based, IDE/ATA hard disk
RAID
controller, supporting levels 0, 1, and 01.
LVM(Logical Volume Management)
What is Logical Volume
Management?
 Logical volume management provides a higher-level view of the disk
storage on a computer system than the traditional view of disks and
partitions.
 This gives the system administrator much more flexibility in allocating
storage to applications and users.
 Storage volumes created under the control of the logical volume
manager can be resized and moved around almost at will, although
this may need some upgrading of file system tools.
 The logical volume manager also allows management of storage
volumes in user-defined groups, allowing the system administrator to
deal with sensibly named volume groups such as "development" and
"sales" rather than physical disk names such as "sda" and "sdb".
Why would I want it?
 Logical volume management is traditionally
associated with large installations containing
many disks but it is equally suited to small
systems with a single disk or maybe two.
Benefits of Logical Volume
Management on a Small System
 One of the difficult decisions facing a new user installing Linux for the first time is how
to partition the disk drive. The need to estimate just how much space is likely to be
needed for system files and user files makes the installation more complex than is
necessary and some users simply opt to put all their data into one large partition in an
attempt to avoid the issue.
 Once the user has guessed how much space is needed for /home /usr / (or has let
the installation program do it) then is quite common for one of these partitions to fill up
even if there is plenty of disk space in one of the other partitions.
 With logical volume management, the whole disk would be allocated to a single
volume group and logical volumes created to hold the / /usr and /home file systems.
If, for example the /home logical volume later filled up but there was still space
available on /usr then it would be possible to shrink /usr by a few megabytes and
reallocate that space to /home.
 Another alternative would be to allocate minimal amounts of space for each logical
volume and leave some of the disk unallocated. Then, when the partitions start to fill
up, they can be expanded as necessary.
Example
 Joe buys a PC with an 8.4 Gigabyte disk on it and installs
Linux using the following partitioning system:
/boot /dev/hda1 10 Megabytes
swap /dev/hda2 256 Megabytes
/ /dev/hda3 2 Gigabytes
/home /dev/hda4 6 Gigabytes
This, he thinks, will maximize the amount of space
available for all his MP3 files.
 Sometime later Joe decides that he wants to install the latest
office suite and desktop UI available but realizes that the root
partition isn't large enough. But, having archived all his MP3s
onto a new writable DVD drive there is plenty of space on
/home.
 His options are not good:
 Reformat the disk, change the partitioning scheme and reinstall.
 Buy a new disk and figure out some new partitioning scheme
that will require the minimum of data movement.
 Set up a symlink farm on / pointing to /home and install the new
software on /home
 With LVM this becomes much easier:
 Jane buys a similar PC but uses LVM to divide up the disk
in a similar manner:
/boot /dev/hda1 10 Megabytes
Swap /dev/vg00/swap 256 Megabytes
/ /dev/vg00/root 2 Gigabytes
/home /dev/vg00/home 6 Gigabytes
boot is not included on the LV because boot loaders
don't understand LVM volumes yet. It's possible boot on
LVM will work, but you run the risk of having an unbootable
system.
 When she hits a similar problem she can reduce the size of
/home by a gigabyte and add that space to the root partition.
 Suppose that Joe and Jane then manage to fill up the /home
partition as well and decide to add a new 20 Gigabyte disk to
their systems.
 Joe formats the whole disk as one partition (/dev/hdb1) and
moves his existing /home data onto it and uses the new disk as
/home.
 But he has 6 gigabytes unused or has to use symlinks to make
that disk appear as an extension of /home, say /home/joe/old-
mp3s.
 Jane simply adds the new disk to her existing volume group and
extends her /home logical volume to include the new disk. Or, in
fact, she could move the data from /home on the old disk to the
new disk and then extend the existing root volume to cover all of
the old disk.
Benefits of Logical Volume
Management on a Large System
 The benefits of logical volume management are more obvious on large systems with
many disk drives.
 Managing a large disk farm is a time-consuming job, made particularly complex if the
system contains many disks of different sizes. Balancing the (often conflicting)
storage requirements of various users can be a nightmare.
 User groups can be allocated to volume groups and logical volumes and these can be
grown as required. It is possible for the system administrator to "hold back" disk
storage until it is required. It can then be added to the volume(user) group that has
the most pressing need.
 When new drives are added to the system, it is no longer necessary to move users
files around to make the best use of the new storage; simply add the new disk into an
existing volume group or groups and extend the logical volumes as necessary.
 It is also easy to take old drives out of service by moving the data from them onto
newer drives - this can be done online, without disrupting user service.
Anatomy of LVM
 Contents:
1. volume group (VG)
2. physical volume (PV)
3. logical volume (LV)
4. physical extent (PE)
5. logical extent (LE)
6. Tying it all together
Anatomy of LVM …
 This diagram gives an overview of the main elements in
an LVM system:
Another way to look at is this
Schematically..
Logical Volume Management
Physical Volume
20GB
Physical Volume
36GB
Physical Volume
34GB
/boot
2GB
ext3
Logical Volume Group
90GB
Logical Volume
/home
50GB
Logical Volume
/
25GB
Free Space
15GB
1. Volume group (VG)
 The Volume Group is the highest level abstraction used
within the LVM. It gathers together a collection of Logical
Volumes and Physical Volumes into one administrative
unit.
2. physical volume (PV)
 A physical volume is typically a hard disk, though it may
well just be a device that 'looks' like a hard disk (eg. a
software raid device).
3. logical volume (LV)
 The equivalent of a disk partition in a non-LVM system. The
LV is visible as a standard block device; as such the LV
can contain a file system (eg. /home).
4. physical extent (PE)
 Each physical volume is divided chunks of data, known as
physical extents, these extents have the same size as the
logical extents for the volume group.
5. logical extent (LE)
 Each logical volume is split into chunks of data, known as
logical extents. The extent size is the same for all logical
volumes in the volume group.
6. Tying it all together
 A concrete example will help:
 Suppose we have a volume group called VG1, this volume group has
a physical extent size of 4MB. Into this volume group we introduce 2
hard disk partitions, /dev/hda1 and /dev/hdb1. These partitions will
become physical volumes PV1 and PV2 (more meaningful names can
be given at the administrators discretion). The PV's are divided up into
4MB chunks, since this is the extent size for the volume group. The
disks are different sizes and we get 99 extents in PV1 and 248
extents in PV2. We now can create ourselves a logical volume, this
can be any size between 1 and 347 (248 + 99) extents. When the
logical volume is created a mapping is defined between logical
extents and physical extents, eg. logical extent 1 could map onto
physical extent 51 of PV1, data written to the first 4 MB of the logical
volume in fact be written to the 51st extent of PV1.
Linux/Unix File System
 A filesystem is a way of storing, organizing and accessing files
(and/or directories) on a storage device.
 Some examples of filesystems are FAT, NTFS for
Windows/DOS, HFS for MAC OS etc.
 In Linux, the popular filesystems are ext2, ext3 and ext4
filesystems.
 Some other filesystems such as ReiserFS are also natively
supported by Linux.
 Here, we discusse various features of extended filesystems in
Linux, i.e. ext2, ext3 and ext4.
ext2 - Second Extended Filesystem
 The extended filesystem, ext, implemented in Linux in 1992 was the
first filesystem designed specifically for Linux.
 ext2 filesystem is the second extended filesystem.
 It was default filesystem in many Linux distros for many years.
 Features of ext2 are:
 Developed by Remi Card
 Introduced in January 1993
 Replacement for extended filesystem
 Maximum file size: 16GiB - 2TiB, depending upon block size (1K, 2K, 4K
or 8K)
 Maximum volume/filesystem size: 2TiB - 32TiB
 Maximum filename length: 255 bytes (255 characters)
 Maximum number of files: 10^18
 Filenames: All characters except NULL('0') and '/' are allowed in a file
name
 Date range: December 14, 1901 - January 18, 2038
ext3 - Third Extended Filesystem
 With ext3, the concept of journaling was introduced.
 With ext2 filesystem, when system crashed, or power failure
occurred, the whole filesystem needed to be checked for
consistency and bad blocks.
 With journaling, the filesystem keeps track of the changes
made in the filesystem before committing them to
filesystem.
 These changes are stored at a specified location in a dedicated
area of the filesystem.
 So in the event of power failure or system crash, the filesystems
can be brought back much quickly.
 ext3 filesystem is fully compatible with its previous version, i.e.
ext2 filesystem.
 The other features are:
 Developed by Stephen Tweedie
 Introduced in November 2001 (with Linux 2.4.15)
 Journaled filesystem.
 An ext2 filesystem can be converted to ext3 without any need of backup.
 Maximum file size: 16GiB - 2TiB
 Maximum volume/filesystem size: 2TiB - 32TiB
 Maximum filename length: 255 bytes (255 characters)
 Maximum number of files: Variable
 Filenames: All characters except NULL('0') and '/' are allowed
 Date range: December 14, 1901 - January 18, 2038
 The ext4 filesystem, developed as an extension to ext3 is the newest filesystem in the
series of extended filesystems (ext's).
 It has many performance improvements over ext3.
 In most modern distros, the default filesystem is ext4.
 The features are:
 Developers: Mingming Cao, Andreas Dilger, Alex Zhuravlev (Tomas), Dave Kleikamp,
Theodore Ts'o, Eric Sandeen, Sam Naghshineh and others (from wikipedia.org)
Introduced in October 2008 (stable)
 Journaled filesystem
 Performance enhancements over its predecessor (ext3)
 Maximum file size: 16TB
 Maximum volume/filesystem size: 1EIB (exabyte) (1Eib = 1024PiB, 1PiB = 1024TiB,
1TiB = 1024GiB
 Maximum filename length: 255 bytes (255 characters)
 Maximum number of files: 4 billion
 Filenames: All characters except NULL('0') and '/' are allowed
 Date range: December 14, 1901 - April 25, 2514
 Total filesystem check time improved (fsck time)
 An ext3 filesystem can be converted to ext4 filesystem

More Related Content

Similar to Chapter 2 Linux File System and net.pptx

Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line conceptsArtem Nagornyi
 
Introduction to linux2
Introduction to linux2Introduction to linux2
Introduction to linux2Gourav Varma
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)anandvaidya
 
Linux introduction-commands2338
Linux introduction-commands2338Linux introduction-commands2338
Linux introduction-commands2338Cam YP Co., Ltd
 
Linux introduction-commands2338
Linux introduction-commands2338Linux introduction-commands2338
Linux introduction-commands2338Cam YP Co., Ltd
 
Basics of UNIX Commands
Basics of UNIX CommandsBasics of UNIX Commands
Basics of UNIX CommandsSubra Das
 
Command Line Tools
Command Line ToolsCommand Line Tools
Command Line ToolsDavid Harris
 
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS
 
Unit 7
Unit 7Unit 7
Unit 7siddr
 
Nguyễn Vũ Hưng: Basic Linux Power Tools
Nguyễn Vũ Hưng: Basic Linux Power Tools Nguyễn Vũ Hưng: Basic Linux Power Tools
Nguyễn Vũ Hưng: Basic Linux Power Tools Vu Hung Nguyen
 
Linux_Ch2 Lecture (1).pdf
Linux_Ch2 Lecture (1).pdfLinux_Ch2 Lecture (1).pdf
Linux_Ch2 Lecture (1).pdfAllinOne746595
 
File Input/output, Database Access, Data Analysis with Pandas
File Input/output, Database Access, Data Analysis with PandasFile Input/output, Database Access, Data Analysis with Pandas
File Input/output, Database Access, Data Analysis with PandasPrabu U
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structureSreenatha Reddy K R
 
Karkha unix shell scritping
Karkha unix shell scritpingKarkha unix shell scritping
Karkha unix shell scritpingchockit88
 

Similar to Chapter 2 Linux File System and net.pptx (20)

Unix command line concepts
Unix command line conceptsUnix command line concepts
Unix command line concepts
 
Introduction to linux2
Introduction to linux2Introduction to linux2
Introduction to linux2
 
Linux Introduction (Commands)
Linux Introduction (Commands)Linux Introduction (Commands)
Linux Introduction (Commands)
 
Linux introduction-commands2338
Linux introduction-commands2338Linux introduction-commands2338
Linux introduction-commands2338
 
Linux introduction-commands2338
Linux introduction-commands2338Linux introduction-commands2338
Linux introduction-commands2338
 
Basics of UNIX Commands
Basics of UNIX CommandsBasics of UNIX Commands
Basics of UNIX Commands
 
Command Line Tools
Command Line ToolsCommand Line Tools
Command Line Tools
 
Linux[122-150].pdf
Linux[122-150].pdfLinux[122-150].pdf
Linux[122-150].pdf
 
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformaticsBITS: Introduction to Linux - Text manipulation tools for bioinformatics
BITS: Introduction to Linux - Text manipulation tools for bioinformatics
 
Basics of Linux
Basics of LinuxBasics of Linux
Basics of Linux
 
Unit 7
Unit 7Unit 7
Unit 7
 
Nguyễn Vũ Hưng: Basic Linux Power Tools
Nguyễn Vũ Hưng: Basic Linux Power Tools Nguyễn Vũ Hưng: Basic Linux Power Tools
Nguyễn Vũ Hưng: Basic Linux Power Tools
 
Linux_Ch2 Lecture (1).pdf
Linux_Ch2 Lecture (1).pdfLinux_Ch2 Lecture (1).pdf
Linux_Ch2 Lecture (1).pdf
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
QSpiders - Unix Operating Systems and Commands
QSpiders - Unix Operating Systems  and CommandsQSpiders - Unix Operating Systems  and Commands
QSpiders - Unix Operating Systems and Commands
 
Linux shell scripting
Linux shell scriptingLinux shell scripting
Linux shell scripting
 
File Input/output, Database Access, Data Analysis with Pandas
File Input/output, Database Access, Data Analysis with PandasFile Input/output, Database Access, Data Analysis with Pandas
File Input/output, Database Access, Data Analysis with Pandas
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
Command
CommandCommand
Command
 
Karkha unix shell scritping
Karkha unix shell scritpingKarkha unix shell scritping
Karkha unix shell scritping
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 

Recently uploaded (20)

ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 

Chapter 2 Linux File System and net.pptx

  • 2. 2.1. Objectives:  The UNIX file system  Typical UNIX directory structure  Directory and file handling commands  Making hard and soft (symbolic) links  Specifying multiple filenames  Quotes  File and directory permissions  Inspecting file content  Finding files  Finding text in files  Sorting files  File compression and backup  Handling removable media
  • 3. 2.2 The UNIX Filesystem  Every item such as configuration information, temporary files , user data etc that can be stored in a UNIX filesystem belongs to one of four types:
  • 4. 2.2 The UNIX Filesystem… 1. Ordinary files Ordinary files can contain text, data, or program information. Files cannot contain other files or directories. Unlike other operating systems, UNIX filenames are not broken into a name part and an extension part (although extensions are still frequently used as a means to classify files). Instead they can contain any keyboard character except for '/' and be up to 256 characters long (note however that characters such as *,?,# and & have special meaning in most shells and should not therefore be used in filenames).
  • 5. 2.2 The UNIX Filesystem… 2. Directory Files Directories are containers or folders that hold files, and other directories. 3. Device Files To provide applications with easy access to hardware devices, UNIX allows them to be used in much the same way as ordinary files. There are two types of devices in UNIX:  block-oriented devices which transfer data in blocks (e.g. hard disks) and  character-oriented devices that transfer data on a byte-by-byte basis (e.g. modems and dumb terminals).
  • 6. 2.2 The UNIX Filesystem… 4. Links A link is a pointer to another file. There are two types of links:  A hard link to a file is indistinguishable from the file itself.  A soft link (or symbolic link) provides an indirect pointer or shortcut to a file.  A soft link is implemented as a directory file entry containing a pathname.
  • 7. 2.3 Typical UNIX Directory Structure  The UNIX filesystem is laid out as a hierarchical tree structure which is anchored at a special top-level directory known as the root (designated by a slash '/').  Because of the tree structure, a directory can have many child directories, but only one parent directory.  Fig. 2.1 illustrates this layout.
  • 8. Fig. 2.1: Part of a typical UNIX filesystem tree
  • 9.  To specify a location in the directory hierarchy, we must specify a path through the tree.  The path to a location can be defined by an absolute path from the root /, or as a relative path from the current working directory.  To specify a path, each directory along the route from the source to the destination must be included in the path, with each directory in the sequence being separated by a slash.  To help with the specification of relative paths, UNIX provides the shorthand "." for the current directory and ".." for the parent directory.  For example, the absolute path to the directory "play" is /home/will/play, while the relative path to this directory from "zeb" is ../will/play.  Fig. 2.2 shows some typical directories you will find on UNIX systems and briefly describes their contents.  Note that although these subdirectories appear as part of a seamless logical filesystem, they do not need be present on the same hard disk device; some may even be located on a remote machine and accessed across a network.
  • 10.
  • 11.  When you log into UNIX, your current working directory is your user home directory.  You can refer to your home directory at any time as "~" and the home directory of other users as "~<login>".  So ~will/play is another way for user jane to specify an absolute path to the directory /home/will/play.  User will may refer to the directory as ~/play.
  • 12. 2.4 Directory and File Handling Commands  pwd (print [current] working directory)  pwd displays the full absolute path to the your current location in the filesystem. So $ pwd /usr/bin implies that /usr/bin is the current working directory.
  • 13.  ls (list directory)  ls lists the contents of a directory. If no target directory is given, then the contents of the current working directory are displayed. So, if the current working directory is /,  $ ls bin dev home mnt share usr var boot etc lib proc sbin tmp vol
  • 14.  Actually, ls doesn't show you all the entries in a directory.  Files and directories that begin with a dot (.) are hidden (this includes the directories '.' and '..' which are always present).  The reason for this is that files that begin with a . usually contain important configuration information and should not be changed under normal circumstances. If you want to see all files, ls supports the -a option:  $ ls -a  Even this listing is not that helpful - there are no hints to properties such as the size, type and ownership of files, just their names.  To see more detailed information, use the -l option (long listing), which can be combined with the - a option as follows:
  • 15. 2.3. Each line of the output looks like this:
  • 16.  where:  type is a single character which is either 'd' (directory), '-' (ordinary file), 'l' (symbolic link), 'b' (block-oriented device) or 'c' (character-oriented device).  permissions is a set of characters describing access rights. There are 9 permission characters, describing 3 access types given to 3 user categories. The three access types are read ('r'), write ('w') and execute ('x'), and the three users categories are the user who owns the file, users in the group that the file belongs to and other users (the general public). An 'r', 'w' or 'x' character means the corresponding permission is present; a '-' means it is absent.  links refers to the number of filesystem links pointing to the file/directory (see the discussion on hard/soft links in the next section).  owner is usually the user who created the file or directory.  group denotes a collection of users who are allowed to access the file according to the group access rights specified in the permissions field.  size is the length of a file, or the number of bytes used by the
  • 17.  ls supports more options. To find out what they are, type:  $ man ls  man is the online UNIX user manual, and you can use it to get help with commands and find out about what options are supported.  It has quite a terse style which is often not that helpful, so some users prefer to use the (non- standard) info utility if it is installed:  $ info ls
  • 18. cd (change [current working] directory)  $ cd path changes your current working directory to path (which can be an absolute or a relative path). One of the most common relative paths to use is '..' (i.e. the parent directory of the current directory).  Used without any target directory  $ cd  resets your current working directory to your home directory (useful if you get lost).  If you change into a directory and you subsequently want to return to your original directory, use  $ cd -
  • 19.  mkdir (make directory) $ mkdir directory  creates a subdirectory called directory in the current working directory. You can only create subdirectories in a directory if you have write permission on that directory.  rmdir (remove directory)  $ rmdir directory  removes the subdirectory directory from the current working directory.  You can only remove subdirectories if they are completely empty (i.e. of all entries besides the '.' and '..' directories).
  • 20.  cp (copy)  cp is used to make copies of files or entire directories. To copy files, use:  $ cp source-file(s) destination  where source-file(s) and destination specify the source and destination of the copy respectively. The behavior of cp depends on whether the destination is a file or a directory. If the destination is a file, only one source file is allowed and cp makes a new file called destination that has the same contents as the source file. If the destination is a directory, many source files can be specified, each of which will be copied into the destination directory.
  • 21.  To copy entire directories (including their contents), use a recursive copy:  $ cp -rd source-directories destination-directory  mv (move/rename)  mv is used to rename files/directories and/or move them from one directory into another. Exactly one source and one destination must be specified:  $ mv source destination  If destination is an existing directory, the new name for source (whether it be a file or a directory) will be destination/source.  If source and destination are both files, source is renamed destination.  N.B.: if destination is an existing file it will be destroyed and overwritten by source (you can use the -i option if you would like to be asked for confirmation before a file is overwritten in this way).
  • 22.  rm (remove/delete)  $ rm target-file(s)  removes the specified files. Unlike other operating systems, it is almost impossible to recover a deleted file unless you have a backup (there is no recycle bin!) so use this command with care. If you would like to be asked before files are deleted, use the - i option:  $ rm -i myfile rm: remove 'myfile'?  rm can also be used to delete directories (along with all of their contents, including any subdirectories they contain).  To do this, use the -r option. To avoid rm from asking any questions or giving errors (e.g. if the file doesn't exist) you use the -f (force) option. Extreme care needs to be taken when using this option - consider what would happen if a system administrator was trying to delete user will's home directory and accidentally typed:  $ rm -rf / home/will (instead of rm -rf /home/will).
  • 23.  cat (catenate/type)  $ cat target-file(s)  displays the contents of target-file(s) on the screen, one after the other. You can also use it to create files from keyboard input as follows (> is the output redirection operator, which will be discussed in the next chapter): $ cat > hello.txt hello world! [ctrl-d] $ ls hello.txt hello.txt $ cat hello.txt hello world! $
  • 24.  more and less (catenate with pause)  $ more target-file(s)  displays the contents of target-file(s) on the screen, pausing at the end of each screenfull and asking the user to press a key (useful for long files).  It also incorporates a searching facility (press '/' and then type a phrase that you want to look for).  You can also use more to break up the output of commands that produce more than one screenfull of output as follows (| is the pipe operator, which will be discussed in the next chapter):  $ ls -l | more  less is just like more, except that it has a few extra features (such as allowing users to scroll backwards and forwards through the displayed file).  less not a standard utility, however and may not be present on all UNIX systems.
  • 25. 2.5 Making Hard and Soft (Symbolic) Links  Direct (hard) and indirect (soft or symbolic) links from one file or directory to another can be created using the ln command.  $ ln filename linkname  creates another directory entry for filename called linkname (i.e. linkname is a hard link).  Both directory entries appear identical (and both now have a link count of 2).  If either filename or linkname is modified, the change will be reflected in the other file (since they are in fact just two different directory entries pointing to the same file).
  • 26.  $ ln -s filename linkname  creates a shortcut called linkname (i.e. linkname is a soft link). The shortcut appears as an entry with a special type ('l'):  $ ln -s hello.txt bye.txt $ ls -l bye.txt lrwxrwxrwx 1 will finance 13 bye.txt -> hello.txt $  The link count of the source file remains unaffected.  Notice that the permission bits on a symbolic link are not used (always appearing as rwxrwxrwx).  Instead the permissions on the link are determined by the permissions on the target (hello.txt in this case).
  • 27.  Note that you can create a symbolic link to a file that doesn't exist, but not a hard link.  Another difference between the two is that you can create symbolic links across different physical disk devices or partitions, but hard links are restricted to the same disk partition.  Finally, most current UNIX implementations do not allow hard links to point to directories.
  • 28. 2.6 Specifying multiple filenames  Multiple filenames can be specified using special pattern-matching characters. The rules are:  '?' matches any single character in that position in the filename.  '*' matches zero or more characters in the filename. A '*' on its own will match all files. '*.*' matches all files with contains a '.'.  Characters enclosed in square brackets ('[' and ']') will match any filename that has one of those characters in that position.  A list of comma separated strings enclosed in curly braces ("{" and "}") will be expanded as a Cartesian
  • 29.  For example:  ??? matches all three-character filenames.  ?ell? matches any five-character filenames with 'ell' in the middle.  he* matches any filename beginning with 'he'.  [m-z]*[a-l] matches any filename that begins with a letter from 'm' to 'z' and ends in a letter from 'a' to 'l'.  {/usr,}{/bin,/lib}/file expands to /usr/bin/file /usr/lib/file /bin/file and /lib/file.  Note that the UNIX shell performs these expansions (including any filename matching) on a command's arguments before the command is executed.
  • 30. 2.7 Quotes  As we have seen, certain special characters (e.g. '*', '-','{' etc.) are interpreted in a special way by the shell.  In order to pass arguments that use these characters to commands directly (i.e. without filename expansion etc.), we need to use special quoting characters.  There are three levels of quoting that you can try:  Try inserting a '' in front of the special character.  Use double quotes (") around arguments to prevent most expansions.  Use single forward quotes (') around arguments to prevent all expansions.  There is a fourth type of quoting in UNIX. Single backward quotes (`) are used to pass the output of some command as an input argument to another.  For example:
  • 31. 2.8. File and Directory Permissions
  • 32.  As we have seen earlier, every file or directory on a UNIX system has three types of permissions, describing what operations can be performed on it by various categories of users.  The permissions are read (r), write (w) and execute (x), and the three categories of users are user/owner (u), group (g) and others (o).  Because files and directories are different entities, the interpretation of the permissions assigned to each differs slightly, as shown in Fig 2.4.  File and directory permissions can only be modified by their owners, or by the superuser (root), by using the chmod system utility.
  • 33.  chmod (change [file or directory] mode)  $ chmod options files  chmod accepts options in two forms.  Firstly, permissions may be specified as a sequence of 3 octal digits (octal is like decimal except that the digit range is 0 to 7 instead of 0 to 9).  Each octal digit represents the access permissions for the user/owner, group and others respectively.  The mappings of permissions onto their corresponding octal digits is as follows:
  • 34.
  • 35.  For example the command:  $ chmod 600 private.txt  sets the permissions on private.txt to rw------- (i.e. only the owner can read and write to the file).  Permissions may be specified symbolically, using symbols u (user), g (group), o (other), a (all), r (read), w (write) , x (execute), + (add permission), - (take away permission) and = (assign permission).  For example, the command:  $ chmod ug=rw,o-rw,a-x *.txt  sets the permissions on all files ending in *.txt to: rw-rw---- (i.e. the owner and users in the file's group can read and write to the file, while the general public do not have any sort of access).
  • 36.  chmod also supports a -R option which can be used to recursively modify file permissions, e.g.  $ chmod -R go+r play  will grant group and other read rights to the directory play and all of the files and directories within play.  chgrp (change group)  $ chgrp group files  can be used to change the group that a file or directory belongs to.  It also supports a -R option.
  • 37. 2.9. Inspecting File Content  Besides cat, there are several other useful utilities for investigating the contents of files:  file filename(s)  file analyzes a file's contents for you and reports a high-level description of what type of file it appears to be:  $ file myprog.c letter.txt webpage.html myprog.c: C program text letter.txt: English text webpage.html: HTML document text  file can identify a wide range of files but sometimes gets understandably confused (e.g. when trying to automatically detect the difference between C++ and Java code).
  • 38.  head, tail filename  head and tail display the first and last few lines in a file respectively. You can specify the number of lines as an option, e.g.  $ tail -20 messages.txt $ head -5 messages.txt  tail includes a useful -f option that can be used to continuously monitor the last few lines of a (possibly changing) file. This can be used to monitor log files, for example:  $ tail -f /var/log/messages  continuously outputs the latest additions to the system log file.
  • 39.  objdump options binaryfile  objdump can be used to disassemble binary files - that is it can show the machine language instructions which make up compiled application programs and system utilities.  od options filename (octal dump)  od can be used to displays the contents of a binary or text file in a variety of formats, e.g.  $ cat hello.txt hello world $ od -c hello.txt 0000000 h e l l o w o r l d n 0000014 $ od -x hello.txt 0000000 6865 6c6c 6f20 776f 726c 640a 0000014
  • 40.  There are also several other useful content inspectors that are non-standard (in terms of availability on UNIX systems) but are nevertheless in widespread use. They are summarised in Fig. 2.5. 
  • 41. 2.8. Finding Files  There are at least three ways to find files when you don't know their exact location:  find  If you have a rough idea of the directory tree the file might be in, you can use find:  $ find directory -name targetfile -print  find will look for a file called targetfile in any part of the directory tree rooted at directory.  targetfile can include wildcard characters. For example:  $ find /home -name "*.txt" -print 2>/dev/null  will search all user directories for any file ending in ".txt" and output any matching files (with a full absolute or relative path). Here the quotes (") are necessary to avoid filename expansion, while the 2>/dev/null suppresses error messages (arising from errors such as not being able to read the contents of directories for which the user does not have the right permissions).
  • 42.  find can in fact do a lot more than just finding files by name. It can find files by type (e.g. -type f for files, -type d for directories), by permissions (e.g. -perm o=r for all files and directories that can be read by others), by size (-size) etc.  You can also execute commands on the files you find. For example,  $ find . -name "*.txt" -exec wc -l '{}' ';'  counts the number of lines in every text file in and below the current directory. The '{}' is replaced by the name of each file found and the ';' ends the -exec clause.  For more information about find and its abilities, use man find and/or info find.
  • 43.  which (sometimes also called whence) command  If you can execute an application program or system utility by typing its name at the shell prompt, you can use which to find out where it is stored on disk. For example:  $ which ls /bin/ls
  • 44.  locate string  find can take a long time to execute if you are searching a large filespace (e.g. searching from / downwards). The locate command provides a much faster way of locating all files whose names match a particular search string. For example:  $ locate ".txt"  will find all filenames in the filesystem that contain ".txt" anywhere in their full paths.  One disadvantage of locate is it stores all filenames on the system in an index that is usually updated only once a day. This means locate will not find files that have been created very recently.  It may also report filenames as being present even though the file has just been deleted.  Unlike find, locate cannot track down files on the basis of their permissions, size and so on.
  • 45. 2.11. Finding Text in Files  grep (General Regular Expression Print)  $ grep options pattern files  grep searches the named files (or standard input if no files are named) for lines that match a given pattern. The default behaviour of grep is to print out the matching lines. For example:  $ grep hello *.txt  searches all text files in the current directory for lines containing "hello". Some of the more useful options that grep provides are: -c (print a count of the number of lines that match), -i (ignore case), -v (print out the lines that don't match the pattern) and -n (printout the line number before printing the matching line). So  $ grep -vi hello *.txt  searches all text files in the current directory for lines that do not contain any form of the word hello (e.g. Hello, HELLO, or hELlO).
  • 46.  If you want to search all files in an entire directory tree for a particular pattern, you can combine grep with find using backward single quotes to pass the output from find into grep. So  $ grep hello `find . -name "*.txt" -print`  will search all text files in the directory tree rooted at the current directory for lines containing the word "hello".  The patterns that grep uses are actually a special type of pattern known as regular expressions. Just like arithmetic expressions, regular expressions are made up of basic sub expressions combined by operators.  The most fundamental expression is a regular expression that matches a single character. Most characters, including all letters and digits, are regular expressions that match themselves. Any other character with special meaning may be quoted by preceding it with a backslash (). A list of characters enclosed by '[' and ']' matches any single character in that list; if the first character of the list is the caret `^', then it matches any character not in the list. A range of characters can be specified using
  • 47.  a dash (-) between the first and last items in the list. So [0-9] matches any digit and [^a-z] matches any character that is not a letter.  The caret `^' and the dollar sign `$' are special characters that match the beginning and end of a line respectively. The dot '.' matches any character. So  $ grep ^..[l-z]$ hello.txt  matches any line in hello.txt that contains a three character sequence that ends with a lowercase letter from l to z.  egrep (extended grep) is a variant of grep that supports more sophisticated regular expressions. Here two regular expressions may be joined by the operator `|'; the resulting regular expression matches any string matching either subexpression. Brackets '(' and ')' may be used for grouping regular expressions. In addition, a regular expression may be followed by one of several repetition operators:
  • 48.  `?' means the preceding item is optional (matched at most once). `*' means the preceding item will be matched zero or more times. `+' means the preceding item will be matched one or more times. `{N}' means the preceding item is matched exactly N times. `{N,}' means the preceding item is matched N or more times. `{N,M}' means the preceding item is matched at least N times, but not more than M times.  For example, if egrep was given the regular expression  '(^[0-9]{1,5}[a-zA-Z ]+$)|none'  it would match any line that either:  begins with a number up to five digits long, followed by a sequence of one or more letters or spaces, or  contains the word none  You can read more about regular expressions on the grep and egrep manual pages.
  • 49.  Note that UNIX systems also usually support another grep variant called fgrep (fixed grep) which simply looks for a fixed string inside a file (but this facility is largely redundant).
  • 50. 2.12. Sorting files  There are two facilities that are useful for sorting files in UNIX:  sort filenames  sort sorts lines contained in a group of files alphabetically (or if the - n option is specified numerically). The sorted output is displayed on the screen, and may be stored in another file by redirecting the output. So  $ sort input1.txt input2.txt > output.txt  outputs the sorted concatenation of files input1.txt and input2.txt to the file output.txt.  uniq filename  uniq removes duplicate adjacent lines from a file.  This facility is very useful when combined with sort:  $ sort input.txt | uniq > output.txt
  • 51. 2.13. File Compression and Backup  UNIX systems usually support a number of utilities for backing up and compressing files. The most useful are:  tar (tape archiver)  tar backs up entire directories and files onto a tape device or (more commonly) into a single disk file known as an archive.  An archive is a file that contains other files plus information about them, such as their filename, owner, timestamps, and access permissions.  tar does not perform any compression by default.  To create a disk file tar archive, use  $ tar -cvf archivename filenames  where archivename will usually have a .tar extension. Here the c option means create, v means verbose (output filenames as they are archived), and f means file.
  • 52.  To list the contents of a tar archive, use: $ tar -tvf archivename  To restore files from a tar archive, use $ tar -xvf archivename
  • 53.  cpio  cpio is another facility for creating and reading archives.  Unlike tar, cpio doesn't automatically archive the contents of directories.  So it's common to combine cpio with find when creating an archive: $ find . -print -depth | cpio -ov -Htar > archivename  This will take all the files in the current directory and the directories below and place them in an archive called archivename.  The -depth option controls the order in which the filenames are produced and is recommended to prevent problems with directory permissions when doing a restore. The -o option creates the archive, the -v option prints the names of the files archived as they are added and the -H option specifies an archive format type (in this case it creates a tar archive).  Another common archive type is crc, a portable format with a checksum for error control.
  • 54.  To list the contents of a cpio archive, use $ cpio -tv < archivename  To restore files, use: $ cpio -idv < archivename  Here the -d option will create directories as necessary.  To force cpio to extract files on top of files of the same name that already exist (and have the same or later modification time), use the -u option.
  • 55.  Compress and gzip  compress and gzip are utilities for compressing and decompressing individual files (which may be or may not be archive files).  To compress files, use: $ compress filename or $ gzip filename  In each case, filename will be deleted and replaced by a compressed file called filename.Z or filename.gz.  To reverse the compression process, use: $ compress -d filename or $ gzip -d filename
  • 56. 2.14. Handling Removable Media (e.g. floppy disks)  UNIX supports tools for accessing removable media such as CDROMs and floppy disks.  mount, umount  The mount command serves to attach the filesystem found on some device to the filesystem tree.  Conversely, the umount command will detach it again (it is very important to remember to do this when removing the floppy or CDROM).  The file /etc/fstab contains a list of devices and the points at which they will be attached to the main filesystem:  $ cat /etc/fstab /dev/fd0 /mnt/floppy auto rw,user,noauto 0 0 /dev/hdc /mnt/cdrom iso9660 ro,user,noauto 0 0  In this case, the mount point for the floppy drive is /mnt/floppy and the mount point for the CDROM is /mnt/cdrom.
  • 57.  To access a floppy we can use: $ mount /mnt/floppy  Then you can do: $ cd /mnt/floppy $ ls (etc...)  To force all changed data to be written back to the floppy and to detach the floppy disk from the filesystem, we use: $ umount /mnt/floppy
  • 58. RAIDS  Outline:  RAID 0  RAID 1  RAID 5  RAID 10  Performance  Storage space  Fault tolerant
  • 59. What is RAID?  Stands for Redundant Array of Independent Disks.  It’s a technology that enables greater levels of performance, reliability and/or large volumes when dealing with data.  How?? By concurrent use of two or more ‘hard disk drives’.  How Exactly?? Mirroring, Stripping (of data) and Error correction techniques combined with multiple disk arrays give you the reliability and performance.
  • 60. RAID flavors  Commonly used ones: 1. RAID 0 2. RAID 1 3. RAID 5 4. RAID 10  Other types used…but rarely: RAID 2,3,4,6,50……
  • 61. RAID 0 a. RAID 0 is block-level data striping b. No parity or mirroring c. It splits data among two or more disks. d. Provides best performance. e. Lack of data redundancy means there is no fail over support (no fault tolerance)with this configuration. f. In the diagram to the right, the odd blocks are written to disk 0 and the even blocks to disk 1 such that A1, A2, A3, A4, … would be the order of blocks read if read sequentially from the beginning. g. Used in read only NFS systems and gaming systems.
  • 62. RAID 0 …  Storage space used is all the disks’ space combined.  The probability of failure increases with increase in the number of disks.  The more hard drives we have, the faster RAID 0 becomes.  The fragments are written to their respective disks simultaneously on the same sector.  This allows smaller sections of the entire chunk of data to be read off the drive in parallel, hence best performance.
  • 63. RAID 1 •RAID1 is ‘data mirroring’. •Two copies of the data are held on two physical disks, and the data is always identical. • Twice as many disks are required to store the same data when compared to RAID 0. •Array continues to operate so long as at least one drive is functioning.
  • 64. RAID 1 … Performance:  If we use independent disk controllers for each disk, then we can increase the read or write speeds by doing operations in parallel.  Storage space used is half the discs’ space combined and the other half is used as a backup.
  • 65. RAID 5 • RAID 5 is an ideal combination of good performance, good fault tolerance and high capacity and storage efficiency. • An arrangement of parity and CRC to help rebuilding drive data in case of disk failures. • “Distributed Parity” is the key word here.
  • 66. RAID 5  MTBF is slightly better than RAID 0. This is because failure of one disk is not quite a harm. We need more time if 2 or more disks fail.  Performance is also as good as RAID 0  We can read and write parallel blocks of data.  One of the drawbacks is that the write involves heavy parity calculations by the RAID controller. Write operations are slower compared to RAID 0.  Pretty useful for general purpose uses where ‘read’s’ are more frequent than ‘write’s’.
  • 67. RAID 10 a. Striping and mirroring b. Combines RAID 1 and RAID 0. c. Which means having the pleasure of both - good performance and good failover handling. d. Also called ‘Nested RAID’.
  • 68. Implementations Software based RAID:  Software implementations are provided by many Operating Systems.  A software layer sits above the disk device drivers and provides an abstraction layer between the logical drives(RAIDs) and physical drives.  Server's processor is used to run the RAID software.  Used for simpler configurations like RAID0 and RAID1.
  • 69. Implementations … Hardware based RAID:  A hardware implementation of RAID requires at least a special- purpose RAID controller.  On a desktop system this may be built into the motherboard.  Processor is not used for RAID calculations as a separate controller present. A PCI-bus-based, IDE/ATA hard disk RAID controller, supporting levels 0, 1, and 01.
  • 71. What is Logical Volume Management?  Logical volume management provides a higher-level view of the disk storage on a computer system than the traditional view of disks and partitions.  This gives the system administrator much more flexibility in allocating storage to applications and users.  Storage volumes created under the control of the logical volume manager can be resized and moved around almost at will, although this may need some upgrading of file system tools.  The logical volume manager also allows management of storage volumes in user-defined groups, allowing the system administrator to deal with sensibly named volume groups such as "development" and "sales" rather than physical disk names such as "sda" and "sdb".
  • 72. Why would I want it?  Logical volume management is traditionally associated with large installations containing many disks but it is equally suited to small systems with a single disk or maybe two.
  • 73. Benefits of Logical Volume Management on a Small System  One of the difficult decisions facing a new user installing Linux for the first time is how to partition the disk drive. The need to estimate just how much space is likely to be needed for system files and user files makes the installation more complex than is necessary and some users simply opt to put all their data into one large partition in an attempt to avoid the issue.  Once the user has guessed how much space is needed for /home /usr / (or has let the installation program do it) then is quite common for one of these partitions to fill up even if there is plenty of disk space in one of the other partitions.  With logical volume management, the whole disk would be allocated to a single volume group and logical volumes created to hold the / /usr and /home file systems. If, for example the /home logical volume later filled up but there was still space available on /usr then it would be possible to shrink /usr by a few megabytes and reallocate that space to /home.  Another alternative would be to allocate minimal amounts of space for each logical volume and leave some of the disk unallocated. Then, when the partitions start to fill up, they can be expanded as necessary.
  • 74. Example  Joe buys a PC with an 8.4 Gigabyte disk on it and installs Linux using the following partitioning system: /boot /dev/hda1 10 Megabytes swap /dev/hda2 256 Megabytes / /dev/hda3 2 Gigabytes /home /dev/hda4 6 Gigabytes This, he thinks, will maximize the amount of space available for all his MP3 files.
  • 75.  Sometime later Joe decides that he wants to install the latest office suite and desktop UI available but realizes that the root partition isn't large enough. But, having archived all his MP3s onto a new writable DVD drive there is plenty of space on /home.  His options are not good:  Reformat the disk, change the partitioning scheme and reinstall.  Buy a new disk and figure out some new partitioning scheme that will require the minimum of data movement.  Set up a symlink farm on / pointing to /home and install the new software on /home
  • 76.  With LVM this becomes much easier:  Jane buys a similar PC but uses LVM to divide up the disk in a similar manner: /boot /dev/hda1 10 Megabytes Swap /dev/vg00/swap 256 Megabytes / /dev/vg00/root 2 Gigabytes /home /dev/vg00/home 6 Gigabytes boot is not included on the LV because boot loaders don't understand LVM volumes yet. It's possible boot on LVM will work, but you run the risk of having an unbootable system.
  • 77.  When she hits a similar problem she can reduce the size of /home by a gigabyte and add that space to the root partition.  Suppose that Joe and Jane then manage to fill up the /home partition as well and decide to add a new 20 Gigabyte disk to their systems.  Joe formats the whole disk as one partition (/dev/hdb1) and moves his existing /home data onto it and uses the new disk as /home.  But he has 6 gigabytes unused or has to use symlinks to make that disk appear as an extension of /home, say /home/joe/old- mp3s.  Jane simply adds the new disk to her existing volume group and extends her /home logical volume to include the new disk. Or, in fact, she could move the data from /home on the old disk to the new disk and then extend the existing root volume to cover all of the old disk.
  • 78. Benefits of Logical Volume Management on a Large System  The benefits of logical volume management are more obvious on large systems with many disk drives.  Managing a large disk farm is a time-consuming job, made particularly complex if the system contains many disks of different sizes. Balancing the (often conflicting) storage requirements of various users can be a nightmare.  User groups can be allocated to volume groups and logical volumes and these can be grown as required. It is possible for the system administrator to "hold back" disk storage until it is required. It can then be added to the volume(user) group that has the most pressing need.  When new drives are added to the system, it is no longer necessary to move users files around to make the best use of the new storage; simply add the new disk into an existing volume group or groups and extend the logical volumes as necessary.  It is also easy to take old drives out of service by moving the data from them onto newer drives - this can be done online, without disrupting user service.
  • 79. Anatomy of LVM  Contents: 1. volume group (VG) 2. physical volume (PV) 3. logical volume (LV) 4. physical extent (PE) 5. logical extent (LE) 6. Tying it all together
  • 80. Anatomy of LVM …  This diagram gives an overview of the main elements in an LVM system:
  • 81. Another way to look at is this
  • 82. Schematically.. Logical Volume Management Physical Volume 20GB Physical Volume 36GB Physical Volume 34GB /boot 2GB ext3 Logical Volume Group 90GB Logical Volume /home 50GB Logical Volume / 25GB Free Space 15GB
  • 83. 1. Volume group (VG)  The Volume Group is the highest level abstraction used within the LVM. It gathers together a collection of Logical Volumes and Physical Volumes into one administrative unit. 2. physical volume (PV)  A physical volume is typically a hard disk, though it may well just be a device that 'looks' like a hard disk (eg. a software raid device).
  • 84. 3. logical volume (LV)  The equivalent of a disk partition in a non-LVM system. The LV is visible as a standard block device; as such the LV can contain a file system (eg. /home). 4. physical extent (PE)  Each physical volume is divided chunks of data, known as physical extents, these extents have the same size as the logical extents for the volume group.
  • 85. 5. logical extent (LE)  Each logical volume is split into chunks of data, known as logical extents. The extent size is the same for all logical volumes in the volume group.
  • 86. 6. Tying it all together  A concrete example will help:  Suppose we have a volume group called VG1, this volume group has a physical extent size of 4MB. Into this volume group we introduce 2 hard disk partitions, /dev/hda1 and /dev/hdb1. These partitions will become physical volumes PV1 and PV2 (more meaningful names can be given at the administrators discretion). The PV's are divided up into 4MB chunks, since this is the extent size for the volume group. The disks are different sizes and we get 99 extents in PV1 and 248 extents in PV2. We now can create ourselves a logical volume, this can be any size between 1 and 347 (248 + 99) extents. When the logical volume is created a mapping is defined between logical extents and physical extents, eg. logical extent 1 could map onto physical extent 51 of PV1, data written to the first 4 MB of the logical volume in fact be written to the 51st extent of PV1.
  • 87. Linux/Unix File System  A filesystem is a way of storing, organizing and accessing files (and/or directories) on a storage device.  Some examples of filesystems are FAT, NTFS for Windows/DOS, HFS for MAC OS etc.  In Linux, the popular filesystems are ext2, ext3 and ext4 filesystems.  Some other filesystems such as ReiserFS are also natively supported by Linux.  Here, we discusse various features of extended filesystems in Linux, i.e. ext2, ext3 and ext4.
  • 88. ext2 - Second Extended Filesystem  The extended filesystem, ext, implemented in Linux in 1992 was the first filesystem designed specifically for Linux.  ext2 filesystem is the second extended filesystem.  It was default filesystem in many Linux distros for many years.  Features of ext2 are:  Developed by Remi Card  Introduced in January 1993  Replacement for extended filesystem  Maximum file size: 16GiB - 2TiB, depending upon block size (1K, 2K, 4K or 8K)  Maximum volume/filesystem size: 2TiB - 32TiB  Maximum filename length: 255 bytes (255 characters)  Maximum number of files: 10^18  Filenames: All characters except NULL('0') and '/' are allowed in a file name  Date range: December 14, 1901 - January 18, 2038
  • 89. ext3 - Third Extended Filesystem  With ext3, the concept of journaling was introduced.  With ext2 filesystem, when system crashed, or power failure occurred, the whole filesystem needed to be checked for consistency and bad blocks.  With journaling, the filesystem keeps track of the changes made in the filesystem before committing them to filesystem.  These changes are stored at a specified location in a dedicated area of the filesystem.  So in the event of power failure or system crash, the filesystems can be brought back much quickly.  ext3 filesystem is fully compatible with its previous version, i.e. ext2 filesystem.
  • 90.  The other features are:  Developed by Stephen Tweedie  Introduced in November 2001 (with Linux 2.4.15)  Journaled filesystem.  An ext2 filesystem can be converted to ext3 without any need of backup.  Maximum file size: 16GiB - 2TiB  Maximum volume/filesystem size: 2TiB - 32TiB  Maximum filename length: 255 bytes (255 characters)  Maximum number of files: Variable  Filenames: All characters except NULL('0') and '/' are allowed  Date range: December 14, 1901 - January 18, 2038
  • 91.  The ext4 filesystem, developed as an extension to ext3 is the newest filesystem in the series of extended filesystems (ext's).  It has many performance improvements over ext3.  In most modern distros, the default filesystem is ext4.  The features are:  Developers: Mingming Cao, Andreas Dilger, Alex Zhuravlev (Tomas), Dave Kleikamp, Theodore Ts'o, Eric Sandeen, Sam Naghshineh and others (from wikipedia.org) Introduced in October 2008 (stable)  Journaled filesystem  Performance enhancements over its predecessor (ext3)  Maximum file size: 16TB  Maximum volume/filesystem size: 1EIB (exabyte) (1Eib = 1024PiB, 1PiB = 1024TiB, 1TiB = 1024GiB  Maximum filename length: 255 bytes (255 characters)  Maximum number of files: 4 billion  Filenames: All characters except NULL('0') and '/' are allowed  Date range: December 14, 1901 - April 25, 2514  Total filesystem check time improved (fsck time)  An ext3 filesystem can be converted to ext4 filesystem