Linux 磁盘卷扩容

首先识别磁盘,成功之后会显示在/dev下

[root@oracle01 ~]# fdisk /dev/sda

## /dev/sda为通过fdisk -l 查看到的物理磁盘(第一行)

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): n ## n为创建一个新的分区
Partition type: ## 这里需要选择时创建主分区还是扩展分区,都可以,这里直接选了主分区
p primary (2 primary, 0 extended, 2 free) 
e extended
Select (default p): p ## 选择创建一个主分区,主分区只能有4个,编号为1-4,下面的全部直接回车就好了,会自动将剩余所用空间都创建
Partition number (3,4, default 3): 
First sector (104857600-209715199, default 104857600): 
Using default value 104857600
Last sector, +sectors or +size{K,M,G} (104857600-209715199, default 209715199): 
Using default value 209715199
Partition 3 of type Linux and of size 50 GiB is set

Command (m for help): t ## t为修改分区类型
Partition number (1-3, default 3): 3 ## 刚才创建的分区编号为3
Hex code (type L to list all codes): 8e ## 8e就是 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.

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 or kpartx。所以,这里直接执行partprobe

[root@oracle01 ~]# partprobe

2. 创建了物理分区后,就需要将物理分区创建为物理卷:

## 将物理分区3 创建物理卷,这里这个/dev/sda3是第一步创建的物理分区,通过fdisk -l 就可以看到
## 是在第一个物理磁盘/dev/sda下面的分区(一个磁盘可以有多个分区),原本已有/dev/sda1,/dev/sda2
## 通过第一步创建生成/dev/sda3这个分区,然后将这个分区 创建成物理卷

[root@oracle01 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@oracle01 ~]# pvdisplay ## 查看物理卷
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size 49.51 GiB / not usable 3.00 MiB
Allocatable yes 
PE Size 4.00 MiB
Total PE 12674
Free PE 11
Allocated PE 12663
PV UUID 8T9dpf-SrDj-maVi-IlAb-tpPb-Lzyt-WLeRHG

"/dev/sda3" is a new physical volume of "50.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name 
PV Size 50.00 GiB
Allocatable NO
PE Size 0 
Total PE 0
Free PE 0
Allocated PE 0
PV UUID uRRJtJ-Ds7J-dvqs-y5Lb-W95H-FXeh-C2QNtl


3. 物理卷创建成功后,则需要将物理卷添加到卷组中,这样才能在卷组中进行分配。

[root@oracle01 ~]# vgdisplay ## 查看卷组
--- Volume group ---
VG Name centos
System ID 
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <49.51 GiB
PE Size 4.00 MiB
Total PE 12674
Alloc PE / Size 12663 / 49.46 GiB
Free PE / Size 11 / 44.00 MiB ## 可以看到这个卷组只剩下44M的剩余空间了,其他的都划分为逻辑卷了,类似于已分区
VG UUID 3TMbc1-A7aP-DAMv-QtUU-VTjC-4tOf-iAxDkc

 

[root@oracle01 ~]# vgextend centos /dev/sda3 ## 将物理卷加入到卷组
Volume group "centos" successfully extended
[root@oracle01 ~]# vgdisplay ## 加入后,再次查看卷组
--- Volume group ---
VG Name centos
System ID 
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 99.50 GiB
PE Size 4.00 MiB
Total PE 25473
Alloc PE / Size 12663 / 49.46 GiB
Free PE / Size 12810 / <50.04 GiB ## 可以看到,加入成功后,卷组的剩余空间变大了,这样就有更多的空间可以进行分配,或新创建新的逻辑卷
VG UUID 3TMbc1-A7aP-DAMv-QtUU-VTjC-4tOf-iAxDkc


4. 添加进卷组后,就是将剩余空间对逻辑卷进行扩容。

[root@oracle01 ~]# lvdisplay ## 查看逻辑卷
--- Logical volume ---
LV Path /dev/centos/root ## 逻辑卷名称
LV Name root
VG Name centos
LV UUID RaEygR-53tg-UaJQ-5dJs-e8V4-by51-fcp1DQ
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-09-30 19:12:05 +0800
LV Status available
# open 1
LV Size 45.46 GiB ## 增加前,逻辑卷大小
Current LE 11639
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

[root@oracle01 ~]# lvextend -l +100%FREE /dev/centos/root ## 将剩余百分百空间都添加到逻辑卷中
Size of logical volume centos/root changed from 45.46 GiB (11639 extents) to 95.50 GiB (24449 extents).
Logical volume centos/root successfully resized.
[root@oracle01 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID RaEygR-53tg-UaJQ-5dJs-e8V4-by51-fcp1DQ
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-09-30 19:12:05 +0800
LV Status available
# open 1
LV Size 95.50 GiB ## 增加后,逻辑卷大小
Current LE 24449
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

5. 然后重新识别一下分区大小,就可以通过df -h看到新增的容量了

[root@oracle01 ~]# xfs_growfs /dev/centos/root ## 命令,后面跟的是逻辑卷的path
meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=2979584 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=11918336, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=5819, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11918336 to 25035776

[root@oracle01 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 96G 32G 64G 34% / ## 这里可以看到,已成功扩容 devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 17M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 497M 125M 372M 26% /boot tmpfs 379M 0 379M 0% /run/user/0

OK,到此,扩容完成。并且不需要重启,方便好用。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值