如何给VMWare workstation虚拟机Linux操作系统扩容磁盘容量

在实际使用VMWare workstation创建Linux操作系统时,Linux系统被总共分配了50GB磁盘容量,

后来若干个月后某一天突然发现Linux系统磁盘空间不够用啦,这时我们想到必须扩容虚拟机操作系统的磁盘容量

第一件事:修改VMWare workstation上创建的这台磁盘空间不够用的磁盘容量大小,

以下是Windows终端命令下修改磁盘容量配置,这只是改了一个磁盘总的容量大小,实际上增加这一部分容量,

还无法被系统直接识别使用,我们需要创建一个主分区给扩容的这一部分磁盘空间使用,还需要格式化操作,

扩容的这一部分容量,你希望分配给那个目录使用 ------ 也就是说这个新增加的主分区你希望挂载到那个目录上使用。

最开始Linux系统磁盘容量50GB ,现在把磁盘容量扩容到80GB,按照以下操作步骤来达到扩容磁盘容量的目的

第一部分:Windows系统上需要执行的终端命令如下:

Microsoft Windows [版本 10.0.16299.547]
(c) 2017 Microsoft Corporation。保留所有权利。

C:\Users\ZiGoo> cd "C:\Program Files (x86)\VMware\VMware Workstation\"

C:\Program Files (x86)\VMware\VMware Workstation> vmware-vdiskmanager -x 80Gb "D:\VMware Workstation\192.168.10.13\192.168.10.13.vmdk"
Failed to open the disk 'D:\VMware Workstation\192.168.10.13\192.168.10.13.vmdk' : The specified virtual disk needs repair (0x3e86).
Failed to open disk 'D:\VMware Workstation\192.168.10.13\192.168.10.13.vmdk' : The specified virtual disk needs repair (0x3e86).

C:\Program Files (x86)\VMware\VMware Workstation> vmware-vdiskmanager -R "D:\VMware Workstation\192.168.10.13\192.168.10.13.vmdk"
The virtual disk, 'D:\VMware Workstation\192.168.10.13\192.168.10.13.vmdk', was corrupted and has been successfully repaired.

C:\Program Files (x86)\VMware\VMware Workstation> vmware-vdiskmanager -x 80Gb "D:\VMware Workstation\192.168.10.13\192.168.10.13.vmdk"
Grow: 100% done.

必须以root用户的身份连接Linux操作系统终端命令接口

第二部分:Linux系统上需要执行的终端命令如下:

[root@contoso ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   46G   31G   15G  68% /
devtmpfs                 9.8G     0  9.8G   0% /dev
tmpfs                    9.8G     0  9.8G   0% /dev/shm
tmpfs                    9.8G   13M  9.8G   1% /run
tmpfs                    9.8G     0  9.8G   0% /sys/fs/cgroup
/dev/sda1               1014M  222M  793M  22% /boot
tmpfs                    2.0G  4.0K  2.0G   1% /run/user/42
tmpfs                    2.0G   28K  2.0G   1% /run/user/0
/dev/sr0                 4.2G  4.2G     0 100% /run/media/root/CentOS 7 x86_64
[root@contoso ~]# fdisk -l

Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000abc85

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM

Disk /dev/mapper/centos-root: 48.4 GB, 48444211200 bytes, 94617600 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: 4160 MB, 4160749568 bytes, 8126464 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@contoso ~]# 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 (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 按回车键
First sector (104857600-167772159, default 104857600): 按回车键
Using default value 104857600
Last sector, +sectors or +size{K,M,G} (104857600-167772159, default 167772159): 按回车键
Using default value 167772159
Partition 3 of type Linux and of size 30 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.
[root@contoso ~]# reboot

严格按照上面命令顺序 一条一条地执行,必须重新启动Linux操作系统,

否则接下来的刚刚创建的Linux主分区没法识别也不能格式化。

扫描二维码关注公众号,回复: 3325094 查看本文章

重新启动Linux系统之后再一次使用root身份进入命令行终端环境继续执行如下命令:

