Linux disks and file systems

Source: Internet
Author: User

Linux disks and file systems
I. physical disk structure


1. disk: consists of disks. From the perspective of disk structure, the gray concentric circles in the circle in the figure are one track, and a straight line is drawn from the center of the circle. The track can be divided into several arc segments, the arc block on each track is called a sector. The sector is the smallest unit of the disk, usually 512 bytes.

2.

2. Disk Partition: Specify the start and end columns of the split area.
3. the disk partition tells the operating system that the disk is in this partition. For example, the block between A magnetic column and B MAGNETIC column, as A result, the operating system Moxibustion can know that he can specify A block for file read/write query operations.
4. Format: because the file attributes and permissions set by each operating system and the format of data storage are different, you need to format the file before using the hard disk.

Ii. File System
  1. Ext2 \ Ext3 \ Ext4 differences
    1. All three are in the file system format.
    2. Linux kernel officially supports the new file system Ext4 since 2.6.28
    3. Ext4 is the ultimate version of Ext3. It modifies some important data structures in Ext3.
    4. Compared with Ext3, Ext3 only adds a log system. Ext4 provides better performance and reliability, as well as richer features and larger file systems and files.
    5. Compared with the 16 TB file system and 2 TB File System Supported by Ext3, Ext4 supports 1 EB (1048576 TB 1 EB = 1024 Pb 1 Pb = TB) file systems and 16 TB files respectively.
    6. Ext3 only supports 32000 subdirectories, while Ext4 supports an unlimited number of subdirectories.
    7. Extents)
      1. Ext3 uses indirect block ing. When operating large files, the efficiency is extremely low. For example, a 25600 MB file requires data blocks to be created in Ext3 (each data block is 4 kb). In Ext3, each physical block must have a logical structure corresponding to it.
      2. Ext4 introduces the concept of Extents. Improve efficiency. Each Extents is a continuous set of data blocks. Ideally, the above file only needs an Extent to record the ing link.
    8. Multi-block allocation
      1. When writing data to the Ext3 file system, the Ext3 data block distributor can allocate only one 4 kb block each time. To write a 25600 MB file, it is necessary to call data blocks, ext4 supports allocating multiple data blocks at a time.
    9. Delay allocation
      1. The data block allocation policy of Ext3 is to allocate data as soon as possible. The allocation policy of Ext4 is to delay allocation as much as possible. The data block allocated is written to the disk only after the file is written in catch.
      2. This can optimize the data block allocation of the entire file and significantly improve the performance.
    10. Fast fsck (File System check)
      1. The old fsck will be slow because it wants to check all inode
      2. Ext4 returns inode tables to each group. Instead, it only checks the list of unused inode added to the inode in use and performs fsck.
    11. Log Verification
      1. Logs are the most common part and can easily lead to disk hardware faults. Restoring data from damaged logs will cause more data corruption.
      2. The Log check function of Ext4 can easily determine whether the log data is damaged, and combine the Log Mechanism of the past two phases into a segment to improve the performance.
      3. Two-phase log submission:
        1. The file system writes the specific content of the transaction to be executed to the log.
        2. File System Operations
        3. After the operation is successful, delete the specific transaction content from the log.
    12. Nojournaling Mode
      1. Ext4 allows you to disable logs so that users with special requirements can further improve performance.
    13. Online fragment Management
      1. Ext4 supports online fragment and provides the e4defrag tool for fragment of individual files or the entire file system.
    14. Inode-related features
      1. Ext4 supports a larger inode. Compared with the default inode size of 128 bytes in Ext3, Ext4 supports more extended features (such as the nanosecond timestamp or inode version) in inode ), default inode size: 256 bytes
    15. Permanent pre-allocation
      1. In order to ensure sufficient storage space for the downloaded files, P2P software often creates an empty file with the same size as the downloaded file in advance to avoid downloading failure due to insufficient disk space in the next few hours or days. Ext4 implements persistent pre-allocation at the file system level and provides corresponding APIs, which is more efficient than the implementation by the application software.
  2. Swap Introduction

    1. Using disk storage, the memory is insufficient and the "overflow" content is displayed.
    2. When the system's physical memory is insufficient, you need to release a portion of the physical memory for use by the currently running program.
    3. It is easy to be released objects: Programs that haven't been operated for a long time. Some released space is temporarily stored in the Swap space. The stored data will be restored from the Swap to the memory when the converted programs continue to run.
    4. Generally, you can set the Swap size according to the following rules:
      1. 4G physical memory, SWAP is set to 2 times the memory.
      2. 4-8 GB physical memory, SWAP is set to the same memory size
      3. 8 GB physical memory and 8 GB SWAP
      4. 64G-256G physical memory, SWAP is set to 16G
    5. When will the system use swap?

      1. In fact, swap space is not used until all the physical memory is fully consumed.

        [Root @ localhost ~] # Cat/proc/sys/vm/swappiness60 the default value is 60. When swappiness is set to 0, the physical memory is used to the maximum extent, and then the swap space is used. When swappiness is set to 100, the swap space is used actively, and the data in the memory is moved to the swap space in a timely manner.
      2. Modify swap parameters:

        1. Temporary Modification

          [Root @ localhost ~] # Sysctl vm. swappiness = 10vm. swappiness = 10 [root @ localhost ~] # Cat/proc/sys/vm/swappiness10 has been modified here, but it will change to 60 after the system is restarted.
        2. Permanent modification

          Add the following parameter to the/etc/sysctl. conf file: vm. swappiness = 10 operation: [root @ localhost ~] # Vim/etc/sysctl. conf write vm by I. swappiness = 10 Press esc to input wq (save and exit) and press ENTER
      3. Swap enabling and disabling

        Enable swapon-a to disable swapoff-
