Linux   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linux磁盘挂载和扩容。大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

扩容: 1、磁盘分区 [ [email protected] ~]# fdisk /dev/vda WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to switch off the mode (command ‘c‘) and change display units to sectors (comman
扩容:
1、磁盘分区
[ [email protected] ~]# fdisk /dev/vda

WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
switch off the mode (command ‘c‘) and change display units to
sectors (command ‘u‘).

Command (m for Help): n ---新增分区
Command action
e extended
p priMary partition (1-4)
p ---P表示主分区
Partition number (1-4): 3 ----分区盘序号
First cylinder (1-166440,default 1): 83221 ---分区开始序号
Last cylinder,+cylinders or +size{K,M,G} (83221-166440,default 166440): ---直接回车
Using default value 166440

Command (m for Help): t -----改变分区格式
Partition number (1-4): 3
Hex code (type L to list codes): 8e -----分区为lvm格式
Changed system type of partition 3 to 8e (Linux LVM)

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.

2.可以看到,新增的40G已划分成/dev/vda3了

linux磁盘挂载和扩容。

这一步完成后最好重启一下服务器。

3、添加新LVM到已有的LVM组
1)pvcreate /dev/vda3

linux磁盘挂载和扩容。

2)查看vg name

linux磁盘挂载和扩容。

3)将pv加入到vg卷组
[[email protected] ~]# vgextend VolGroup /dev/vda3

linux磁盘挂载和扩容。


4)查看 Free PE/Size 大小,这里为10239

linux磁盘挂载和扩容。


5)查看根目录的lv名称

linux磁盘挂载和扩容。

6)扩容lv
[[email protected] ~]# lvextend -l +10239 /dev/VolGroup/lv_root

linux磁盘挂载和扩容。

linux磁盘挂载和扩容。

lvextend指令用于在线扩展逻辑卷的空间大小,而不中断应用程序对逻辑卷的访问。其后有两个选项
选项 说明
-L 指定逻辑卷的大小,单位为“kKmMgGtT”字节,也就是Size
-l 指定逻辑卷的大小,单位为PE数

4、扩容文件系统
以上只是卷扩容了,还要对文件系统实现真正扩容

CentOS 6 下执行:
[[email protected] ~]# resize2fs /dev/VolGroup/lv_root

linux磁盘挂载和扩容。

CentOS 7 下执行:
[[email protected] ~]# xfs_growfs /dev/VolGroup/lv_root

5、查看磁盘空间是否扩容

linux磁盘挂载和扩容。

如果没有卷组,可以创建卷组,再挂载。

再次使用 fdisk -l 查看系统内磁盘情况发现 /dev/sdb上已有一个 Linux LVM 格式的 /dev/sdb1分区

linux磁盘挂载和扩容。

使kernel重新读取分区表
命令:partprobe
对于 /dev/sda 的警告不予理会

创建PV:
扫面系统PV:pvscan
创建PV:pvcreate /dev/sdb1
查看PV:pvdisplay
这样我们就创建一个 4.98G的PV,注意 Allocatable 为 NO

linux磁盘挂载和扩容。

创建 VG:
扫面系统VG:vgscan
创建VG:vgcreate vg_test /dev/sdb1
查看VG:vgdisplay
这样我们就创建一个 4.98G(1274 个PE,要记住这个数字)的VG(名字为vg_test)

linux磁盘挂载和扩容。

创建LV:
扫面系统LV:lvscan
创建LV:lvcreate -l 1274 -n lv_test vg_test (1274是VG中PE的个数)
查看LV:lvdisplay
这样我们就创建一个名字为 lv_test 的LV

linux磁盘挂载和扩容。

格式化刚刚创建的LV
命令:mkfs -t ext4 /dev/vg_test/lv_test

创建目录并挂载
创建目录:mkdir /test
挂载:mount /dev/vg_test/lv_test /test
查看:df -h
我们发现系统已经挂载了刚刚创建的LV

linux磁盘挂载和扩容。

还有最后一步,设置开机挂载将 /dev/mapper/vg_test-lv_test /test ext4 defaults 1 2 写入 /etc/fstab至此,大功告成!欲知如何增加LV容量,且待下回分享~~

大佬总结

以上是大佬教程为你收集整理的linux磁盘挂载和扩容。全部内容,希望文章能够帮你解决linux磁盘挂载和扩容。所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。