[root@contoso ~]# df -T #只可以查看已经挂载的分区和文件系统类型
Filesystem              Type     1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root xfs       47285700 31952540  15333160  68% /
devtmpfs                devtmpfs  10171660        0  10171660   0% /dev
tmpfs                   tmpfs     10188804        0  10188804   0% /dev/shm
tmpfs                   tmpfs     10188804    12648  10176156   1% /run
tmpfs                   tmpfs     10188804        0  10188804   0% /sys/fs/cgroup
/dev/sda1               xfs        1038336   226312    812024  22% /boot
tmpfs                   tmpfs      2037764       12   2037752   1% /run/user/42
tmpfs                   tmpfs      2037764        0   2037764   0% /run/user/0
[root@contoso ~]# fdisk -l #可以显示出所有挂载和未挂载的分区,但不显示文件系统类型

Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000abc85

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM
/dev/sda3       104857600   167772159    31457280   83  Linux

Disk /dev/mapper/centos-root: 48.4 GB, 48444211200 bytes, 94617600 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: 4160 MB, 4160749568 bytes, 8126464 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@contoso ~]# parted -l #可以查看未挂载的文件系统类型,以及哪些分区尚未格式化
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 85.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  53.7GB  52.6GB  primary               lvm
 3      53.7GB  85.9GB  32.2GB  primary


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 4161MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system     Flags
 1      0.00B  4161MB  4161MB  linux-swap(v1)


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 48.4GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  48.4GB  48.4GB  xfs


Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0
has been opened read-only.
Model: NECVMWar VMware IDE CDR10 (scsi)                                   
Disk /dev/sr0: 4470MB
Sector size (logical/physical): 2048B/2048B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 2      4850kB  41.7MB  36.8MB  primary


[root@contoso ~]# lsblk -f #也可以查看未挂载的文件系统类型
NAME            FSTYPE      LABEL           UUID                                   MOUNTPOINT
sda                                                                                
├─sda1          xfs                         23856307-3639-4701-8455-6ea76b82451e   /boot
├─sda2          LVM2_member                 X9ClfX-o9J1-UHzo-YKwc-8L5j-imUQ-K69lRv 
│ ├─centos-root xfs                         f8d8385c-1ab5-45fe-9366-adaf5344a5fe   /
│ └─centos-swap swap                        35b51023-1bb9-4484-9e4d-a575f3dae760   [SWAP]
└─sda3                                                                             
sr0             iso9660     CentOS 7 x86_64 2018-05-03-20-55-23-00                 
[root@contoso ~]# 

从以上命令输出的结果我们可以发现 sda3是刚刚创建的Linux主分区还尚未格式化,

我们还发现Linux系统使用的系统文件类型为 xfs ,不是ext3也不是ext4格式,为了保持文件系统类型一致,

sda3这个主分区必须格式为xfs这样的系统文件类型

