首页 > 系统相关 >VMware虚拟机添加新硬盘以及对磁盘进行分区挂载

VMware虚拟机添加新硬盘以及对磁盘进行分区挂载

时间:2023-08-08 12:36:46浏览次数:35  
标签:虚拟机 sudo bytes dev VMware 512 分区 硬盘 size


有时候我们需要在VMware 中添加新的虚拟磁盘。 比如原来已经有sda盘,现在我们需要新的空白sdb盘。

方法如下:

VMware新增磁盘的设置步骤

(建议:在设置虚拟的时候,不要运行虚拟机的系统,不然添加了新的虚拟磁盘则要重启虚拟机)

1、选择“VM”—-“设置”并打开,将光标定位在硬盘这一选项,然后点击下方的添加按钮

VMware虚拟机添加新硬盘以及对磁盘进行分区挂载_新增硬盘


点击下一步,执行下一个步骤

VMware虚拟机添加新硬盘以及对磁盘进行分区挂载_虚拟机_02


按照默认的,选择SCSI格式的磁盘即可,点击执行下一步

VMware虚拟机添加新硬盘以及对磁盘进行分区挂载_新增硬盘_03

创建新的虚拟磁盘

VMware虚拟机添加新硬盘以及对磁盘进行分区挂载_分区_04

按照需要的空间配置,点击下一步即可完成虚拟磁盘的添加

VMware虚拟机添加新硬盘以及对磁盘进行分区挂载_分区_05


默认指定磁盘文件

VMware虚拟机添加新硬盘以及对磁盘进行分区挂载_虚拟机_06

如下添加完成:

VMware虚拟机添加新硬盘以及对磁盘进行分区挂载_vmware_07

重新分区和挂载

新增的磁盘也可参考如下步骤,不过只要从新增n步骤开始即可。 不需要有删除的动作。

目标是使用 fdisk /dev/sda 删除/dev/sda2,新建 11G的sda2 和 10G的sda3。

步骤如下:

注意,分区是危险操作,请注意备份。

查看磁盘情况,使用命令

sudo fdisk -l

输出如下:

[zzq@ceph2 ~]$ sudo fdisk -l
[sudo] password for zzq: 

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00092a44

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM

Disk /dev/mapper/vg_localhost-lv_root: 18.9 GB, 18865979392 bytes
255 heads, 63 sectors/track, 2293 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_localhost-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

卸下分区

cd /home/
sudo umount /dev/sda2
# 如果 umount 出现 device is busy,使用命令fuser -m /dev/sda2查看读写磁盘的pid,找出来kill之

我们这里将sda的21.5GB重新分区,使用命令

sudo fdisk /dev/sda

此时要输入命令,m 帮助菜单 \ p 该整磁盘详细信息 \ d 删除分区 \ n 添加分区

我们的命令步骤如下:
d #删除动作\选择删除的区号2\n #新建分区\p 选择类型为primary partition\选择分区为2\直接回车从默认的磁盘扇区开始即可\输入 +11G 回车 #懒得计算扇区,可以照提示使用”+容量”的方式
这样就完成了新建11G的sda2分区。
n #新建分区\p 选择类型为primary partition\选择分区为3\直接回车从默认的磁盘扇区开始即可\直接回车 #使用所有剩余的容量作为sda3的容量
这样就完成了新建10G的sda3分区。

使用p命令再次查看分区表

确认无误后使用 w命令写入磁盘即可(危险操作,需谨慎确认无误),如果有误的话 使用q命令不保存退出。

输出如下:

[zzq@ceph2 home]$ sudo fdisk /dev/sda
[sudo] password for zzq: 

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): d  #删除动作
Partition number (1-4): 2

Command (m for help): n #新建分区
Command action
   e   extended
   p   primary partition (1-4)
p #选择类型为primary partition
Partition number (1-4): 2  #选择分区为2
First cylinder (64-2610, default 64): 
Using default value 64
Last cylinder, +cylinders or +size{K,M,G} (64-2610, default 2610): +11G

