Click the blue “Most Programmer” to follow me!
Add a “Star“, every day at 18:03 to learn technology together
Linux – Storage Management
1 Storage Methods
1. Classify disks based on the working principle of the disk Mechanical Disk HDD Solid State Disk SSD
2. Classify disks based on the hot-swappable method Hot-swappable Non-hot-swappable
3. Classify disks based on the hard disk interface IDE-SATA (Serial ATA) SCSI-SAS (Serial SCSI) PCIe Interface FC Fiber Interface
4. Classify based on connection methods Local Storage External Storage Network Storage
5. Differentiate based on partitioning methods
- • MBR

MBR is MSDOS;
Compatible with Windows MBR (Master Boot Record);
Can only handle disks smaller than 2TB;
Use fdisk tool for partitioning;
Can have a maximum of 14 partitions (4 primary partitions, extended partition, logical partitions);
The first sector of the disk, the first sector has 512 bytes, stores two types of data: MBR and partition table
MBR: Installed with boot management program, occupies 446 bytes
Partition table: Records the status of the entire disk partition, occupies 64 bytes
## Since the partition table is only 64 bytes, it can have a maximum of four record areas (each record occupies 16 bytes), each record area records the starting and ending sector numbers of that segment;
## Therefore, each disk can only have four partition slots;
## These four partition slots are primary partitions and extended partitions;
Each partition has a boot sector in front of it, used to store the operating system's boot program;
The extended partition has an extended partition boot record area occupying multiple sectors, used to store the starting and ending sector numbers of all logical partitions inside;
The extended partition cannot be formatted, it can only be divided into several logical partition slots;
The extended partition uses multiple sectors to record logical partition information, and since it uses multiple sectors to record, it supports more than 4 logical partitions;

The logical partition slot number starts from 5, 1-4 is reserved for primary and extended partitions
P1: /dev/sda1
P2: /dev/sda2
L1: /dev/sda5
L2: /dev/sda6
L3: /dev/sda7
L4: /dev/sda8
L5: /dev/sda9
- • Summary of primary partitions, extended partitions, and logical partitions in MBR: There can be a maximum of 4 primary and extended partitions; there can be at most 1 extended partition; logical partitions are derived from the extended partition; partitions that can be formatted and used are primary and logical partitions; the extended partition cannot be used directly; the number of logical partitions is determined by the operating system.
- • GPT (GUID Partition Table)
Can handle disks larger or smaller than 2TB;
In CentOS6, use parted tool for partitioning; in CentOS7, use gdisk tool for partitioning;
Can have a maximum of 128 partitions; there is no concept of extended and logical partitions, all are primary partitions
GPT plans all blocks of the disk using LBA; LBA: Logical Block Address, preset each LBA to 512 bytes, the first LBA is called LBA0;
GPT uses the first 34 LBA; in addition, it uses the last 33 LBA for backup;
In GPT partitioning, there is no concept of primary, extended, and logical partitions, each partition can be used;
The disk management program fdisk does not recognize GPT partitions; gdisk and parted can recognize;
grub version 1 does not recognize GPT

