Table of contents
vim /etc/fstab permanently mounted
Linux file system
Linux disk mounting 1 (hard disk partition)_linux disk formatting and mounting-CSDN Blog
File system type
Everything in a Linux system is a file
So everything in Linux can be changed, including the kernel
The hard disk will be mapped to the hard disk file and saved in the /dev file.
The running status of the system will be saved in the /proc file
What is a file system
The file system is the data structure and organization
of files. The software structure responsible for managing and storing file information in the operating system is called the file management system, or file system for short. The file system
includes the data in the file and the file system structure; all Linux users and programs see The files, directories, soft links, etc. are stored in the file systemLinux file system types
RHEL 4 uses ext2 file system
RHEL 5 uses ext3 file system
RHEL 6 uses ext4 file system
RHEL 7 uses xfs file system
RHEL 8 uses xfs file system
ext2 file system
Supports partitions up to 16TB and single files up to 2TB
No logging function (sudden server power outage or crash will cause data loss)
ext3 file system
Supports partitions up to 16TB and single files up to 2TB
Compared with ext2, a logging function is added to ensure system reliability when the operating system crashes.
But the performance is not enough
ext4 file system
Is a 32-bit file system
Compared with ext3, the performance has been improved, and the supported storage capacity reaches a maximum of 1EB partition and a single 16TB file size.
Added an unlimited number of subdirectories, the concept of Extents continuous data blocks, multi-block allocation, delayed allocation, persistent allocation, fast FSCK, log verification, no log mode, inode enhancement, etc.
xfs file system
It is a 64-bit file system that supports a maximum storage space of 18EB, but its performance is similar to ext4.
Compared with ext4, the biggest change is the increase in capacity (in order to meet the large capacity of cloud computing and big data)
How to save files in Linux
Linux does not write the contents of the file directly to the hard disk, but divides the file into two parts and saves it.
Save the file permissions and attribute information through inode, and save the actual file content through block
inode records file attributes and pointers
Each file occupies an independent inode table. This table defaults to 128 bytes.
Inode is a string of data. The inode corresponding to different files is unique in the file system.
Pointer: points to a block through a pointer (occupies 4 bytes)
File attributes: including file permissions (general permissions, special permissions, hidden permissions), owner, group, file size, file last access time, file modification time, etc.
block
The data block that actually stores the data (the size is generally 1k, 2k, 4k)
When the file is large, there will be multiple blocks, and then the multiple blocks are connected end to end (the end of the first block is used as a pointer to point to the second block, and then the end of the second block is also used as a pointer to point to the third block, in sequence so)
Precautions
After a file is created, it will occupy at least one inode and one block.
There can only be one inode for a file, but there are multiple blocks. You can increase the inode of the file by making a link file (the folder will occupy two inodes by default)
If the block size is 1k
When the file is 1.2k in size, it will directly occupy 2 blocks.
When the file is 0.8k in size, the remaining 0.2k cannot be used by other files (that is, one block can only store the data of one file)
VFS virtual file system
VFS provides a unified operating interface and programming interface for various file systems, so that users no longer care about the underlying file system of the system when making system calls, and can convert system call instructions into instructions that can be read by specific file systems.
File formatting commands
mkfs format file system
After formatting the hard disk partition, the Linux system can know how to write data on the hard disk.
Before formatting the file, use the lsblk command to check the disk partition status. If the disk partition is not displayed,
Requires reboot system
mkfs.filesystem1 device1 format device1 as filesystem1
mkfs -t file system 2 device 2 format device 2 as file system 2
Command examples
mkfs.xfs /dev/sdb5 formats sdb5 into an xfs file system
mkfs -t xfs /dev/sdb1 formats sdb1 as an xfs file system
lsblk -f View disk file system
Disk mount command
After the disk is formatted, the disk needs to be mounted.
The action of associating a device file with a directory (mount point) is called mounting.
This device can only be used after the device file is mounted to the mount point.
mount temporary mount command
mount device 1 mount point 1 mounts device 1 to mount point 1
mount -o rw,remount /sysroot to remount /sysroot in a readable and writable manner
-t specifies the file type to mount
-o indicates that the specified mounted file system is remounted
rw mounts in read-write mode
ro is mounted as read-only
remount remounts an already mounted file system
defaults uses default values for all options (auto, nouser, rw, suid)
auto allows mounting with -a
nouser does not allow general users to mount
suid confirms suid and guid bits
Command examples (you need to create the mounting directory mkdir directory first)
Mount /dev/sdb1 to the /media/sdb1 directory
Mount /dev/sdb5 to the /media/sdb5 directory
Mounting precautions
For MBR partitions, extended partitions cannot be mounted, only primary partitions and logical partitions can be mounted.
When the device file is mounted to a directory with future contents, the original files in the directory will be hidden; when the device is unmounted, the file contents will return.
The mounting directory does not have to be a subdirectory of the /media directory, any directory can be used, but in order to comply with the FHS protocol, it is recommended to mount it to the /media directory.
umount Unmount a file system
Disassociate a device from a mount point
umount device file name/mount directory Unmount the file system of the device
-v displays detailed information when executing
-r attempts to remount the file system read-only
vim /etc/fstab permanently mounted
Mounting using the mount command only takes effect temporarily, and the mount point will disappear after restarting.
We need to permanently mount the device file by editing the /etc/fstab file so that the computer can automatically mount the device file after restarting.
/etc/fstab file content format
/dev/sdb1 device command (absolute path - can also be a hard disk number)
/media/sdb1 device mount point (absolute path)
xfs mounted file system format
defaults permissions (defaults is the default)
0 (Do not enable automatic backup, 1 or 2 means enable automatic backup. The smaller the number, the greater the priority)
0 (Do not turn on automatic verification. If it is 1 or 2, it means turning on automatic verification. The smaller the number, the greater the priority)
Check the hard disk number corresponding to the hard disk (UUID--that is, the GUID of the hard disk)
blkid /dev/sdb1 - Check the hard disk number corresponding to the hard disk (if the displayed result does not have Type, it means that the partition has not been formatted yet)