[root@contoso ~]# mkfs.xfs /dev/sda3    #格式化主分区sda3
meta-data=/dev/sda3              isize=512    agcount=4, agsize=1966080 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=7864320, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=3840, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@contoso ~]# cd / && du -ah --max-depth=1    #查看系统文件根目录的下文件(夹)大小
189M    ./boot
0       ./dev
du: cannot access ‘./proc/6435/task/6435/fd/3’: No such file or directory
du: cannot access ‘./proc/6435/task/6435/fdinfo/3’: No such file or directory
du: cannot access ‘./proc/6435/fd/4’: No such file or directory
du: cannot access ‘./proc/6435/fdinfo/4’: No such file or directory
0       ./proc
4.2G    ./run
0       ./sys
41M     ./etc
20G     ./root
1.9G    ./var
28M     ./tmp
6.3G    ./usr
0       ./bin
0       ./sbin
0       ./lib
0       ./lib64
427M    ./home
0       ./media
0       ./mnt
2.0G    ./opt
0       ./srv
35G     .
[root@contoso ~]# cd /root && du -ah --max-depth=1    #查看最大文件夹/root下的所有文件大小
4.0K    ./.bash_logout
4.0K    ./.bash_profile
4.0K    ./.bashrc
4.0K    ./.cshrc
4.0K    ./.tcshrc
4.0K    ./anaconda-ks.cfg
114M    ./.cache
8.0K    ./.dbus
117M    ./.config
4.0K    ./initial-setup-ks.cfg
32K     ./.bash_history
8.0K    ./.ICEauthority
2.7M    ./.local
4.0K    ./.esd_auth
20K     ./Desktop
90M     ./Downloads
0       ./Templates
0       ./Public
0       ./Documents
0       ./Music
0       ./Pictures
0       ./Videos
47M     ./.eclipse
4.0K    ./.p2
76K     ./.tooling
76M     ./.mozilla
4.0K    ./.swt
4.0K    ./.codemix.properties
218M    ./.codemix
196K    ./.java
28K     ./.pki
76M     ./.vscode
4.0K    ./.rediscli_history
4.0K    ./.mysql_history
12K     ./.gnupg
20K     ./.gnome
0       ./.android
180M    ./.IdeaIC2018.1
200M    ./.IntelliJIdea2018.1
4.0K    ./README.md
4.0K    ./.gitconfig
4.0K    ./hello.erl
4.0K    ./hello.beam
35M     ./zipkin-server-2.10.2-exec.jar
118M    ./.IdeaIC2018.2
19G     ./.docker
367M    ./.m3
4.0K    ./.oracle_jre_usage
4.0K    ./.rs
48K     ./.razorsql
20G     .
[root@contoso ~]# 
# 把主分区sda3挂载到系统根目录下
[root@contoso ~]# cat >> /etc/fstab
/dev/sda3  /data  xfs  defaults 0 0
[root@contoso ~]# reboot    #重新启动Linux系统主分区sda3自动挂载到系统根目录下
[root@contoso ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Jun 19 23:14:45 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=23856307-3639-4701-8455-6ea76b82451e /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sda3  /data  xfs  defaults 0 0

#实际上是挂载到根目录下data文件夹下

重新启动Linux系统后,再一次使用多种方式查看一下已经挂载成功主分区和其它分区信息

[root@contoso ~]# df -T
Filesystem              Type     1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root xfs       47285700 31954412  15331288  68% /
devtmpfs                devtmpfs  10171660        0  10171660   0% /dev
tmpfs                   tmpfs     10188804        0  10188804   0% /dev/shm
tmpfs                   tmpfs     10188804    12948  10175856   1% /run
tmpfs                   tmpfs     10188804        0  10188804   0% /sys/fs/cgroup
/dev/sda3               xfs       31441920    38896  31403024   1% /data
/dev/sda1               xfs        1038336   226312    812024  22% /boot
tmpfs                   tmpfs      2037764        4   2037760   1% /run/user/42
tmpfs                   tmpfs      2037764       40   2037724   1% /run/user/0
/dev/sr0                iso9660    4364408  4364408         0 100% /run/media/root/CentOS 7 x86_64
[root@contoso ~]# fdisk -l

Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 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: 0x000abc85

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM
/dev/sda3       104857600   167772159    31457280   83  Linux

Disk /dev/mapper/centos-root: 48.4 GB, 48444211200 bytes, 94617600 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: 4160 MB, 4160749568 bytes, 8126464 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@contoso ~]# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 85.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  53.7GB  52.6GB  primary               lvm
 3      53.7GB  85.9GB  32.2GB  primary  xfs


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 4161MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system     Flags
 1      0.00B  4161MB  4161MB  linux-swap(v1)


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 48.4GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  48.4GB  48.4GB  xfs


Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0
has been opened read-only.
Model: NECVMWar VMware IDE CDR10 (scsi)                                   
Disk /dev/sr0: 4470MB
Sector size (logical/physical): 2048B/2048B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 2      4850kB  41.7MB  36.8MB  primary


[root@contoso ~]# lsblk -f
NAME            FSTYPE      LABEL           UUID                                   MOUNTPOINT
sda                                                                                
├─sda1          xfs                         23856307-3639-4701-8455-6ea76b82451e   /boot
├─sda2          LVM2_member                 X9ClfX-o9J1-UHzo-YKwc-8L5j-imUQ-K69lRv 
│ ├─centos-root xfs                         f8d8385c-1ab5-45fe-9366-adaf5344a5fe   /
│ └─centos-swap swap                        35b51023-1bb9-4484-9e4d-a575f3dae760   [SWAP]
└─sda3          xfs                         b5ca5156-7fdf-4831-bac3-b72be4c282ae   /data
sr0             iso9660     CentOS 7 x86_64 2018-05-03-20-55-23-00                 /run/media/root/CentOS 7 x86_64
[root@contoso ~]# 

虚拟机操作系统扩容还有另外一种实现方式,直接添加一块虚拟磁盘,扩容到Linux系统,请看详细步骤教程

如何在虚拟机操作系统CentOS 7.5上部署TiDB数据库群集

猜你喜欢

转载自blog.csdn.net/zhengzizhi/article/details/81412023