虚拟机增加磁盘空间后lv扩容详细流程,linux扩容根目录详细流程【openstack和VMware虚拟机方法同理】,2024尾声祝福送上。

[root@lv-test ~]#

[root@lv-test ~]# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

home centos -wi-ao---- <41.12g

root centos -wi-ao---- 150.00g

swap centos -wi-ao---- <7.88g

[root@lv-test ~]#

  • 现在df呢,是看不到150g空间的,需要刷新以后才能看到

刷新之前呢,需要先看这个是啥格式的,如我的根是xfs格式的,那么我就需要用xfs的方式来刷新

[root@lv-test ~]# df -Th

Filesystem Type Size Used Avail Use% Mounted on

/dev/mapper/centos-root xfs 50G 1.1G 49G 3% /

devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev

tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm

tmpfs tmpfs 3.9G 12M 3.8G 1% /run

tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup

/dev/sda1 xfs 1014M 146M 869M 15% /boot

/dev/mapper/centos-home xfs 42G 33M 42G 1% /home

tmpfs tmpfs 781M 0 781M 0% /run/user/0

[root@lv-test ~]#

xfs的刷新,ext4不能用

一般是用挂载目录作为刷新地址,所以我直接用 /

[root@lv-test ~]# xfs_growfs /

meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0 spinodes=0

data = bsize=4096 blocks=13107200, imaxpct=25

= sunit=0 swidth=0 blks

naming =version 2 bsize=4096 ascii-ci=0 ftype=1

log =internal bsize=4096 blocks=6400, version=2

= sectsz=512 sunit=0 blks, lazy-count=1

realtime =none extsz=4096 blocks=0, rtextents=0

data blocks changed from 13107200 to 39321600

刷新后就可以看到/目录空间已经增加了

[root@lv-test ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/centos-root 150G 1.1G 149G 1% /

devtmpfs 3.8G 0 3.8G 0% /dev

tmpfs 3.9G 0 3.9G 0% /dev/shm

tmpfs 3.9G 12M 3.8G 1% /run

tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup

/dev/sda1 1014M 146M 869M 15% /boot

/dev/mapper/centos-home 42G 33M 42G 1% /home

tmpfs 781M 0 781M 0% /run/user/0

[root@lv-test ~]#

扩容后信息一览和说明

  • 其中就pv能看到多了一个空间罢了,其他基本看不出啥

[root@lv-test ~]# pvs

PV VG Fmt Attr PSize PFree

/dev/sda2 centos lvm2 a-- <99.00g 0

/dev/sda3 centos lvm2 a-- <100.00g 0

[root@lv-test ~]#

[root@lv-test ~]# vgs

VG #PV #LV #SN Attr VSize VFree

centos 2 3 0 wz–n- 198.99g 0

[root@lv-test ~]#

[root@lv-test ~]# lvs

LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert

home centos -wi-ao---- <41.12g

root centos -wi-ao---- 150.00g

swap centos -wi-ao---- <7.88g

[root@lv-test ~]#

  • lsblk的话就能看到很多东西了,可以看到sda2下面的centos-root和sda3下面同样有一个centos-root,这2个信息是一摸一样的,别慌这是正常的,表示 centos-root是由 sda2和sda3的空间组成的一个总容量为150G【这时候可以看到sda3有100g,所以可以得知sda2中用了50g】

[root@lv-test ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 200G 0 disk

├─sda1 8:1 0 1G 0 part /boot

├─sda2 8:2 0 99G 0 part

│ ├─centos-root 253:0 0 150G 0 lvm /

│ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP]

│ └─centos-home 253:2 0 41.1G 0 lvm /home

└─sda3 8:3 0 100G 0 part

└─centos-root 253:0 0 150G 0 lvm /

sdb 8:16 0 300G 0 disk

sr0 11:0 1 4.3G 0 rom

[root@lv-test ~]#

新增一块硬盘,把容量加到固定的vg和lv上


做扇区

  • 做扇区的意义其实还是挺重要的,比如我现在有一个300g的新硬盘,我这次只想用100g,把100g的空间加到某个lv上,剩下的200g先不用。

然后后面200g想用的时候再随时做扇区,这样有规划的使用是不是正规的多?【其实最主要的是如果想把空间增加到不同的vg上,就必须这么做】

如果只有一个vg,那么我们直接把这300g做成一个扇区也无所谓,300g全部划到vg上。lv用多少取多少,只是只能在这一个vg上做罢了,不能跨vg使用这300g容量

  • 我这呢准备用2个vg来做实验,方便更能理解vg,所以我扇区先做2个100g的,剩余100g我后面做其他实验用。

现在没有扇区的

[root@lv-test ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@lv-test ~]#

开始增加2个100g空间

[root@lv-test ~]# 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 0x359bff9f.

Command (m for help): n

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-629145599, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599): +100G

Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): p

Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x359bff9f

Device Boot Start End Blocks Id System

/dev/sdb1 2048 209717247 104857600 83 Linux

Command (m for help): n

Partition type:

p primary (1 primary, 0 extended, 3 free)

e extended

Select (default p): p

Partition number (2-4, default 2): 2

First sector (209717248-629145599, default 209717248):

Using default value 209717248

Last sector, +sectors or +size{K,M,G} (209717248-629145599, default 629145599): +100G

Partition 2 of type Linux and of size 100 GiB is set

Command (m for help): p

Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x359bff9f

Device Boot Start End Blocks Id System

/dev/sdb1 2048 209717247 104857600 83 Linux

/dev/sdb2 209717248 419432447 104857600 83 Linux

Command (m for help): t

Partition number (1,2, default 2): 1

Hex code (type L to list all codes): 8e

Changed type of partition ‘Linux’ to ‘Linux LVM’

Command (m for help): t

Partition number (1,2, default 2): 2

Hex code (type L to list all codes): 8e

Changed type of partition ‘Linux’ to ‘Linux LVM’

Command (m for help): p

Disk /dev/sdb: 322.1 GB, 322122547200 bytes, 629145600 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x359bff9f

Device Boot Start End Blocks Id System

/dev/sdb1 2048 209717247 104857600 8e Linux LVM

/dev/sdb2 209717248 419432447 104857600 8e Linux LVM

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@lv-test ~]#

可以看到已经有2个100g空间了,还剩100g

[root@lv-test ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 200G 0 disk

├─sda1 8:1 0 1G 0 part /boot

├─sda2 8:2 0 99G 0 part

│ ├─centos-root 253:0 0 150G 0 lvm /

│ ├─centos-swap 253:1 0 7.9G 0 lvm [SWAP]

│ └─centos-home 253:2 0 41.1G 0 lvm /home

└─sda3 8:3 0 100G 0 part

└─centos-root 253:0 0 150G 0 lvm /

sdb 8:16 0 300G 0 disk

├─sdb1 8:17 0 100G 0 part

└─sdb2 8:18 0 100G 0 part

sr0 11:0 1 4.3G 0 rom

[root@lv-test ~]#

增加pv空间

  • 现在的pv信息

注:pv实际上都是新增,而不是把空间加到某个已有vp上

[root@lv-test ~]# pvs

PV VG Fmt Attr PSize PFree

/dev/sda2 centos lvm2 a-- <99.00g 0</

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值