centos

CentOS上VirtualBox如何使用命令行

小樊
39
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"  
    

其他常用操作

注意事项

以上信息综合自。

0
看了该问题的人还看了