centos7 根目录增加磁盘空间

查看磁盘空间大小,后续加完好对比一下

[root@node1 ~]# df -h

由于创建虚拟机时仅给根目录分配 38G 的空间,后续明显不够用,想再扩展 20G 的空间。

 查看新添加的磁盘空间20GB

[root@node1 ~]# fdisk -l

创建分区 /dev/sdb ,注意选择 8e 也即是 LVM 类型

[root@node1 ~]# 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 0xf9d73537.

Command (m for help): n   # 输入命令n,建立一个新的分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p    # 输入 p,或者直接按回车
Partition number (1-4, default 1): 1  # 输入 1,或者直接按回车
First sector (2048-20971519, default 2048):   # 直接按回车
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519):   # 直接按回车
Using default value 20971519
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): t  # 输入命令 t,定义新分区的类型
Selected partition 1
Hex code (type L to list all codes): 8e # 输入 8e,8e是Linux LVM类型的代码
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): w  # 输入命令 w 完成修改
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

看到已经存在分区 /dev/sdb1 了

​创建 PV 

[root@node1 ~]# pvcreate /dev/sdb1

 

 查看 LV,显示 LV Path 为 /dev/centos/root,VG Name 为 centos

[root@node1 ~]# lvdisplay
......
     --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                eh3XHa-w5Hy-pbGA-qqbi-p4j6-H5Gl-LdBRlu
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-09-13 23:42:05 +0800
  LV Status              available
  # open                 1
  LV Size                <8.00 GiB
  Current LE             2047
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

扩展 VG centos 

[root@node1 ~]# vgextend centos /dev/sdb1
  Volume group "centos" successfully extended

扩展 LV /dev/centos/root

[root@node1 ~]# lvextend /dev/centos/root /dev/sdb1
  Size of logical volume centos/root changed from <37.04 GiB (9481 extents) to 57.03 GiB (14600 extents).
  Logical volume centos/root successfully resized.

如果系统是用的XFS文件系统,需要要运行以下命令:

xfs_growfs /dev/centos/root

如果系统不是使用XFS文件系统,需要运行以下命令:

resize2fs /dev/centos/root

我这是xfs文件系统,所以运行

[root@node1 ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=2427136 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=9708544, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=4740, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 9708544 to 14950400

查看磁盘空间信息,/dev/mapper/centos-root 已经扩充到 58 G了

[root@node1 ~]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 898M     0  898M    0% /dev
tmpfs                    910M     0  910M    0% /dev/shm
tmpfs                    910M  9.5M  901M    2% /run
tmpfs                    910M     0  910M    0% /sys/fs/cgroup
/dev/mapper/centos-root   58G   17G   41G   29% /
/dev/sda1               1014M  151M  864M   15% /boot
/dev/mapper/centos-home   19G  259M   18G    2% /home
tmpfs                    182M     0  182M    0% /run/user/0

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值