Nothing Special   »   [go: up one dir, main page]

1.1.file System Hierarchy

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

File system management

Linux filesystems hierarchy


The file system hierarchy

The file system


hierarchy The file system


File types
File names
The file system hierarchy standard
The root directory and root partition
/bin, /boot, /dev, /etc directories
/home, /lib, /opt, /proc directories
/root, /sbin, /srv, /tmp directories
The /usr hierarchy
/var
Mount points
The file system


The file system is organized in a hierarchy (tree)
– The directory (/) root is at the top of the tree structure.


Pieces of the filesystem may exist on multiple disk partitions or on
remote file servers on the network
The pieces are 'mounted' onto directories to make the file system

appear as a single tree


File types


Several types of object exist in the filesystem

Normal files
– A set of contiguous data identified by a name
– Includes text files, graphics files, executable programs, etc;
– the filesystem does not distinguish the type of data
–The '.' is not a special character in file names and the filesystem does
not recognise separate names and extensions (e.g. report.txt), though
many applications do use an extension to identify the type of data in the
file


Directories
– Directories contain named 'links' to other files
– They cannot be opened, read and written like ordinary files
File types (continued)

Device Files
–Devices (disks, tape drives, mice, etc) are identified by ( block or
character) device file entries which are usually in the /dev directory
–If access permissions allow, some device files may be opened, read and
written like ordinary files (for example an archive may be written directly
to a tape device)

Symbolic Links
– References to files located at other points in the file system
– Allow a single file to be referenced using multiple names
Symbolic links can be opened like regular files, but the operation is

automatically redirected to the file that the link points to



Sockets and FIFOs
- Named communication end points used for interprocess communication

Named pipes
-Named communication end points used for interprocess communication
File names

File names can be up to 255 characters long


Case sensitive
All characters except '/' are legal in filenames

'/' is used as a separator in path names



Some characters have special meaning to the shell. They are awkward
to work with in file names and are best avoided:
+, %, $, #, !, \, -, ~, =, space, others ...
Recommend use only upper and lower case letters, digits, and '_'
Maximum length of a path name is 4096 characters

FHS – Filesystem Hierarchy Standard


The Filesystem Hierarchy Standard (FHS) is a vendor-independent
guideline that specifies the layout of the upper levels of the file system
tree
See www.pathname.com/fhs
Aims to provide consistency across UNIX versions

FHS distinguishes two major characteristics of files


Sharable (across multiple machines) vs non-sharable.


Static (do not change without system admin intervention) vs dynamic.
Files that differ in either respect should be in different directories


In the following slides we will tour some of the important directories
specified by the FHS
Filesystem hierarchy
Root directory and root partition

This is where "/", or the root directory, is located.


The root directory is the top-level of the directory structure.


Do not confuse this with the home directory of the superuser, which is
usually /root

The root partition is the partition containing the root directory


At boot time, the root partition is initially the only one mounted.
Files needed at boot time must be in directories on the root partition
/bin, /dev, /etc, /lib and /sbin
Binary directory: /bin


The /bin contains important executable (binary) programs
– Needed early in boot sequence
– Needed for emergency maintenance if other partitions unavailable
– Includes shells, filesystem maintenance commands, other tools
– Contents include:
File Description
/bin/bash The bash shell
/bin/cat Display / concatenate f iles
/bin/cp Copy f iles
/bin/mv Rename f iles
/bin/rm Remove f iles
/bin/mount Mount f ile systems
/bin/vi Text editor
/bin/tar Tape archiver
Boot directory: /boot


The /boot contains the files needed to get the linux kernel up and
running
– Second-stage files for the boot loader (GRUB or LILO)
– Backup of Master Boot Record
– The image of the linux kernel


Sometimes /boot is on a separate partition
–Early stages of booting on a PC rely on the PC's BIOS firmware to access
the hard drive.
–On early PCs the BIOS could not access cylinder numbers beyond 1023
so it was essential that the kernel image lay below this boundary
– Putting /boot on a separate (small) partition guarentees this
Device files: /dev


Device files give file names to hardware devices
– Associates a name (e.g. /dev/sda1) with a major / minor device number
Identifies the device and the driver used to read/write data on the