3. File System Operations
  1. Mount point

    1. Each file system has independent inode, block, superblock, and other information. This file system must be linked to the directory tree before it can be used. The action of combining the file system with the directory tree is called mounting.
    2. The mount point must be a directory, which is the entry to the file system.
    3. Mount command: mount the device to a directory
    4. Common mount parameters
      1. -T: Specifies the file system type of the device.
        1. Ext4 common file systems in linux
        2. Nfs Network File System
        3. ISO CD-ROM CD standard file system
        4. Auto automatically detects the File System
      2. -O specifies the option for mounting a File System
        1. Ro mounting in read-only mode
        2. Rw mounting in read/write mode
    5. Umount: unmount directory or mount point
    6. Instance:

      [Outman02 @ bogon tj] $ df-hFilesystem Size Used Avail Use % Mounted on/dev/sda2 8.6G 2.5G 5.7G 31%/tmpfs 491 M 228 K 491 M 1%/dev/ shm/dev/sda1 291 M 34 M 242 M 13%/boot [outman02 @ bogon tj] $ lsblkNAME MAJ: min rm size ro type MOUNTPOINTsr0 1 1024 M 0 rom sda 0 10G 0 disk restart-sda1 80 300 M 0 part/boot restart-sda2 0 8.7G 0 part/ └ ── sda3 8:3 0 1G 0 part [SWAP] [outman02 @ bogon tj] $ su Password: [root @ bogon tj] # mount/dev/sda1/tj/udiskmount: mount point/tj/udisk does not exist [root @ bogon tj] # mount/dev/sda1 outman02/tj/udiskmount: mount point outman02/tj/udisk does not exist [root @ bogon tj] # lltotal 12drwxr-xr-x. 2 root 4096 Nov 2 06:02 adrwxr-xr-x. 2 root 4096 Nov 2 06:02 bdrwxr-xr-x. 2 root 4096 Nov 4 23:53 udisk [root @ bogon tj] # mount/dev/sda1/udiskmount: mount point/udisk does not exist [root @ bogon tj] # mount/dev/sda1 udisk [root @ bogon tj] # lsblkNAME MAJ: min rm size ro type MOUNTPOINTsr0 1 1024 M 0 rom sda 0 10G 0 disk restart-sda1 80 300 M 0 part/boot restart-sda2 0 8.7G 0 part/ └ ── sda3 0 1G 0 part [SWAP] [root @ bogon tj] # df-hFilesystem Size Used Avail Use % Mounted on/dev/sda2 8.6G 2.5G 5.7G 31% /tmpfs 491 M 228 K 491 M 1%/dev/shm/dev/sda1 291 M 34 M 242 M 13%/boot/dev/sda1 291 M 34 M 242 M 13%/home/ outman02/tj/udisk ** if you view the U disk after mounting garbled content ** [root @ bogon tj] # localeLANG = en_US.UTF-8LC_CTYPE = "en_US.UTF-8" LC_NUMERIC = "en_US.UTF-8" LC_TIME = "en_US.UTF-8 "LC_COLLATE =" en_US.UTF-8 "LC_MONETARY =" en_US.UTF-8 "LC_MESSAGES =" en_US.UTF-8 "LC_PAPER =" en_US.UTF-8 "LC_NAME =" en_US.UTF-8 "LC_ADDRESS =" en_US.UTF-8 "LC_TELEPHONE =" en_US.UTF-8 "LC_MEASUREMENT =" en_US.UTF-8 "LC_IDENTIFICATION =" en_US.UTF-8 "LC_ALL = [root @ bogon tj] # man mount [root @ bogon tj] # mount-o iocharset = UTF-8/dev/sda1/home/outman02/tj /udisk
    7. /Etc/fstab file: it is automatically mounted to the Linux file system when it is started.
    8. Df: list the overall disk usage of the file system

      1. -A: List all file systems.
      2. -K: displays the file system in Bytes.
      3. -M: displays the file system with the capacity of MBytes.
      4. -H: Self-display in GBytes, MBytes, and KByte formats
      5. -I: displayed in inode count

        [root@bogon tj]# df Filesystem     1K-blocks    Used Available Use% Mounted on/dev/sda2        8985528 2600612   5928468  31% /tmpfs             502204     228    501976   1% /dev/shm/dev/sda1         297485   34642    247483  13% /boot/dev/sda1         297485   34642    247483  13% /home/outman02/tj/udisk[root@bogon tj]# df -aFilesystem     1K-blocks    Used Available Use% Mounted on/dev/sda2        8985528 2600612   5928468  31% /proc                   0       0         0    - /procsysfs                  0       0         0    - /sysdevpts                 0       0         0    - /dev/ptstmpfs             502204     228    501976   1% /dev/shm/dev/sda1         297485   34642    247483  13% /bootnone                   0       0         0    - /proc/sys/fs/binfmt_miscvmware-vmblock         0       0         0    - /var/run/vmblock-fuse/dev/sda1         297485   34642    247483  13% /home/outman02/tj/udisk[root@bogon tj]# df -kFilesystem     1K-blocks    Used Available Use% Mounted on/dev/sda2        8985528 2600628   5928452  31% /tmpfs             502204     228    501976   1% /dev/shm/dev/sda1         297485   34642    247483  13% /boot/dev/sda1         297485   34642    247483  13% /home/outman02/tj/udisk[root@bogon tj]# df -mFilesystem     1M-blocks  Used Available Use% Mounted on/dev/sda2           8775  2540      5790  31% /tmpfs                491     1       491   1% /dev/shm/dev/sda1            291    34       242  13% /boot/dev/sda1            291    34       242  13% /home/outman02/tj/udisk[root@bogon tj]#  df -hFilesystem      Size  Used Avail Use% Mounted on/dev/sda2       8.6G  2.5G  5.7G  31% /tmpfs           491M  228K  491M   1% /dev/shm/dev/sda1       291M   34M  242M  13% /boot/dev/sda1       291M   34M  242M  13% /home/outman02/tj/udisk
    9. Du: disk usage or directory usage of the file system

      1. -A: List the directory capacity of all files
      2. -H: displayed in readable format (G/M)
      3. -S: list the total amount, not the size occupied by each individual directory.
      4. -K: displays the capacity in Bytes
      5. -M: displays the capacity in MBytes.

        [root@bogon tj]# du251 ./udisk/efi/EFI/redhat24439   .[root@bogon tj]# du -a3   ./udisk/grub/splash.xpm.gz16  ./udisk/grub/reiserfs_stage1_52   ./udisk/grub/device.map1   ./udisk/grub/menu.lst276 ./udisk/grub24427   ./udisk4   ./a4   ./b24439   .[root@bogon tj]# du -h13K ./udisk/lost+found276K    ./udisk/grub24M ./udisk24M .[root@bogon tj]# du -s24439   .[root@bogon tj]#  du -k24427   ./udisk4   ./a4   ./b24439   .[root@bogon tj]# du -m1   ./udisk/efi/EFI/redhat1   ./b24  .
    10. Dumpe2fs: Observe the File System

      1. Dumpe2fs [options]

        1. -H: only lists superblock data and does not list content of other segments.

          [root@localhost ~]#dummpe2fs -h /dev/sda1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.