zl程序教程

您现在的位置是:首页 >  其他

当前栏目

[虚拟工具] Virtual box;虚拟技术的一点总结

技术工具 总结 虚拟 一点 Virtual Box
2023-09-14 09:13:12 时间

虚拟技术的总结

虚拟机上不是说我想在上面创建多少虚拟机就能创建多少个。这个要看处理器的能力,处理器有多少个core。虚拟机出出现的一个原因,当处理器能力到了天花板之后,多个处理器协同处理成为必然,而对于多处理器怎么发挥其最高的性能,此时出现的是虚拟技术,充分利用。

虚拟化设置

使用virtualBox安装时,主板需要将芯片组换成ICH9,
处理器,去掉扩展特性,PAE/NX
硬件加速器也需要去掉虚拟化设置

与windows主机共享目录,

第一步是在虚拟机设备下,按装增强功能
第二步是添加一个共享目录:example,创建了一个共享目录是 openssl
第三步,在虚拟机上创建一个目录 /root/share/
第四步 是mount 这个目录: sudo mount -t vboxsf openssl /root/share/

设置共享网络

添加网卡2, 连接方式:桥接网卡,然后选择当前本机上网的网卡

3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:66:5b:96 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.101/24 brd 192.168.0.255 scope global noprefixroute dynamic enp0s8
valid_lft 6597sec preferred_lft 6597sec
inet6 fe80::f50d:407:eabd:f9d2/64 scope link noprefixroute
valid_lft forever preferred_lft forever

这样就可以看到一个外部的网络IP

给虚拟机添加硬盘容量

0), 正常关闭虚拟机

  1. resize the disk from virtual box
    C:\Program Files\Oracle\VirtualBox>
    VBoxManage modifymedium --resize 40960 “C:\Users\mzhan017\VirtualBox VMs\rhel7.4\rhel7.4.vdi” 40960 == 40G
    0%…10%…20%…30%…40%…50%…60%…70%…80%…90%…100%
  2. restart VM and patition
    重新启动虚拟机,查看磁盘情况。
    2.1) check by “fdisk -l /dev/sda”
      Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 sectors 40G
[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 40 GiB, 42949672960 bytes, 83886080 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
Disklabel type: dos
Disk identifier: 0xa97571a4

Device     Boot   Start      End  Sectors Size Id Type
/dev/sda1  *       2048  2099199  2097152   1G 83 Linux
/dev/sda2       2099200 52428799 50329600  24G 8e Linux LVM

2.2)使用 fdisk 将虚拟磁盘的空闲空间创建为一个新的分区。注意要使用代表 Linux LVM 的分区号 8e 来作为 ID。 需要选择 w保存退出。
  # fdisk /dev/sda —用root用户操作
  n {new partition} 选择这一个
  p {primary partition}
  3 {partition number}
Return for size
t change it to 8e ///然后更改 hex code
w save changes

[root@localhost ~]# fdisk /dev/sda

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3):
First sector (52428800-83886079, default 52428800):
Last sector, +sectors or +size{K,M,G,T,P} (52428800-83886079, default 83886079):

Created a new partition 3 of type 'Linux' and of size 15 GiB.

Command (m for help): t
Partition number (1-3, default 3): 3
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi ea  Rufus alignment
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ee  GPT
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f1  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f4  SpeedStor
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      f2  DOS secondary
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fb  VMware VMFS
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fc  VMware VMKCORE
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fd  Linux raid auto
1c  Hidden W95 FAT3 75  PC/IX           bc  Acronis FAT32 L fe  LANstep
1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot    ff  BBT
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): w       **/保存**
The partition table has been altered.
Syncing disks.

  1. reboot and do
    3.1) check current VG and PG name
    vgdisplay
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               rhel
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <24.00 GiB
  PE Size               4.00 MiB
  Total PE              6143
  Alloc PE / Size       6143 / <24.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               wZo1Ax-KNs7-B0gC-5iXg-RuAR-7iIF-JfYFGL

3.2)create one VG with new partition /dev/sda3
pvcreate /dev/sda3
3.3) check PV by “pvdisplay”
3.4) extend VG
vgextend rhel /dev/sda3
3.5) Extend LV
lvextend /dev/mapper/rhel-root /dev/sda3
/dev/mapper/rhel-root from “df -h”
3.6) adjust the size of LV
通过/etc/fstab, 查看文件系统类型

[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Jul  5 10:24:33 2019
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=518c9512-5c68-44e3-9487-4eaf933d6709 /boot                   xfs     defaults        0 0
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0

如果是xfs:
xfs_growfs / / (根目录)
如果是ext2-4
resize2fs /dev/mapper/rhel-root for ex2-4

[root@localhost ~]# xfs_growfs /dev/mapper/rhel-root
xfs_growfs: /dev/mapper/rhel-root is not a mounted XFS filesystem
[root@localhost ~]# resize2fs /dev/mapper/rhel-root
resize2fs 1.44.3 (10-July-2018)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/rhel-root
Couldn't find valid filesystem superblock.
[root@localhost ~]# xfs_growfs /
meta-data=/dev/mapper/rhel-root  isize=512    agcount=4, agsize=1436928 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=5747712, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2806, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5747712 to 9678848
[root@localhost ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               900M     0  900M   0% /dev
tmpfs                  915M     0  915M   0% /dev/shm
tmpfs                  915M  8.4M  907M   1% /run
tmpfs                  915M     0  915M   0% /sys/fs/cgroup
/dev/mapper/rhel-root   37G  3.0G   34G   9% /
/dev/sda1             1014M  165M  850M  17% /boot
tmpfs                  183M     0  183M   0% /run/user/0

  1. check disk size
    df -h
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/rhel-root 37G 4.4G 33G 12% /

错误总结

  • 不能为虚拟电脑打开一个新任务,明细:
Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter' (VERR_INTNET_FLT_IF_NOT_FOUND).
Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND).
//错误提示,未能打开/创建内部网络接口,解决方法试再设置里对网络进行设置,找一个可以用的选项。
比如这里的提示就说明“HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter”这个网络接口找不到,
可以选择“桥接网卡-Intel(R) Dual Band Wireless-AC7265”。本地windows使用的是这个无线网卡。
返回 代码: 
E_FAIL (0x80004005)
组件: 
ConsoleWrap
界面: 
IConsole {872da645-4a9b-1727-bee2-5585105b9eed}

NAT 网络转发22端口的数据到虚拟机,这样就可以通过访问主机的22端口到虚拟机的端口。
在这里插入图片描述

virtio-net

准虚拟化网络( virtio-net ),在网络配置里的高级选项卡里控制芯片选项,可以找到这个选项