Linux should learn this way-disk mounting

System Hierarchy Standard (FHS, Filesystem Hierarchy Standard), udev hardware naming rules, and hard disk partition planning methods. There are no drive letters such as C/D/E/F in the Linux system. All files in the Linux system are from The "root (/)" directory starts with a tree structure to store files in accordance with the File System Hierarchy Standard (FHS) and defines the purpose of common directories. In addition, the file and directory names in the Linux system are strictly case sensitive. In order to facilitate location and search, each directory in Linux generally stores a specific type of file. The following table lists the common directories of various Linux distributions.

The naming rules of physical devices

Everything is a file in a Linux system, and hardware devices are no exception. Since it is a file, it must have a file name. The udev device manager in the system kernel will automatically standardize the hardware name . The purpose is to allow users to guess the general attributes and partition information of the device through the name of the device file; this is particularly convenient for unfamiliar devices. In addition, the service of the udev device manager will always run as a daemon and listen to the signal sent by the kernel to manage the device files in the /dev directory 

硬件设备	文件名称
IDE设备	/dev/hd[a-d]
SCSI/SATA/U盘	/dev/sd[a-z]
virtio设备	/dev/vd[a-z]
软驱	/dev/fd[0-1]
打印机	/dev/lp[0-15]
光驱	/dev/cdrom
鼠标	/dev/mouse
磁带机	/dev/st0或/dev/ht0

The understanding of device names such as /dev/sda is determined by the recognition order of the system kernel , and it happens that the slot order of many motherboards is the recognition order of the system kernel, so it is named /dev/sda

Understanding of the partition name The numerical code of the partition is not necessarily forced to be postponed , and it may also be manually specified. Therefore, sda3 can only indicate that it is the partition numbered 3, and it cannot be judged that 3 partitions already exist on the sda ​​device.

 

The so-called extended partition, strictly speaking, it is not a partition of practical significance, it is only a pointer to the next partition, and this pointer structure will form a singly linked list.

Chapter 6 Storage Structure and Disk Division.  Chapter 6 Storage Structure and Disk Division.

File system and data

 

There are many types of file systems, such as:

  • ext2: The file system commonly used in early Linux;
  • ext3: an upgraded version of ext2, with log function;
  • RAMFS: memory file system, fast;
  • iso9660: CD or CD image;
  • NFS: Network file system, invented by SUN, mainly used for remote file sharing;
  • MS-DOS: MS-DOS file system;
  • FAT: the file system adopted by the Windows XP operating system;
  • NTFS: File system adopted by Windows NT/XP operating system
Linux并不是把文件内容直接写入到这个“硬盘地图”里面,而是在里面记录着整个文件系统的信息。因为如果把所有的文件内容都写入到这里面,它的体积将变得非常大,而且文件内容的查询与写入速度也会变得很慢。Linux只是把每个文件的权限与属性记录在inode中,而且每个文件占用一个独立的inode表格,该表格的大小默认为128字节,里面记录着如下信息:

该文件的访问权限(read、write、execute);

该文件的所有者与所属组(owner、group);

该文件的大小(size);

该文件的创建或内容修改时间(ctime);

该文件的最后一次访问时间(atime);

该文件的修改时间(mtime);

文件的特殊权限(SUID、SGID、SBIT);

该文件的真实数据地址(point)。

而文件的实际内容则保存在block块中(大小可以是1KB、2KB或4KB),一个inode的默认大小仅为128B(Ext3),记录一个block则消耗4B。当文件的inode被写满后,Linux系统会自动分配出一个block块,专门用于像inode那样记录其他block块的信息,这样把各个block块的内容串到一起,就能够让用户读到完整的文件内容了。对于存储文件内容的block块,有下面两种常见情况(以4KB的block大小为例进行说明)。

情况1:文件很小(1KB),但依然会占用一个block,因此会潜在地浪费3KB。

情况2:文件很大(5KB),那么会占用两个block(5KB-4KB后剩下的1KB也要占用一个block)。

 Mount the hardware device 

After you get a new hard disk storage device to the first partition , and then format , and finally to mount and use it normally.

                                  Parameters and functions in the mount command

parameter effect
-a Mount all file systems defined in /etc/fstab
-t Specify the type of file system

 

For example, to mount the device /dev/sdb2 to the /backup directory, you only need to fill in the device and mount directory parameters in the mount command, and the system will automatically determine the type of file to be mounted, so you only need to execute the following command To:

[root@linuxprobe ~]# mount /dev/sdb2 /backup

Although the file system can be used immediately after executing the mount command according to the above method, the system will fail to mount after restarting, which means that we need to manually mount it every time after booting. This is definitely not the effect we want. If you want to make the hardware device and the directory automatically associate permanently, you must fill in the mount information according to the specified format "device file mount directory format type permission option is backup or self-check" ( The meaning of each field is shown in Table 6-4) Write it into the /etc/fstab file. This file contains many information items needed for mounting, once it is configured, it can be done once and for all.

             The meaning of each field in the specified filling format used for mounting information

Field significance
Device file Generally it is the path of the device + the name of the device, and you can also write a unique identifier (UUID, Universally Unique Identifier)
Mount directory Specify the directory to be mounted to, which needs to be created before mounting
Format type Specify the format of the file system, such as Ext3, Ext4, XFS, SWAP, iso9660 (this is an optical disc device), etc.
Permission options If set to defaults, the default permissions are: rw, suid, dev, exec, auto, nouser, async
Whether to backup If it is 1, use dump for disk backup after booting, and if it is 0, do not backup
Whether to self-check If it is 1, it will automatically perform disk self-check after booting, and if it is 0, it will not self-check.

 Add a hard disk, view disk information with lsblk blkid or fsdisk -l

 

 fdisk command

In Linux systems, the most commonly used method for managing hard disk devices is the fdisk command.

                                                Parameters and functions in the fdisk command

parameter effect
m View all available parameters
n Add new partition
d Delete a partition information
l List all available partition types
t Change the type of a partition
p View partition table information
w Save and exit
q Exit without saving

 Partition

 

format

 In order to avoid losing the mount text after booting and restarting, write the configuration to the /etc/fstab file

Guess you like

Origin blog.csdn.net/yanghuadong_1992/article/details/112758058