VM虚拟机中Linux扩展磁盘空间的方法

一、首先在虚拟机中调整硬盘容量

二、在linux系统中进行配置

1、查看硬盘:fdisk -l

[root@localhost .ssh]# 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: 0x000ccdc8

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

Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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: 2147 MB, 2147483648 bytes, 4194304 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

 发现已经变成53.7G了

2、操作分区表

命令:fdisk /dev/sda

[root@localhost .ssh]# 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)

键入p 查看分区数量

Command (m for help): p

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: 0x000ccdc8

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

由此判断我们增加的分区号应该为3(dev/sda1,dev/sda2……接下来应该是dev/sda3了吧)

键入n,增加一个分区,得到:

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended

键入 p,主分区,并键入3(编号),也可以回车默认,默认起始扇区和结束扇区即可(键入两次Enter)

Select (default p): p
Partition number (3,4, default 3):    
First sector (41943040-104857599, default 41943040): 
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-104857599, default 104857599): 
Using default value 104857599
Partition 3 of type Linux and of size 30 GiB is set

键入t,修改分区类型为8e:

Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

键入w,写分区表,然后重启:

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@localhost .ssh]# reboot
Connection closing...Socket close.

3、格式化

 mkfs.xfs /dev/sda3        初始化刚才的分区

[root@localhost ~]# mkfs.xfs /dev/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@localhost ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
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/mapper/centos-root xfs        17G   15G  2.7G  85% /
/dev/sda1               xfs      1014M  151M  864M  15% /boot
tmpfs                   tmpfs     781M     0  781M   0% /run/user/0

4、卷扩容:

pvcreate /dev/sda3 初始化刚才的分区

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

vgextend centos /dev/sda3   将初始化过的分区加入到虚拟卷组centos

[root@localhost ~]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended

lvextend -L +29G /dev/centos/root 扩展已有卷的容量

[root@localhost ~]# lvextend -L +29G /dev/centos/root 
  Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <46.00 GiB (11775 extents).
  Logical volume centos/root successfully resized.

pvdisplay              查看卷容量

  Logical volume centos/root successfully resized.
[root@localhost ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <19.00 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              4863
  Free PE               0
  Allocated PE          4863
  PV UUID               iE79X6-Jp4j-8vSk-HZPI-yF6z-5xf6-o4Xjsx
   
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               centos
  PV Size               30.00 GiB / not usable 4.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              7679
  Free PE               255
  Allocated PE          7424
  PV UUID               A4cQsp-WHHt-65i0-O0CQ-wm1G-hLVT-x0Co1l

5、文件系统扩容:

xfs_growfs /dev/mapper/centos-root

[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, 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 4455424 to 12057600

如果不是xfs,则执行命令: resize2fs  /dev/mapper/centos-root

6、查看结果

[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
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/mapper/centos-root   46G   15G   32G  32% /
/dev/sda1               1014M  151M  864M  15% /boot
tmpfs                    781M     0  781M   0% /run/user/0

可以看到centos-root已经变成46G了

  • 16
    点赞
  • 65
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
Win10 VM虚拟机访问磁盘变慢可能有多种原因。以下是可能的解决方案: 1. 虚拟机设置:首先,确保你在虚拟机的设置为其分配了足够的资源,包括计算机内存和处理器。如果虚拟机资源不足,磁盘访问速度可能会受到影响。 2. 硬盘分区:虚拟机使用的硬盘如果分区不正确,也会导致访问速度变慢。检查虚拟机使用的硬盘分区是否有错误或者是否需要重新分区。 3. 驱动程序更新:确保虚拟化软件(如VMware、VirtualBox等)和主机操作系统都是最新版本,以确保驱动程序兼容性和性能的优化。 4. 硬件加速:更改虚拟机设置,启用硬件加速选项,可以提高磁盘访问速度。硬件加速可以利用主机计算机的物理资源来加快虚拟机的性能。 5. 使用SSD硬盘:如果虚拟机使用的是传统的机械硬盘,请考虑将其替换为固态硬盘(SSD)。SSD硬盘具有更快的读写速度,可以提高磁盘访问效率。 6. 关闭磁盘压缩:如果虚拟机启用了磁盘压缩功能,尝试禁用它。磁盘压缩可能会导致磁盘访问速度减慢。 7. 清理虚拟机磁盘:定期清理虚拟机不再需要的文件和数据,可以减少虚拟磁盘的碎片和文件数量,从而提高磁盘访问速度。 8. 网络带宽设置:如果虚拟机同时进行网络传输,考虑限制其网络带宽使用,以避免网络传输对磁盘访问的干扰。 综上所述,通过确保虚拟机分配的资源充足、硬盘分区正确、驱动程序更新、启用硬件加速、使用SSD硬盘、禁用磁盘压缩、清理虚拟机磁盘和限制网络带宽使用等方法,可以尝试解决Win10 VM虚拟机访问磁盘慢的问题。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值