Theory + Experiment: Disk Management and File System

One, disk basics

  • The physical structure of the hard disk
    1. Disk: the hard disk has multiple disks, each with 2 sides
    2. Magnetic head: one magnetic head on each side
  • Hard disk data structure
    1. Sector: The disk is divided into multiple sector areas, each sector stores 512 bytes of data.
    2. Track: Concentric circles with different radii on the same disk
    3. Different disks are composed of the same radius Cylindrical surface
  • Disk storage capacity = number of heads × number of tracks (cylinders) × number of sectors per track × number of bytes per sector
  • Can use cylinder/head/sector to uniquely locate each area on the disk
  • Disk interface type
    IDE, SATA, SCSI, SAS, Fibre Channel

1.2. MBR and disk partition representation

  • Master Boot Record (MBR)
    1. MBR is located at the first physical sector of the hard disk
    2. MBR contains the master boot program of the hard disk and the hard disk partition table
    3. The partition table has 4 partition record areas, each of which occupies 16 Bytes
  • In Linux, hard disks, partitions and other devices are represented as files

1.3, disk partition structure

  • The number of primary partitions in the hard disk is only 4
  • The serial number of primary partition and extended partition is limited to 1~4
  • Extended partition is divided into logical partition
  • The serial number of the logical partition will always start from 5

1.4, file system type

  • xFS file system
    1, partition for storing files and directory data
    2, high-performance journal file system
    3, the file system used by default in CentOS7 system
  • SWAP, swap file system
    1. Create swap partition for Linux system
  • Other file system types supported by Linux
    1, FAT16, FAT32, NTFS
    2, EXT4, JFS...

2. Detect and confirm the new disk

2.1, fdisk command

  • View or manage disk partitions
fdisk -l [磁盘设备]

or

fdisk[磁盘设备]
  • Common commands
    m, p, n, d, t, w, q in interactive mode

1, d ## Delete partition
2, m ## List manual
3, n ## Add partition
4, p ## List partition
5, q ## Exit without saving
6, t ## Change partition type
7, w # # Save and exit

[root@tx ~]# fdisk -l
Device      Boot      Start         End        Blocks   Id  System
/dev/sda1    *         2048       4196351     2097152   83  Linux
/dev/sda2            4196352     209715199   102759424  8e  Linux LVM
  • Device partition device name
  • Whether Boot is a boot partition, such as *
  • Start position (number of hard disk cylinders)
  • End end position (number of hard disk cylinders)
  • Blocks partition size is in blocks, the default block size is 1024 bytes
  • System ID number corresponding to ID partition, 7 means NTFS format, 81 means logical partition, 82 means SWAP, 83 means EXT4, 8e means LVM logical volume
  • System partition type

Three, create a file system

3.1, mkfs command

  • Create file system, format
mkfs -t 文件系统类型 分区设备

3.2, mkswap command

  • Create a swap file system
mkswap 分区设备

3.2.1, example

  1. We first create a partition 1, and then change the ID to 82
    Insert picture description here

  2. The most important thing is not to mount when using mkswap! ! !
    Exchange partition on sdb1

    Insert picture description here

  3. The original

Insert picture description here

  1. After opening with swapon

Insert picture description here

  1. After closing with swapoff

Insert picture description here
swapon temporarily enable swap partition

swapoff close the swap partition

free -m can view the memory

Four, mount and unmount the file system

4.1, mount command

  • Mount the file system and ISO image to the specified folder
mount [-t类型] 存储设备挂载点目录
mount -o loop ISO 镜像文件挂载点目录

4.2, umount command

  • Unmount the mounted file system
umount 存储设备位置
umount 挂载点目录

4.3. Mount and unmount file system operations

  • Hard disk partition mounting and unmounting
  • Mounting and unmounting of optical disc devices
  • ISO image file mounting example
  • Unmount the file system

4.4. Set the automatic mounting of the file system

  • /etc/fstab configuration file
    Contains file system records that need to be automatically mounted after booting
vi /etc/fstab

4.5. Check disk usage

  • df command
df [选项] 文件

Example:

[root@tx ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        82G  8.5G   74G  11% /
devtmpfs                devtmpfs  1.9G     0  1.9G   0% /dev
tmpfs                   tmpfs     1.9G     0  1.9G   0% /dev/shm
tmpfs                   tmpfs     1.9G   12M  1.9G   1% /run
tmpfs                   tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sr0                iso9660   4.3G  4.3G     0 100% /mnt
/dev/sda1               xfs       2.0G  146M  1.9G   8% /boot
tmpfs                   tmpfs     378M     0  378M   0% /run/user/0

Guess you like

Origin blog.csdn.net/m0_46563938/article/details/109185667