table of Contents
One, disk basics
■ The physical structure of the hard disk
- Disc: The hard disk has multiple discs, each with 2 sides
- Magnetic head: one magnetic head on each side
■ Hard disk data structure - Sector: The disc is divided into multiple sectors, each sector stores 512 bytes of data
- Track: Concentric circles with different radii on the same disc
- Cylindrical surface: a cylindrical surface composed of different discs with the same radius
■ Disk storage capacity = number of heads × number of tracks (cylinders) × number of sectors per track × number of bytes per sector
■ Cylinder/head/sector can be used 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)
- MBR is located at the first physical sector of the hard disk
- MBR contains the hard disk's master boot program and hard disk partition table
- The partition table has 4 partition record areas, each of which occupies 16 bytes
■ In Linux, devices such as hard disks and partitions are represented as files
1.3, disk partition structure
■ The number of primary partitions in the hard disk is only 4
■ The serial numbers of primary and extended partitions are limited to 1~4
■ Extended partitions are then divided into logical partitions
■ The number of logical partitions will always start from 5.
1.4, file system type
■ xFS file system
- Partition to store file and directory data
- High-performance journal file system
- The file system used by default in CentOS7 system
■ SWAP, swap file system - Create swap partition for Linux system
■ Other file system types supported by Linux
- FAT16、FAT32、NTFS
- EXT4、JFS…
2. Detect and confirm the new disk
2.1. Detect and confirm the new hard disk
■ fdisk command
- View or manage disk partitions
fdisk -l [磁盘设备]
或
fdisk[磁盘设备]
■ Common commands in interactive mode
-
m、p、n、d、t、w、q
-
d ## Delete partition
-
m ## List manuals
-
n ## Add partition
-
p ## List partition
-
q ## Exit without saving
-
t ## Change the partition type
-
w ## Save and exit
[root@zk ~]# 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 分区设备
■ Example
[root@zk ~]# mkswap /dev/sdb5
[root@tx ~]# cat /proc/meminfo |grep Swap Total
[root@tx ~]# swapon /dev/sdb5
[root@tx ~]# cat /proc/meminfo | grep Swap Total
[root@tx ~]# swapoff /dev/sdb5
Four, mount and unmount the file system
4.1. Mount and unmount the file system
■ mount command
- Mount the file system and ISO image to the specified folder
mount [-t类型] 存储设备挂载点目录
mount -o loop ISO 镜像文件挂载点目录
■ umount command
- Unmount the mounted file system
umount 存储设备位置
umount 挂载点目录
4.2. 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
Unmount
4.3, 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.4, 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
Five, summary operation
1. Create a primary partition.
Create an extended partition.
Create a logical partition.
2. Mount (temporary)
mkfs.xfs /dev/sdb1. Change sdb1 to xfs and format it.
Then use df -Th to look at the mounting situation
3. Enter vi /etc/fstab mounting method (permanent)
4. Enter vi /etc/fstab to correct the mounting error
and then enter vi /etc/fstab
5. Permanent mount CD,
first hit temporary mount
, use df -Th to view
, enter vi /etc/fstab to
check if there is any problem with the mount
Restart
Check the mounting situation
6. Enable swapon /dev/sdb
Enable the swap partition swapon /dev/sdb1 to
become permanently mounted
7. Kill the process