Document Details

PainlessSerpentine2858

Uploaded by PainlessSerpentine2858

Vietnam National University Ho Chi Minh City International University

Le Hai Duong

Tags

filesystem Linux system administration computer science

Summary

This document provides notes on system and network administration, focusing on the filesystem. It details topics such as pathnames, mounting, organization of the file tree, and various file types. It also describes access control lists, devices, and sockets.

Full Transcript

System & Network Administration The Filesystem Le Hai Duong, PhD. ([email protected]) Outline Pathnames Filesystem mounting and unmouting Organization of the file tree File types File attributes Access control lists Overview Overview (conti.) The basic purpose of a...

System & Network Administration The Filesystem Le Hai Duong, PhD. ([email protected]) Outline Pathnames Filesystem mounting and unmouting Organization of the file tree File types File attributes Access control lists Overview Overview (conti.) The basic purpose of a filesystem is to represent and organize the system’s storage resources Programmers, for convenience, map other type of objects into the filesystem namespace → advantages: consistent programming interface, easy access from the shell → disadvantages: filesystem implementations suggestive of Frankenstein’s monster Overview (conti.) Pathnames Single unified hierarchy that starts at the directory / (root directory) Windows uses the concept of partition-specific namespaces Pathname = the list of directories that must be traversed to locate a particular file plus that file’s filename Pathnames can be either absolute or relative Relative pathnames are interpreted starting at the current directory The filesystem can be arbitrarily deep Each component of a pathname (that is, each directory) must have a name no more than 255 characters long Total path length = 4,095 bytes on Linux Filesystem mounting and unmounting The filesystem is composed of smaller chunks —also called filesystems — each of which consists of one directory and its subdirectories and files Some filesystems live on disk partitions or on logical volumes backed by physical disks Filesystems can be anything that obeys the proper API: a network file server, a kernel component, a memory-based disk emulator, etc. mount maps a directory within the existing file tree, called the mount point, to the root of the newly attached filesystem /etc/fstab file lists filesystems that are normally mounted on the system umount detachs filesystems Show all the UUID of filesystems Check processes hold references to filesystem Organization of file tree Files are divided by function The root filesystem includes at least the root directory and a minimal set of files and subdirectories Organization of file tree (conti.) OS kernel usually lives under /boot /etc for critical system and configuration files /sbin and /bin for important utilities /tmp for temporary files /dev for devices /lib or /lib64 for shared library files /usr is where most standard-but-not-system-critical programs are kept + manuals + libraries (/usr/lib) /var houses spool directories, log files, accounting information, and various other items that grow or change rapidly and that vary on each host Organization of file tree (conti.) File types Regular files Directories Character device files Block device files Local domain sockets Named pipes (FIFOs) Symbolic links File types (conti.) The first character of the ls output encodes the type Regular files Consist of a series of bytes Filesystems impose no structure on their contents Text files, data files, executable programs, and shared libraries are all stored as regular files Both sequential access and random access are allowed Directories Contains named references to other files Create directories with mkdir and delete them with rmdir if they are empty “.” and “..” refer to the directory itself and to its parent directory Hard links A file’s name is stored within its parent directory, not with the file itself More than one directory can refer to a file at one time, and the references can have different names These additional references (“links,” or “hard links”) are synonymous with the original file; all links to the file are equivalent The filesystem maintains a count of the number of links that point to each file and does not release the file’s data blocks until its last link has been deleted Hard links cannot cross filesystem boundaries Create hard links with ln and remove them with rm Example of hard link Character and block device files Kernel’s driver software takes care of the messy details of managing each device → kernel is relatively abstract and hardware-independent Device drivers present a standard communication interface that looks like a regular file → device files Device files are just rendezvous points that communicate with drivers Device files are characterized by two numbers, called the major and minor device numbers ○ major device number → which driver the file refers to ○ minor device number → which physical unit to address E.g. The first serial port (/dev/tty0) would have major device number 4 and minor device number 0 Local domain sockets Sockets are connections between processes that allow them 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 E.g., Syslog and the X Window System Created with the socket system call and removed with the rm command or the unlink system call once they have no more users Named pipes Allow communication between two processes running on the same host; also known as “FIFO files” Create named pipes with mknod and remove them with rm Named pipes and local domain sockets serve similar purposes, and the fact that both exist is essentially a historical artifact Symbolic links A symbolic or “soft” link points to a file by name Symbolic links are distinct from the files they point to Create symbolic links with ln -s and remove them with rm Can refer to files on other filesystems or to nonexistent files File attributes Every file has a set of nine permission bits that control who can read, write, and execute the contents of the file Three other bits that primarily affect the operation of executable programs, these bits constitute the file’s “mode.” File’s owner and the superuser can modify the twelve mode bits with the chmod (change mode) command The permission bits Only the most specific permissions apply For a regular file: ○ Read bit allows the file to be opened and read ○ Write bit allows the contents of the file to be modified or truncated BUT the ability to delete or rename the file is controlled by the permissions on its parent directory ○ Execute bit allows the file to be executed; two types of executable files: binaries and scripts For a directory: ○ Execute bit (“search” or “scan” bit ) allows the directory to be entered or passed through as a pathname is evaluated, but not to have its contents listed ○ Combination of read and execute bits allows the contents of the directory to be listed ○ Combination of write and execute bits allows files to be created, deleted, and renamed files within the directory The setuid and setgid bits The bits with octal values 4000 and 2000 are the setuid and setgid bits When set on executable files, these bits allow programs to access files and processes that would otherwise be off-limits to the user that runs them When set on a directory, the setgid bit causes newly created files within the directory to take on the group ownership of the directory rather than the default group of the user that created the file → makes it easier to share a directory of files among several users The sticky bit Has octal value 1000 Meaning of the sticky bit is now obsolete and modern systems silently ignore the sticky bit when it’s set on regular files If the sticky bit is set on a directory, the filesystem won’t allow you to delete or rename a file unless you are the owner of the directory, the owner of the file, or the superuser ls: list and inspect files Can inspect link count, owner, group, mode, size, last access time, last modification time, and type with ls -l (or ls -ld for a directory) All directories have at least two hard links: the link from the parent directory (..) and the link from the special file called. inside the directory itself. ls output is slightly different for a device file; instead of a size in bytes, ls shows the major and minor device numbers Other ls options chmod: change permissions Only the owner of the file and the superuser can change a file’s permissions Current versions accept both octal notation and a mnemonic syntax ○ Octal: chmod 711 myprog ○ Mnemonic combines a set of targets (u, g, or o for user, group, other, or a for all three) with an operator (+, -, = to add, remove, or set) and a set of permissions chmod: change permissions (conti.) Copying modes from an existing file chmod --reference=filea fileb -R option for recursively updates the file permissions within a directory chown and chgrp: change ownership and group To change a file’s group, you must either be the superuser or be the owner of the file and belong to the group you’re changing to chown is now a privileged operation Use recursive -R flag to change the settings of a directory and all the files underneath it chown can change both the owner and group of a file at once with the syntax umask: assign default permissions umask command sets the shell’s own umask attribute → which is then inherited by commands that you run The umask is specified as a three-digit octal value that represents the permissions to take away E.g., umask 027 allows all permissions for the owner but forbids write permission to the group and allows no permissions for anyone else

Use Quizgecko on...
Browser
Browser