在Linux服务器上使用Vbox安装虚拟机

时间:2023-12-01 21:47:02

先去官网(www.virtualbox.org)上下载对应Linux系统的Vbox版本。

我这边用的是Oracle Linux 7系统(KDE安装)

在Linux服务器上使用Vbox安装虚拟机

使用rpm安装virtualbox

在Linux服务器上使用Vbox安装虚拟机

发现报错,按照提示安装需要的包yum install libSDL*

再重新执行安装依旧报错。

在Linux服务器上使用Vbox安装虚拟机

按照提示进入日志文件,查看具体的报错原因

在Linux服务器上使用Vbox安装虚拟机

意思是没有找到我们系统当前内核  安装gcc就行

yum install gcc

执行完成后再次重新安装·这次就可以成功安装了

在Linux服务器上使用Vbox安装虚拟机

然后我们就可以去图形界面打开Vbox安装虚拟机了,比较简单这里就不进行说明了,现在主要讲的是在命令行下安装虚拟机。

1、安装扩展包,以便使用RDP协议3389远程登录安装操作系统

下载地址http://download.virtualbox.org/virtualbox/

wget http://download.virtualbox.org/virtualbox/5.1.30/Oracle_VM_VirtualBox_Extension_Pack-5.1.30-118389.vbox-extpack

安装扩展包

VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.1.30-118389.vbox-extpack

在Linux服务器上使用Vbox安装虚拟机

注意:一定要下载与Vbox版本相匹配的扩展包,我这边第一次安装时因为这个问题导致安装失败,附上删除方法

查看所有的扩展包  VBoxManage list extpacks

卸载扩展包  VBoxManage extpack uninstall "Oracle VM VirtualBox Extension Pack"

清除扩展包  VBoxManage extpack cleanup

在Linux服务器上使用Vbox安装虚拟机

2、创建虚拟机

创建一个Oracle_64 内核的操作系统虚拟机,名称为centos6,虚拟机的文件存放路径在 /opt/virtualbox/

在Linux服务器上使用Vbox安装虚拟机

发现报错  按照错误提示 执行 sudo /sbin/vboxconfig

发现问题是我们的Vbox的程序内核没法在当前系统内核上加载。我们需要重新编译系统内核组件来满足VBOX的安装需求。

yum install kernel-devel-$(uname -r)  会安装一些包 然后reboot重启就行了。

将之前创建的虚拟机文件删除再重新执行

在Linux服务器上使用Vbox安装虚拟机

3、创建虚拟磁盘

创建一个20G(大小根据自己需要)的虚拟磁盘

VBoxManage createvdi --filename /opt/virtualbox/centos7.vdi --size 20000

在Linux服务器上使用Vbox安装虚拟机

4、创建虚拟机的硬盘控制器

VBoxManage storagectl centos7 --name storage_controller_1 --add ide

5、挂载虚拟硬盘和虚拟光驱

先创建存放iso文件的文件夹然后上传到文件夹里面

mkdir –p /opt/setup/

VBoxManage storageattach centos7 --storagectl storage_controller_1 --type hdd --port 0 --device 0  --medium /opt/virtualbox/centos7.vdi

VBoxManage storageattach centos7 --storagectl storage_controller_1 --type dvddrive --port 1 --device 0 --medium /opt/setup/OracleLinux-R7-U2-Server-x86_64-dvd.iso

6、设置启动顺序

将光驱设置为第一启动顺序,以便安装操作系统。

VBoxManage modifyvm centos7 --boot1 dvd

VBoxManage modifyvm centos7 --boot2 disk

在Linux服务器上使用Vbox安装虚拟机

7、创建桥接的网络

需要找到当前主机的网卡名称,如果不知道可以使用ifconfig命令查看,我这边是enp0s25

VBoxManage modifyvm centos7 --nic1 bridged --cableconnected1 on --nictype1 82540EM --bridgeadapter1 enp0s25 --intnet1 brigh1 --macaddress1 auto

8、启动vrde模块

VRDE模块用于启动RDP协议,使用微软的3389客户端即可连接

VBoxManage modifyvm centos7 --vrde on

当我们安装完成操作系统时,可以关闭此屏幕输出

VBoxManage modifyvm centos7 --vrde off

9、调整系统参数(如内存、CPU等)

VBoxManage modifyvm centos7 --memory 2048

VBoxManage modifyvm centos7 --cpus 2

10、启动虚拟机

VBoxHeadless -startvm centos7

在Linux服务器上使用Vbox安装虚拟机

11、3389远程连接安装操作系统

在window电脑上直接运行mstsc连接

在Linux服务器上使用Vbox安装虚拟机

在Linux服务器上使用Vbox安装虚拟机

在Linux服务器上使用Vbox安装虚拟机

12、常用命令

查看所有的虚拟机  vboxmanage list vms

启动虚拟机  VBoxHeadless -startvm vmname       ##  vmname 是虚拟机的名字

关闭虚拟机  VBoxManage controlvm vmname poweroff

删除虚拟机  VBoxManage unregistervm  --delete  vmname