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
- Ext2 \ Ext3 \ Ext4 differences
- All three are in the file system format.
- Linux kernel officially supports the new file system Ext4 since 2.6.28
- Ext4 is the ultimate version of Ext3. It modifies some important data structures in Ext3.
- 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.
- 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.
- Ext3 only supports 32000 subdirectories, while Ext4 supports an unlimited number of subdirectories.
- Extents)
- 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.
- 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.
- Multi-block allocation
- 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.
- Delay allocation
- 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.
- This can optimize the data block allocation of the entire file and significantly improve the performance.
- Fast fsck (File System check)
- The old fsck will be slow because it wants to check all inode
- 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.
- Log Verification
- Logs are the most common part and can easily lead to disk hardware faults. Restoring data from damaged logs will cause more data corruption.
- 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.
- Two-phase log submission:
- The file system writes the specific content of the transaction to be executed to the log.
- File System Operations
- After the operation is successful, delete the specific transaction content from the log.
- Nojournaling Mode
- Ext4 allows you to disable logs so that users with special requirements can further improve performance.
- Online fragment Management
- Ext4 supports online fragment and provides the e4defrag tool for fragment of individual files or the entire file system.
- Inode-related features
- 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
- Permanent pre-allocation
- 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.
Swap Introduction
- Using disk storage, the memory is insufficient and the "overflow" content is displayed.
- 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.
- 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.
- Generally, you can set the Swap size according to the following rules:
- 4G physical memory, SWAP is set to 2 times the memory.
- 4-8 GB physical memory, SWAP is set to the same memory size
- 8 GB physical memory and 8 GB SWAP
- 64G-256G physical memory, SWAP is set to 16G
When will the system use swap?
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.
Modify swap parameters:
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.
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
Swap enabling and disabling
Enable swapon-a to disable swapoff-
3. File System Operations
Mount point
- 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.
- The mount point must be a directory, which is the entry to the file system.
- Mount command: mount the device to a directory
- Common mount parameters
- -T: Specifies the file system type of the device.
- Ext4 common file systems in linux
- Nfs Network File System
- ISO CD-ROM CD standard file system
- Auto automatically detects the File System
- -O specifies the option for mounting a File System
- Ro mounting in read-only mode
- Rw mounting in read/write mode
- Umount: unmount directory or mount point
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
- /Etc/fstab file: it is automatically mounted to the Linux file system when it is started.
Df: list the overall disk usage of the file system
- -A: List all file systems.
- -K: displays the file system in Bytes.
- -M: displays the file system with the capacity of MBytes.
- -H: Self-display in GBytes, MBytes, and KByte formats
-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
Du: disk usage or directory usage of the file system
- -A: List the directory capacity of all files
- -H: displayed in readable format (G/M)
- -S: list the total amount, not the size occupied by each individual directory.
- -K: displays the capacity in Bytes
-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 .
Dumpe2fs: Observe the File System
Dumpe2fs [options]
-H: only lists superblock data and does not list content of other segments.
[root@localhost ~]#dummpe2fs -h /dev/sda1