Skip to content

Instantly share code, notes, and snippets.

@ijash
Last active December 6, 2024 06:27
Show Gist options
  • Save ijash/bd4f0a76e55c27a2f3886ae9cc7bfd84 to your computer and use it in GitHub Desktop.
Save ijash/bd4f0a76e55c27a2f3886ae9cc7bfd84 to your computer and use it in GitHub Desktop.
How to Make an Installed Ubuntu in VirtualBox Bootable on an External Disk

How to Make an Installed Ubuntu in VirtualBox Bootable on an External Disk

Installing Ubuntu in VirtualBox

  1. Download Ubuntu
    Download the Ubuntu ISO file from the official website.

  2. Set Up VirtualBox

    • Create a new virtual machine in VirtualBox.
    • Use a dynamic virtual disk (.vdi) with a maximum size (e.g., 16GB).
    • Enable EFI by checking the EFI option in the system settings.
  3. Install and Configure Ubuntu

    • Install Ubuntu as you would normally.
    • Update the system to the latest version using:
      sudo apt update && sudo apt upgrade -y
  4. Prepare the Disk for Booting

    • Download vtoyboot.
    • Decompress the archive, then run the script as root to make the disk bootable:
      sudo sh vtoyboot.sh
    • For additional details, refer to the vtoyboot documentation.

Adding the Virtual Disk to an External Drive

  1. Prepare a Ventoy Disk

    • Create a Ventoy disk using the official guide.
    • Ensure the Ventoy partition is larger than the .vdi file size.
    • (Optional) Add extra partitions:
      • Ext4 Partition: For direct usage with Ubuntu, mount later using gnome-disks or CLI (e.g., /data).
      • ExFAT Partition: For sharing files between OSes like Windows and Ubuntu. Windows cannot read ext4, so ExFAT is a good alternative.
  2. Resize the Dynamic VDI

    • In VirtualBox, go to File -> Tools -> Virtual Media Manager.
    • Select your disk, right-click, and choose Resize. Increase the size as desired.
      Note: Dynamic disks won’t occupy extra space until needed.
  3. Copy the Disk

    • Right-click the disk again and select Copy.
    • Follow the wizard, choose .vdi, and check Pre-allocate Full Size.
      Note: Choose .vhd if it's more than 200gb (bug). refer to this link
    • Set the output path to the Ventoy disk and define the size.
      Important: The copied size cannot exceed the source size, so resizing earlier is crucial.
    • rename the copied file to [your_image].vdi.vtoy
      Important: This is mandatory to make ventoy detects the file.

Booting Ubuntu from the External Drive

  1. Select Boot Option in BIOS

    • Restart your computer and enter the BIOS/UEFI settings.
    • Select the external drive as the boot device.
  2. Boot with Ventoy

    • Ventoy will display a menu. Select the copied .vdi file to boot Ubuntu.
  3. Resize the Partition

    • Once inside Ubuntu, open gnome-disks and resize the current partition to its maximum size.

Congratulations! Your external drive is now bootable with Ubuntu installed from VirtualBox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment