df -h
df 是来自于coreutils 软件包,系统安装时,就自带的;我们通过这个命令可以查看磁盘的使用情况以及文件系统被挂载的位置;
可以看到我们的/dev/mapper/centos-root,也就是根目录’/'已经满载了。
df -Th
使用df -Th 检查分区类型,检查分区是否为逻辑分区 ,如果不是则不能调整
红色为主分区sda1,主分区和扩展分区总共不能超过四个,青色为逻辑分区。
fdisk -l
fdisk 是一款强大的磁盘操作工具,通过-l 参数,能获得机器中所有的硬盘的分区情况;fdisk -l 能列出机器中所有磁盘的个数,也能列出所有磁盘分区情况;Blocks中,表示的是分区的大小,Blocks的单位是byte;
xfs分区大小调整 注意 xfs缩小分区需要格式化,提前做好数据备份
通过缩小 home 空间 扩大 root空间。
# 1.终止占用 /home 进程
fuser -m -v -i -k /home
# 2.备份/home
cp -r /home/ homebak/
# 3.卸载 /home
umount /home
# 4.删除/home所在的lv
lvremove /dev/mapper/centos-home
这里可以不删除 使用
lvreduce -L 5G /dev/mapper/centos-home
缩小5G 空间
# 5.扩展/root所在的lv,增加100G
lvextend -L +100G /dev/mapper/centos-root
# 6.扩展/root文件系统
xfs_growfs /dev/mapper/centos-root
# 7.重新创建home lv,这里可能出现文件系统大小不够的情况,这时,你需要删除/目录里的一部分数据。
lvcreate -L 40G -n home centos
这里如果第4步没有删除 home直接进行第8步
# 8.创建文件系统
mkfs.xfs /dev/centos/home
# 9.挂载
mount /dev/centos/home /home
# 10.还原 /home 相关文件以及对应目录权限
如果是ext2/ext3/ext4文件系统的调整命令是resize2fs(增大和减小都支持),上述为xfs文件系统的分区。
lvextend -L 120G /dev/mapper/centos-home //增大至120G
lvextend -L +20G /dev/mapper/centos-home //增加20G
lvreduce -L 50G /dev/mapper/centos-home //减小至50G
lvreduce -L -8G /dev/mapper/centos-home //减小8G
resize2fs /dev/mapper/centos-home //执行调整
fdisk /dev/sda
[root@centos7 matt]# fdisk /dev/sda
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.
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 # n 表示创建一个新的分区
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 # w 表示写入并退出
x extra functionality (experts only)
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3 #选择磁盘命名 为 /sda3
First sector (24537088-104857599, default 24537088): #确定创建的新分区写入的大小,全部的话就直接确认
Using default value 24537088
Last sector, +sectors or +size{K,M,G} (24537088-104857599, default 104857599):
Using default value 104857599
Partition 3 of type Linux and of size 38.3 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
刷新
partprobe
格式化分区;创建/dev/sda3,将/dev/sda3分区格式化为物理卷
pvcreate /dev/sda3
pvdisplay #查看磁盘
vgs
使用vgextend centos /dev/sda3命令为centos卷组增加物联卷/dev/sda3
vgextend centos /dev/sda3
[root@centos7 matt]# vgextend centos /dev/sda3
Couldn’t create temporary archive name.
这是因为我们的/分区已经满了,需要删除一些根目录中一些不需要的文件。再重新操作就会成功。
lvextend -L +35G /dev/centos/root
vgdisplay
如果有什么建议和问题欢迎大家在评论区进行讨论。