DIVECES LINUX FILESYSTEMS
Linux Professional Institute 1 AND THE FILESYSTEM
HIERACHY
Content
1. Devices, Linux FileSystems
and FileSystem Hierachy
Standard
TEACH A COURSE 2
Objectives
Create Partitions and Filesystems Manage File Permissions and Ownership
◦ Disk Drives Under Linux ◦ Linux Access Control
◦ Setting Access Modes
Maintain the Integrity of Filesystems
◦ Monitoring Free Disk Space and Inodes ◦ Setting Up a Workgroup Directory
◦ Monitoring Disk Usage
Create and Change Hard and Symbolic Links
◦ Modifying a Filesystem
◦ Why Links?
◦ Checking and Repairing Filesystems
Control Filesystem Mounting and Unmounting Find System Files and Place Files in the Correct
◦ Managing the Filesystem Table Location
◦ Mounting Filesystems ◦ Datatypes
◦ Unmounting Filesystems ◦ The root Filesystem
Set and View Disk Quotas ◦ Locating Files
◦ Quota Limits
◦ Quota Commands
◦ Enabling Quotas
LINUX PROFESSIONAL INSTITUTE 1 3
Create Partitions and Filesystems
➢Disk Drives Under Linux
◦ Linux supports many types of disk devices and formats:
- Disk Types: Any SCSI or IDE hard disk will work with Linux, as will floppy disks, CD-ROMs, CD-Rs, USB
flash drives, and other types of removable media
- 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
LINUX PROFESSIONAL INSTITUTE 1 4
Create Partitions and Filesystems
➢ Disk Drives Under Linux
◦ IDE Disk:
- 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)
LINUX PROFESSIONAL INSTITUTE 1 5
Create Partitions and Filesystems
➢ Disk Drives Under Linux
◦ SCSI Disk:
- 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
LINUX PROFESSIONAL INSTITUTE 1 6
Create Partitions and Filesystems
➢ Disk Drives Under Linux
◦ Disk partitions
◦ Almost every operating system supports a system for dividing a disk into logical devices, called partitions
◦ Partition Type:
- Primary partitions
- Extended partitions
- Logical partitions
LINUX PROFESSIONAL INSTITUTE 1 7
Create Partitions and Filesystems
➢Disk Drives Under Linux
◦ The root filesystem and mount points
◦ 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
◦ 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
◦ swap partition is used for a Linux system to enable virtual memory
LINUX PROFESSIONAL INSTITUTE 1 8
Create Partitions and Filesystems
➢ Disk Drives Under Linux
◦ The root filesystem and mount points
- Examples: the disk partitions for an IDE-based system with two physical disks (40 GB and 200 GB).
LINUX PROFESSIONAL INSTITUTE 1 9
Create Partitions and Filesystems
➢ Disk Drives Under Linux
◦ Managing partitions
◦ 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 after mastering fdisk is cfdisk
LINUX PROFESSIONAL INSTITUTE 1 10
Create Partitions and Filesystems
➢ Disk Drives Under Linux
◦ fdisk command:
◦ Manipulate or display the partition table for device using a command-driven interactive text interface
◦ 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
LINUX PROFESSIONAL INSTITUTE 1 11
Create Partitions and Filesystems
➢ Disk Drives Under Linux
◦ fdisk command:
LINUX PROFESSIONAL INSTITUTE 1 12
Create Partitions and Filesystems
➢ Disk Drives Under Linux
◦ fdisk command:
LINUX PROFESSIONAL INSTITUTE 1 13
Create Partitions and Filesystems
➢Disk Drives Under Linux
➢fdisk command:
LINUX PROFESSIONAL INSTITUTE 1 14
Create Partitions and Filesystems
➢ Disk Drives Under Linux
◦ Creating filesystems:
◦ Once a disk is partitioned, filesystems may be created in those partitions using the mkfs utility
LINUX PROFESSIONAL INSTITUTE 1 15
Create Partitions and Filesystems
➢Disk Drives Under Linux
◦ mkfs utility
LINUX PROFESSIONAL INSTITUTE 1 16
Create Partitions and Filesystems
➢ Disk Drives Under Linux
◦ Creating swap partitions
◦ The command to create a swap partition is mkswap
LINUX PROFESSIONAL INSTITUTE 1 17
Maintain the Integrity of Filesystems
➢ Monitoring Free Disk Space and Inodes
◦ Inodes
◦ Every filesystem contains a finite number of inodes, set when the filesystem is created
◦ This number is also the maximum number of files that the filesystem can accommodate
◦ 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
◦ The df command gives you the information you need on the status of both disk space utilization and inode
utilization.
LINUX PROFESSIONAL INSTITUTE 1 18
Maintain the Integrity of Filesystems
➢ Monitoring Free Disk Space and Inodes
◦ df command:
LINUX PROFESSIONAL INSTITUTE 1 19
Maintain the Integrity of Filesystems
➢ Monitoring Free Disk Space and Inodes
◦ df command:
LINUX PROFESSIONAL INSTITUTE 1 20
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
LINUX PROFESSIONAL INSTITUTE 1 21
Maintain the Integrity of Filesystems
➢ Monitoring Disk Usage
◦ du command:
LINUX PROFESSIONAL INSTITUTE 1 22
Maintain the Integrity of Filesystems
➢Modifying a Filesystem
◦ Using tune2fs command
LINUX PROFESSIONAL INSTITUTE 1 23
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.
LINUX PROFESSIONAL INSTITUTE 1 24
Maintain the Integrity of Filesystems
➢ Checking and Repairing Filesystems
◦ fsck command
LINUX PROFESSIONAL INSTITUTE 1 25
Maintain the Integrity of Filesystems
➢ Checking and Repairing Filesystems
◦ fsck command
LINUX PROFESSIONAL INSTITUTE 1 26
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:
◦ Device: specifies the device file of the partition holding the filesystem
◦ Mount point: specifies the directory on which the filesystem is to be mounted
◦ Filesystem type: may include ext2 filesystems,swap, nfs, iso9660 (CD-ROM), and others
◦ Mount options: This field contains a comma-separated list of options. Some options are specific
to particular filesystem types. Options are described later in this Objective.
◦ Dump frequency: The dump program, a standard Unix backup utility
◦ 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.
LINUX PROFESSIONAL INSTITUTE 1 27
Control Filesystem Mounting and Unmounting
Table structure
The table itself is a 6 column structure, where each column designates a specific parameter and must be set up in the correct
order. The columns of the table are as follows from left to right:
•Device: usually the given name or UUID of the mounted device (sda1/sda2/etc).
•Mount Point: designates the directory where the device is/will be mounted.
•File System Type: nothing trick here, shows the type of filesystem in use.
•Options: lists any active mount options. If using multiple options they must be separated by commas.
•Backup Operation: (the first digit) this is a binary system where 1 = dump utility backup of a partition. 0 = no backup. This is an
outdated backup method and should NOT be used.
•File System Check Order: (second digit) Here we can see three possible outcomes. 0 means that fsck will not check the
filesystem. Numbers higher than this represent the check order. The root filesystem should be set to 1 and other partitions set
to 2.
TEACH A COURSE 28
Control Filesystem Mounting and Unmounting
1.auto/noauto: controls whether the partition is mounted automatically on boot (or not).
2.exec/noexec: controls whether or not the partition can execute binaries. In the name of security, this
is usually set to noexec.
3.ro/rw: controls read and write privileges - ro = read-only, where rw= read-write.
4.nouser/user: controls whether or not the user has mounting privileges. This defaults to noexec for all
user accounts.
5. sync và async: This is the option for reading and writing to the file system. sync means all is done at
the same time, this option is usually applied to floppy disks
6.defaults: rw, suid, dev, exec, auto, nouser, and async
TEACH A COURSE 29
Control Filesystem Mounting and Unmounting
➢Managing the Filesystem Table
◦ The /etc/fstab file:
◦ blkid
LINUX PROFESSIONAL INSTITUTE 1 30
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
LINUX PROFESSIONAL INSTITUTE 1 31
Control Filesystem Mounting and Unmounting
➢ Mounting Filesystems
◦ Filesystem types
◦ Ext2: The standard Linux filesystem.
◦ Ext3: A journaling filesystem that is backward-compatible with ext2
◦ Msdos: The MS-DOS FAT filesystem, limited to “8.3” filenames (eight characters, a dot, and a three-character
extension).
◦ Ntfs: The native MS Windows partition since Windows 2000
◦ Iso9660: The CD-ROM format
◦ Nfs: Remote servers.
◦ Swap: Swap partitions
LINUX PROFESSIONAL INSTITUTE 1 32
Control Filesystem Mounting and Unmounting
➢Mounting Filesystems
LINUX PROFESSIONAL INSTITUTE 1 33
Control Filesystem Mounting and Unmounting
➢ Unmounting Filesystems
◦ Filesystems can be unmounted
using the umount command
LINUX PROFESSIONAL INSTITUTE 1 34
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
LINUX PROFESSIONAL INSTITUTE 1 35
Set and View Disk Quotas
➢ Quota Command
◦ Displays quota limits on user or group
LINUX PROFESSIONAL INSTITUTE 1 36
Set and View Disk Quotas
➢ quotaon Command
◦ Enable previously configured disk quotas on one or more filesystems
LINUX PROFESSIONAL INSTITUTE 1 37
Set and View Disk Quotas
➢quotaoff Command
◦ Disables disk quotas on one or more filesystems
LINUX PROFESSIONAL INSTITUTE 1 38
Set and View Disk Quotas
➢ quotacheck Command
◦ Examine filesystems and compile quota databases
LINUX PROFESSIONAL INSTITUTE 1 39
Set and View Disk Quotas
➢ edquota Command
◦ Modify user or group quotas
LINUX PROFESSIONAL INSTITUTE 1 40
Set and View Disk Quotas
➢ repquota Command
◦ Used to report on the status of quotas
LINUX PROFESSIONAL INSTITUTE 1 41
Set and View Disk Quotas
➢Enabling Quotas
◦ Note that you may enable user quotas only, group quotas only, or both, as your needs dictate
LINUX PROFESSIONAL INSTITUTE 1 42
Set and View Disk Quotas
➢Enabling Quotas
LINUX PROFESSIONAL INSTITUTE 1 43
Manage File Permissions and Ownership
➢ Linux Access Control
◦ A file’s mode controls access by these three classes of users:
LINUX PROFESSIONAL INSTITUTE 1 44
Manage File Permissions and Ownership
➢ The mode
LINUX PROFESSIONAL INSTITUTE 1 45
Manage File Permissions and Ownership
➢ ls -al
LINUX PROFESSIONAL INSTITUTE 1 46
Manage File Permissions and Ownership
➢ The mode
LINUX PROFESSIONAL INSTITUTE 1 47
Manage File Permissions and Ownership
➢ Linux Access Control
◦ SUID:
◦ The SUID property is for executable files only and has no effect on directories.
◦ This offers anyone temporary root access for the duration of the command.
◦ 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
◦ 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!
LINUX PROFESSIONAL INSTITUTE 1 48
Manage File Permissions and Ownership
➢ SUID
LINUX PROFESSIONAL INSTITUTE 1 49
Manage File Permissions and Ownership
➢SGID
LINUX PROFESSIONAL INSTITUTE 1 50
Manage File Permissions and Ownership
➢ Sticky bit
LINUX PROFESSIONAL INSTITUTE 1 51
Manage File Permissions and Ownership
➢ Linux Access Control
◦ SGID
◦ The SGID property works the same way as SUID for executable files
◦ The SGID property has a special effect on directories
◦ When SGID is set on a directory, new files created within that directory are assigned the same group ownership as the
directory itself
◦ 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
◦ When applied to a directory, the sticky bit offers additional security for files within the directory.
◦ 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
◦ 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
LINUX PROFESSIONAL INSTITUTE 1 52
Manage File Permissions and Ownership
➢ The mode
LINUX PROFESSIONAL INSTITUTE 1 53
Manage File Permissions and Ownership
➢ Umask
Bash permission của file: 666 = 110110110
umask: 022 = 000010010
NOT (umask) = NOT (000010010 ) = 111101101
110 110 110 AND 111 101 101 = 110 100 100 = 644.
LINUX PROFESSIONAL INSTITUTE 1 54
Manage File Permissions and Ownership
Ý nghĩa các cột trong file :
▪ 1 – Tên user ( login name )
▪ 2 – Mật khẩu group đã được mã hóa ( vì có file /etc/shadow ) nên mặc định ở
đây là x
▪ 3 – User ID ( uid )
▪ 4 – Group ID ( gid )
▪ 5 – Tên mô tả người sử dụng ( comment )
▪ 6 – Thư mục home của user ( thường là /home/user_name )
▪ 7 – Loại shell sẽ hoạt động khi user login , thường là /bin/bash
LINUX PROFESSIONAL INSTITUTE 1 55
Manage File Permissions and Ownership
Ý nghĩa các cột :
▪ 1 – Tên user , giống với trong /etc/passwd ( login name )
▪ 2 – Mật khẩu đã được mã hóa
▪ Để trống ( empty ) – không có mật khẩu
▪ * – tài khoản bị tạm ngưng ( disable )
▪ 3 – Số ngày kể từ lần cuối thay đổi mật khẩu ( tính từ 1/1/1970 )
▪ 4 – Số ngày trước khi có thể thay đổi mật khẩu . Giá trị 0 có nghĩa có thể thay đổi bất cứ lúc nào .
▪ 5 – Số ngày mật khẩu có giá trị . 99999 có nghĩa mật khẩu có giá trị vô thời hạn .
▪ 6 – Số ngày cảnh báo user trước khi mật khẩu hết hạn
▪ 7 – Số ngày sau khi mật khẩu hết hạn tài khoản sẽ bị khóa . Thường có giá trị là 7 ( 1 tuần )
▪ 8 – Số ngày kể từ khi tài khoản bị khóa ( tính từ 1/1/1970 )
LINUX PROFESSIONAL INSTITUTE 1 56
Thank You!
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas porttitor congue massa. Fusce posuere,
magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna.