1. 存储管理概述
Linux存储管理是系统管理的重要组成部分,包括磁盘管理、分区管理、文件系统管理、LVM管理、交换空间管理和RAID管理等。本文将详细介绍Linux系统的存储管理方法。更多学习教程www.fgedu.net.cn
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 500G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 10G 0 part [SWAP]
└─sda3 8:3 0 489G 0 part /
sdb 8:16 0 100G 0 disk
└─sdb1 8:17 0 100G 0 part /data
2. 磁盘管理
磁盘管理是存储管理的基础,包括磁盘识别、分区、格式化和挂载等操作。
# fdisk -l
Disk /dev/sda: 500 GiB, 536870912000 bytes, 1048576000 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 12345678-1234-1234-1234-1234567890ab
Device Start End Sectors Size Type
/dev/sda1 2048 2099199 2097152 1G EFI System
/dev/sda2 2099200 23068671 20969472 10G Linux swap
/dev/sda3 23068672 1048575966 1025507295 489G Linux filesystem
Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 87654321-4321-4321-4321-0987654321ab
Device Start End Sectors Size Type
/dev/sdb1 2048 209715166 209713119 100G Linux filesystem
3. 分区管理
分区管理是将磁盘划分为多个逻辑区域的过程,便于管理和使用。学习交流加群风哥微信: itpux-com
# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199): +50G
Created a new partition 1 of type ‘Linux’ and of size 50 GiB.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (104859648-209715199, default 104859648):
Last sector, +sectors or +size{K,M,G,T,P} (104859648-209715199, default 209715199):
Created a new partition 2 of type ‘Linux’ and of size 50 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
# parted /dev/sdc mklabel gpt
# parted /dev/sdc mkpart primary ext4 1MiB 50GiB
# parted /dev/sdc mkpart primary ext4 50GiB 100GiB
# parted /dev/sdc print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdc: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 50.0GB 50.0GB primary
2 50.0GB 100GB 50.0GB primary
4. 文件系统管理
文件系统是操作系统用于管理和存储数据的方式,Linux支持多种文件系统,如ext4、XFS、Btrfs等。
# mkfs.ext4 /dev/sdc1
mke2fs 1.44.3 (10-July-2018)
Creating filesystem with 13107200 4k blocks and 3276800 inodes
Filesystem UUID: 12345678-1234-1234-1234-1234567890ab
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424
Allocating group tables: done
Writing inode tables: done
Creating journal (65536 blocks): done
Writing superblocks and filesystem accounting information: done
# 格式化分区为XFS文件系统
# mkfs.xfs /dev/sdc2
meta-data=/dev/sdc2 isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
# mkdir /mnt/data1 /mnt/data2
# mount /dev/sdc1 /mnt/data1
# mount /dev/sdc2 /mnt/data2
# 查看挂载信息
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 489G 15G 474G 3% /
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 8.5M 32G 1% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/sda1 1022M 128M 895M 13% /boot
/dev/sdb1 100G 20G 80G 20% /data
/dev/sdc1 50G 200M 47G 1% /mnt/data1
/dev/sdc2 50G 200M 47G 1% /mnt/data2
# 永久挂载
# vi /etc/fstab
/dev/sdc1 /mnt/data1 ext4 defaults 0 0
/dev/sdc2 /mnt/data2 xfs defaults 0 0
5. LVM管理
LVM(逻辑卷管理)是一种灵活的存储管理方式,可以动态调整逻辑卷大小,提高存储利用率。学习交流加群风哥QQ113257174
# pvcreate /dev/sdd /dev/sde
Physical volume “/dev/sdd” successfully created.
Physical volume “/dev/sde” successfully created.
# 查看物理卷
# pvdisplay
— Physical volume —
PV Name /dev/sdd
VG Name vg_data
PV Size 100.00 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25599
Free PE 0
Allocated PE 25599
PV UUID 12345678-1234-1234-1234-1234567890ab
— Physical volume —
PV Name /dev/sde
VG Name vg_data
PV Size 100.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 25599
Free PE 25599
Allocated PE 0
PV UUID 87654321-4321-4321-4321-0987654321ab
# 创建卷组
# vgcreate vg_data /dev/sdd /dev/sde
Volume group “vg_data” successfully created
# 查看卷组
# vgdisplay
— Volume group —
VG Name vg_data
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 199.99 GiB
PE Size 4.00 MiB
Total PE 51198
Alloc PE / Size 25599 / 100.00 GiB
Free PE / Size 25599 / 100.00 GiB
VG UUID abcdefgh-1234-1234-1234-1234567890ab
# 创建逻辑卷
# lvcreate -L 100G -n lv_data vg_data
Logical volume “lv_data” created.
# 格式化逻辑卷
# mkfs.ext4 /dev/vg_data/lv_data
# 挂载逻辑卷
# mkdir /mnt/lv_data
# mount /dev/vg_data/lv_data /mnt/lv_data
# 扩展逻辑卷
# lvextend -L +50G /dev/vg_data/lv_data
Size of logical volume vg_data/lv_data changed from 100.00 GiB (25599 extents) to 150.00 GiB (38399 extents).
Logical volume vg_data/lv_data successfully resized.
# 扩展文件系统
# resize2fs /dev/vg_data/lv_data
resize2fs 1.44.3 (10-July-2018)
Resizing the filesystem on /dev/vg_data/lv_data to 39321600 (4k) blocks.
The filesystem on /dev/vg_data/lv_data is now 39321600 (4k) blocks long.
6. 交换空间管理
交换空间是系统内存不足时的临时存储区域,对系统稳定性至关重要。
# free -h
total used free shared buff/cache available
Mem: 62G 2.1G 58G 8.5M 1.8G 59G
Swap: 32G 0B 32G
# 创建交换分区
# fdisk /dev/sdf
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199): +16G
Created a new partition 1 of type ‘Linux’ and of size 16 GiB.
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 82
Changed type of partition ‘Linux’ to ‘Linux swap / Solaris’.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
# 格式化交换分区
# mkswap /dev/sdf1
Setting up swapspace version 1, size = 16 GiB (17179869184 bytes)
no label, UUID=12345678-1234-1234-1234-1234567890ab
# 启用交换分区
# swapon /dev/sdf1
# 永久启用交换分区
# vi /etc/fstab
/dev/sdf1 swap swap defaults 0 0
# 查看交换分区信息
# swapon -s
Filename Type Size Used Priority
/dev/sda2 partition 10485760 0 -2
/dev/sdf1 partition 16777216 0 -3
7. RAID管理
RAID(冗余阵列)是一种通过多块磁盘组合提高存储性能和可靠性的技术。更多学习教程公众号风哥教程itpux_com
# yum install -y mdadm
# 创建RAID 1阵列
# mdadm –create /dev/md0 –level=1 –raid-devices=2 /dev/sdg /dev/sdh
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device.
If you plan to store ‘/boot’ on this device,
please ensure that your boot-loader understands md/v1.x metadata,
or use –metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
# 查看RAID状态
# mdadm –detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Apr 2 10:00:00 2026
Raid Level : raid1
Array Size : 104857600 (100.00 GiB 107.37 GB)
Used Dev Size : 104857600 (100.00 GiB 107.37 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Apr 2 10:00:00 2026
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Consistency Policy : resync
Name : fgedu:0 (local to host fgedu)
UUID : 12345678:12345678:12345678:12345678
Events : 17
Number Major Minor RaidDevice State
0 8 96 0 active sync /dev/sdg
1 8 112 1 active sync /dev/sdh
# 格式化RAID阵列
# mkfs.ext4 /dev/md0
# 挂载RAID阵列
# mkdir /mnt/raid1
# mount /dev/md0 /mnt/raid1
# 永久挂载RAID阵列
# vi /etc/fstab
/dev/md0 /mnt/raid1 ext4 defaults 0 0
# 配置RAID自动启动
# mdadm –detail –scan >> /etc/mdadm.conf
8. 存储监控
存储监控是确保存储系统正常运行的重要手段,需要定期检查存储状态和性能。
# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 489G 15G 474G 3% /
devtmpfs 32G 0 32G 0% /dev
tmpfs 32G 0 32G 0% /dev/shm
tmpfs 32G 8.5M 32G 1% /run
tmpfs 32G 0 32G 0% /sys/fs/cgroup
/dev/sda1 1022M 128M 895M 13% /boot
/dev/sdb1 100G 20G 80G 20% /data
/dev/sdc1 50G 200M 47G 1% /mnt/data1
/dev/sdc2 50G 200M 47G 1% /mnt/data2
/dev/vg_data/lv_data 150G 200M 142G 1% /mnt/lv_data
/dev/md0 100G 200M 95G 1% /mnt/raid1
# 查看磁盘I/O性能
# iostat -d -x 1 5
Linux 3.10.0-1160.el7.x86_64 (fgedu.net.cn) 04/02/2026 _x86_64_ (32 CPU)
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdd 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sde 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdf 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdg 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sdh 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
md0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
# lvdisplay
— Logical volume —
LV Path /dev/vg_data/lv_data
LV Name lv_data
VG Name vg_data
LV UUID 12345678-1234-1234-1234-1234567890ab
LV Write Access read/write
LV Creation host, time fgedu, 2026-04-02 10:00:00 +0800
LV Status available
# open 1
LV Size 150.00 GiB
Current LE 38399
Segments 2
Allocation inherit
Read ahead sectors auto
– currently set to 8192
Block device 253:0
# 查看RAID状态
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdh[1] sdg[0]
104857600 blocks super 1.2 [2/2] [UU]
unused devices:
9. 存储故障排查
存储故障排查是系统管理员的重要技能,需要掌握基本的排查方法和工具。
# 检查磁盘状态
# smartctl -a /dev/sda
# 检查文件系统
# fsck -f /dev/sda3
# 排查挂载问题
# 检查fstab文件
# cat /etc/fstab
# 检查挂载点
# mount -a
# 排查LVM故障
# 检查物理卷
# pvscan
# 检查卷组
# vgscan
# 检查逻辑卷
# lvscan
# 排查RAID故障
# 检查RAID状态
# mdadm –detail /dev/md0
# 替换故障磁盘
# mdadm /dev/md0 –fail /dev/sdg –remove /dev/sdg
# mdadm /dev/md0 –add /dev/sdi
10. 最佳实践
存储管理的最佳实践可以提高系统的可靠性和性能。author:www.itpux.com
– 使用LVM进行存储管理,提高存储灵活性
– 配置适当的交换空间,确保系统稳定性
– 使用RAID提高存储可靠性和性能
– 定期备份重要数据
– 定期监控存储使用情况和I/O性能
– 合理规划分区和文件系统
– 选择合适的文件系统类型
# 备份分区表
# sfdisk -d /dev/sda > /backup/partition-table-sda.txt
# 备份LVM配置
# vgcfgbackup -f /backup/lvm-backup
# 备份RAID配置
# mdadm –detail –scan > /backup/raid-config.txt
# 备份fstab文件
# cp /etc/fstab /backup/fstab.bak
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
