温馨提示×

CentOS上VirtualBox如何使用命令行

小樊
44
2025-08-24 14:48:58
栏目: 智能运维

在CentOS上使用VirtualBox命令行工具VBoxManage可完成虚拟机管理操作,以下是常用命令及示例:

基础操作

  1. 列出虚拟机
    VBoxManage list vms 
  2. 创建虚拟机
    VBoxManage createvm --name "VM名称" --ostype RedHat_64 --register 
  3. 删除虚拟机
    VBoxManage unregistervm "VM名称" --delete 
  4. 启动/关闭虚拟机
    # 启动(支持headless模式,无图形界面)  VBoxManage startvm "VM名称" --type headless|gui # 关闭  VBoxManage controlvm "VM名称" poweroff 

配置管理

  1. 设置内存和CPU
    VBoxManage modifyvm "VM名称" --memory 2048 --cpus 2 
  2. 添加虚拟硬盘
    # 创建硬盘  VBoxManage createhd --filename "/path/to/disk.vdi" --size 20000 # 挂载到虚拟机  VBoxManage storageattach "VM名称" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "/path/to/disk.vdi" 
  3. 配置网络
    # 设置NAT网络  VBoxManage modifyvm "VM名称" --nic1 nat # 桥接网络(需指定物理网卡)  VBoxManage modifyvm "VM名称" --nic1 bridged --bridgeadapter1 "eth0" 

其他常用操作

  • 挂载ISO镜像
    VBoxManage storageattach "VM名称" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium "/path/to/centos.iso" 
  • 查看虚拟机状态
    VBoxManage list runningvms # 查看运行中的虚拟机  VBoxManage showvminfo "VM名称" # 查看详细信息  

注意事项

  • 命令需在宿主机执行,确保已安装VirtualBox并配置环境变量。
  • 部分操作(如删除虚拟机)需谨慎,避免数据丢失。
  • 详细命令可参考官方文档:VBoxManage手册

以上信息综合自。

0