Transcript Directories

Operating System
&
Administration
UNIT-III
Introduction to File System
OUTLINE
1.PathName
2.File System Mounting and Unmounting
3.Organization of File Tree
4.File Type
5.File Attribute
6.Access Control List
What is a file
• File is a collection of data items stored on disk. Or, it's
device which can store the information like data, music
(mp3 files), picture, movie, sound, book etc.
• In fact whatever you store in computer it must be in the
form of file.
• File is the last object in your file system tree.
Component of File System
• A namespace – a way to name things and organize them
in a hierarchy
• An API –
a set of system calls for navigating and
manipulating objects
• A security model – a scheme for protecting, hiding, and
sharing things
• An implementation – software to tie the logical model to
the hardware.
• Note:- file should not contain / in between file name
characters.
• Modern kernels define an abstract interface that
contains many different back-end filesystems.
• Windows - NTFS, FAT
• Linux - Ext
– Ext2
– Ext3
– Ext4
Linux file system(History)
• It has maximum size limit of 64 megabytes
• There was also a filename length limit of 14 characters.
• In 1991 a new file system came with addition of new
file system as a layer on top of linux kerenl that provide
generic file API. Termed as VFS termed as ext.
• But has problems like allowed 2 gigabytes of data and
filenames of up to 255 characters. with problems like
there was no support for separate access, inode
modification and data modification with timestamps.
• Ext2:– Introduced in 1993 by Rémy Card.
– maximum filename length of 255 characters
– has variable length block size(maximum data size of
2047 gigabytes).
– Maximum individual file size can be from 16 GB to 2TB
– Overall ext2 file system size can be from 2 TB to 32 TB
• Ext3:-
– Introduced in 2001 by Stephen Tweedie
– The main benefit of ext3 is that it allows journaling.
– Journaling has a dedicated area in the file system, where
all the changes are tracked. When the system crashes, the
possibility of file system corruption is less because o
journaling.
– maximum filename length of 255 characters
– Maximum individual file size can be from 16 GB to 2 TB
– Overall ext3 file system size can be from 2 TB to 32 TB
Ext4
• It was introduced in 2008.
• Starting from Linux Kernel 2.6.19 ext4 was available.
• Supports huge individual file size and overall file system
size.
• Maximum individual file size can be from 16 GB to 16
TB
• Overall maximum ext4 file system size is 1 EB (exabyte).
1 EB = 1024 PB (petabyte).
• 1 PB = 1024 TB (terabyte).
• Directory can contain a maximum of 64,000
subdirectories (as opposed to 32,000 in ext3)
• You can also mount an existing ext3 filesystem as ext4
filesystem (without having to upgrade it).
• Several other new features are introduced in ext4:
–
–
–
–
multiblock allocation,
delayed allocation,
journal checksum. fast fsck, etc.
All you need to know is that these new features have
improved the performance and reliability of the
filesystem when compared to ext3
Filesystem Hierarchy Standard
• Started by Dennis Ritchie, 1993
• Defines the main directories and their contents in most
Linux-based systems
11
FHS
• There is no any drive C:, D:, …
• All directories are under “/”
– “/” is the root directory
• It is possible
– to have multiple partitions
– to multiple filesystems
12
The “/”
• The primary hierarchy in FSH
– The root of tree of filesystem
• All paths start form here
• There is only one “/” in filesystem
13
Pathname
• What is Path
• Path Types
• Setting Path
What is path
• A path is a unique location to a file or a directory in a
file system of an OS.
• A path to a file is a combination of / and alpha-numeric
characters
• Ex.
–
–
–
–
/home/fedora/abc.txt
/etc/passwd
/proc/partitions
/etc/yum.d/yum.conf
Path Types in Linux
• Absolute path
-An absolute path is defined as the specifying the
location of a file or directory from the root directory(/).
-In other words we can say absolute path is a complete
path from start of actual filesystem from “ / “directory
• Relative path
-Relative path is defined as path related to the present
working directory(pwd).
Examples of relative path and absolute path
• Example1: Present location is /abc/xyz,
remove /abc/xyz/read/hello.txt file.
Using relative path:
rm read/hello.txt
Using absolute path:
rm /abc/xyz/read/hello.txt
• Example2: My present location is /etc/samba
and now I want to change directory to /etc.
Using relative path:
cd ..
Using absolute path:
cd /etc
Note:- there should be no ‘/’ in file Name
Ex:- “abc/pqr” it will be assumed that pqr is in
abc directory
The Organization Of The File Tree
/
boot
bin
dev
etc
lib
proc
root
sbin
tmp
19
usr
var
boot
• Linux kernel
• Boot loader configuration
• vmlinuz-2.6.3.1 is a executable that loads
operating system in memory.(vmlinuz is a kernel).
• If you lost boot
– You cannot boot your OS
boot
Grand Unified
boot Loader
Dev by Erich
Stefan Boleyn
boot
vmlinuz-2.6.12
grub
config-2.6.12
grub.conf
21
bin
• Essential programs
• Need for system startup
• Common programs, shared by the system, the system
administrator and the users.
• Basic commands for
– Navigating in filesystem
– File management
22
bin
bin
bash
bzip2
cat
...
gzip
ls
23
mv
rm
dev
• Everything is file
– Hardware components (devices) are file
• Hard disk
• Key board
• All device files are here
• Direct interaction with device driver
– Open the device file
– Read & Write
24
dev
dev
hda
fda
sda
...
tty
random
25
null
etc
• System configuration directory
• Critical startup and configuration files
• All configuration file are text files
– You can view and edit it manually
etc
etc
bashrc
fstab
inittab
passwd
shadow
init.d
X11
network
named
httpd
X11.conf
27
home
• Home directory of user
• Each user has a directory
– /home/xyz
– /home/abc
• All files of user are stored here
28
lib
• Libraries, shared libraries and parts of the C
compiler
• Programs need libraries
– Dynamically linked libraries
• All essential libraries are here
– Needed for system startup
29
lib
lib
libc
libm
libcrypt
libpthread
modules
30
proc
• Information about all running processes
• It represent current state of kernel
31
Directories with names as numbers
Do a ls -l /proc, and you’ll see lot of directories with just
numbers. These numbers represents the process ids, the files
inside this numbered directory correspond to the process
with that particular PID
Following are some file located in proc directory as
• cmdline – command line of the command.
• environ – environment variables.
• fd – Contains the file descriptors which is linked to the
appropriate files.
• limits – Contains the information about the specific limits to th
process.
Files about the system information
It contains system information such as cpuinfo, meminfo,
•
•
•
•
/proc/cpuinfo – information about CPU,
/proc/meminfo – information about memory,
/proc/partitions – partition related information,
/proc/version – linux version
• mounts – mount related information
proc
proc
cpuinfo
meminfo
devices
net
interrupts
tcp
sys
udp
net
35
1
129
kernel
root
• Home directory of root user or super user
• Don’t confuse
–
/ is the “root of Filesystem”
–
root is the name of system admin
– /root is the admin
36
sbin
• It contains executable programs (ready to run).
• They are mostly admin tool and made available to
root user.
• System configuration programs
– Format hard disk (fdisk,fsck, ifconfig,modinfo(info
for kernel module)
– Halt, reboot,fasthalt(stop system without disk
checking).
37
• /sbin should contain only binaries essential for
booting, restoring, recovering, and/or repairing the
system in addition to the binaries in /bin.
sbin
sbin
fsck
mkfs
mount
...
adduser
39
poweroff
tmp
•
•
•
•
Temporary directory
All temp files are created by programs
Your temp files
It is emptied regularly
40
usr
• It contains all the user binaries, their documentation,
libraries, header files, etc and its supporting libraries can
be found here.
• Also termed as Secondary hierarchy
• Very useful programs
– We usually use them for
• compiler, tools
• Are not essential for system startup
41
• /usr/bin:– This directory contains the vast majority of binaries on
your system.
– Executables in this directory vary widely.
– For instance vi, gcc, gnome-session and mozilla and are
all found here.
• /usr/doc:– The central documentation directory.
– Documentation is actually located in /usr/share/doc and
linked from here.
usr
usr
bin
doc
include
lib
local
sbin
src
Linux-2.6.14
43
var
• Contains variable data like system logging files, mail
and printer spool directories, and transient and
temporary files.
• Some portions of /var are not shareable between
different systems.like
– /var/log, /var/lock, and /var/run.
• The shared
– /var/mail, /var/cache/man,
/var/spool/new
/var/cache/fonts,
• The variable directory
• All dynamic files, User cannot change the
files
44
and
var
var
cache
lib
lock
message
log
www
boot.log
45
named
File Types
• Filesystem implementation define seven types of
files
1. Regular files
2. Directories
3. Character device files
4. Block domain sockets
5. Local domain sockets
6. Named pipes (FIFO)
7. Symbolic links
47
• How to create and remove files
48
Regular File :
• It is consist of a series of bytes, filesystems
impose no structure on their contents.
• Example: text files, data files, executable
programs.
Directories :
• It contains named references to other files.
49
Character and Block device files :
• Device files let programs communicate with the
system’s hardware and peripherals.
• The kernel loads driver software for each of the
system’s devices.
Program
request
Device
Driver
Files
Hardware
• Character device files allow their associated
drivers to do their own i/p and o/p buffering.
50
• Block device files are used by drivers that handle
i/o in large chunks and want the kernel to perform
buffering for them.
• Device files are characterized by two numbers,
called the major and minor device numbers.
• The major device number tells the kernel which
driver the file refers to, and the minor device
number typically tells the driver which physical
unit to address.
51
Local domain sockets :
• Sockets are connections between processes that
allow processes to communicate.
• Local domain sockets are accessible only from the
local host and are referred to through a filesystem
object rather than a network port.
52
Named pipes :
• It also allow communication between two
processes running on the same host. It is also
known as “FIFO files”
53
Symbolic links :
•
•
•
•
•
Symbolic or “soft” link points to a file by name.
Pathname stored as the contents of the link.
Links : hard link and soft link
Hard link is a direct reference
Soft link is a reference by name
54
File Attributes
1. Permission bits :
• Every file has a set of nine permission bits that
control who can read , write, and execute the
contents of the file.
• There are 3 basic permissions
– Read (r)
– Write (w)
– Execute (x)
• How to change them
– chmod +/- r/w/x <filename>
55
• File permissions in terms of octal numbers
because each digit of an octal no. represents three
bits and each group of permission bits consists of
three bits.
• In each triplet bits, the high bit is the read bit,
middle bit is the write bit, and low bit is the
execute bit.
• Two types of executable files exist: binaries,
which the CPU runs directly , and script, which
must be interpreted by a shell (bash or sh scripts).
56
2. Chmod : change permissions
• Chmod cmd changes the permissions of a file.
• Only the owner of the file and the superuser can
change its permissions.
• Permission encoding for chmod:
57
3. chown and chgrp : change ownership and
group:
• Using –R flag to change the setting of a directory
and all the files underneath.
• Example :
chown –R user:group dir/.*
4. umask : assign default permissions
58
Mounting and Unmounting
• Mount :
– To add a filesystem to other filesystem
• Filesystems are attached to the tree with the mount
cmd.
• Mount maps a directory within the existing file tree,
called the mount point, to the root of the newly
attached filesystem.
• The previous contents of the mount point become
inaccessible as long as another filesystem is
mounted there.
• Mount points are usually empty directories.
60
• How?
– mount <options> <device> <mount point>
– mount -t vfat /dev/sdb1 /mnt/flash
• To detach filesystems with the umount cmd.
• Don’t forget the umount
– umount <mount point>
– umount /mnt/flash
61
Access Control List
• What is an ACL?
– Access Control List: collection of Access
Control Entries (ACEs) associated with a file.
• What is an ACE?
– A structure specifying permission for a user,
group, or other entity.
setfacl
• User command utility to set, modify, or delete
ACLs on a file
• Can be ran by file owner or anyone given
permission to modify permissions
• Sample commands:
–
–
–
–
setfacl
setfacl
setfacl
setfacl
–s
–m
–u
–d
u:alice:+rx:i myFile
o::drwx myFile
myFile
u:alice myFile
getfacl
• User utility to examine the ACL on a
particular file
• Examines a file’s inode to detemine what
permissions are set
• Sample:
– getfacl myFile