VM虚拟机模拟Linux服务器新增物理硬盘

1、关闭虚拟机,增加2张磁盘,模拟新增2块物理硬盘





根据需求修改磁盘大小



添加完成后如图所示

2、启动服务器,以root登录

3、查看磁盘信息

[root@localhost /]# fdisk -l

Disk /dev/sda: 37.6 GB, 37580963840 bytes, 73400320 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: 0x000ae75e

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

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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/sdc: 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

4、分别对每个磁盘进行分区

[root@localhost /]# 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 0xa8bf9e37.

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-2097151, default 2048):    #按回车取默认值

Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151):
Using default value 2097151
Partition 1 of type Linux and of size 1023 MiB is set

Command (m for help): w                        #w回车保存设置
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost /]# fdisk /dev/sdc
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 0xe7c0c272.

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-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303):
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

5、新增分区后再次查看磁盘信息

[root@localhost /]# fdisk -l

Disk /dev/sda: 37.6 GB, 37580963840 bytes, 73400320 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: 0x000ae75e

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

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 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: 0xa8bf9e37

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     2097151     1047552   83  Linux

Disk /dev/sdc: 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
Disk label type: dos
Disk identifier: 0xe7c0c272

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1            2048     4194303     2096128   83  Linux

6、格式化分区

[root@localhost /]# mkfs -t ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 261888 blocks
13094 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost /]# mkfs -t xfs /dev/sdc1
meta-data=/dev/sdc1              isize=512    agcount=4, agsize=131008 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=524032, 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

8、格式化后再次查看磁盘信息

[root@localhost /]# lsblk -f
NAME        FSTYPE      LABEL           UUID                                   MOUNTPOINT
sda
├─sda1      xfs                         e008266f-d10b-4b54-b2ce-902e28f1f8fe   /boot
└─sda2      LVM2_member                 pCRmuu-Qdz1-BGnm-Z4hZ-3Eic-4uRx-CeEL5o
  ├─cl-root xfs                         82e0dbc6-4e34-4ce3-8c51-2a37779e1041   /
  └─cl-swap swap                        a9fdb3a2-c3be-4d58-9aca-d5308dd24c63   [SWAP]
sdb
└─sdb1      ext4                        4698d481-b50d-433c-8476-855fe7ff5f64
sdc
└─sdc1      xfs                         790ed65d-110d-40ee-b997-4a74274c5c70
sr0         iso9660     CentOS 7 x86_64 2016-12-05-13-55-45-00

9、新建文件夹并挂载分区

mkdir /data1/
mkdir /data2/
[root@localhost /]# mount /dev/sdb1 /data1/
[root@localhost /]# mount /dev/sdc1 /data2/

10、查看硬盘大小及挂载分区

[root@localhost /]# df -h
Filesystem           Size  Used Avail Use% Mounted on
/dev/mapper/cl-root   26G  8.1G   18G  32% /
devtmpfs             473M     0  473M   0% /dev
tmpfs                489M   84K  489M   1% /dev/shm
tmpfs                489M  7.1M  482M   2% /run
tmpfs                489M     0  489M   0% /sys/fs/cgroup
/dev/sda1           1014M  173M  842M  18% /boot
tmpfs                 98M     0   98M   0% /run/user/0
tmpfs                 98M   16K   98M   1% /run/user/42
/dev/sdb1            991M  2.6M  922M   1% /data1
/dev/sdc1            2.0G   33M  2.0G   2% /data2
[root@localhost /]# lsblk -f
NAME        FSTYPE      LABEL           UUID                                   MOUNTPOINT
sda
├─sda1      xfs                         e008266f-d10b-4b54-b2ce-902e28f1f8fe   /boot
└─sda2      LVM2_member                 pCRmuu-Qdz1-BGnm-Z4hZ-3Eic-4uRx-CeEL5o
  ├─cl-root xfs                         82e0dbc6-4e34-4ce3-8c51-2a37779e1041   /
  └─cl-swap swap                        a9fdb3a2-c3be-4d58-9aca-d5308dd24c63   [SWAP]
sdb
└─sdb1      ext4                        4698d481-b50d-433c-8476-855fe7ff5f64   /data1
sdc
└─sdc1      xfs                         790ed65d-110d-40ee-b997-4a74274c5c70   /data2
sr0         iso9660     CentOS 7 x86_64 2016-12-05-13-55-45-00

11、配置开机自动挂载

[root@localhost /]# vim /etc/fstab

在最后加入下面内容

/dev/sdb1 /data1 ext4 defaults 0 0
/dev/sdc2 /data2 xfs defaults 0 0
12、重启服务器看配置是否生效


