A slightly different approach that also works:
Using the CentOS 7 Cloud Image found here: https://cloud.centos.org/centos/7/images/ (choose CentOS-7-x86_64-GenericCloud.qcow2)
user-data
#!/bin/bash
##
## dependencies required for:
## VBoxGuestAdditions
## Minimal Desktop
##
DEPS='wget unzip python-pip git gnome-classic-session gnome-terminal nautilus-open-terminal control-center liberation-mono-fonts bzip2 libguest libguestfs binutils gcc make kernel-headers kernel-devel'
update(){
sudo yum -y -q update
}
install_epel(){
sudo yum -y install epel-release
sudo yum -y update
}
configure(){
sudo yum -y -q install $DEPS
yum -y groupinstall "X Window System"
unlink /etc/systemd/system/default.target
ln -sf /lib/systemd/system/graphical.target /etc/systemd/system/default.target
reboot
}
set -x
update
install_epel
configure
meta-data
instance-id: dev
local-hostname: dev.example.com
public-keys:
- ssh-rsa AAAAB3NzaC1y[...]2yX3 admin@example.com
network-interfaces: |
auto eth1
iface eth1 inet dhcp
vbox-config-drive.sh
#!/bin/bash
##
## generate the config-drive iso
##
gen_iso(){
echo "Generating ISO"
genisoimage -output vbox-config.iso -volid cidata -joliet -r meta-data user-data
}
##
## resize as necessary
##
resize(){
echo "Resizing Disk"
qemu-img create -f qcow2 -o preallocation=metadata CentOS-7-x86_64-GenericCloud.qcow2.new 12G
virt-resize --quiet --expand /dev/sda1 CentOS-7-x86_64-GenericCloud.qcow2 CentOS-7-x86_64-GenericCloud.qcow2.new
mv CentOS-7-x86_64-GenericCloud.qcow2.new CentOS-7-x86_64-GenericCloud.qcow2
}
##
## convert the qcow to vmdk
##
make_vmdk(){
echo "Converting QCOW to VMDK"
qemu-img convert -f qcow2 CentOS-7-x86_64-GenericCloud.qcow2 -O vmdk CentOS-7-x86_64-GenericCloud.vmdk
}
gen_iso
##
## OPTIONAL
## resize
##
make_vmdk
echo "Done"
Use the resulting VMDK as your VirtualBox primary disk and the resulting ISO as the optical drive.
Hope this helps. M.
1Can you please copy the relevant information here? It is good practise in case the original url is removed. Which happened. – Jan – 2015-09-21T19:14:42.833
2https://web.archive.org/web/20150119071718/http://indieboxproject.org/blog/2014/10/virtualbox-and-cloud-init/ – thyme – 2015-10-23T21:18:08.280
This is a bit misleading: your example is for a "NoCloud" datasource rather than a "Cloud Drive" datasource. The
cidata
label on config.img is one of the determinants. – Dan Dye – 2017-01-03T14:00:05.023