Uploaded by DAT LE QUY QUOC

Module 06 - Devices, Linux Filesystems, and the Filesystem Hierarchy

advertisement
Module 06
Devices, Linux FileSystems
and FileSystem Hierarchy
Standard
Objectives
•
•
•
•
Create Partitions and Filesystems
– Disk Drives Under Linux
Maintain the Integrity of Filesystems
– Monitoring Free Disk Space and
Inodes
– Monitoring Disk Usage
– Modifying a Filesystem
– Checking and Repairing
Filesystems
Control Filesystem Mounting and
Unmounting
– Managing the Filesystem Table
– Mounting Filesystems
– Unmounting Filesystems
Set and View Disk Quotas
– Quota Limits
– Quota Commands
– Enabling Quotas
•
•
•
Manage File Permissions and
Ownership
– Linux Access Control
– Setting Access Modes
– Setting Up a Workgroup Directory
Create and Change Hard and Symbolic
Links
– Why Links?
Find System Files and Place Files in the
Correct Location
– Datatypes
– The root Filesystem
– Locating Files
Create Partitions and Filesystems
 Disk Drives Under Linux
 Linux supports many types of disk devices and formats:
o Disk Types: Any SCSI or IDE hard disk will work with Linux, as
will floppy disks, CD-ROMs, USB flash drives, and other types
of removable media
o Format: standard Linux ext2 filesystem, FAT, NTFS, as well as
other filesystem types.
 This flexibility makes Linux coexist nicely with other operating
systems on multiboot systems
Create Partitions and Filesystems
 Disk Drives Under Linux
 IDE Disk:
o A single IDE interface is capable of attaching two disk drives to
a system. One device is named master and the other is the
slave. Most PCs have a primary and secondary IDE
interface. Together, these interfaces allow up to four devices
(primary master, primary slave, secondary master, and
secondary slave)
Create Partitions and Filesystems
 Disk Drives Under Linux
 SCSI Disk:
o Typically, SCSI devices are used for their increased speed and
reliability in large-scale and high-end server environments
 Compared to IDE, SCSI offers excellent performance, lower CPU
utilization, and a much more flexible connection scheme capable of
handling up to 15 devices on a single bus
Create Partitions and Filesystems
 Disk Drives Under Linux
 Disk partitions
o Almost every operating system supports a system for dividing a
disk into logical devices, called partitions
o Partition Type:
– Primary partitions
– Extended partitions
– Logical partitions
Create Partitions and Filesystems
 Disk Drives Under Linux
 The root filesystem and mount points
o The root filesystem /, also known as the root directory, shouldn’t
be confused with the root superuser account or the superuser’s
home directory, /root
o
includes:
– /bin and /sbin: Contains required system binary programs
– /dev: Contains device files
– /etc: Contains configuration information
– /lib: Contains shared libraries
– /boot: holds static files used by the boot loader
– /home: user profiles
– /tmp: used to prevent temporary files from filling the root filesystem
– /var: Logfiles are stored here
– /usr: contain user commands, source code, and documentation
o swap partition is used for a Linux system to enable virtual memory
Create Partitions and Filesystems
 Disk Drives Under Linux
 The root filesystem and mount points
o Examples: the disk partitions for an IDE-based system with two
physical disks (40 GB and 200 GB).
Create Partitions and Filesystems
 Disk Drives Under Linux
 Managing partitions
o Linux has two basic options for partitioning disk drives
– The fdisk command is a text-based program that is easy to
use and exists on every Linux distribution
– Another option you may wish to explore: parted
Create Partitions and Filesystems
 Disk Drives Under Linux
 fdisk command:
o Manipulate or display the partition table for device using a
command-driven interactive text interface
o Options:
–
–
–
–
–
–
–
–
d: delete partition
l: List the known partition types
m: Display the brief help menu for these commands.
n: Add a new partition
p: Display the partition table
q: Quit without saving changes.
t: Change a partition’s system ID (Linux ext2 partitions are type 83)
w: Write (save) the partition table to disk and exit
Create Partitions and Filesystems
 Disk Drives Under Linux
 fdisk command:
Create Partitions and Filesystems
 Disk Drives Under Linux
 fdisk command:
Create Partitions and Filesystems
 Disk Drives Under Linux
 fdisk command:
Create Partitions and Filesystems
 Disk Drives Under Linux
 Creating filesystems:
o Once a disk is partitioned, filesystems may be created in those
partitions using the mkfs utility
Create Partitions and Filesystems
 Disk Drives Under Linux
 mkfs utility
Create Partitions and Filesystems
 Disk Drives Under Linux
 Creating swap partitions
o The command to create a swap partition is mkswap
Maintain the Integrity of Filesystems
 Monitoring Free Disk Space and Inodes
 Inodes
o Every filesystem contains a finite number of inodes, set when
the filesystem is created
o This number is also the maximum number of files that the
filesystem can accommodate
o Because filesystems are created with a huge number of inodes,
you’ll probably never create as many files as it would take to run
out of inodes
o The df command gives you the information you need on the
status of both disk space utilization and inode utilization.
Maintain the Integrity of Filesystems
 Monitoring Free Disk Space and Inodes
 df command:
