在服务器上创建虚拟机

来源:互联网 发布:五点共圆 知乎 编辑:程序博客网 时间:2024/09/21 06:37

由于服务器一般是没有显示器这种图形显示设备的,所以讲一讲如何在服务器中创建虚拟机。


前提准备

  1. 在服务器上安装了VirtualBox。
  2. 服务器上有虚拟机操作系统的iso文件。(以Ubuntu16.04为例)
    下载ubuntu16.04镜像命令:
    wget http://releases.ubuntu.com/16.04/ubuntu-16.04.3-server-amd64.iso  
  3. 一个连接到服务器的终端(例如xshell)。


创建步骤

  1. 创建一个新的虚拟机:
    VBoxManage createvm --name "ubuntu" --ostype ubuntu_64 --register
    注意:如果没有指定--register参数,那么需要在后续的命令中使用registervm命令。
    特别注意:指定--ostype参数,可以为新的虚拟机使用默认参数,例如RAM大小,虚拟网络设备等。查看VirtualBox支持的所有操作系统,可以使用
    VBoxManage list ostypes
  2. 为虚拟机指定设置信息:

    VBoxManage modifyvm "ubuntu" --memory 256 --acpi on --boot1 dvd --nic1 nat

  3. 为虚拟机创建虚拟硬盘(例如,20GB):

    VBoxManage createhd --filename "ubuntu.vdi" --size 20000

  4. 为虚拟机添加IDE控制器:

    VBoxManage storagectl "ubuntu" --name "IDE Controller" --add ide --controller PIIX4

  5. 将第三步中创建的虚拟硬盘添加到虚拟机:

    VBoxManage storageattach "ubuntu" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium "ubuntu.vdi"

  6. 将需要安装的操作系统iso文件添加到虚拟机:

    VBoxManage storageattach "ubuntu" --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium /full/path/to/iso.iso

  7. 启动虚拟机:

    VBoxManage startvm "ubuntu" --type headless


其他命令

  • 关闭虚拟机:

    VBoxManage controlvm "ubuntu" poweroff

原创粉丝点击