Command (m for help): n #新建分区
Command action
   e   extended
   p   primary partition (1-4)
p  #选择类型为primary partition
Partition number (1-4): 3  #选择分区为3
First cylinder (1501-2610, default 1501): 
Using default value 1501
Last cylinder, +cylinders or +size{K,M,G} (1501-2610, default 2610): 
Using default value 2610

Command (m for help): p  #查看现在的分区情况

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00092a44

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1500    11535726   83  Linux
/dev/sda3            1501        2610     8916075   83  Linux

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.
[zzq@ceph2 home]$

看到上面的warning报错别紧张,回到shell后看看是否重新分区成功
使用命令

sudo fdisk -l

输出如下:

[zzq@ceph2 home]$ sudo fdisk -l
[sudo] password for zzq: 

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00092a44

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1500    11535726   83  Linux
/dev/sda3            1501        2610     8916075   83  Linux

Disk /dev/mapper/vg_localhost-lv_root: 18.9 GB, 18865979392 bytes
255 heads, 63 sectors/track, 2293 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_localhost-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

这个时候分区是不能被系统识别的,需要强制重读
否则在格式化和使用时会报错
Could not stat /dev/sda2 — No such file or directory
The device apparently does not exist; did you specify it correctly?

通知内核强制重读磁盘分区表:
CentOS 5,6,7:partprobe,partx, kpartx
partprobe [device]
partx -a [device]
kpartx -af [device]

我们这里是centos 6,使用命令,注意 device的参数使用的是顶层,比如我们划分了/dev/sda的sda2和sda3使用的参数应该是/dev/sda,否则报错last arg is not the whole disk

sudo partx -a /dev/sda

如果报错

[zzq@ceph2 home]$ sudo partx -a /dev/sda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3

试试partprobe

sudo partprobe

警告如下:

Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy).  As a result, it may not reflect all of your changes until after reboot.

那我们只能重启,重启之前需要删除已经失效的UUID挂载和永久的挂载新分区,使用命令
否则会报错
目录对应的设备/dev/sda2已经被删除了,如果/etc/fstab中还存在着旧信息,开机会提示您:
fsck.ext4: unable to resolve ‘uuid=000120ad–6480-40ba-9a64-3d5c27d1ff96’……然后无法进入系统

sudo vi /etc/fstab

输出如下:

# /etc/fstab
# Created by anaconda on Mon Mar 20 01:50:54 2017
#
# 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/vg_localhost-lv_root /                       ext4    defaults        1 1
UUID=d79fc2d2-0dba-4681-b7d3-b727930427e3 /boot                   ext4    defaults        1 2
/dev/mapper/vg_localhost-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

没有sda2的相关信息。所以不需要删除什么,新增两个挂载信息如下

/dev/sda2    /home  ext4 defaults 0 0
/dev/sda3    /ceph  ext4 defaults 0 0

相关参数

/etc/fstab下面分为6个字段:
1、要挂载的设备(可以使用LABEL、UUID、设备文件)
2、挂载点
3、文件系统类型
4、挂载选项(defaults使用默认挂载选线,如需同时指明,则:defaults,acl)
5、转储频率
  0:从不备份
  1:每天备份
  2:每隔一天备份
6、自检次序
  0:不自检
  1:首先自检,通常只用于根文件系统
  2:次级自检

重启

sudo reboot -h

格式化
要想使用新的分区,首先要对新创的分区进行格式化,才能用于创建文件系统
使用命令

sudo mkfs -t ext4  /dev/sda2
sudo mkfs -t ext4  /dev/sda3

两种挂载方式

下面便是对于分好区的/dev/sdb1 这一个分区进行挂载及访问

注意挂载到的目录必须提前新建好
使用命令

cd /
sudo mkdir -p ./ceph

手动挂载

使用mount /dev/sdb1 /要挂载的目录(自己自定义)
访问时:cd /挂载的目录 即可对其进行存储和访问

自动挂载

修改/etc/fstab即可
使用vim /etc/fstab打开配置的文件,然后将下面的一行文字添加即可
/dev/sdb1 /media(这个挂载的目录你自己设置即可) ext4 defaults 0 1