Maintain the Integrity of Filesystems
 Monitoring Free Disk Space and Inodes
 df command:
Maintain the Integrity of Filesystems
 Monitoring Disk Usage
 du command recursively examines directories and reports detailed
or summarized information on the amount of space consumed
Maintain the Integrity of Filesystems
 Monitoring Disk Usage
 du command:
Maintain the Integrity of Filesystems
 Modifying a Filesystem
 Using tune2fs command
Maintain the Integrity of Filesystems
 Checking and Repairing Filesystems
 Filesystems are checked with fsck command
 Part of the information written on disk to describe a filesystem is
known as the superblock, written in block 1 of the partition
 Because the superblock is so important, copies of it are made in
the filesystem at regular intervals, by default every 8192 blocks.
The first superblock copy is located at block 8193, the second copy
is at block 16385, and so on
 fsck can use the information in the superblock copies to restore
the main superblock.
Maintain the Integrity of Filesystems
 Checking and Repairing Filesystems
 fsck command
Maintain the Integrity of Filesystems
 Checking and Repairing Filesystems
 fsck command
Control Filesystem Mounting and Unmounting
 Managing the Filesystem Table
 Each of these separate filesystems (on disk drives, CD-ROMs,
USB flash drives, and floppy disks…) is mounted to the parent
filesystem as a directory (or mount point)
 All of this information is recorded in the /etc/fstab file
 The /etc/fstab file is plain text and consists of lines with six fields:
o Device: specifies the device file of the partition holding the filesystem
o Mount point: specifies the directory on which the filesystem is to be mounted
o Filesystem type: may include ext2 filesystems,swap, nfs, iso9660 (CD-ROM),
and others
o Mount options:
o Dump frequency: The dump program, a standard Unix backup utility
o Pass number for fsck: used when the -A option is specified:
– A 1 should be entered for the root filesystem and instructs fsck to check
that filesystem first.
– A 2 instructs fsck to check corresponding filesystems after those with a 1.
– A 0 instructs fsck not to check the filesystem.
Control Filesystem Mounting and Unmounting
 Managing the Filesystem Table
 The /etc/fstab file:
Control Filesystem Mounting and Unmounting
 Mounting Filesystems
 Filesystems are mounted using the mount command
 At boot time, those filesystems with a nonzero pass number in
/etc/fstab are checked and automatically mounted
Control Filesystem Mounting and Unmounting
 Mounting Filesystems
 Filesystem types
o Ext2: The standard Linux filesystem.
o Ext3: A journaling filesystem that is backward-compatible with ext2
o Msdos: The MS-DOS FAT filesystem, limited to “8.3” filenames (eight
characters, a dot, and a three-character extension).
o Ntfs: The native MS Windows partition since Windows 2000
o Iso9660: The CD-ROM format
o Nfs: Remote servers.
o Swap: Swap partitions
Control Filesystem Mounting and Unmounting
 Mounting Filesystems
Control Filesystem Mounting and Unmounting
 Unmounting Filesystems
 Filesystems can be unmounted using the umount command
Set and View Disk Quotas
 Which allow you to assign a limit to the amount of space
individual users or groups have on a filesystem
 Quota Limits
 Per-user hard limit: Once the user reaches his quota limit, he
won’t be allowed to write files to the disk
 Per-user soft limit: The soft limit implements a sort of warning
zone, instructing the user to clean up while still allowing her to work
 Per-group hard limit
 Per-group soft limit
 Grace period: Once a soft limit is reached, the user or group
enters the grace period. After the grace period expires, the soft limit
becomes a hard limit until enough files are deleted to eliminate the
over-quota situation
Set and View Disk Quotas
 Enabling Quotas
 Note that you may enable user quotas only, group quotas only, or
both, as your needs dictate
Set and View Disk Quotas
 Enabling Quotas
Set and View Disk Quotas
 Quota Command
 Displays quota limits on user or group
Set and View Disk Quotas
 quotaon Command
 Enable previously configured disk quotas on one or more
filesystems
Set and View Disk Quotas
 quotaoff Command
 Disables disk quotas on one or more filesystems
Set and View Disk Quotas
 quotacheck Command
 Examine filesystems and compile quota databases
Set and View Disk Quotas
 edquota Command
 Modify user or group quotas
Set and View Disk Quotas
 repquota Command
 Used to report on the status of quotas
Manage File Permissions and Ownership
 Linux Access Control
 A file’s mode controls access by these three classes of users:
Manage File Permissions and Ownership
 Linux Access Control
 SUID:
o The SUID property is for executable files only and has no effect on directories.
o This offers anyone temporary root access for the duration of the command.
o An example of an SUID program is passwd. This command needs special
access to manipulate the shadow password file (/etc/shadow), and runs as user
root
o On the other hand,SUID can be a security risk if access is granted unwisely. For
example, consider a situation where /bin/vi was set to SUID mode. Any user
would be able to edit any file on the system!
Manage File Permissions and Ownership
 Linux Access Control
 SGID
o The SGID property works the same way as SUID for executable files
o The SGID property has a special effect on directories
o When SGID is set on a directory, new files created within that directory are
assigned the same group ownership as the directory itself
o For example, if directory /home/fin has the group finance and has SGID
enabled, then all files under /home/fin are created with group ownership of
finance, regardless of the creator’s group. T
 Sticky
o When applied to a directory, the sticky bit offers additional security for files
within the directory.
o When used in a team environment, the sticky bit allows groups to create
and modify files but allows only file owners the privilege of deleting or
renaming them
o Example: the /tmp directory on Linux systems usually has the sticky bit
set, to allow any user to write to it, but allow only the file owner to delete
files or directories
Manage File Permissions and Ownership
 The mode
Manage File Permissions and Ownership
 The mode
Manage File Permissions and Ownership
 The mode string
 Instead of adding three more bits to the left of rwxr-xr-x, the SUID
permission is indicated in the string by changing the user execute
position from x to s
 The sticky permission is indicated by replacing x in the other
execute position with t
 For example, an executable program with mode 6755 would have
the following equivalent symbolic mode:
 A directory with mode 1774 would have this equivalent string:
Manage File Permissions and Ownership
 Setting Access Modes
 When new files are created, the protection bits are set according to
the user’s default setting. That default is established using the
umask command
 Without a value, umask reports the current value:
 To save umask value: /etc/bashrc
Manage File Permissions and Ownership
 Changing access modes
 Access modes can be changed with the chmod command, which
accepts either octal or symbolic access mode specifications
Manage File Permissions and Ownership
 Changing access modes
 Examples:
Manage File Permissions and Ownership
 Changing access modes
 chmod command:
Manage File Permissions and Ownership
 Changing access modes
 chmod command:
Manage File Permissions and Ownership
 Changing access modes
 chown command:
Manage File Permissions and Ownership
 Changing access modes
 chown command:
Manage File Permissions and Ownership
 Changing access modes
 chgrp command: Change the group owner of files to groupowner
Manage File Permissions and Ownership
 Setting Up a Workgroup Directory
Manage File Permissions and Ownership
Create and Change Hard and Symbolic Links
 Often
it is useful to have access to a file in multiple
locations in a filesystem. To avoid creating multiple copies
of the file, use a link
 Symbolic links
 A symbolic link is simply a pointer to another filename
 Symbolic links can point to other filesystems, both local and
remote, and they can point to directories.
 The ls -l command clearly lists them as links by displaying a special
“l”
 Hard links
Create and Change Hard and Symbolic Links
 Hard links:
 A hard link is not really a link at all; it is simply another directory
entry for an existing file.
 The two directory entries have different names but point to the
same inode and thus to the same actual data, ownership,
permissions, and so on.
 when you delete a file, you are only removing a directory entry (in
other words, one hard link to the file)
 In fact, a file is not deleted until its link count drops to zero
 Hard links have two important limitations
o First, because all of the links to a file point to the same inode,
any hard links must by definition reside on the same filesystem
o Second, hard links cannot point to directories
Create and Change Hard and Symbolic Links
 Why Links?
 To see an example of the use of links in practice:
 Inside init.d are scripts to start and stop many of the services on
your system, such as httpd, crond, and syslogd. Some of these files
are to be executed with a start argument, while others are run with
a stop argument, depending on the runlevel of your system
 These directories are named rc0.d through rc6.d, one for each
runlevel. Each of the runlevel-specific directories contains several
links
Create and Change Hard and Symbolic Links
 Why Links?
 All of these links point back to the scripts in init.d as indicated by
the arrows (->) after the script name.
 Links allow us to:
o Make changes to the original file once. References to the links
will yield the updated contents as long as the filename doesn’t
change
o Avoid wasting disk space by having multiple copies of the same
file in different places
Create and Change Hard and Symbolic Links
 ln command: used to create symbolic and hard links
Create and Change Hard and Symbolic Links
 ln command: used to create symbolic and hard links
Create and Change Hard and Symbolic Links
 Preserving links
 Programs such as tar and cp contain options that control whether
symbolic links are followed during operation
 When a symbolic link is encountered with cp, the contents of the file
to which the link points are copied, unless the -d option is specified
Create and Change Hard and Symbolic Links
 Finding links to a file
 Finding the file pointed to by a symbolic link is simple. The ls -l
command displays a convenient pointer notation
 The -lname option to the find utility locates them for you by
searching for symbolic links containing the original filename
 Since hard links aren’t really links but duplicate directory entries,
you can locate them by searching directory entries for the inode.
Find System Files and Place Files in the
Correct Location
 which command:
Find System Files and Place Files in the
Correct Location
 find command:
Find System Files and Place Files in the
Correct Location
 locate command:
Find System Files and Place Files in the
Correct Location
 whereis command:
Find System Files and Place Files in the
Correct Location
 type command:
Download