LBA0: Compatible with MBR. This LBA0 block is also divided into two parts, the first part is a 446 bytes block similar to MBR, storing the first stage boot management program; the second part places a special flag partition to indicate that this block disk is in GPT partition format, disk management programs that cannot recognize GPT partition tables cannot modify this partition information.
LBA1: Records the header data of the GPT partition table, content includes: the location and size of the partition table itself; the location of the backup GPT (last 34 LBA blocks); places the partition table verification mechanism code CRC32, the operating system uses this code to determine if GPT is correct, if incorrect, restore from the backup GPT.
LBA2-33: The actual place to record partition information, each LBA can record information for 4 partition slots, so there can be a total of 128 partition slots
7.2 Basic Partitioning
7.2.1 Adding a New Disk
” lsblk ” – View the partition status of the system
[root@localhost boot]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 29G 0 part
├─centos-root 253:0 0 26G 0 lvm /
└─centos-swap 253:1 0 3G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 8G 0 part
sr0 11:0 1 4.4G 0 rom /run/media/root/CentOS 7 x86_64
7.2.2 MBR Partitioning
” fdisk -l ” – View the number of hard disks mounted in the system and the partition status
[root@localhost boot]# fdisk -l /dev/sda
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/best): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a533f
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 62914559 30407680 8e Linux LVM
- • Use MBR partition table, use fdisk to partition sdc
[root@localhost boot]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory until you decide to write them to disk.
Think twice before using the write command.
Command (type m for help):
- • Enter ” m ” to view help information, understand the specific functions of each parameter, and the specific operations of partitioning, etc.
- • Enter ” n ” to attempt to create a new partition
Command (type m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
- • Enter ” P ” parameter, the system defaults to select primary partition, just press Enter;
- • Enter ” l ” parameter, the system creates a logical partition;
Select (default p):
Using default response p
- • Partition numbers are 2~4, the system defaults to 2, just press Enter; (partition number depends on personal situation)
Partition number (2-4, default 2):
- • The system will prompt for the starting sector position, the system will automatically select the earliest available sector position, just press Enter
Starting sector (16779264-41943039, default=16779264):
Using default value 16779264
- • The user defines the ending position of the sector by adding sectors or adding size, which defines the final partition space size
Last sector, +sectors or +size{K,M,G} (16779264-41943039, default=41943039): +100M
Partition 2 has been set to Linux type, size set to 100 MiB
- • Enter ” P ” parameter to view the partition status in the hard disk
Command (type m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/best): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x43c3e080
Device Boot Start End Blocks Id System
/dev/sdb1 2048 16779263 8388608 83 Linux
/dev/sdb2 16779264 16984063 102400 83 Linux
- • Enter ” w ” parameter to save all partition settings
Command (type m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Synchronizing disks.
- • Use ll command to view the device files of the new partition
[root@localhost boot]# ll /dev/sdb*
brw-rw----. 1 root disk 8, 16 Nov 26 21:01 /dev/sdb
brw-rw----. 1 root disk 8, 17 Nov 26 21:01 /dev/sdb1
brw-rw----. 1 root disk 8, 18 Nov 26 21:01 /dev/sdb2
7.2.3 GPT Partitioning
” gdisk ” – Partition the hard disk, the system displays the creation of a new GPT partition
[root@localhost boot]# gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present
- • Enter ” ? ” parameter to view help information, enter ” n ” parameter to partition, at this time there are no partition selections, just press Enter to create a primary partition, use the default starting sector, press Enter to define the ending sector. Set to add 100MiB, the system prompts that the current type is Linux system, just press Enter.
Command (? for help): n
Partition number (3-128, default 3):
First sector (34-41943006, default=16984064) or {+-}size{KMGTP}:
Last sector (16984064-41943006, default=41943006) or {+-}size{KMGTP}: +100M
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
- • Create another partition
Command (? for help): n
Partition number (4-128, default 4):
First sector (34-41943006, default=17188864) or {+-}size{KMGTP}:
Last sector (17188864-41943006, default=41943006) or {+-}size{KMGTP}: +5G
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
- • Enter ” p ” parameter to display partition information, enter ” w ” to save, the system will prompt that it is about to write GPT data, which will overwrite existing partitions, ask if to continue, enter ” y ” to proceed
Command (? for help): p
Disk /dev/sdb: 41943040 sectors, 20.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): DA12D06C-8701-4074-9A0B-0FE8E70FD2D8
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 41943006
Partitions will be aligned on 2048-sector boundaries
Total free space is 14270397 sectors (6.8 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 16779263 8.0 GiB 8300 Linux filesystem
2 16779264 16984063 100.0 MiB 8300 Linux filesystem
3 16984064 17188863 100.0 MiB 8300 Linux filesystem
4 17188864 27674623 5.0 GiB 8300 Linux filesystem
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
- • If it is a real hard disk, execute the partprobe command to view the new partition status
[root@localhost boot]# partprobe /dev/sdb
[root@localhost boot]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 29G 0 part
├─centos-root 253:0 0 26G 0 lvm /
└─centos-swap 253:1 0 3G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 8G 0 part
├─sdb2 8:18 0 100M 0 part
├─sdb3 8:19 0 100M 0 part
└─sdb4 8:20 0 5G 0 part
sr0 11:0 1 4.4G 0 rom /run/media/root/CentOS 7 x86_64
- • View the partition table types of sdb and sda hard disks
[root@localhost boot]# fdisk -l /dev/sdb
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/best): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: DA12D06C-8701-4074-9A0B-0FE8E70FD2D8
# Start End Size Type Name
1 2048 16779263 8G Linux filesystem Linux filesystem
2 16779264 16984063 100M Linux filesystem Linux filesystem
3 16984064 17188863 100M Linux filesystem Linux filesystem
4 17188864 27674623 5G Linux filesystem Linux filesystem
[root@localhost boot]# fdisk -l /dev/sda
Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/best): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000a533f
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 62914559 30407680 8e Linux LVM
7.2.4 Creating a Filesystem
After creating a partition, data cannot be stored immediately; the partition needs to be formatted
” mkfs ” – Pressing the tab key twice in succession can view all filesystem types, the default filesystem for CentOS 7 is XFS
[root@localhost boot]# mkfs
mkfs mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs
mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat
- • Use EXT4 filesystem to format /dev/sdb1 primary partition, block size is 1024 bytes. A block is the smallest unit of file storage; if a file is smaller than 1KiB, it will still occupy 1KiB of storage space
[root@localhost boot]# mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: Done
Writing inode table: Done
Creating journal (32768 blocks): Done
Writing superblocks and filesystem accounting information: Done
- • Use XFS filesystem to format /dev/sdb2 primary partition
[root@localhost boot]# mkfs.xfs /dev/sdb2
meta-data=/dev/sdb2 isize=512 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
7.2.5 Mounting Partitions
After formatting is complete, the partition needs to be mounted. First, create two directories as mount points, then use the mount command to temporarily mount the sdb1 and sdb2 partitions to the date01 and date02 directories respectively. Now the two directories are no longer ordinary directories, but the mount points of the devices. Users need to use the mount points to store data in the devices
[root@localhost ~]# mkdir /date01
[root@localhost ~]# mkdir /date02
[root@localhost ~]# mount /dev/sdb1 /date01
[root@localhost ~]# mount /dev/sdb2 /date02
” df -h ” – View the mount points of the filesystem
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 13M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 26G 6.6G 20G 26% /
/dev/sda1 1014M 185M 830M 19% /boot
tmpfs 378M 32K 378M 1% /run/user/0
/dev/sr0 4.4G 4.4G 0 100% /run/media/root/CentOS 7 x86_64
tmpfs 378M 36K 378M 1% /run/user/1000
/dev/sdb1 7.8G 36M 7.3G 1% /date01
/dev/sdb2 97M 5.3M 92M 6% /date02
- • After mounting, create two empty directories dir01 and dir02 under these two directories, then use the ll command to check the date01 and date02 directories. The same size of empty directories occupies different storage space.
[root@localhost ~]# mkdir /date01/dir01
[root@localhost ~]# mkdir /date02/dir02
[root@localhost ~]# ll /date01
Total used 20
drwxr-xr-x. 2 root root 4096 Nov 26 21:28 dir01
drwx------. 2 root root 16384 Nov 26 21:19 lost+found
[root@localhost ~]# ll /date02
Total used 0
drwxr-xr-x. 2 root root 6 11月 26 21:28 dir02
- • Using the mount command is temporary; after the system restarts, it will be invalid, and you need to mount it again. Users can modify the /etc/fstab configuration file to make it permanent.
” blkid ” – View the UUID of the device
[root@localhost ~]# blkid
/dev/sdb1: UUID="67e9447b-a6dd-47d2-a738-55983bc3c915" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="fbc32bc2-b7da-4912-a191-920413125325"
/dev/sdb2: UUID="570e001f-162e-4ecd-8873-6d2c82c0edfb" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="1254b3e7-55be-40ca-b198-0b57f29dbf6a"
/dev/sdb3: PARTLABEL="Linux filesystem" PARTUUID="b5eaddb3-5935-4d8b-b755-2d4f47599a7a"
/dev/sdb4: PARTLABEL="Linux filesystem" PARTUUID="ed1ede26-7603-4f30-b52a-8247f0f49f6a"
/dev/sda1: UUID="f4b88752-547e-4442-bfbc-2ec46b75510c" TYPE="xfs"
/dev/sda2: UUID="8yl9fP-Nj4t-OTt8-P2Q2-B3p8-1nrp-PUKcfd" TYPE="LVM2_member"
/dev/sr0: UUID="2020-11-04-11-36-43-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/centos-root: UUID="cf8c0d8c-19ca-496c-8ff6-6f8fc7a88517" TYPE="xfs"
/dev/mapper/centos-swap: UUID="93521d4e-9ae4-4c93-8909-e46441105623" TYPE="swap"
- • Write the UUID of the device in the /etc/fstab configuration file, where the sdc1 partition’s mount point is data03, filesystem type is xfs, mount options are defaults, the last two numbers are 0, indicating no backup, no check; the sdc5 partition’s mount point is data04, filesystem type is auto (automatic), mount options are ro (read-only), the last two numbers are 0, indicating no backup, no check.
#
# /etc/fstab
# Created by anaconda on Sun Sep 10 14:53:15 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=f4b88752-547e-4442-bfbc-2ec46b75510c /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
UUID="67e9447b-a6dd-47d2-a738-5598bc3c915" /date01 xfs defaults 0 0
UUID="570e001f-162e-4ecd-8873-6d2c82c0edfb" /date02 auto ro 0 0
Restarting the system will allow reading the newly mounted devices, and the “mount -a” command can be used to read the /etc/fstab file and mount the devices. Use the df command to view the information of the mounted devices, adding the “-T” parameter can display the type of device files, adding the “-h” parameter can display the size of the devices.
[root@localhost ~]# mount -a
[root@localhost ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 1.9G 13M 1.9G 1% /run
tmpfs tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 26G 6.6G 20G 26% /
/dev/sda1 xfs 1014M 185M 830M 19% /boot
tmpfs tmpfs 378M 32K 378M 1% /run/user/0
/dev/sr0 iso9660 4.4G 4.4G 0 100% /run/media/root/CentOS 7 x86_64
/tmpfs tmpfs 378M 36K 378M 1% /run/user/1000
/dev/sdb1 ext4 7.8G 36M 7.3G 1% /date01
/dev/sdb2 xfs 97M 5.3M 92M 6% /date02
After completing the partitioning, mounting, and formatting of the hard disk, you can try to store data through the mount points: simultaneously copy the /etc/hosts file to the data03 and data04 directories. The data03 directory can be written to, while data04 prompts that it cannot create a regular file. The details are as follows.
[root@localhost ~]# cp -rf /etc/host /date01
[root@localhost ~]# cp -rf /etc/host /date02
cp: cannot stat '/etc/host': No such file or directory
” mount ” – Display the permissions of the device
/dev/sdb1 on /date01 type ext4 (rw,relatime,seclabel,data=ordered)
/dev/sdb2 on /date02 type xfs (ro,relatime,seclabel,attr2,inode64,noquota)
7.3 Chapter Summary
This chapter mainly introduces the methods of storage (disk parameters and performance) and basic partitioning (MBR and GPT). Through the study of this chapter, I have mastered the methods of creating basic partitions, creating filesystems, and mounting.
Link: https://www.cnblogs.com/twlwbiubiu/p/17858056.html