01. fdisk disk partition
fdisk is a commonly used disk partitioning tool for Linux (only disks smaller than 2TB can be partitioned, and the parted partitioning tool should be used for more than 2TB)
partition example
https://blog.csdn.net/qq_18297675/article/details/52719171
Common commands
fdisk /dev/sdb
mkfs.ext4 /dev/sdb1
mount /dev/sdb1 /opt
umount /opt
vim /etc/fstab
mount -a
df -Th
lsblk
02. partprobe refresh partition table
The partprobe command is used to update the hard disk partition table data in the linux kernel when the hard disk partition changes. Sometimes after partitioning the hard disk with the fdisk and part commands, it is found that no new partitions are found. At this time, the system needs to be restarted for the modification to take effect, but using partprobe can make the modified partition table take effect without restarting the system.
[root@ufo130 ~]# partprobe /dev/sda
03. tune2fs view and adjust file system parameters
Adjust or view the parameters of the ext2/ext3/ext4 file system (rarely used, just understand)
04. parted disk partition
Both fdisk and parted can be used for disks smaller than 2TB, but the parted tool can only be used for disks larger than 2TB, and the disk needs to be converted to GPT format.
05. mkfs create file system
[root@ufo130 ~]# mkfs -t ext4 -v /dev/sdb
或
[root@ufo130 ~]# mkfs.ext4 -v /dev/sdb
06. dumpe2fs export file system information
Export ext2/ext3/ext4 file system information (rarely used, just understand)
07. resize2fs refresh to display the expansion result
Used to expand or shrink the unmounted ext2/ext3/ext4 file system. It is often used for partitions after LVM expansion.
08. fsck check and repair the file system
- The file system must be unmounted
- Do not check and repair partitions. Normally, they will be checked and repaired in the order in /etc/fstab
- Generally, the fsck command is used only when the disk error is displayed at boot
09. dd copy, convert, format files
Back up the contents of the specified partition to the specified file
[root@ufo130 ~]# dd if=/dev/sda1 of=ufo.img
Delete the specified partition
[root@ufo130 ~]# dd if=/dev/zero of=/dev/sda1
/dev/zero is a 0-character device file, which can generate a continuous data stream, and the generated file is a special format data file (binary file)
Important : Pay special attention to the position of the if and of parameters. If the position is reversed, big problems will occur.
Generate test files of any size ( bs*count )
[root@ufo130 ~]# dd if=/dev/zero of=ufo.log bs=1M count=2
10. mount mount system files
11. umount uninstall system files
12. df View system disk space usage
13. mkswap creates swap partition
14. swapon activate swap partition
15. swapoff closes the swap partition
16. sync refresh file system cache
sync forces the data in the memory buffer to be flushed to the disk, and it will also be automatically refreshed when it reboots.
17. lsblk View LVM partition disk usage
Physical Storage Media : Refers to the physical storage device of the system. Disks, such as /dev/hda, /dev/sda, etc., are the bottom storage unit of the storage system.
Physical Volume (PV) : Refers to a disk partition or a device that has the same function as a disk partition (such as RAID). It is the basic storage logical block of LVM, but it is compatible with basic physical storage media (such as partitions, disks, etc.). ) Comparison, but it contains management parameters related to LVM.
Volume Group (Volume Group, VG) : It is a storage pool composed of one or more physical volumes. One or more logical volumes can be created on the volume group.
Logical Volume (LV) : Similar to the hard disk partition in a non-LVM system, it is built on a volume group and is a standard block device. A file system can be built on the logical volume.
The relationship between the three : If PV is compared to a plate of the earth, VG is an earth, because the earth is composed of multiple plates, then divide a region on the earth and mark it as Asia, then Asia is equivalent to a LV .
Create LVM, physical volume, volume group, logical volume, format, mount
Temporary mounting, permanent mounting requires modification of the configuration file /etc/fstab
Online expansion: increase and decrease the size of logical volume
View the occupancy of the current LVM disk partition
lsblk
View corresponding to the current disk: physical volume PV name, volume group VG name
pvscan
View the corresponding mount directory: logical volume LV name
lvscan
The disk /dev/sdb can be partitioned or not, but it must be in the 8e system format of LVM
fdisk -l
Extend Volume Group VG
vgextend vg01 /dev/sdb
Extend Logical Volume LV
lvextend -L +200G /dev/vg01/data
lvextend -L +200G /dev/vg01/bak
Reformulation of file system
resize2fs -p /dev/vg01/data
resize2fs -p /dev/vg01/bak
Note: The entire process does not require unloading and mounting operations, all are online extensions
18. Delete files without releasing space
Sometimes after deleting files, disk space cannot be released immediately
rm -rf ...
View the deletion process
lsof | greo del..
Check and kill the process to release the disk usage
kill -9 ...