vmware常用操作之磁盘扩容

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vmware常用操作之磁盘扩容相关的知识,希望对你有一定的参考价值。

概要

无论虚拟机还是企业维护的正式服务器,安装应用过多过,必定面临磁盘不够用的情况,特别个人实验使用的虚拟机,应该对磁盘使用做好规划。文件系统使用的基本规划

挂载目录

系统类型

作用

是否扩展

/

本地系统

存放OS文件和常用包

/opt

lvm

存放应用软件和数据

扩展过程

1查看文件系统使用情况

[root@localhost ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 18G 17G 1G 99% /

devtmpfs 471M 0 471M 0% /dev

tmpfs 487M 0 487M 0% /dev/shm

tmpfs 487M 8.4M 478M 2% /run

tmpfs 487M 0 487M 0% /sys/fs/cgroup

/dev/sda1 297M 147M 151M 50% /boot

tmpfs 98M 8.0K 98M 1% /run/user/42

tmpfs 98M 0 98M 0% /run/user/0

2用虚拟机增加磁盘

vmware常用操作之磁盘扩容_文件系统

3 查看增加后的磁盘

[root@localhost ~]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sda 8:0 0 20G 0 disk

├─sda1 8:1 0 300M 0 part /boot

├─sda2 8:2 0 2G 0 part [SWAP]

└─sda3 8:3 0 17.7G 0 part /

sdb 8:16 0 5G 0 disk

sr0 11:0 1 1024M 0 rom

4 对新增磁盘分区

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


Command (m for help): n

Partition type:

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

e extended

Select (default p):

Using default response p

Partition number (1-4, default 1):

First sector (2048-10485759, default 2048):

Using default value 2048

Last sector, +sectors or +sizeK,M,G (2048-10485759, default 10485759):

Using default value 10485759

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


Command (m for help): w

The partition table has been altered!


Calling ioctl() to re-read partition table.

Syncing disks.

5 写分区信息到内核

[root@localhost ~]# partprobe

6 验证分区已添加

[root@localhost ~]# fdisk -l


Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000afea4


Device Boot Start End Blocks Id System

/dev/sda1 * 2048 616447 307200 83 Linux

/dev/sda2 616448 4810751 2097152 82 Linux swap / Solaris

/dev/sda3 4810752 41943039 18566144 83 Linux


Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x53ba8de0


Device Boot Start End Blocks Id System

/dev/sdb1 2048 10485759 5241856 83 Linux


lvm原理图如下

vmware常用操作之磁盘扩容_ci_02

具体原理可参考

​https://blog.csdn.net/beginerToBetter/article/details/129367828​

7 按图中所示步骤创建lvm

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

Physical volume "/dev/sdb1" successfully created.

[root@localhost ~]# pvdisplay

"/dev/sdb1" is a new physical volume of "<5.00 GiB"

--- NEW Physical volume ---

PV Name /dev/sdb1

VG Name

PV Size <5.00 GiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID 7S3jJR-jJuf-2bJA-ZDJP-tEz1-QjGm-CHeOVG


[root@localhost ~]# vgcreate vg1 /dev/sdb1

Volume group "vg1" successfully created

[root@localhost ~]# vgs

VG #PV #LV #SN Attr VSize VFree

vg1 1 0 0 wz--n- <5.00g <5.00g

[root@localhost ~]# pvdisplay

--- Physical volume ---

PV Name /dev/sdb1

VG Name vg1

PV Size <5.00 GiB / not usable 3.00 MiB

Allocatable yes

PE Size 4.00 MiB

Total PE 1279

Free PE 1279

Allocated PE 0

PV UUID 7S3jJR-jJuf-2bJA-ZDJP-tEz1-QjGm-CHeOVG


[root@localhost ~]# lvcreate -L 2G -n lv_app vg1

Logical volume "lv_app" created.

[root@localhost ~]# lvs

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

lv_app vg1 -wi-a----- 2.00g

[root@localhost ~]# mkfs.xfs /dev/vg1/lv_app

meta-data=/dev/vg1/lv_app isize=512 agcount=4, agsize=131072 blks

= sectsz=512 attr=2, projid32bit=1

= crc=1 finobt=0, sparse=0

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

= sunit=0 swidth=0 blks

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

log =internal log bsize=4096 blocks=2560, versinotallow=2

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

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

8 挂载磁盘到对那个lvm

[root@localhost ~]# mount /dev/vg1/lv_app /opt/

挂载原来如下图

vmware常用操作之磁盘扩容_ide_03

9 扩容lvm

[root@localhost ~]# lvextend -L +100M /dev/mapper/vg1-lv_app -r

Size of logical volume vg1/lv_app changed from 2.30 GiB (589 extents) to <2.40 GiB (614 extents).

Logical volume vg1/lv_app successfully resized.

10 挂载永久生效

[root@localhost ~]# df -T
/dev/mapper/vg1-lv_app xfs 2086912 32992 2053920 2% /opt
[root@localhost ~]# vi /etc/fstab

/dev/mapper/vg1-lv_app /opt xfs defaults 0 0

#最终重启生效
[root@localhost ~]# reboot

以上是关于vmware常用操作之磁盘扩容的主要内容,如果未能解决你的问题,请参考以下文章

VMware 之ubuntu扩容

Linux中VMware虚拟机增加磁盘空间的扩容操作

一文了解,如何在VMware指定磁盘分区 扩容

vmware中如何为虚拟机增加硬盘容量

VMware虚拟机下linux(Centos)磁盘扩容

VMware虚拟机下linux(Centos)磁盘扩容