Skip to content

Instantly share code, notes, and snippets.

@itzg
Last active February 22, 2021 01:21
Show Gist options
  • Save itzg/d0e2c0bc98259d602327 to your computer and use it in GitHub Desktop.
Save itzg/d0e2c0bc98259d602327 to your computer and use it in GitHub Desktop.
Manually adding persistent storage to a VirtualBox VM of boot2docker

These instructions build on those provided here and here.

Before doing the following, create a new virtual disk and attach it to your VM. The size of the virtual disk just depends on what you intend to use/run and how many containers you intend to run. The default, 8 GB, is probably more than enough and is reasonable to use if in doubt since the default mode dynamically allocates the drive as needed.

Boot the VM and run just

fdisk -l

To see the disk device name(s) and their size. In this case it's the /dev/sda shown here that has 8 GB capacity:

Disk /dev/sda: 8589 MB, 8589934592 bytes

Run the following to setup a partition on that disk:

sudo fdisk /dev/sda

Use the n option to create a new partition, choose a p (primary) partition and go with partition number 1. Accept the defaults for the cylinder choices to fill the entire disk.

Use w to write the partition changes and exit.

If you get an error about ioctl not able to re-read, then reboot the VM:

sudo reboot

Format the filesystem on that partition being sure to assign the label boot2docker expects for the data volume:

sudo mkfs.ext4 -L boot2docker-data /dev/sda1

Reboot to allow the new disk and mount point to go into affect:

sudo reboot

To make sure it did what we expected, run

df

and confirm there is are /mnt/sda1 and /mnt/sda1/var/lib/docker mounts (but with appropriate disk and partition identifiers for your setup). If you really want to connect all the dots, do

ls -ld /var/lib/docker

NOTE: don't forget to configure two virtual network devices:

  • A NAT device so the boot2docker instance can get to the external repos
  • A host-only device so you can ssh into the boot2docker
@hoahuathien
Copy link

thanks, it is very useful for me

@amnonkhen
Copy link

This is fantastic! I have been looking for this for days. Thanks for the clear explanations and walkthrough.

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