VMware Workstation 扩容 Linux 虚拟机硬盘容量

文章
林里克斯

VMware Workstation 扩容 Linux 虚拟机硬盘容量


实验平台:CentOS Linux release 7.6.1810 (Core)

VMware Version:15.5.6 build-16341506


一、VMware 添加磁盘


1.VMware 为虚拟扩容硬盘

编辑虚拟机设置 --> 选择硬盘 --> 扩展

VMware Workstation 扩容 Linux 虚拟机硬盘容量

需要虚拟机关机 和 没有快照的虚拟机 才可以扩容硬盘

2.扩容至 10G

VMware Workstation 扩容 Linux 虚拟机硬盘容量

3.开机进入系统扩容


二、分区划区


1.查看系统盘还是没有扩容至 10G

VMware Workstation 扩容 Linux 虚拟机硬盘容量

2.查看磁盘容量

$ sudo fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000c0704

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1050623      524288   83  Linux
/dev/sda2         1050624    10485759     4717568   8e  Linux LVM

Disk /dev/mapper/centos-root: 4827 MB, 4827643904 bytes, 9428992 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

3.新建分区

$ sudo fdisk /dev/sda
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): p         #查看现有磁盘空间

Disk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000c0704

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1050623      524288   83  Linux
/dev/sda2         1050624    10485759     4717568   8e  Linux LVM

Command (m for help): n         #新建分区
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p           #使用主分区
Partition number (3,4, default 3): 3    #使用默认的分区号
First sector (10485760-20971519, default 10485760):     #使用默认的起始分区
Using default value 10485760
Last sector, +sectors or +size{K,M,G} (10485760-20971519, default 20971519):    #使用默认结束分区,使用全部容量
Using default value 20971519
Partition 3 of type Linux and of size 5 GiB is set

4.更改分区的系统 id,使用 LVM

Command (m for help): t
Partition number (1-3, default 3): 3
#需要修改的分区号
Hex code (type L to list all codes): 8e
#使用 Linux LVM 分区类型
Changed type of partition 'Linux' to 'Linux LVM'

5.保存退出

Command (m for help): 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 或 kpartx 之后同步磁盘。暂时忽略

三、扩容分区


1.手动合并分区或重启自动合并分区

$ sudo partprobe
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
# /dev/sr0 是光驱的设备名忽视此报错

2.查看原有磁盘分区格式

$ sudo blkid 
/dev/sda1: UUID="14f65369-a320-4d08-8af4-6ace66b734f4" TYPE="xfs" 
/dev/sda2: UUID="85zSiH-GSGT-3iRI-JiXO-mIyA-24bs-LSehG5" TYPE="LVM2_member" 
/dev/sr0: UUID="2018-11-25-21-21-31-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/mapper/centos-root: UUID="6a4d2076-f34d-47e6-9026-505f05d0345c" TYPE="xfs"

3.格式化新分区

$ sudo mkfs.xfs /dev/sda3 
meta-data=/dev/sda3              isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

4.进入逻辑卷合并

$ sudo lvm
lvm> pvcreate /dev/sda3             #格式
WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created.

lvm> vgextend centos /dev/sda3      #将新分区添加进系 Volume group,默认为 centos。可使用 vgdisplay 查看 Volume group name
  Volume group "centos" successfully extended

lvm> vgdisplay -v   #查看逻辑卷信息
····
--- Physical volumes ---
PV Name               /dev/sda2     
PV UUID               85zSiH-GSGT-3iRI-JiXO-mIyA-24bs-LSehG5
PV Status             allocatable
Total PE / Free PE    1151 / 0

PV Name               /dev/sda3     
PV UUID               I8RBb8-KVsp-x6nD-7gjM-hNAE-cg3h-YGAZbC
PV Status             allocatable
Total PE / Free PE    1279 / 1279       #记住这个容量

lvm> lvextend -l+1279 /dev/mapper/centos-root
  Size of logical volume centos/root changed from <4.50 GiB (1151 extents) to 9.49 GiB (2430 extents).
  Logical volume centos/root successfully resized.
#扩容系统盘

lvm> quit
  Exiting.
退出逻辑卷操作

5.让系统识别到我们的扩容操作

$ sudo xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=294656 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=1178624, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
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 1178624 to 2488320

6.验证

$ df -lh
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  9.5G  2.3G  7.3G  24% /
devtmpfs                 898M     0  898M   0% /dev
tmpfs                    910M     0  910M   0% /dev/shm
tmpfs                    910M  9.6M  901M   2% /run
tmpfs                    910M     0  910M   0% /sys/fs/cgroup
/dev/sda1                509M  139M  370M  28% /boot
tmpfs                    182M     0  182M   0% /run/user/0
tmpfs                    182M     0  182M   0% /run/user/1000

Over~

版权协议须知!

本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

1552 0 2021-03-09


分享:
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
博主卡片
林里克斯 博主大人
一个致力于Linux的运维平台
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。

现在时间 2024-12-28

今日天气
站点统计
  • 文章总数:241篇
  • 分类总数:29个
  • 评论总数:12条
  • 本站总访问量 353520 次

@奥奥

@Wong arrhenius 牛比

@MakerFace 厉害了!