Week 10 - The Linux Filesystem Flashcards
(42 cards)
File system
– The way files are stored and organized to:
* Simplify access to data
* Help OS keep track of how files are organized and how available space is managed on a disk
– Consists of disk partitions
* Disk partitions allow better organization and productivity, data security, data backup, and more
Linux File system
Hierarchical directory structure descending from root
directory (/)
– All partitions are contained under root directory
– All objects, such as devices and directories, treated as files
– Treats each device, such as a monitor, keyboard, or hard drive, as a single file and stores it in /dev directory
Creating links
Use ln command
Inode
Inode
Data structure that stores all information about a file except the actual data and filename
* Stores Filesystem Attributes such as:
– Metadata (create time, modify time)
– Owner and permission data
– Disk block location of data
Inode number
Like an address
References an entry in inode table
– List of inodes for all files on a Linux partition
– Table entry points to the data’s location on the disk
Command to view a file’s inode number
ls -il
Hard links
Files that point to data on hard drive
Create a file (e.g. touch)
– Automatically linked to the actual data stored on a partition
– Assigned an inode number referencing this data
Create a hard link
Create a hard link:
– ln existingFile hardLinkToExisingFile
– > ln notes ~/Math
- Delete files
– Data isn’t deleted until the last link is deleted
Symbolic (Soft) links
Symbolic links
– Also called soft links
– Special types of files that point to other files instead of pointing to data on the hard drive
– Do not share the same inode number
* Benefit of creating a symbolic link
– Link files that are on separate partitions or even different computers
Storage access
File Space = Collection of Storage Devices
* Storage Devices
– Hard Disks
– Optical Disks
– Solid State Drives
– USB Drives
– Tape Drives
- File Space exists two levels of abstraction–
- Logical: Partitions, Directories, Files
–Physical: File Systems, Disk Blocks, Pointers
Use file space to store executable programs and data files - two operations Read or write
Disk storage and blocks
To store a file, it is decomposed into fixed size blocks
Each block is then stored at a disk location
Kernel must manage distribution of files to blocks in three ways
1. Given a file and block: map that block onto a physical location on storage medium
- Direct the disk drive to access that particular block through (via SSD electrical circuits, or via read/write head of HD)
- Maintain free file space (available blocks), including the return of file blocks once a file has been deleted
How does the Kernel locate a particular block of a disk?
File systems use an indexing scheme
- Windows used File Allocation Table (FAT)
- Upgraded to NFTS (New Technology File System)
In Linux, indexing is handled through inode data structure
Inode structure
Typically, an inode will contain 15 pointers
– 12 Direct pointers
– 1 indirect pointer
– 1 double indirect pointer
– 1 triple indirect pointer
- Indirect pointers point to Indirect Block
- Disk block stores ~1-8Kb
– If our file uses 500 blocks: 500 * 8kb = 4000KB ( 4MB)
If one pointer is 8 bytes, how many can we fit inside an Indirect Block
Number Pointers = Size Of Indirect Block / Size Of Pointer
Number Pointers = 4KB / 8 B
Number Pointer = 4096B / 8B
Number Pointers = 512
Inodes and Files
The system admin will rarely (if ever) have to deal
directly with inodes or pointers
* The Linux filesystem commands operate at a higher level of abstraction
– Admin or Users Operate on Files and Directories
– Device drivers must deal with inodes and the location of disk blocks
Directories
Directory does not store content like files
File = Collection of data blocks on File Content
Directory = Collection of data blocks on Directory Structure
– Directory data blocks are different
– Blocks contain lists of names and inode numbers
Filesystem
can be thought of as a type of database of files and directories
– Supplies structure to transform simple block device into sophisticated hierarchy of files and sub directories that users can understand
Filesystem types
Linus supports many file systems
– Disk file system
* Mounted on a local computer
– Network File System (NFS)
* Mounted on a different partition of a local computer or on a remote computer
Disk Based Filesystems
– Native: ext2, ext3, ext4, btrfs
– Foreign: FAT, NTFS, HFS+
– Universal: ISO 9660 (CDROM)
- Network Based Filesystems
– Network File System (NFS)
Virtual File System (VFS)
– Many types of Filesystems
– VFS ensures that all filesystem implementations support a standard interface so that user applications can access files in the same manner
Partition
Logical Divisions of Hard Drive
– Disk drives make up Linux Storage space
* Each disk drive can be divided in partitions
* Each partition will contain an independent filesystem
* Multiple partitions can be placed on single physical disk
- Terminology
– Storage Space = Collection of storage devices
– Filesystem = Block Structure for a specific Partition
Why use partitions?
– Multiple OS’s
– Storing different file systems
– Limiting data growth
* E.g /home directory on different partition to OS file and programs files
* If /home runs out of space, the operating system can still create update files, create logs, install programs etc.
Partition table
Used to describe partitions on that disk
Partition Table is store in Master Boot Record
What can partition utilities be used for?
– Create a partition table
– Add a partition
– Create a file system on a disk
– For example: fdisk
fdisk
– Command line tool
– Can create and modify the partition table provided by Linux
– Can be run only as root
– Can access IDE, SCSI and SATA hard drives
Options for fdisk command
-a Toggles bootable flag, which indicated whether a partition is bootable
-d Deletes a partition
-l Lists all partition types and their corresponding ID’s
-m displays menu of all options to use with fdisk
-n adds a partition
-p displays a partition table
-q exits fdisk without saving changes
-t changes partition’s system ID
-u Toggles displaying entry units to sectors or cylinders
-v verifies a partition table
-w exits fdisk and saves changes