需求:当前系统中的/home目录存储空间为50G,由于需要在home目录中存储东西,需要将home目录扩展到不小于1T

新加1T硬盘,并对硬盘创建分区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost mapper]# fdisk /dev/sdb
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.

The size of this disk is 2 TiB (2199023255552 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).

Command (m for help): n
Partition type
p primary (2 primary, 0 extended, 2 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1,2, default 1): 1
...........: 默认
.................: +1T # 容量
Command (m for help): t # 更换磁盘类型
Partition number (1,2, default 2): 1
............: 8e # LVM类型
Command (m for help): w # w保存退出

将新建的分区格式化

1
2
3
[root@localhost mapper]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1
[root@localhost mapper]# mkfs.xfs /dev/sdb1

进去lvm管理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@localhost mapper]# lvm
lvm> pvcreate /dev/sdb1 // 创建逻辑卷
lvm>vgextend cl /dev/sdb1 // 将初始化过的分区加入到虚拟卷组cl
lvm>vgdisplay -v
lvm>lvextend -L +1024G /dev/mapper/cl-home // 对home增加1024G
lvm>pvdisplay // 查看卷容量
lvm>quit // 退出

[root@localhost mapper]# xfs_growfs /dev/mapper/cl-home
meta-data=/dev/mapper/cl-home 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
data blocks changed from 13107200 to 281542656

验证

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost mapper]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 16G 0 16G 0% /dev
tmpfs tmpfs 16G 0 16G 0% /dev/shm
tmpfs tmpfs 16G 9.6M 16G 1% /run
tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/mapper/cl-root xfs 20G 4.1G 16G 21% /
/dev/sda1 ext4 9.8G 226M 9.1G 3% /boot
tmpfs tmpfs 3.2G 1.2M 3.2G 1% /run/user/42
tmpfs tmpfs 3.2G 4.6M 3.2G 1% /run/user/0
/dev/mapper/cl-home xfs 1.1T 7.6G 1.1T 1% /home

# /home成功扩容到1T