一.安装virtualbox
sudo apt-get install virtualbox
二.安装拓展包
安装拓展包首先查看virtualbox的版本号:
sudo vboxmanage |more
输出如下:
Oracle VM VirtualBox Command Line Management Interface Version 7.0.14_Ubuntu
Copyright (C) 2005-2024 Oracle and/or its affiliates
Usage - Oracle VM VirtualBox command-line interface:
VBoxManage [-V | --version] [--dump-build-type] [-q | --nologo] [--settingspw=password] [--settingspwfile=pw-file]
[@response-file] [[help] subcommand]
VBoxManage list [--long] [--sorted] [bridgedifs | cloudnets | cloudprofiles | cloudproviders | cpu-profiles |
dhcpservers | dvds | extpacks | floppies | groups | hddbackends | hdds | hostcpuids | hostdrives | hostdvds |
hostfloppies | hostinfo | hostonlyifs | hostonlynets | intnets | natnets | ostypes | runningvms |
screenshotformats | systemproperties | usbfilters | usbhost | vms | webcams]
VBoxManage showvminfo <uuid | vmname> [--details] [--machinereadable] [--password-id] [--password]
VBoxManage showvminfo <uuid | vmname> <--log=index> [--password-id id] [--password file|-]
VBoxManage registervm <filename> --password file
VBoxManage unregistervm <uuid | vmname> [--delete] [--delete-all]
VBoxManage createvm <--name=name> [--basefolder=basefolder] [--default] [--group=group-ID,...] [--ostype=ostype]
[--register] [--uuid=uuid] [--cipher cipher] [--password-id password-id] [--password file]
--More--
我安装的版本号为7.0.14,使用wget下载对应版本号的拓展包:
wget https://download.virtualbox.org/virtualbox/7.0.14/Oracle_VM_VirtualBox_Extension_Pack-7.0.14-161095.vbox-extpack
其他版本的下载链接可以在https://download.virtualbox.org/virtualbox找到。
安装拓展包:
sudo vboxmanage extpack install Oracle_VM_VirtualBox_Extension_Pack-7.0.14-161095.vbox-extpack
查看拓展包是否安装成功:
sudo vboxmanage list extpacks
输出:
Extension Packs: 2
Pack no. 0: VNC
Version: 7.0.14
Revision: 161095
Edition:
Description: VNC plugin module
VRDE Module: VBoxVNC
Crypto Module:
Usable: true
Why unusable:
Pack no. 1: Oracle VM VirtualBox Extension Pack
Version: 7.0.14
Revision: 161095
Edition:
Description: Oracle Cloud Infrastructure integration, Host Webcam, VirtualBox RDP, PXE ROM, Disk Encryption, NVMe, full VM encryption.
VRDE Module: VBoxVRDP
Crypto Module: VBoxPuelCrypto
Usable: true
Why unusable:
设置拓展包特性:
sudo vboxmanage setproperty vrdeextpack "Oracle VM VirtualBox Extension Pack"
三、创建windows10虚拟机
下载windows10的iso镜像,这里我用的是Tiny10 (23H1) - 极限精简版 Windows 10
ps:如果需要安装其他版本可以通过命令查看支持的系统,部分输出如下(太多了,这里就不都贴出来了):
VBoxManage list ostypes
输出:
ID: Windows10
Description: Windows 10 (32-bit)
Family ID: Windows
Family Desc: Microsoft Windows
64 bit: false
ID: Windows10_64
Description: Windows 10 (64-bit)
Family ID: Windows
Family Desc: Microsoft Windows
64 bit: true
ID: Windows2016_64
Description: Windows 2016 (64-bit)
Family ID: Windows
Family Desc: Microsoft Windows
64 bit: true
ID: Windows2019_64
Description: Windows 2019 (64-bit)
Family ID: Windows
Family Desc: Microsoft Windows
64 bit: true
ID: Windows11_64
Description: Windows 11 (64-bit)
Family ID: Windows
Family Desc: Microsoft Windows
64 bit: true
ID: Windows2022_64
Description: Windows 2022 (64-bit)
Family ID: Windows
Family Desc: Microsoft Windows
64 bit: true
ID: WindowsNT
Description: Other Windows (32-bit)
Family ID: Windows
Family Desc: Microsoft Windows
64 bit: false
ID: WindowsNT_64
Description: Other Windows (64-bit)
Family ID: Windows
Family Desc: Microsoft Windows
64 bit: true
1.创建虚拟机使用的虚拟硬盘
sudo vboxmanage createmedium disk --filename win10.vdi --size 204800
例子中,虚拟硬盘名称为 win10.vdi 大小200G(--size参数的单位是MB,需要换算一下)。
2. 创建虚拟机,名称为windows10,类型为windows10 64位:
sudo vboxmanage createvm --name windows10 --ostype "Windows10_64" --register
3. 创建SATA磁盘控制器,并绑定第一步创建的虚拟硬盘:
sudo vboxmanage storagectl windows10 --name "SATA Controller" --add sata --controller IntelAHCI
sudo vboxmanage storageattach windows10 --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium win10.vdi
4.创建IDE控制器,设置为dvd,并将其与windows10的安装用iso文件绑定:
sudo vboxmanage storagectl windows10 --name "IDE Controller" --add ide
sudo vboxmanage storageattach windows10 --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium "Win10_64.iso"
注意,ios镜像位置和名称要换成自己的。
5.设置虚拟机使用的CPU、内存和显存,这里分别设置为2核、4G和16M
sudo vboxmanage modifyvm windows10 --cpus 2 --memory 4096 --vram 16 --hwvirtex on
6.设置I/O:
sudo vboxmanage modifyvm windows10 --ioapic on
7.设置启动项
sudo vboxmanage modifyvm windows10 --boot1 disk --boot2 dvd --boot3 none --boot4 none
8.打开VARD(默认端口3389)
sudo vboxmanage modifyvm windows10 --vrde on
9.设置无GUI开机
sudo vboxmanage startvm windows10 --type=headless
现在虚拟机已经开机了。
四、通过远程桌面连接安装系统
1.安装系统
找一台windows的机器win+R搜索mstsc 打开远程桌面连接软件,输入物理机的ip地址(注意区分网络环境,如果物理机有公网ip那么输入公网ip,如果是内网环境则需要用于连接的windows机器和物理机在同一内网下)。连接上后就是普通的操作系统安装操作了。
2.安装用户拓展
关闭虚拟机
vboxmanage controlvm windows10 poweroff
使用wget 下载对应版本的用户拓展,这里选择VBoxGuestAdditions_7.0.14.iso
wget https://download.virtualbox.org/virtualbox/7.0.14/VBoxGuestAdditions_7.0.14.iso
挂载安装包到虚拟机
sudo vboxmanage storageattach windows10 --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium "VBoxGuestAdditions_5.1.34.iso"
重新启动虚拟机
sudo vboxmanage startvm windows10 --type=headless
待虚拟机启动后,连接虚拟机,打开文件资源管理器,发现CD驱动器多了VBoxGuest Additions,打开之后,点击VBoxWindowsAdditions_amd64(这里要根据虚拟机的位数选择),然后按照提示安装。
五、修改网络模式,并启用Windows自带的远程桌面连接
1.启用虚拟机的远程桌面连接
控制面板->系统和安全->系统->允许远程访问,然后勾选“允许远程连接到此计算机”。
2.关闭vrde
sudo VBoxManage modifyvm windows10 --vrde off
3.设置网络为桥接模式
虚拟机默认网络模式为NAT,在我的需求中,我需要将网络模式改为桥接,让路由器单独为虚拟机分配一个ip,方便端口映射共享usb加密狗。(注意,在路由器中设置ip与mac绑定,不然虚拟机重启关机路由器分配的ip会变)
sudo vboxmanage modifyvm windows10 --nic1 bridged --cableconnected1 on --nictype1 82540EM --bridgeadapter1 eth0 --intnet1 brigh1 --macaddress1 auto
现在可以通过虚拟机ip通过远程桌面访问虚拟机了。
六、设置usb设备直通虚拟机
将加密盘插入物理机的usb端口
查看所有可用的usb设备:
sudo vboxmanage list usbhost
输出类似:
UUID: 735c2efb-6522-49bc-9164-9040ef66860d
VendorId: 0x8087 (8087)
ProductId: 0x0026 (0026)
Revision: 0.2 (0002)
Port: 9
USB version/speed: 2/Full
Manufacturer: Intel Corp.
Address: sysfs:/sys/devices/pci0000:00/0000:00:14.0/usb1/1-10//device:/dev/vboxusb/001/004
Current State: Busy
UUID: a96294fd-7d6b-43fe-9ac2-f3e7f8e3e618
VendorId: 0x152d (152D)
ProductId: 0xa561 (A561)
Revision: 150.226 (150226)
Port: 1
USB version/speed: 3/Super
Manufacturer: ACASIS
Product: ACASIS EC-7352
SerialNumber: 98765432100B
Address: sysfs:/sys/devices/pci0000:00/0000:00:14.0/usb2/2-2//device:/dev/vboxusb/002/002
Current State: Busy
UUID: 1901c2a6-8a33-447b-9ccd-ca6c1dafe358
VendorId: 0x0bda (0BDA)
ProductId: 0x0129 (0129)
Revision: 57.96 (5796)
Port: 4
USB version/speed: 2/High
Manufacturer: Generic
Product: USB2.0-CRW
SerialNumber: 20100201396000000
Address: sysfs:/sys/devices/pci0000:00/0000:00:14.0/usb1/1-5//device:/dev/vboxusb/001/003
Current State: Busy
根据UUID将你想绑定的设备连接到虚拟机:
sudo vboxmanage controlvm "windows10" usbattach 735c2efb-6522-49bc-9164-9040ef66860d
七、安装USB over Network
1.安装USB over Network,windows防火墙开放3300端口设置共享设备即可。
下载链接:
通过百度网盘分享的文件:vb虚拟机
链接:https://pan.baidu.com/s/1aVruuiz8ImcoT7CV8_6vHA?pwd=iydp
提取码:iydp
--来自百度网盘超级会员V6的分享
相关命令:
启动:
vboxmanage startvm windows10 --type=headless
关闭:
vboxmanage controlvm windows10 poweroff
卸载
vboxmanage unregistervm windows10 --delete
鸣谢:ubuntu 命令行安装virtualbox,安装windows10系统并用远程桌面连接_ubuntu virtualbox 命令行-CSDN博客