{"id":16961065,"url":"https://github.com/ricsanfre/ubuntu-cloud-vbox","last_synced_at":"2025-04-14T11:20:46.279Z","repository":{"id":111459608,"uuid":"396899777","full_name":"ricsanfre/ubuntu-cloud-vbox","owner":"ricsanfre","description":"Automating the creation of Ubuntu VM in VBOX from a cloud image.","archived":false,"fork":false,"pushed_at":"2025-01-12T12:19:27.000Z","size":367,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T00:41:16.372Z","etag":null,"topics":["cloud-image","cloud-init","ubuntu","virtual-box"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ricsanfre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-16T17:29:47.000Z","updated_at":"2025-02-08T20:42:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"1da6c957-259b-4fa9-b380-79d734ba5a29","html_url":"https://github.com/ricsanfre/ubuntu-cloud-vbox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricsanfre%2Fubuntu-cloud-vbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricsanfre%2Fubuntu-cloud-vbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricsanfre%2Fubuntu-cloud-vbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricsanfre%2Fubuntu-cloud-vbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ricsanfre","download_url":"https://codeload.github.com/ricsanfre/ubuntu-cloud-vbox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248868767,"owners_count":21174758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cloud-image","cloud-init","ubuntu","virtual-box"],"created_at":"2024-10-13T22:50:55.361Z","updated_at":"2025-04-14T11:20:46.252Z","avatar_url":"https://github.com/ricsanfre.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Creation Ubuntu VM in VBox from Ubuntu cloud image\n\nThis repository contains the manual instructions and automation scripts (Windows' PowerShell and Linux bash) for generating a VM in VBox from Ubuntu Cloud Image. Windows and Ubuntu VirtualBox Host OS are supported.\n\n\n## Why\n\nThe goal is to automate the deployment of a headless Ubuntu server in VBox using a cloud-image ready to be configured in boot time using **cloud-init**.\n\nCanonical generates cloud-specific images which are available on https://cloud-images.ubuntu.com/\nImages for VMware/VBox in vmdk disk formats can be found there.\nThose images can be configured through **cloud-init** at boot time, using [**NoCloud**](https://cloudinit.readthedocs.io/en/latest/topics/datasources/nocloud.html) data source.\n\nCloud-init metadata and user-data can be provided to a local VM boot via files in vfat or iso9660 filesystems. The filesystem volume label must be `cidata` or `CIDATA` and it must contain at least two files\n\n    /user-data\n    /meta-data\n\nNetwork configuration can be provided to cloud-init formated in yaml file `network-config`\n\n## PowerShell script for Windows. Windows as VirtualBox Host OS\n\nRequired Software:\n - [Oracle VBox](https://www.virtualbox.org/)\n - [Qemu-img for Windows](https://cloudbase.it/qemu-img-windows/)\n - [CDBurnerXP](https://cdburnerxp.se/)\n - [PowerShell 7.0](https://github.com/PowerShell/PowerShell)\n\n\nCreate in windows a `SCRIPT` folder and place there script `create_vbox_vm_ubuntu_cloud.ps1`\nWithin SCRIPT directory create a `templates` directory and copy template files from the repository:\nThis folder contains the user-data and network-config templates used by the script.\n\nFrom PowerShell console execute the script `create_vbox_vm_ubuntu_cloud.ps1`\n\nScript execution\n\n\n```\ncreate_vbox_vm_ubuntu_cloud.ps1 -name \u003cserver_name\u003e\n                                -path \u003cpath\u003e\n                                -ip \u003cserver_ip\u003e\n                                -cores \u003ccpu_cores\u003e\n                                -memory \u003cserver_memory_MB\u003e\n                                -disk_size \u003cserver_disk_size_MB\u003e\n                                -ubuntuversion \u003cubuntu_release\u003e\n                                -vbox_bridged_adapter \u003cbridged_if\u003e\n                                -vbox_host_only_adapter \u003chostonly_if\u003e\n                                -force_download \u003ctrue/false\u003e\n\n```\n\n\nParameters:\n\n- **name**: (M) server name. VM server name and hostname. (M)\n- **ip**: (M) must belong to VBox HostOnly network\n- **path**: (O) Base path used for creating the VM directory (default value: '.' current directory). A directory with name - **name** is created in **path** directory. If a server already exists within that directory, VM is not created. \n- **memory**: (O) VM memory in MB (default value 1024, 1GB)\n- **cores**: (O) VM cpu cores (default value 1)\n- **disk_size** (O) VM disk size in MB (default value 8192, 8GB)\n- **ubuntu_version** (O) Ubuntu relase 18.04, 20.04 (default value 20.04)\n- **vbox_bridged_adapter** (O) and **vbox_host_only_adapter** (O): VBOX interfaces names\n- **force_download** (O): Force download of img even when there is an existing image\n\n\nVM is created with two interfaces:\n- **NIC1** hostonly with static ip (server_ip)\n- **NIC2** bridgeadapter with dynamic ip, dhcp\n\n\u003e NOTE: VBOX interfaces adapter names might need to be adapted to your own environment\n\u003e Commands for obtained VBOX configured interfaces\n    vboxmanage list hostonlyifs\n    vboxmanage list bridgedifs\n\nThe script will download img from ubuntu website if it is not available in `img` directory or *force_download* true parameter has been selected\n\nThe script will be use user-data and network-config templates located in `templates` directory named with *server_name* suffix:\n- user-data-*server_name*.yml\n- network-config-*server_name*.yml\n\nIf any of the files is missing the `default` files will be used.\n\nExample execution:\n\n```\ncreate_vbox_vm_ubuntu_cloud.ps1 -name \"server_name\" -ip \"192.168.56.201\"\n```\n\n## Bash script for Ubuntu host. Ubuntu as VirtualBox Host OS\n\nRequired Software:\n - qemu-utils\n - cloud-image-utils\n\n```shell\nsudo apt-get install qemu-utils cloud-image-utils\n```\n\nCreate a `SCRIPT` folder and place there script `create_vbox_vm_ubuntu_cloud.sh`\nWithin SCRIPT directory create a `templates` directory and copy template files from the repository:\nThis folder contains the user-data and network-config templates used by the script.\n\nFrom the directory where the VM is going to be located exectute the script `create_vbox_vm_ubuntu_cloud.sh`\n\nScript execution\n\n\n```\ncreate_vbox_vm_ubuntu_cloud.ps1 -n \u003cserver_name\u003e\n                                -ip \u003cserver_ip\u003e\n                                -c \u003ccpu_cores\u003e\n                                -m \u003cserver_memory_MB\u003e\n                                -d \u003cserver_disk_size_MB\u003e\n                                -r \u003cubuntu_release\u003e\n                                -f \u003cforce download\u003e\n\n```\n\nThe script will download img from ubuntu website if it is not available in `img` directory or *force_download* option (-f) is being used.\n\nThe script will be use user-data and network-config templates located in `templates` directory named with *server_name* suffix:\n- user-data-*server_name*.yml\n- network-config-*server_name*.yml\n\nIf any of the files is missing the `default` files will be used.\n\n\n\n## Manual Instructions.\n\n### Step 1. Download Ubuntu 20.04 LTS 64 bits cloud-image in VMDK format\n\nDownload the specific image format from https://cloud-images.ubuntu.com/releases\n\n\u003e In our case, Ubuntu-20.04-server-cloudimg-amd64.vmdk\n\u003e \n\u003e https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img\n\n### Step 2. Convert img file to raw disk\n\nConvert to raw format the img downloaded in step 2. Use `qemu-img` to conver it with the following command:\n\n    qemu-img convert -O raw ubuntu-20.04-server-cloudimg-amd64.img ubuntu-20.04-server-cloudimg-amd64.raw\n\n\u003e NOTE: In windows qemu-img utility can be installed from [here](https://cloudbase.it/qemu-img-windows/)\n\n### Step 3. Convert raw disk to VBox vdi disk\n\nConvert the raw image to vdi format with VirtualBox tool `vboxmanage`\n \n    vboxmanage convertfromraw ubuntu-20.04-server-cloudimg-amd64.raw ubuntu-20.04-server-cloudimg-amd64.vdi\n\n\u003e In windows the command should be something like this:\n\u003e \n\u003e    \"C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe\" convertfromraw ubuntu-20.04-server-cloudimg-amd64.raw ubuntu-20.04-server-cloudimg-amd64.vdi\n\n\n### Step 4: Clone the base vdi disk every time a new VM is created\n\nSame vdi disk cannot be used for more than one VM (VDI's UUID must be unique within VBox instalation).\nClone Vdi disk procedure generated in step 3 every time a new VM need to be created\n\n     vboxmanage clonehd ubuntu-20.04-server-cloudimg-amd64.vdi server1-ubuntu20.04.vdi\n\n\u003e In windows the command should be something like this:\n\u003e \n\u003e    \"C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe\" clonehd ubuntu-20.04-server-cloudimg-amd64.vdi server1-ubuntu20.04.vdi\n\n\n### Step 5. Create SSH keys\n\nAuthentication using SSH keys will be the only mechanism available to login to the server.\nWe will create SSH keys for two different users:\n\n- **ricsanfre** user, used to connect from my home laptop\n\n    For generating SSH private/public key in Windows, Putty Key Generator can be used:\n\n    ![ubuntu-SSH-key-generation](images/ubuntu-user-SSH-key-generation.png \"SSH Key Generation\")\n\nPublic-key string will be used in Step 6 to configure ssh_authorized_keys of the default user (ubuntu)\n\n- **ansible** user, used to automate configuration activities with ansible\n \n     For generating ansible SSH keys in Ubuntu server execute command:\n\n        ssh-keygen\n\n    In directory `$HOME/.ssh/` public and private key files can be found for the user\n\n    `id_rsa` contains the private key and `id_rsa.pub` contains the public key.\n\n    Content of the id_rsa.pub file has to be copied in Step 6 to configure ssh_authorized_keys of the ansible user\n    ```\n    cat id_rsa.pub \n    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsVSvxBitgaOiqeX4foCfhIe4yZj+OOaWP+wFuoUOBCZMWQ3cW188nSyXhXKfwYK50oo44O6UVEb2GZiU9bLOoy1fjfiGMOnmp3AUVG+e6Vh5aXOeLCEKKxV3I8LjMXr4ack6vtOqOVFBGFSN0ThaRTZwKpoxQ+pEzh+Q4cMJTXBHXYH0eP7WEuQlPIM/hmhGa4kIw/A92Rm0ZlF2H6L2QzxdLV/2LmnLAkt9C+6tH62hepcMCIQFPvHVUqj93hpmNm9MQI4hM7uK5qyH8wGi3nmPuX311km3hkd5O6XT5KNZq9Nk1HTC2GHqYzwha/cAka5pRUfZmWkJrEuV3sNAl ansible@pimaster\n    ```\n\n### Step 6. Create seed iso file\n\nFor creating the iso file in a windows hots, an open-source tool like [CDBurnerXP](https://cdburnerxp.se/).\n\nFor Ubuntu host a utility `cloud-localds` can be used (this utility is part of the package `cloud-image-utils`)\n\n- Create in a temporary directory `seed_iso`\n- Create a file `meta-data`\n  \n     ```\n     instance-id: ubuntucloud-001\n     local-hostname: ubuntucloud1\n     ```\n- Create a file `user-data`\n  \n    ```yml\n    #cloud-config\n    # Set TimeZone and Locale\n    timezone: Europe/Madrid\n    locale: es_ES.UTF-8\n\n    # Hostname\n    hostname: servername\n    # Ensure an entry in /etc/host is created\n    manage_etc_hosts: localhost\n\n    # Users. Remove default (ubuntu) + ansible user for remoto control\n    users:\n    - name: ricsanfre\n        gecos: Ricardo Sanchez\n        primary_group: users\n        shell: /bin/bash\n        sudo: ALL=(ALL) NOPASSWD:ALL\n        lock_passwd: true\n        ssh_authorized_keys:\n        - ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAusTXKfFoy6p3G4QAHvqoBK+9Vn2+cx2G5AY89WmjMikmeTG9KUseOCIAx22BCrFTNryMZ0oLx4u3M+Ibm1nX76R3Gs4b+gBsgf0TFENzztST++n9/bHYWeMVXddeV9RFbvPnQZv/TfLfPUejIMjFt26JCfhZdw3Ukpx9FKYhFDxr2jG9hXzCY9Ja2IkVwHuBcO4gvWV5xtI1nS/LvMw44Okmlpqos/ETjkd12PLCxZU6GQDslUgGZGuWsvOKbf51sR+cvBppEAG3ujIDySZkVhXqH1SSaGQbxF0pO6N5d4PWus0xsafy5z1AJdTeXZdBXPVvUSNVOUw8lbL+RTWI2Q== ubuntu@mi_pc\n    - name: ansible\n        gecos: Ansible user\n        primary_group: users\n        shell: /bin/bash\n        sudo: ALL=(ALL) NOPASSWD:ALL\n        lock_passwd: true\n        ssh_authorized_keys:\n        - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsVSvxBitgaOiqeX4foCfhIe4yZj+OOaWP+wFuoUOBCZMWQ3cW188nSyXhXKfwYK50oo44O6UVEb2GZiU9bLOoy1fjfiGMOnmp3AUVG+e6Vh5aXOeLCEKKxV3I8LjMXr4ack6vtOqOVFBGFSN0ThaRTZwKpoxQ+pEzh+Q4cMJTXBHXYH0eP7WEuQlPIM/hmhGa4kIw/A92Rm0ZlF2H6L2QzxdLV/2LmnLAkt9C+6tH62hepcMCIQFPvHVUqj93hpmNm9MQI4hM7uK5qyH8wGi3nmPuX311km3hkd5O6XT5KNZq9Nk1HTC2GHqYzwha/cAka5pRUfZmWkJrEuV3sNAl ansible@pimaster\n    ```\n- Create `network-configuration` file\n  \n    ```yml\n    version: 2\n    ethernets:\n    enp0s3:\n      dhcp4: no\n      addresses: [192.168.56.100/24]\n    enp0s8:\n      dhcp4: yes\n    ```\n\n- Create ISO file with [CDBurnerXP](https://cdburnerxp.se/) (Windows Host)\n    \n  \n  Select the folder where the files has been generated and specify `CIDATA` as Volume Name\n\n  In windows the command should be something like this:\n\n  ```dos\n  \"C:\\Program Files\\CDBurnerXP\\cdbxpcmd.exe\" --burndata -folder:seed_iso -iso:seed.iso -format:iso -changefiledates -name:CIDATA\n  ```\n\n- Create ISO file with clouds-local (Ubuntu Host)\n\n  ```shell\n  cloud-localds --network-config network-config seed.iso user-data meta-data\n  ```\n\n### Step 7. Create VM in VirtualBOX\n\n- Create new VM without creating any virtual disk\n\n    ![Create-VM-VBox](images/VBox_create_ubuntu_cloud_image_1.png \"Create new VM\")\n\n    ![Create-VM-VBox](images/VBox_create_ubuntu_cloud_image_2.png \"Configure Memory\")\n\n    ![Create-VM-VBox](images/VBox_create_ubuntu_cloud_image_3.png \"Do not create virtual disk\")\n\n- Copy vdi disk created in step 4 and seed.iso file created in step 6 to new VM's folder\n\n- Configure new VM, add vmdiks and iso\n\n   Add vmdk containing ubuntu image as new disk under SATA controller.\n\n   Load seed.iso file in the Optical Disk (IDE Controller)\n\n    ![Create-VM-VBox](images/VBox_create_ubuntu_cloud_image_4.png \"Configure Disk\")\n\n- Configure Serial Port\n    Serial Port **Port1** need to be enabled.\n\n    ![Create-VM-VBox](images/VBox_create_ubuntu_cloud_image_5.png \"Create new VM\")\n\n- Configure network interfaces\n\n    Two interfaces enabled: \n    \n    Host-only interface\n\n    ![Create-VM-VBox](images/VBox_create_ubuntu_cloud_image_6.png \"Host-only interface\")\n\n    NAT interface to provide internet access to the VM\n\n    ![Create-VM-VBox](images/VBox_create_ubuntu_cloud_image_7.png \"NAT interface\")\n\n\n### Step 8. Enlarge Disk size\n\nThe converterd vdi size is arround 2GB. It can be enlarged using VBOX GUI (form 6.0 release)\n\n- Open Virtual Media Manager in VirtualBox\n  \n    ![Create-VM-VBox](images/VBox_create_ubuntu_cloud_image_8.png \"Virtual Media Manager\")\n\n- Modify the size of the vdi created in step 4\n\n    ![Create-VM-VBox](images/VBox_create_ubuntu_cloud_image_9.png \"Modify size of vdi\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricsanfre%2Fubuntu-cloud-vbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fricsanfre%2Fubuntu-cloud-vbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricsanfre%2Fubuntu-cloud-vbox/lists"}