<think>嗯,用户想要在虚拟机环境中模拟SSD硬盘的行为,特别是在VMware或VirtualBox中。这个问题很实用,可能是在做性能测试或者需要特定存储特性的场景。 用户之前提到了快速排序的示例,但当前问题完全转向了虚拟化存储配置。需要专注解决SSD模拟问题。从技术角度看,虚拟机模拟SSD主要涉及三个方面:磁盘类型声明、TRIM功能支持和性能参数调整。 对于VMware,重点在于vmdk格式的选择和SCSI控制器类型。使用lsilogic-sas或nvme控制器能更好模拟SSD特性,而启用scsi0:0.virtualSSD=1这个隐藏参数是关键。VirtualBox方面则相对简单,直接通过GUI就能设置SSD模拟选项,但要注意TRIM功能需要额外启用。 用户可能是开发人员或系统管理员,需要测试应用在SSD环境的表现。考虑到实际性能差异,应该提醒用户虚拟机无法完全模拟物理SSD的延迟和IOPS,建议结合磁盘基准测试工具验证效果。 突然想到用户可能还需要知道如何验证SSD模拟是否生效,这很重要。应该补充Linux和Windows下的检测方法,比如hdparm和powercfg命令。另外NVMe控制器虽然更现代,但兼容性可能有问题,需要根据客户机系统权衡选择。 在整理步骤时发现VirtualBox的TRIM功能需要特别说明,因为默认不启用。而VMware的SSD标识参数文档较少,属于高级技巧,应该标注清楚修改.vmx文件的风险。最后性能优化部分,建议用户根据负载类型调整预读和缓存策略,随机读写测试时关闭页面合并可能更准确。 用户没有提到具体使用场景,但模拟SSD通常用于数据库或文件系统测试,所以在注意事项里加入了fio测试建议。如果用户后续需要性能调优,可以再深入讨论IO调度器设置。</think>在VMware或VirtualBox中模拟SSD硬盘主要涉及**磁盘类型声明**、**TRIM功能支持**和**性能参数调整**,以下是详细配置方法: --- ### **一、VMware 配置方法** 1. **创建SSD标识磁盘** 编辑虚拟机`.vmx`配置文件,添加以下参数声明磁盘为SSD: ```bash scsi0:0.virtualSSD = 1 # 标识为SSD scsi0:0.throughputIOPS = 10000 # 自定义IOPS值(可选) ``` > ⚠️ 修改前需关闭虚拟机,修改后重启生效。 2. **启用TRIM支持** - **客户机系统**:安装VMware Tools - **虚拟机设置**:在`.vmx`文件中添加: ```bash sched.scsi0:0.rotateSSD = 1 # 启用SSD优化调度 ``` 3. **使用NVMe控制器(更接近现代SSD)** 在虚拟机设置中将磁盘控制器改为 **NVMe**: ```bash scsi0.virtualDev = "nvme" # 使用NVMe控制器 ``` --- ### **二、VirtualBox 配置方法** 1. **创建虚拟SSD磁盘** ```bash VBoxManage createmedium disk --filename ~/ssd_disk.vdi --size 20480 --format VDI --variant Fixed VBoxManage storageattach <VM名称> --storagectl "SATA" --port 0 --device 0 --type hdd --medium ~/ssd_disk.vdi --nonrotational on --discard on ``` - `--nonrotational on`:标记为SSD(非机械盘) - `--discard on`:启用TRIM支持 2. **图形界面操作** - 存储设置 → 选择磁盘 → **勾选"固态驱动器"** - 高级功能 → **启用"Discard"**(对应TRIM) --- ### **三、验证SSD模拟是否生效** - **Linux客户机**: ```bash lsblk -d -o name,rota # 查看ROTA值,0表示SSD ``` 输出示例: ```bash NAME ROTA sda 0 # ROTA=0 标识为SSD ``` - **Windows客户机**: 运行`powercfg -energy`生成报告,检查**磁盘信息**是否包含"SSD"标识。 --- ### **四、性能优化建议** 1. **启用写入缓存**(VMware/VirtualBox均支持) - 虚拟机设置 → 磁盘 → **启用"主机I/O缓存"** 2. **调整I/O参数**(VMware高级选项) ```bash sched.scsi0:0.ioschedQ = 32 # 增加队列深度 ``` 3. **对齐分区**:客户机内分区时使用4K对齐(`fdisk -u=sectors`)。 --- ### **注意事项** 1. **性能差异**:虚拟SSD的IOPS仍受限于主机物理磁盘性能[^1]。 2. **TRIM依赖**:需客户机操作系统支持(如Linux的`fstrim`,Win7+的优化驱动器)。 3. **NVMe兼容性**:旧版系统需手动安装驱动(如Win8以下)。 > 💡 **扩展场景**:若需更精确的SSD延迟模拟,可结合`qemu-img`创建带特定IOPS限制的磁盘(需命令行工具): > ```bash > qemu-img create -f qcow2 -o latency_target=0.1,latency_window=1 ssd.qcow2 20G > ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值