Saturday, July 26, 2008

Linux Filesystem

Partitions
  • Formating is the operation that separating partition into several blocks which normally is 4 K big. Block is the least storage unit to sort files. If a file is 11k it would use 3 blocks which is 4 k*3=12 k.
Inodes
  • An inode is a data structure used in typical unix liked file system. There is an inode table which contains metadatas of all files and directories sorted on an ext2 or ext3 file system. Inode number equals the number of files and directories which sorted in the file system. So that the mix inode number is the max number of files and directories can be sorted in the system.
    I-
    number
    File TypePerm
    ission
    Link CountUIDGIDsizeTime Stamp......pointer
    1
    -
    644
    1
    500
    500




    2
    d
    755
    1
    0
    0




    I-number is the inode number. File type: "-" present file, "d" present directory. Link count record hard links. Time stamp include access time, modify time and change time. Modify time is the last time user change the file content. Change time is the last time the change of inode data. Pointer is the address of the blocks which sort the file of directory on the disk.
  • Directory is a mapping between the file name and the inode number. The kernel must search a directory looking for a particular filename and then convert the filename to the correct corresponding inode number if the name is found.
  • Filetypes
    • - regular file
    • d directory
    • l symbolic link
    • b block special file eg: /dev/sda1
    • c character special file eg: /dev/mice
    • p named pipe
    • s socket
Checking Free Space
  • df - reports disk space usage
    • non parameter - report total kilobytes, kilobytes used, kilobytes free per file system
    • -h - displays sizes in easier to read units
  • du - Reports disk space usage
    • Report kilobytes used per directory
    • Includes subtotals for each subdirectory
      • -s option only reports single directory summary
    • Also takes -h option
Mount removable dives (cd/dvd rom/writer, floppy, usb dives.)
  • floppy
    • mount /dev/fd0 /media/floppy/
    • format low level format fdformat /dec/fd0H1440 and high level format mkfs -t ext2 /dev/fd0 or mke2fs /dev/fd0 or mkfs -t vfat /dev/fd0
  • cd/dvd rom/writer
  • usb dives
Archive
tar - standard Linux archiving command. It will archive files with their inode table but do not compress files without specific parameter.
  • Syntax - tar [option] archive_name files
    • Create Archive - "tar cvf archive_name files..."
      • c - creates a new archive
      • v - produces verbose messages
      • f - archive_name is name of new file
    • Compress Archives
      • z - for gzip compression
      • j - for bzip2 compression
    • Inspect Archive
      • "tar tf archive_name" display a list of all files in the archive
      • "tar tvf archive_name" the v causes a long listing (like 'ls -l') of each file in the archive
    • Extract Archive - "tar xvf archive_name" The archive will be extracted in the current directory. So that extract command need execute in the target folder. Files maintain their hierarchy relative to the current directory.
    • Save the archive to removable use parameter M follow with the dives path
File Compression Utilities
  • gzip, gunzip - "*.gz" standard Linux compression utility which has over 75% compression for text files. gzip can only compress files. It will pop error when trying to compress directory
    Compress - "gzip filename" the compressed file will replace original file or "gzip -vc filename > archive_name.gz" -c indicate gzip keep the original file.
    Extract - "gunzip filename.gz"

  • bzip2, bunzip2 - "*.bz2"Newer Linux compress tool which generally perform better compress than gzip



No comments: