VMware虚拟机磁盘扩展

VMware虚拟机磁盘扩展

一、VMware调整硬盘大小方式扩容

1.1 调整硬盘大小

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

扩展完成之后VMware会给虚拟机原有的磁盘增加空间, 然后进行下面的步骤对磁盘进行分区挂载

1. 2、进入linux系统(centos7)

1.2.1 查看当前磁盘分区情况

# 先查看增加的磁盘名称(系统分配的名称), SCSI设备的系统命名: sd前缀, 例如 sda, sdb, sdc, 以此类推。
# 命令: fdisk -l
# 由于使用的硬盘扩展的方式, 所以硬盘只能看到一个 /dev/sda, 一共分为三个区,即:/dev/sda1, /dev/sda2, /dev/sda3, 再看其总大小 53.7GB,而实际挂载的只有41.8G
# 所以需要增加新增的分区,才能查看和扩展的硬盘空间。
[root@centos7 ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x00034479

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    31457279    14679040   8e  Linux LVM
/dev/sda3        31457280    83886079    26214400   8e  Linux LVM

Disk /dev/mapper/centos-root: 40.3 GB, 40256929792 bytes, 78626816 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 /dev/mapper/centos-swap: 1610 MB, 1610612736 bytes, 3145728 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

1.2.2 在原来的磁盘增加一个新的分区

# 依次输入: 
1、 fdisk /dev/sda  # 进入磁盘分管理
2、m # 查看命令提示,可以略过此步骤
3、n # 增加分区
4、p # p添加主分区, 然后后续的内容可以全部选择默认,即全部输入enter键即可
5、m # 重点,要保存分区

[root@centos7 ~]# 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): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)


#----------
Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): 

#------------
Select (default e): p
Selected partition 4
First sector (83886080-104857599, default 83886080):

#----------
Using default value 83886080
Last sector, +sectors or +size{K,M,G} (83886080-104857599, default 104857599): 

#----------
Using default value 104857599
Partition 4 of type Linux and of size 10 GiB is set

#----------
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.

1.2.3 再次查看磁盘设备

