Linux Red Hat Enterprise 7 扩展 root LV空间

前题:安装Splunk后发现在web页面中提示"可用磁盘空间小于5000M",splunk 安装路径在/opt/下,只要扩展rootlv即可

系统是在VMware Workstation Pro 虚拟中给虚拟硬盘扩展空间,需要在关机状态下扩展

VM

没扩展前磁盘情况

[root@localhost rhel]# df -h
文件系统               容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root   10G  4.1G   5.9G   42% /
devtmpfs               908M     0  908M    0% /dev
tmpfs                  914M     0  914M    0% /dev/shm
tmpfs                  914M  8.6M  905M    1% /run
tmpfs                  914M     0  914M    0% /sys/fs/cgroup
/dev/sda1              497M   96M  402M   20% /boot

在sdb磁盘上创建第三个分区

[root@localhost /]# fdisk /dev/sda
命令(输入 m 获取帮助):n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
分区号 (3,4,默认 3):3
起始 扇区 (20971520-41943039,默认为 20971520):
将使用默认值 20971520
Last 扇区, +扇区 or +size{K,M,G} (20971520-41943039,默认为 41943039):
将使用默认值 41943039
分区 3 已设置为 Linux 类型,大小设为 10 GiB

命令(输入 m 获取帮助):p

磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0008970f

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    20971519     9972736   8e  Linux LVM
/dev/sda3        20971520    41943039    10485760   83  Linux

命令(输入 m 获取帮助):t
分区号 (1-3,默认 3):3
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”

命令(输入 m 获取帮助):p

磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0008970f

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    20971519     9972736   8e  Linux LVM
/dev/sda3        20971520    41943039    10485760   8e  Linux LVM

命令(输入 m 获取帮助):w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。

发现没有sda3 设备文件,内核重读

[root@localhost dev]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0   20G  0 disk 
├─sda1          8:1    0  500M  0 part /boot
└─sda2          8:2    0  9.5G  0 part 
  ├─rhel-root 253:0    0  8.5G  0 lvm  /
  └─rhel-swap 253:1    0    1G  0 lvm  [SWAP]
[root@localhost dev]# partprobe
[root@localhost dev]# lsblk
NAME          MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda             8:0    0   20G  0 disk 
├─sda1          8:1    0  500M  0 part /boot
├─sda2          8:2    0  9.5G  0 part 
│ ├─rhel-root 253:0    0  8.5G  0 lvm  /
│ └─rhel-swap 253:1    0    1G  0 lvm  [SWAP]
└─sda3          8:3    0   10G  0 part 

扩展vg

[root@localhost /]# vgextend rhel /dev/sda3 
WARNING: dos signature detected on /dev/sda3 at offset 510. Wipe it? [y/n] y
  Wiping dos signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created
  Volume group "rhel" successfully extended
[root@localhost /]# vgs
 VG   #PV #LV #SN Attr   VSize  VFree 
 rhel   2   2   0 wz--n- 19.50g 10.00g
[root@localhost /]#

扩展lv

[root@localhost /]# lvextend -L +10G /dev/rhel/root 
  Extending logical volume root to 18.51 GiB
  Insufficient free space: 2560 extents needed, but only 2559 available
发现添加10G空间会报错,只能添加到18.51G。难道sda3空间没有10吗?只有8G?以后再研究
[root@localhost /]# lvextend -L +8G /dev/rhel/root 
退而求其次 添加8G空间
  Extending logical volume root to 16.51 GiB
  Logical volume root successfully resized
[root@localhost /]# lvs
查看lvs情况
  LV   VG   Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  root rhel -wi-ao---- 16.51g                                             
  swap rhel -wi-ao----  1.00g

查看磁盘情况,没有发生变化

[root@localhost /]# df -h
文件系统               容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root  8.5G  4.1G  4.5G   48% /
devtmpfs               908M     0  908M    0% /dev
tmpfs                  914M     0  914M    0% /dev/shm
tmpfs                  914M  8.6M  905M    1% /run
tmpfs                  914M     0  914M    0% /sys/fs/cgroup
/dev/sda1              497M   96M  402M   20% /boot

 

使用xfs_growfs /dev/rhel/root 命令使系统重新读取大小 参考:https://www.cnblogs.com/liutao97/p/6775093.html

[root@localhost /]# xfs_growfs /dev/rhel/root 
meta-data=/dev/mapper/rhel-root  isize=256    agcount=4, agsize=557568 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=2230272, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
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 2230272 to 4327424

查看磁盘情况

[root@localhost /]# df -h
文件系统               容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root   17G  4.1G   13G   25% /
devtmpfs               908M     0  908M    0% /dev
tmpfs                  914M     0  914M    0% /dev/shm
tmpfs                  914M  8.6M  905M    1% /run
tmpfs                  914M     0  914M    0% /sys/fs/cgroup
/dev/sda1              497M   96M  402M   20% /boot

问题解决了

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值