Resizing Boot2Docker Disk Volumes

image

Once developers really start containerizing their applications, they often generate a large number of images and quickly fill up the 20GB hard drive space allocated to the Boot2Docker virtual machine by default. To make sure the Boot2Docker virtual machine has plenty of disk space, we should resize /dev/sda1 to a number that is more reasonable.

Host% boot2docker ssh
                            ##        .
                      ## ## ##       ==
                   ## ## ## ##      ===
               /""""""""""""""""\___/ ===
          ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
               \______ o          __/
                 \    \        __/
                  \____\______/
     _                 _   ____     _            _
    | |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
    | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
    | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
    |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
    Boot2Docker version 1.4.1, build master : 86f7ec8 - Tue Dec 16 23:11:29 UTC 2014
    Docker version 1.4.1, build 5bc2ff8
docker@boot2docker:~$ df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    1.8G     85.8M      1.7G   5% /
tmpfs                     1.8G     85.8M      1.7G   5% /
tmpfs                  1004.0M         0   1004.0M   0% /dev/shm
/dev/sda1                18.2G     58.2M     17.2G   0% /mnt/sda1
cgroup                 1004.0M         0   1004.0M   0% /sys/fs/cgroup
none                    930.7G    231.8G    699.0G  25% /Users
/dev/sda1                18.2G     58.2M     17.2G   0% /mnt/sda1/var/lib/docker/aufs

As documented on Docker’s official website, the solution is to resize the disk volume using a hard drive partitioning tool called Gnome Partition Editor (GParted). Available as a free bootable ISO, GParted is a free partition manager that enables users to resize, copy, and move partitions without data loss. The version of GParted used in this tutorial is gparted-live-0.20.0-2-i486.iso.

  1. Stop the Boot2Docker virtual machine.

    Host% boot2docker stop
    
  2. The Boot2Docker package installer ships with a VMDK volume, which VirtualBox’s native tools cannot resize. In order to resize the Boot2Docker disk volume, first clone the VDI volume from the default VMDK volume.

    Host% vboxmanage clonehd /full/path/to/boot2docker-vm.vmdk /full/path/to/boot2docker-vm.vdi --format VDI --variant Standard
    
    # For Boot2Docker installations using the default settings, "/full/path/to/"
    # is typically "~/VirtualBox\ VMs/boot2docker-vm/".  This tutorial will assume
    # "/full/path/to/" to be "~/VirtualBox\ VMs/boot2docker-vm/".
    
    Host% vboxmanage clonehd ~/VirtualBox\ VMs/boot2docker-vm/boot2docker-vm.vmdk ~/VirtualBox\ VMs/boot2docker-vm/boot2docker-vm.vdi --format VDI --variant Standard
    0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
    Clone hard disk created in format 'VDI'. UUID: f37d6330-c6f3-4a2d-914b-f61c3249ca0b
    
  3. Resize the newly cloned VDI volume to the desired capacity. We recommend at least 64GB.

    Host% vboxmanage modifyhd ~/VirtualBox\ VMs/boot2docker-vm/boot2docker-vm.vdi --resize <size in MB>
    
  4. Launch the VirtualBox application, and click on the “Settings” gear on top.

    image

  5. Click on the “Storage” icon. Remove the default VMDK volume.

    image

  6. Add a new IDE controller.

    image

  7. Mount the GParted ISO via the “Add CD/DVD Device” option.

    image

  8. Mount the cloned VDI volume via the “Add CD/DVD Device” option.

    image

  9. If you are running Docker on a laptop with a solid-state hard drive, please make sure the “Solid-state Drive” option is selected for the cloned VDI volume.

    image

  10. Click on the “System” icon to review the boot order. Please deselect the first CD/DVD checkbox to ensure the GParted ISO is booted first.

    image

  11. Click on the “Start” icon to boot up the Boot2Docker virtual machine, which will launch the GParted ISO. Select “GParted Live (Default settings)”.

    image

  12. Set the policy for handling keymaps to “Don’t touch keymap”.

    image

  13. Set language preference to option “33”, which maps to “US English”.

    image

  14. Select option “1” to run “Forcevideo” and configure X manually.

    image

  15. Keep the default resolution of “1024×760” by selecting option “2”.

    image

  16. Keep the default “vesa” as the VGA card.

    image

  17. Keep the default color depth of “24” by selecting option “0”.
    image

  18. Once GParted launches, click on the “Resize/Move” icon.
    image

  19. Set the new disk volume size to the maximum. In this example, the maximum size is 127,035MB. Click on the “Resize/Move” button to start the process.

    image

  20. Confirm the resizing operation by clicking on the “Apply” button.

    image

  21. Power off the machine after the resizing operation finishes.

    image

  22. Remove the GParted ISO.

    image

  23. Log into the Boot2Docker virtual machine to verify that the volume resizing was successful.

    Host% boot2docker ssh
                            ##        .
                      ## ## ##       ==
                   ## ## ## ##      ===
               /""""""""""""""""\___/ ===
          ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
               \______ o          __/
                 \    \        __/
                  \____\______/
     _                 _   ____     _            _
    | |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
    | '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
    | |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
    |_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
    Boot2Docker version 1.4.1, build master : 86f7ec8 - Tue Dec 16 23:11:29 UTC 2014
    Docker version 1.4.1, build 5bc2ff8
    docker@boot2docker:~$ df -h
    Filesystem                Size      Used Available Use% Mounted on
    rootfs                    1.8G     85.8M      1.7G   5% /
    tmpfs                     1.8G     85.8M      1.7G   5% /
    tmpfs                  1004.0M         0   1004.0M   0% /dev/shm
    /dev/sda1               122.0G     73.8M    115.7G   0% /mnt/sda1
    cgroup                 1004.0M         0   1004.0M   0% /sys/fs/cgroup
    none                    930.7G    232.8G    697.9G  25% /Users
    /dev/sda1               122.0G     73.8M    115.7G   0% /mnt/sda1/var/lib/docker/aufs
    

2 thoughts on “Resizing Boot2Docker Disk Volumes”

  1. If you want free gift cards download the app called &#Wlt0;Juno8al2e2” from the android store for free and enter the code “GF915772″ to start getting free gift cards from ebay, itunes, xbox live, PSN, and more! Thank you

  2. Brilliant! This worked like a charm. Had several containers acting badly due to lack of space, but now I’m cooking with gas. Thanks for this very clear and detailed post.

Leave a Reply

Your email address will not be published. Required fields are marked *