Linux Disk Management and File

introduction

Managing disks is one of the important tasks of administrators. This article will learn disks and management techniques in Linux systems from the aspects of disk partitioning and formatting operations. In addition, the file system is also one of the important tasks of the administrator. The content of this article will learn about the Linux system file system management technology from the aspects of file system creation, mounting usage and LVM (Logical Volume Manager) dynamic partition creation and management. This video also introduces RAID disk arrays and array cards.

1. Disk structure

1.1 The physical structure of the hard disk

Disc: The hard disk has multiple discs, each with 2 sides.
Head: one head on each side

1.2 The data structure of the disk

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;
Cylinder: Concentric circles with different radii from different discs

Disk storage capacity = number of heads × number of tracks (cylinders) × number of sectors per track × number of bytes per sector
Cylinders/heads/sectors can be used to uniquely determine each area of ​​the
disk. Disk interface types: IDE, SATA, SCSI, SAS, Fibre Channel

1.3 MBR and disk partition representation

The master boot record
MBR is located at the first physical sector of the disk. The
MBR contains the master boot program of the hard disk and the hard disk partition table. The
partition table has 4 partition record tables, each of which occupies 16 bytes.

1.3.1 Files represented by devices such as hard disk partitions in linux

/dev/hda5

1.4 Disk partition structure

The number of primary partitions of the hard disk is only 4.
The serial numbers of primary and extended partitions are limited to 1-4.
Extended partitions cannot be used directly. Logical partitions must be created. The logical partition
number will always start from 5, so "5" means the first one. Logical partition, "6" represents the second logical partition

2. File system content

2.1 XFS file system

Partitions for storing files and directory data
High-performance journal file system
CentOS7 system default file system

2.2 SWAP exchange file system

Create swap partition for linux system

2.3 Other file system types supported by linux

FAT16、FAT32、 NFFS
EXT4、JFS……

Three, disk related operations

3.1 Disk partition operation

If the disk space is less than 2T, you can use the fdisk /dev/sdb command to partition, that is, MBR format partition;
if the disk space is greater than 2T, you can use the parted /dev/sdb command to partition, that is, use the GPT partition format.
After the virtual machine creates a disk, you need to enter the following code. After the disk is restarted, the newly created disk can be detected normally.

init 6

3.1.1 fdisk partition code format

Disk View

fdisk -l [磁盘设备] 

Disk management

fdisk [磁盘设备]

3.1.2 Common commands in fdisk interactive mode

Insert picture description here

3.1.3 Parted partition operation steps

Now use the fdisk -1 command in super user mode to view the mounted hard disk device. Assuming the device number is /dev/sdb, then use the parted command to partition the GPT.
first step:

yum install parted -y
parted /dev/sdb
GNU parted 1.8.1
Using /dev/sdb
welcome to GNU parted ! Type "help" to view a list of commands.

Part 2: Adjust the MBR disk partition format to GPT

(parted) malabel gpt

Step 3: Divide all the space into one partition

(parted) mapart gpt

Step 4: Display the set partition size

(parted) print

Step 5: Exit parted program

(parted) quit

Step 6: After finishing the partition with parted, format it, and then mount it for use

mkfs.ext4 -F /dev/sdb1

Step 7: Finally add /etc/fstab to automatically load

vi /etc/fstab
/dev/sdb1           /data             ext4          defaults     0 0

3.2 Create a file system (format)

3.2.1 View the executable file system type of the partition

[root@server1 ~]#ls /sbin/mkfs*

3.2.2 mkfs code format

mkfs -t ext4或xfs  /dev/sdx1

or

mkfs.ext4或.xfs  /dev/sdx1

3.2.3 Mount sdb1 disk

mkdir /data                  ## 新建一个data目录
mount /dev/sdb1 /data        ## 将sdb1挂载到data目录下
df -Th                       ## 检测sdb1是否挂载成功

Or you can choose to mount it permanently in the second step.

3.3 Create a swap file system

Create a swap file system

mkswap  分区设备

Mount the swap file partition

swapon /dev/sdb5

Unmount the swap file partition

swapoff /dev/sdb5

Check the size of the swap space to confirm whether the swap partition is created successfully during the operation.

cat /proc/meminfo | grep "SwapTotal"

3.4 Mount and unmount the file system

3.4.1 Mount the file system and iso mirror to the specified folder

mount [-t类型] 存储设备 挂载点目录
mount [-o loop] iso镜像文件 挂载点目录

3.4.2 Unmount the mounted file system

umount 存储设备位置
umount 挂载点目录

After unmounting the mount point directory, the file information in the directory will not be lost, and the information in the file can still be read after remounting the file to another directory.

3.5 Mount the U disk to the virtual machine

mount -o iocharset=utf8 /dev/sdc1 /opt

In addition, we need to set the "USB Controller" in the "Settings" of the virtual machine to USB 3.0
Insert picture description here

Four, LVM (logical volume manager) logical volume management

4.1 LVM function

1. Dynamically adjust the disk capacity to improve the flexibility of disk management. The
boot partition is used to store boot files and cannot be created based on lvm.
2. Graphical interface management tool

system-config-lvm

4.2 Basic concept of LVM mechanism

Insert picture description here

4.3 The main management commands of LVM

Insert picture description here

4.4 Logical volume creation process

4.4.1 Creation process

1. Prepare two or more hard disks to connect to the host
2. Restart the system to detect and identify these hard disks
3. Manage the hard disks and divide and save these hard disks
4. Format each hard disk partition
5. Mount and use
6. Create physical volumes
7. Combine multiple physical volumes into one volume group
8. Split the volume group into several logical volumes

4.4.2 Create Command

fdisk -l
fdisk /dev/sdb 、fdisk /dev/sdc (-t成8e)
mkfs -t ext4 /dev/sdb1 、mkfs -t ext4 /dev/sdc1
mount /dev/sdb1 /b1 、mount /dev/sdc1 /c1
df-Th
pvcreate lvm /dev/sdb1 /dev/sdc1
vgcreate lvm /dev/sdb1 /dev/sdc1
lvcreate -L 50G -n xin(lvm名称) lvm(卷组名称)

Guess you like

Origin blog.csdn.net/weixin_50344820/article/details/109079509