标签:虚拟机,sudo,bytes,dev,VMware,512,分区,硬盘,size
From: https://blog.51cto.com/u_16218512/7007079

相关文章

  • 虚拟机 的net模式与 桥接模式, windows可以ping通 虚拟机,但是虚拟机无法ping通 windows
    1第一个问题,net与桥接的模式。    2第二个问题,虚拟机ping不通PC,但是PC可以ping通虚拟机。  ......
  • liunx虚拟机VMware增加磁盘空间后,挂载磁盘
    问题:当虚拟机扩展磁盘空间后提示“您必须从客户机操作系统内部对磁盘重新进行分区和扩展文件系统"处理方法: 1、切换root用户查看磁盘情况:fdisk-l  2、查看磁盘挂载情况:df-h3、对磁盘进行分区:fdisk/dev/sda 默认为4,后两步回车默认,最后输入w保存;可输入m查看命令提......
  • 解决Vmware使用中的卡顿问题
    打开首选项到内存,将其修改为图中的设置打开优先级,设置如图打开对应虚拟机设置,如图做两步设置全部设置完成后,再次打开虚拟机使用发现完全不卡了!......
  • RTSP流媒体服务器LntonNVR(源码版)视频平台接入硬盘录像机的具体操作步骤
    LntonNVR是基于RTSP/Onvif协议接入的视频平台,可支持将前端设备的音视频进行采集、传输、处理并分发,实现视频监控直播、云端录像、云存储、检索回看、国标级联、告警等视频能力。平台兼容性高、可拓展性强、性能稳定,可应用在智慧工地、智慧园区、智慧工厂、智慧校园等场景中。对于新......
  • AMD cpus在VM虚拟机安装macOS10.15和12教程一
    本教程采用软件为vmwareworkstation17pro,操作系统win10,CPU为5600G,macOS10.15或者macOS12VM虚拟机的下载和安装这里不阐述,大家可以百度一下macos13在上述环境下安装后会提示错误,macOS14beta暂时不支持安装,所以13-14可以暂时放弃macOS的下载请百度一下就有了~记得下载带引导......
  • 安装虚拟机
    1、下载vm17prohttps://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=vm17pro&fenlei=256&rsv_pq=0xed24c71a0003c833&rsv_t=a413ycmpC%2BOYJbDMArvm%2FcDuZCP%2FHsJFxns02J4dOXMo5RHuxzHmU%2FcWAqAD&rqlang=en&rsv......
  • ubuntu中VMware虚拟机没有网络可能的原因
    有可能是VMware的网络服务未启动(比如注销账户再进入桌面时不会同时打开VMware的网络服务),可以去顶栏右上角点一下看看是不是这么回事。一般来说重启电脑就可以了,不行的话你就得研究怎么手动启动这个服务了。......
  • [Microsoft Azure] 基于Microsoft Azure VM 虚拟机快速搭建宝塔管理面板
    如果您正在使用MicrosoftAzure虚拟机(VM),并需要快速搭建Web管理面板,那么本文将介绍如何在其中安装宝塔面板。视频演示:[MicrosoftAzure]基于MicrosoftAzureVM虚拟机快速搭建宝塔管理面板-Bilibili1.创建虚拟机首先,您需要创建AzureVM实例。可以选择Linux或W......
  • VMware vSphere vCenter Server Appliance 7.0安装配置​
    VMwarevSpherevCenterServerAppliance7.0安装配置环境说明:将vCenterServerAppliance部署在ESXi主机上,安装配置虚拟机windows2019:准备好VMwarevCenterServer镜像文件将准备好合适版本的vCenterServer镜像文件的电脑与ESXi主机的连通。注意:vCenter版本要高于ESXi版本,否则......
  • mac 虚拟机无法获取网卡
    虚拟机获取不到内置网卡,只能通过外接usb网卡的方式进行相关开发https://forums.kali.org/archive/index.php/t-38367.html已尝试:vmwarefusion,multipass......