Linux disk and file system management-the sky is the sky, the wild, who hasn't been in bed

Linux disk and file system management

Disk basics

Disk structure

★Physical structure of the hard disk
1. Disk: the hard disk has multiple disks, each surface has 2 sides
2. Magnetic head: one head on each side
★The data structure of the hard disk
1. Sector: The disk is divided into multiple sectors , Each sector stores 512 bytes of data, the smallest storage unit of the hard disk
2. Disk: concentric circles with different radii on the same disk are circular tracks drawn on the surface of the disk by the head
3. Cylinder: different disks A cylindrical surface of the same radius is composed of multiple tracks of the same Sakaihara.
4. Hard disk storage capacity = number of heads, number of tracks (cylinders), number of sectors per track * number of bytes per sector (512 bytes)
5. Cylinder/head/sector can be used to uniquely locate each area on the disk.
6. Disk interface type:
IDE: parallel port data cable connects the motherboard and the hard disk, the anti-interference is too poor, and the cable takes up a lot of space, so it is not used The internal heat dissipation of the computer has been gradually replaced by SATA.
SATS: anti-interference, support for hot-swappable and other functions, high speed, strong entanglement
SCSI, minicomputer system interface, SCSI hard disks are widely used in workstation-class personal computers and servers. During data transmission, the CPU occupancy rate is low, the rotation speed is fast, and it supports hot-swappable.
SAS: It is a new generation of SCSI technology, which is the same as the SATA hard disk. It uses serial technology to obtain a higher transmission speed, which can reach 6G/s.

MBR and disk partition representation

★Master boot record (MBR) disk partition
1. MBR is the master boot record, located at the first physical sector of the first hard disk (/dev/sda) 2. MBR
contains the master boot program and hard disk partition table of the hard disk , MBR total 512 bytes
. 3. The first 446 bytes are the master boot record. The partition table is stored in the 447~510 bytes in the MBR sector. There are 4 partition record areas in the partition table, and each partition record area occupies 16 words. Section
4. In Linux, devices such as hard disks and partitions are represented as files.
5. The master boot record (MBR) disk partition supports a maximum volume of 2.2TB, and each disk has up to 4 primary partitions or 3 primary partitions, and 1 extension. Partitions and extended partitions are divided into logical partitions
★ Disk partition representation
For example: /dev/sda1
sd means SCSI device-hd means IDE device
Disk sequence number, and letters a, b, c... represent
the sequence number of the partition, with The numbers 1, 2, 3... indicate that the
primary partition starts from 1-4, and the first logical partition always starts from 5.
The structure of the disk partition
1. The number of primary partitions in the hard disk is only 4
2. The serial number limit of the primary partition and the extended partition In 1~~4
3. The extended partition is divided into logical partition
4. The serial number of logical partition will always start from 5.

File system type

★XFS file system

1. Partition for storing files and directory data
2. High-performance journal file system, good at handling large files, can support millions of terabytes of storage space
3. File system used by default in CentOS7 system

★SWAP exchange file system

1. Create a swap partition for the Linux system
2. Generally set to 1.5~2 times the physical memory

★Other file system types supported by Linux

1. EXT4/3, FAT32, NTFS, LVM[logical volume|scalable]

Disk management

★fdisk command-view or manage disk partitions

★fdisk command-view or manage disk partition
fdisk -l disk device
or
fdisk disk device /dev/sdb[a first block b second block...]
Insert picture description here
★Common commands in interactive mode
-m: get help menu
-p view partition Situation
-n New partition
-d Delete partition
-t Change partition type
-w Save operation exit
-q Exit without saving operation

★ View disk partition

Insert picture description here
Device (device): the device file name of the partition
Boot: whether it is a boot partition, if it is, there is a "*" mark
Start: the starting position of the partition in the hard disk (number of cylinders)
End: the ending position of the partition in the hard disk (Number of cylinders)
Blocks: the size of the partition, in Blcoks (blocks) as the unit, the default block size is 1024 bytes
Id: the system ID number corresponding to the partition, for example, 83 means XFS partition or EXT4 partition in Linux, 8e Represents the LVM logical volume
System: partition type

★Steps to create a new partition

1. Enter the new hard disk file: fdisk /dev/sdb
2. Input command: n (new partition)
Step 1: -> p primary partition, e extended partition, l logical partition
Step 2: -> set partition: 1 (range 1-4, such as press Enter to accept the default value)
Step 3: -> Set partition size: +20G (Specify the size as 20GB, such as press Enter to accept the default value means all space)
Step 4: -w Save
Note: Change the hard disk After the partition setting (especially the hard disk in use), it is recommended to restart the system once, or execute the "partprobe" command to make the operating system detect the new partition expression to prevent damage to the existing data in the hard disk when formatting the partition : Partprobe /dev/sdb

Create file system/swap file system

★mkfs command to create a file system

Make Filesystem Create a file system (format)
mkfs -t file system type partition device
The process of creating a file system is the process of formatting a partition.
Example: mkfs -t xfs /dev/sdb or mkfs.xfs /dev/sdb
after formatting A mount point is required.
Start to mount
mkdir /data
mount /dev/sdb1 /data
Note: df -hT can view the current file system type

★mkswap command to create a swap file system

make swap Create a swap file system
Insert picture description here

mkswap partition device
Note: Before creating swa, the target partition should be set to 82 partition type ID number through the fdisk tool.
Creation steps:
fdisk /dev/sdb
–>t
–>5
–>82
Insert picture description here

swapon starts the newly added swap partition
Insert picture description here

swapoff Disable the specified swap partition
swapon -s View the swap status information of each partition
free -m View the total swap status information
partprobe /dev/sdb Refresh the detected partition

Mount and unmount file system

★mount command

Mount the file system and ISO image to the specified folder
mount [-t type] storage device mount point directory
mount -o loop ISO image file mount point directory
-t file type
-o mount parameter list

★umount command

Unmount the mounted file system
umount storage device location
umount mount point directory
Note: Unmount needs to exit the mount point directory
umount -if storage device directory or mount point directory
-1f: force unmount

★Check the disk mounting situation

1. Direct mount command
Insert picture description here
2.df [option]
-i: display the inode number
-T: display the type of file system
-h: display the capacity unit of the partition
Insert picture description here
3. View the UUID of the device and the file system type
blkid [device]
Insert picture description here

Question: Create a file in the directory where the file system is mounted. Does the file created before still exist after unmounting?
A: The file system is different, and the same file name displays different content

Set up automatic mounting of the file system

1. The /etc/fstab configuration file
contains the file system records that need to be automatically mounted after booting. The
Insert picture description here
first section: partition name or device volume label name. The
second
section: the location of the file system mount point directory. The third section: the file system type. , Such as: xfs, swap
fourth paragraph: mount parameters, that is, the parameters that can be used after the "-o" option of the mount command. For example: default parameters, readable and writable, read-only, and executors disabled. The
fifth paragraph: indicates whether the file system needs dump backup (dump is a backup tool). Generally, it is set to 1 to indicate that it is needed, and to 0 to be ignored by dump
. Sixth segment: This number determines the order of disk checking when the system starts, 0 means no check, 1 means priority check, 2 means second check. The root partition should be set to 1, the other partitions are set to 2

Guess you like

Origin blog.csdn.net/Dark_Tk/article/details/113252927
sky