# 已经新增一个/dev/sda4说明增加新分区成功, 如果找不到则重启一下系统, 或者使用 partprobe 命令
[root@centos7 ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x00034479

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    31457279    14679040   8e  Linux LVM
/dev/sda3        31457280    83886079    26214400   8e  Linux LVM
/dev/sda4        83886080   104857599    10485760   83  Linux

Disk /dev/mapper/centos-root: 40.3 GB, 40256929792 bytes, 78626816 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 /dev/mapper/centos-swap: 1610 MB, 1610612736 bytes, 3145728 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

1.2.4 格式化分区

# 查看当前文件系统类型 Type类即文件系统类型, linux默认 xfs类型
[root@centos7 ~]# df -T
Filesystem              Type     1K-blocks     Used Available Use% Mounted on
devtmpfs                devtmpfs   1918860        0   1918860   0% /dev
tmpfs                   tmpfs      1930668        0   1930668   0% /dev/shm
tmpfs                   tmpfs      1930668    11916   1918752   1% /run
tmpfs                   tmpfs      1930668        0   1930668   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs       39303168 34407244   4895924  88% /
/dev/sda1               xfs        1038336   179204    859132  18% /boot
tmpfs                   tmpfs       386136        0    386136   0% /run/user/0
# 格式化 /dev/sda4分区为 xfs类型, -t指定类型
# $ mkfs -t xfs /dev/sdb4
# /dev/sda4: No such file or directory 如果报此错误则重启系统
[root@centos7 ~]# mkfs -t xfs /dev/sda4
meta-data=/dev/sda4              isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621440, 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

1.2.5 使用新增加的分区

要使用新增加的分区,可以通过挂载,或者增加到lvm组中

1.2.5.1 挂载

注意:如果使用挂载的方式使用新分区,则无法给根目录/ 扩容

[root@centos7 ~]# mkdir /mnt/sda4

[root@centos7 ~]# mount /dev/sda4 /mnt/sda4/
[root@centos7 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   12M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   38G   33G  4.7G  88% /
/dev/sda1               1014M  176M  839M  18% /boot
tmpfs                    378M     0  378M   0% /run/user/0
/dev/sda4                 10G   33M   10G   1% /mnt/sda4

#--------------
 vim  /etc/fstab
 # 增加下面一行,实现系统启动自动挂载
 /dev/sda4 /mnt/sda4 xfs defaults 0 0
1.2.5.2 对逻辑卷扩容,实现对根目录/ 扩容
# 查看当前的lvm(TYPE一列)
[root@centos7 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   14G  0 part 
│ ├─centos-root 253:0    0 37.5G  0 lvm  /
│ └─centos-swap 253:1    0  1.5G  0 lvm  [SWAP]
├─sda3            8:3    0   25G  0 part 
│ └─centos-root 253:0    0 37.5G  0 lvm  /
└─sda4            8:4    0   10G  0 part /mnt/sda4
sr0              11:0    1  4.5G  0 rom  

# -----------
# 如果已经挂载了新分区sda4 则需要先unmout, 否则会报错:Can't open /dev/sda4 exclusively.  Mounted filesystem?
# unmout /dev/sda4
# 查看lvm, 可以看到/dev/sda2  /dev/sda3都是挂载在 VG centos这个虚拟卷组中。

# 进入虚拟卷管理
[root@centos7 ~]# lvm
# 创建虚拟卷
lvm> pvcreate /dev/sda4
WARNING: xfs signature detected on /dev/sda4 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sda4.
  Physical volume "/dev/sda4" successfully created.
# 显示当前虚拟卷
lvm> pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <14.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              3583
  Free PE               0
  Allocated PE          3583
  PV UUID               mlJoFV-WiFS-O8vl-Sjjn-SpJ5-hQ3t-XFstcE
   
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               25.00 GiB / not usable 4.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              6399
  Free PE               0
  Allocated PE          6399
  PV UUID               XNVzWZ-EDaG-QooJ-NY7J-ZFdv-s6Eh-R7pAGd
   
  "/dev/sda4" is a new physical volume of "10.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda4
  VG Name               
  PV Size               10.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               ca4Clb-GXd5-kfJT-tdok-uncu-5gWz-tUIb2S

# 将/dev/sda4加到 centos 虚拟卷组(VG)中
vgextend centos /dev/sda4

# 查看逻辑卷,可以看到 /dev/centos/root,当前大小37.49 GiB 后面呢要扩展
lvm> lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                QGn2gl-jaj1-9FIJ-O7e4-b6ZS-KI17-8Zd7cH
  LV Write Access        read/write
  LV Creation host, time centos7, 2019-10-25 16:38:11 +0800
  LV Status              available
  # open                 2
  LV Size                1.50 GiB
  Current LE             384
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                z0XWnm-NI25-rdJL-y9Rf-jdPn-f8gP-syXdrj
  LV Write Access        read/write
  LV Creation host, time centos7, 2019-10-25 16:38:12 +0800
  LV Status              available
  # open                 1
  LV Size                37.49 GiB
  Current LE             9598
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

# 扩展 /dev/centos/root 逻辑卷,新增加的卷大小是10G,扩展9.9总容量稍微小点即可。
lvm> lvextend -L +9.9G /dev/centos/root
  Rounding size to boundary between physical extents: 9.90 GiB.
  Size of logical volume centos/root changed from 37.49 GiB (9598 extents) to 47.39 GiB (12133 extents).
  Logical volume centos/root successfully resized.

# 逻辑卷扩容,退出
lvm> quit
  Exiting.
  
# 最后挂载点扩容
[root@centos7 ~]# xfs_growfs /
meta-data=/dev/mapper/centos-root isize=512    agcount=13, agsize=818944 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=9828352, 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 9828352 to 12424192

# 再次查看文件系统使用情况
[root@centos7 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   12M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   48G   33G   15G  70% /
/dev/sda1               1014M  176M  839M  18% /boot
tmpfs                    378M     0  378M   0% /run/user/0


二、通过增加一块硬盘的方式扩容

除了vmware增加硬盘的操作与第一章的方式不一样,其他操作基本相同, 所以此章节直接上代码

2.1 vmware 配置

在这里插入图片描述

在这里插入图片描述

略过一些步骤

在这里插入图片描述

2. 2 进入系统查看磁盘及其分区

# 可以看到 新增的 sdb磁盘
[root@centos7 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   14G  0 part 
│ ├─centos-root 253:0    0 47.4G  0 lvm  /
│ └─centos-swap 253:1    0  1.5G  0 lvm  [SWAP]
├─sda3            8:3    0   25G  0 part 
│ └─centos-root 253:0    0 47.4G  0 lvm  /
└─sda4            8:4    0   10G  0 part 
  └─centos-root 253:0    0 47.4G  0 lvm  /
sdb               8:16   0    5G  0 disk 
sr0              11:0    1  4.5G  0 rom  

2.3 分区

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

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

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): 
First sector (2048-10485759, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,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.

2.4 格式化分区为xfs

# 先查看sdb的分区名称: sdb1
[root@centos7 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
├─sda2            8:2    0   14G  0 part 
│ ├─centos-root 253:0    0 47.4G  0 lvm  /
│ └─centos-swap 253:1    0  1.5G  0 lvm  [SWAP]
├─sda3            8:3    0   25G  0 part 
│ └─centos-root 253:0    0 47.4G  0 lvm  /
└─sda4            8:4    0   10G  0 part 
  └─centos-root 253:0    0 47.4G  0 lvm  /
sdb               8:16   0    5G  0 disk 
└─sdb1            8:17   0    5G  0 part 
sr0              11:0    1  4.5G  0 rom  
[root@centos7 ~]# mkfs -t xfs /dev/sdb1


[root@centos7 ~]# mkfs -t xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=327616 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310464, 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

2.5 手动挂载

[root@centos7 ~]# mkdir -p /mnt/dev/sdb1
[root@centos7 ~]# mount /dev/sdb1 /mnt/dev/sdb1
[root@centos7 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G   12M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   48G   33G   15G  70% /
/dev/sda1               1014M  176M  839M  18% /boot
tmpfs                    378M     0  378M   0% /run/user/0
/dev/sdb1                5.0G   33M  5.0G   1% /mnt/dev/sdb1

2.6 系统启动自动挂载

vim /etc/fstab
# 末行增加
/dev/sdb1 /mnt/dev/sdb1 xfs defaults 0 0

# 或者
echo '/dev/sdb1 /mnt/dev/sdb1 xfs defaults 0 0' >> /etc/fstab
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 在VMware虚拟中进行磁盘扩容有几个步骤。首先,你需要使用命令行工具vmware-vdiskmanager来扩展虚拟磁盘的容量。例如,使用命令"vmware-vdiskmanager -x 30GB D:/UbuntuDesk/Ubuntu.vmdk"来将虚拟磁盘的容量扩展到30GB。\[2\]接下来,你需要在虚拟中删除原有的分区,并创建一个新的分区。你可以使用命令行工具来完成这个步骤。首先,输入n,p,回车来创建一个新的分区。然后,输入+40G来指定新分区的大小。最后,输入a和w命令来保存更改并退出命令行。\[3\]完成这些步骤后,你的虚拟磁盘就会成功扩容了。 #### 引用[.reference_title] - *1* *2* [VMware12 + Ubuntu16.04 虚拟磁盘扩容](https://blog.csdn.net/Q1302182594/article/details/51658229)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [VMware虚拟硬盘容量扩容(超简单)](https://blog.csdn.net/qq_37140721/article/details/125619393)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值