RH033 Unit16 The Linux Filesystem In-Depth

Ojectives
Upon completion of this unit, you should be able to:
  • Describe how filesystem information is organized
  • Describe the function of dentries and inodes
  • Describe how cp, mv and rm work at the inode level
  • Create symbolic links and hard links
  • Access removable media
  • Create archives using tar and gzip
Partitions and Filesystems
1) Disk drives are divided into partitions
2) Partitions are formatted with filesystems, allowing users to store data
  • Default filesystems: ext3, the Third Extended Linux Filesystem
  • Other common filesystems:
    • ext2 and msdos (typically used for floppies)
    • iso9660 (typically used for CDs)
    • GFS and GFS2 (typically used for SANs)
Inodes
1) An inode table contains a list of all files in an ext2 or ext3 filesystem
2) An inode (index node) is an entry in the table, containing information of a file (the metadata), including:
  • file type, permissions, UID, GID
  • the link count (count of path names pointing to this file)
  • the file’s size and various stamps
  • pointers to the file’s data blocks on disk
  • other data about the file
Directories
1) The computer’s reference for a file is the inode number
2) The human way to reference a file is by file name
3) A directory is a mapping between the human name for the file and the computer’s inode number
cp and inodes
The cp command:
  • Allocate a free inode number, placing a new entry in the inode table
  • Creates a dentry in the directory, associating a name with the inode number
  • Copies data into the new file
mv and inodes
1) If the destination of the mv command is on the same file system as the source, the mv command:
  • Creates a new directory entry with the new file name
  • Deletes the old directory entry with the old file name
2) Has no imact on the inode table (except for a time stamp) or the location of data on the disk: no data is moved!
3) If the destination is a different filesystem, mv acts as a copy and remove
rm and inodes
1) The rm command:
  • Decrements the link count, thus freeing the inode number to be reused
  • Places data blocks on the free list
  • Removes the directory entry
2) Date is not actually removed, but will be overwritten when the data blocks are used by another file
Hard Links
1) A hard link adds an additional pathname to reference a single file
  • One physical file on the filesystem
  • Each directory references the same inode number
  • Increments the link count
    • The rm command decrements the link count
    • File exists as long as at least one link remains
    • When the link account is zero, the file is removed
  • Cannot span drives or partitions
2) Syntax: ln filename [linkname]
Symbolic (or Soft) Links
1) A symbolic link points to another file
  • ls �Cl displays the link name and the referenced file
  • File type: l for symbolic link
  • The content of a symbolic link is the name of the file that is references
2) Syntax: ln �Cs filename linkname
The Seven Fundamental Filetypes
ls �Cl symbol File Type
- regular file
d directory
l symbolic link
b block special file
c character special file
p named pipe
s socket
   
Checking Free Space
1) df �C Reports disk space usage
  • Reports total kilobytes, kilobytes used, kilobytes free per file system
  • -h and �CH display sizes in easier to read unit
2) du �C Reports disk space usage
  • Reports kilobytes used per directory
  • Includes subtotals for each subdirectory (-s option only reports single directory summary)
  • Also takes �Ch and �CH options
3) Applications �C> System Tools �C> Disk Usage Analyzer or baobab �C Reports disk space usage graphically
Removable Media
1) Mounting means making a foreign filesystem look like part of the main tree
2) Before accessing, media must be mounted
3) Before removing, media must be unmouted
4) By default, non-root users may only mount certain devices (cd, dvd, floppy, usb, etc)
5) Mountpoints are usually under /media
Mounting CDs and DVDs
1) Automatically mounted in Gnome/KDE
2) Otherwise, must be manually mouted
  • CD/DVD Reader �C mount /media/cdrom
  • CD/DVD Writer �C mount /media/cdrecorder
3) eject command unmounts and ejects the disk
Mounting USB Media
1) Detected by the kernel as SCSI devices
  • /dev/sdaX or /dev/sdbX or similar
2) Automatically mounted in Gnome/KDE
  • Icon created in computer window
  • Mounted under /media/Device ID �C Device ID is built into device by vendor
Mounting Floppy Disks
1) Must be manually mounted and unmounted
  • mount /media/floppy
  • umount /media/floppy
2) DOS floppies can be accessed with mtools
  • Mounts and unmounts device transparently
  • uses DOS naming conventions
    • mdir a:
    • mcopy /home/file.txt a:
Archiving Files and Compressing Archives
1) Archiving places many files into on target file
  • Easier to backup, store, and transfer
  • tar �C standard Linux archiving command
2) Archives are commonly compressed
  • Algorithm applied that compressed file
  • Umcompressing retores the original file
  • tar natively supports compression using gzip and gunzip, or bzip2 and bunzip2
Creating, Listing, and Extracting File Archives
1) Action arguments (one is required)
  • -c create an archive
  • -t list an archive
  • -x extracts files from an archive
2) Typically requried:
  • -f archviename name of file archive
3) Optional arguments:
  • -z use gzip compression
  • -j use bzip2 compression
  • -v be verbose
Creating File Archives: Other Tools
1) zip and unzip
  • Supports pkzip-compatible archives
2) file-roller
  • Graphical, multi-format archiving tool
End of Unit16
1) Questions and Answers
2) Summary
  • Linux filesystem structure
  • Using removable media
  • Using unformatted floppies
  • Archiving and compression

你可能感兴趣的:(linux,FileSystem,休闲,the,rhce)