device
earth:~ # ls -l /dev/sda1
earth:~ # ls -l /dev/sda1
brw-rw----
brw-rw---- 11 root
root disk
disk 3,
3, 11 2003-09-23
2003-09-23 18:59
18:59 /dev/sda1
/dev/sda1

b = block device (disks) Minor device number


c = character device Major device number
(printer, mouse, tape etc)


Usually all required device files are created automatically using udev
service
– Many reference hardware which is not actually present
– The mknod command is used to create new device files
Device files: /dev (continued)

Device Device File Description

/dev/console The system console (old days – admin)


Terminals
/dev/tty* Virtual terminals (old days – user)
/dev/ttyS0 ttyS0 is equivalent to DOS “COM1”
Serial ports
/dev/ttyS*
/dev/lp0 lp0 is equivalent to DOS “LPT1”
Parallel ports
/dev/lp*
Floppy disks /dev/fd0 The first floppy disk drive
IDE CDROM IDE CD Rom drives are named within the
/dev/hd*
drives same scheme used for IDE hard drives
/dev/sda The first SCSI drive
SCSI hard
/dev/sdb The second SCSI drive
drives
/dev/sda1 First partition on first SCSI drive
/dev/nvme0n1 The first SCSI drive
SCSI hard
/dev/nvme0n2 The second SCSI drive
drives
/dev/nvme0n1p1 First partition on first SCSI drive
SCSI CDROM
/dev/sr0 First SCSI CDROM drive
drives
Configuration files: /etc

