我尝试使用 VirtualBox 在我的 MacBook Pro 上安装 Ubuntu。但是,似乎没有关于如何操作的指南——大多数都是关于使用 VirtualBox 在 Windows PC 上安装的。
有人能帮我指导一下怎么做吗?谢谢!
答案1
答案2
我在 MacOS 10.15 上的 VirtualBox 6.1.10 中运行 20.04。根据其他答案,按照向导操作,一切正常。
- 下载自https://releases.ubuntu.com/20.04/ubuntu-20.04-live-server-amd64.iso
- 按照 MacOS 上的向导进行设置
- 或者使用 python 作为控制器从命令行执行示例。这几乎与主机操作系统无关 - 路径构建方式在 PowerShell 中不起作用。MacOS 上的默认预置配置文件因此使用带有修补的自定义文件
def vbinstall(alog, config, buildkey):
name = buildkey
home = Path.home()
download = f"{Path.cwd()}/downloads/{config['ubuntu'][buildkey]['dl'].split('/')[-1]}"
vb = hm.vbhost(host=config["virtualbox"])
cfg = f"{Path.cwd()}/bin/UnattendedTemplates/ubuntu_preseed.cfg"
exit, out = vb.cmd("VBoxManage list vms")
# alog.info(f"shared folder {config['sharedstorage']} -exists ")
alog.info(f"shared folder [{config['sharedstorage']}] exists [{Path(config['sharedstorage']).is_dir()}]")
for l in out:
vms = l.split()[0].strip("\"")
if vms == name:
alog.info(f"Server exists {vms}. Skipping setup....")
return
aux = f"{Path.cwd()}/bin/UnattendedTemplates/aux-{buildkey}"
alog.info(f"aux {aux}")
exit, out = vb.cmd(f"rm -rf {aux}")
exit, out = vb.cmd(f"mkdir {aux}")
with open(f"{Path.cwd()}/bin/UnattendedTemplates/autoinstall.yaml") as f: aconfig=yaml.safe_load(f)
# aconfig["autoinstall"]["hostname"] = buildkey
aconfig["autoinstall"]["identity"]["hostname"] = buildkey
aconfig["autoinstall"]["identity"]["username"] = config['mcs']['user']
aconfig["autoinstall"]["identity"]["password"] = config['mcs']['encrypted']
# substitute @@user@@ in late commands
aconfig["autoinstall"]["late-commands"] = \
[re.sub("\@\@user\@\@", config['mcs']['user'], l) for l in aconfig["autoinstall"]["late-commands"]]
with open(f"{aux}/autoinstall.yaml", "w") as f:
f.write("#cloud-config\n")
yaml.dump(aconfig, f)
with open(f"{aux}/user-data", "w") as f:
f.write("#cloud-config\n")
yaml.dump(aconfig, f)
exit, out = vb.cmd(f"touch {aux}/meta-data")
# want to keep UUID of VM constant for remoteit and plex - if defined use it
uuid = f'--uuid {config["ubuntu"][name]["uuid"]}' if "uuid" in config["ubuntu"][name].keys() else ""
# allow for VM specific location of sharedfolder
sharedstorage = config["ubuntu"][name]["sharedstorage"] if "sharedstorage" in config["ubuntu"][name].keys() else \
config["sharedstorage"]
alog.info(f"uuid: [{uuid}] storage: [{sharedstorage}]")
# VBoxManage createvm --name {name} --ostype \"Ubuntu_64\" --register --basefolder {home}/\"VirtualBox VMs\"/
vbi = f'''
VBoxManage createvm --name {name} --ostype \"Ubuntu_64\" --register --basefolder {home}/\"VirtualBox VMs\"/ {uuid}
#Set memory and network
VBoxManage modifyvm {name} --ioapic off
VBoxManage modifyvm {name} --memory 1024 --vram 128
VBoxManage modifyvm {name} --nic1 bridged
VBoxManage modifyvm {name} --bridgeadapter1 'en0: en0'
VBoxManage modifyvm {name} --graphicscontroller vmsvga
VBoxManage modifyvm {name} --audio none
#Create Disk and connect Debian Iso
VBoxManage createhd --filename {home}/\"VirtualBox VMs\"/{name}_DISK.vdi --size 15000 --format VDI
VBoxManage createhd --filename {sharedstorage}/{buildkey}-plex.vhd --size 50000 --format VHD
VBoxManage storagectl {name} --name "SATA Controller" --add sata --controller IntelAhci
VBoxManage storageattach {name} --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium {home}/\"VirtualBox VMs\"/{name}_DISK.vdi
VBoxManage storageattach {name} --storagectl "SATA Controller" --port 1 --device 0 --type hdd --medium {sharedstorage}/{buildkey}-plex.vhd
# shared storage
VBoxManage sharedfolder add {name} --name mcs --hostpath {sharedstorage} --automount
VBoxManage sharedfolder add {name} --name active --hostpath "{config['ubuntu'][name]['media']['active']}" --automount
VBoxManage sharedfolder add {name} --name archive --hostpath "{config['ubuntu'][name]['media']['archive']}" --automount
#Enable RDP
VBoxManage modifyvm {name} --vrde on
VBoxManage modifyvm {name} --vrdemulticon on --vrdeport 10001
# install
VBoxManage unattended install {name} --user={config['mcs']['user']} --password={config['mcs']['pwd']} \
--auxiliary-base-path {aux}/ \
--install-additions --iso={download} --country=SG --post-install-template={cfg} --script-template={cfg}
'''
exit, out = vb.cmd(vbi, assertfail=False)
for l in out: alog.info(f"{l}")
alog.info(f"finished {name} initial setup")
isolinux(aux, buildkey, config, alog)
preseed(aux, buildkey, config, alog)
exit, out = vb.cmd(f"VBoxManage startvm {name} #--type headless", assertfail=False)
alog.info(f"vm start [{exit}] {out}")