Linux基础——根目录扩容
1、准备扩容/dev/mapper/centos-root
[root@ceph-admin ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 484M 0 484M 0% /dev
tmpfs tmpfs 496M 0 496M 0% /dev/shm
tmpfs tmpfs 496M 6.8M 489M 2% /run
tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 9.8G 8.2G 1.7G 84% /
/dev/sda1 xfs 1014M 205M 810M 21% /boot
tmpfs tmpfs 100M 0 100M 0% /run/user/0
2、查看可用磁盘/dev/sdb
[root@ceph-admin ~]# fdisk -l
Disk /dev/sda: 12.9 GB, 12884901888 bytes, 25165824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d06ab
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 25165823 11533312 8e Linux LVM
Disk /dev/sdb: 12.9 GB, 12884901888 bytes, 25165824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-root: 10.5 GB, 10515120128 bytes, 20537344 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 1287 MB, 1287651328 bytes, 2514944 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
3、创建分区/dev/sdb1
[root@ceph-admin ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xca473b44.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1): 1
First sector (2048-25165823, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-25165823, default 25165823):
Using default value 25165823
Partition 1 of type Linux and of size 12 GiB is set
Command (m for help): p
Disk /dev/sdb: 12.9 GB, 12884901888 bytes, 25165824 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xca473b44
Device Boot Start End Blocks Id System
/dev/sdb1 2048 25165823 12581888 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
4、查看分区/dev/sdb1
[root@ceph-admin ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 12G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 11G 0 part
├─centos-root 253:0 0 9.8G 0 lvm /
└─centos-swap 253:1 0 1.2G 0 lvm [SWAP]
sdb 8:16 0 12G 0 disk
└─sdb1 8:17 0 12G 0 part
6、创建物理卷/dev/sdb1
[root@ceph-admin ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
7、查询物理卷/dev/sdb1
[root@ceph-admin ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <11.00 GiB / not usable 3.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2815
Free PE 1
Allocated PE 2814
PV UUID 0JO4Gd-o6tb-VdXZ-Lp87-QhXI-NHlM-M8JMOA
"/dev/sdb1" is a new physical volume of "<12.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <12.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID cnP7e2-MHFa-rS8u-9foh-m4kq-MD7x-OCaQ1h
8、查看卷组名称centos
[root@ceph-admin ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <11.00 GiB
PE Size 4.00 MiB
Total PE 2815
Alloc PE / Size 2814 / 10.99 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID Um6Uo9-NS4w-IEK3-EwVj-GZcc-Z2mY-nK1HN0
9、通过vgextend将新添加卷/dev/sdb1加入到卷组centos中
[root@ceph-admin ~]# vgextend vgextend centos /dev/sdb1
Device centos not found.
[root@ceph-admin ~]# vgextend centos /dev/sdb1
Volume group "centos" successfully extended
10、扩容卷组后,卷组空余块
[root@ceph-admin ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 22.99 GiB
PE Size 4.00 MiB
Total PE 5886
Alloc PE / Size 2814 / 10.99 GiB
Free PE / Size 3072 / 12.00 GiB
VG UUID Um6Uo9-NS4w-IEK3-EwVj-GZcc-Z2mY-nK1HN0
11、通过lvextend命令扩展根目录挂载点/dev/mapper/centos-root
[root@ceph-admin ~]# lvextend -L +12G /dev/mapper/centos-root
Size of logical volume centos/root changed from 9.79 GiB (2507 extents) to 21.79 GiB (5579 extents).
Logical volume centos/root successfully resized.
[root@ceph-admin ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 484M 0 484M 0% /dev
tmpfs tmpfs 496M 0 496M 0% /dev/shm
tmpfs tmpfs 496M 6.8M 489M 2% /run
tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 9.8G 8.2G 1.7G 84% /
/dev/sda1 xfs 1014M 205M 810M 21% /boot
tmpfs tmpfs 100M 0 100M 0% /run/user/0
12、同步文件系统
[root@ceph-admin ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=641792 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2567168, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2567168 to 5712896
13、查看根目录挂载点“/”已经扩容
[root@ceph-admin ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 484M 0 484M 0% /dev
tmpfs tmpfs 496M 0 496M 0% /dev/shm
tmpfs tmpfs 496M 6.8M 489M 2% /run
tmpfs tmpfs 496M 0 496M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 22G 8.2G 14G 38% /
/dev/sda1 xfs 1014M 205M 810M 21% /boot
tmpfs tmpfs 100M 0 100M 0% /run/user/0
[root@ceph-admin ~]#
稳步前行,只争朝夕。
分类:
Management
, System
标签:
Linux 磁盘 扩容
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异