The /etc contains system configuration files
– mostly plain text; editable using any text editor
File Description
/etc/redhat-release Version number of the CentOS product installed
/etc/inittab Master conf iguration f ile for the init process
/etc/init.d/* Scripts for starting services (lots of stuf flater)
/etc/grub.conf Conf iguration f ile for GRUB bootstrap loader
/etc/modules.conf Conf iguration f ile for the kernel modules
/etc/X11/ Conf iguration f ile for the X server
/etc/fstab Table of f ilesystems mounted automatically at boot time
/etc/prof ile System-wide login script for the shell
/etc/passwd Database of locally def ined user accounts
/etc/shadow Database of encrypted user passwords
/etc/group Database of locally def ined groups
/etc/hosts Local mapping of machine names to IP addresses
/etc/motd Message of the day: Message printed after login
/etc/sysconf ig/* Directory containing central system conf ig f iles
User directories: /home

The /home contains the home directories of individual users.


After login, a user's current directory is his home directory.


/home is often on a separate partition or may be mounted from a file
server – this arrangement means that users are not tied to specific
machines
A user's personal configuration files are stored in his home directory.

“Hidden” files (name starts with '.')


Examples: .bashrc, .profile, .bash_history
The shell recognises '~' as a shorthand for your home directory

Example: ~/.bashrc
Libraries: /lib


A library is a collection of compiled binary files
– Contains code for functions used by many programs
–A program that needs access to library functions links to the required
libraries at run time (dynamic linking)
– UNIX refers to dynamically linked libraries as shared objects (.so files)

/lib contains the essential system libraries needed to run the


commands in the root filesystem i.e. /bin and /sbin
/lib/libc.so.6 is the main C runtime library
Most other application libraries are in /usr/lib

/lib/modules contains dynamically loaded kernel modules


Directory of applications /opt

The /opt directory is for "the installation of add-on application software


packages"
● $$ ls
ls /opt
/opt
cxoffice
cxoffice gnome
gnome kde3
kde3 mozilla
mozilla OpenOffice.org
OpenOffice.org


Note that the open source community does not always follow this
guideline. When applications are installed by compiling from source
code, the default installation directory is usually /usr/local
–This can be changed using command line options when the application
is installed
Process files /proc


The files in /proc are a figment of the kernel's imagination, it is virtual
file system or pseudo-file system
–Make internal kernel information available via normal file read
commands
– There is a subdirectory for each process, named after the process ID
– Other 'files' in /proc provide information about the system as a whole
File Description
/proc/cpuinfo Information about the processor
/proc/interrupts Allocation of interrupt vectors
/proc/ioports Allocation of I/O port addresses
/proc/modules Active kernel modules
/proc/partitions The disk partitions and I/O statistics
/proc/mounts Mounted f ile systems
/proc/f ileystems Supported f ile system formats
/proc/version The kernel version
/proc/pci PCI bus devices
/proc/sys/* System and kernel information
The /sys Directory


The /sys/ directory utilizes the new sysfs virtual file system specific
to the kernel.

With the increased support for hot plug hardware devices in the
kernel, the /sys/ directory contains information similar to that held
by /proc/, but displays a hierarchical view of device information
specific to hot plug devices.
Directory of the administrator /root


The /root is the super-user's home directory.
– On the root partition
–Allows root to login even if no additional partitions can be mounted – the
home directories for ordinary accounts (under /home) may be on a
separate partition
System administration commands: /sbin


The /sbin contains binaries essential for booting, restoring, recovering,
configuring or repairing the system (for root)
–Usually only root can run these programs to make changes to the
system
/sbin lies in the root partition
File Description
This SuSE-specif ic tool performs overall system
/sbin/SuSEconf ig
conf iguration, reading the f iles in /etc/sysconf ig
/sbin/conf.d/* The individual conf iguration scripts
/sbin/fdisk Tool for creating and modifying disk partitions
/sbin/fsck Tool for checking the consistency of the f ile system
/sbin/init The f irst process created when the system boots
/sbin/ifconf ig Tool to conf igure network interface
/sbin/modprobe Tool to manually add or remove kernel modules
Server directories and temporary area


The /srv directory contains site-specific data served by this system.
This directory gives users the location of data files for a

particular service, such as FTP, WWW, or CVS.


– Note that many linux systems do not follow this FHS guideline
The /tmp contains temporary files

–Anyone can create files in /tmp

Programs should not rely on files surviving in /tmp between one


program invocation and the next


– Some administrators set up the system to empty /tmp at boot time
–Important to avoid name clashes in /tmp – some applications include
their process ID within the file name
The /usr hierarchy


The FHS standard defines a second level of directories under /usr
– Sharable (across machines); “static” files that do not normally change
– Often on a separate partition; may be mounted read-only
– Subdirectories include:
File Description
/usr/X11R6 Files for the X11 window system
/usr/bin Most “regular” system-wide executable programs are here
/usr/lib Most libraries are here
Locally installed tools and software may be placed here to avoid
/usr/local being removed or replaced during a system upgrade. Many open
source packages install into /usr/local by default
/usr/sbin Non-essential binaries used by the system administrator (root)
Architecture-independent sharable data e.g. Man pages and other
/usr/share
documentation
Changeable files: /var


The /var contains data files that change during normal system
operation
– Spool directories and files
– Administrative and logging data
– Transient and temporary files
– Key subdirectories include:
File Description
Long-term state information held by applications. For example,
/var/lib
/var/lib/rpm contains the database of all installed packages
/var/log Most log f iles live here
Various f iles describing the state of the system since it was
/var/run booted. For example, /var/run/crond.pid is a f ile containing the
process ID of the cron daemon
/var/spool Directory for spool queues (printer and mail susbsystems, etc)
Lock f iles that prevent simultaneous use of a device by more than
/var/lock
one application
Mount points


The file system is often split across several disk partitions
– Each partition has a self-contained file system structure
– Directories (“mount points”) are created on the root filesystem
– The mount command attaches a partition's filesystem to a mount point
– The umount command detaches a filesystem

/mnt /home

mount /dev/sda1 /mnt mount /dev/hdb1 /home

Partition /dev/sda1 Partition /dev/hdb1


Pre-defined mount points

The (empty) directory /mnt is provided as a general-purpose mount


point for temporary mounts



Directories under /media are provided for mounting removable media
– floppy Floppy disks
– cdrom CDRoms
– dvd DVDs
– cdrecorder CD Recorders
– sda1 SCSI disk or devices emulated as SCSI
e.g. USB memory sticks


By default, only root can mount or unmount
–But the system is usually configured to allow non-root users to mount
removable media
File system hierarchy quiz


Where would you expect to find:
– The configuration file for the samba file server
– lpiuser’s home directory
– The superuser's home directory
– The “spool files” that hold incoming mail
– The bootable linux kernel image
– The executable for a regular command such as less
– A file system mounted from a floppy disk
– The device entries for the partitions on your hard drive

You might also like