From 4f648a6a32598140b995c73b10d34fdf1ca59529 Mon Sep 17 00:00:00 2001 From: Steeve Morin Date: Thu, 29 May 2014 20:36:16 +0200 Subject: [PATCH 1/2] VBox guest additions. Refs #282 --- Dockerfile | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index db6516bcc..ae710c4b5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,7 +15,8 @@ RUN apt-get update && apt-get -y install unzip \ xorriso \ syslinux \ automake \ - pkg-config + pkg-config \ + p7zip-full ENV KERNEL_VERSION 3.16.1 ENV AUFS_BRANCH aufs3.16 @@ -46,6 +47,7 @@ RUN jobs=$(nproc); \ # The post kernel build process ENV ROOTFS /rootfs +ENV VBOX_VERSION 4.3.12 ENV TCL_REPO_BASE http://tinycorelinux.net/5.x/x86 ENV TCZ_DEPS iptables \ iproute2 \ @@ -107,6 +109,18 @@ RUN cd /linux-kernel && \ # Prepare the ISO directory with the kernel RUN cp -v /linux-kernel/arch/x86_64/boot/bzImage /tmp/iso/boot/vmlinuz64 +# Build VBox guest additions +RUN mkdir -p /vboxguest && \ + cd /vboxguest && \ + curl -L -o vboxguest.iso http://download.virtualbox.org/virtualbox/${VBOX_VERSION}/VBoxGuestAdditions_${VBOX_VERSION}.iso && \ + 7z x vboxguest.iso -ir'!VBoxLinuxAdditions.run' && \ + sh VBoxLinuxAdditions.run --noexec --target . && \ + mkdir x86 && cd x86 && tar xvjf ../VBoxGuestAdditions-x86.tar.bz2 && cd .. && \ + mkdir amd64 && cd amd64 && tar xvjf ../VBoxGuestAdditions-amd64.tar.bz2 && cd .. && \ + cd amd64/src/vboxguest-${VBOX_VERSION} && KERN_DIR=/linux-kernel/ make && cd ../../.. && \ + cp amd64/src/vboxguest-${VBOX_VERSION}/*.ko $ROOTFS/lib/modules/$KERNEL_VERSION-tinycore64 && \ + mkdir -p $ROOTFS/sbin && cp x86/lib/VBoxGuestAdditions/mount.vboxsf $ROOTFS/sbin/ + # Download the rootfs, don't unpack it though: RUN curl -L -o /tcl_rootfs.gz $TCL_REPO_BASE/release/distribution_files/rootfs.gz @@ -118,6 +132,9 @@ RUN for dep in $TCZ_DEPS; do \ rm -f /tmp/$dep.tcz ;\ done +# Make sure that all the modules we might have added are recognized +RUN depmod -a -b $ROOTFS $KERNEL_VERSION-tinycore64 + # get generate_cert RUN curl -L -o $ROOTFS/usr/local/bin/generate_cert https://github.com/SvenDowideit/generate_cert/releases/download/0.1/generate_cert-0.1-linux-386/ && \ chmod +x $ROOTFS/usr/local/bin/generate_cert From 1bf1671c0f5c103ac4e2229b96a21a04b6d99043 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Mon, 8 Sep 2014 13:39:35 -0600 Subject: [PATCH 2/2] Update VBox Additions code with some minor changes (especially for cache-ability) Also, this includes a hacky init script that bfirsh gets to take all the credit for that tries to mount `/Users` and/or `/c/Users`, since we can't run `VBoxService` proper (thanks to hairy issues with 32bit userspace of TCL; good times). --- Dockerfile | 41 +++++++++++++--------- README.md | 34 +++++++++++++++++++ rootfs/rootfs/bootscript.sh | 3 ++ rootfs/rootfs/etc/rc.d/automount-shares | 45 +++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 16 deletions(-) create mode 100755 rootfs/rootfs/etc/rc.d/automount-shares diff --git a/Dockerfile b/Dockerfile index ae710c4b5..98f615181 100644 --- a/Dockerfile +++ b/Dockerfile @@ -47,7 +47,6 @@ RUN jobs=$(nproc); \ # The post kernel build process ENV ROOTFS /rootfs -ENV VBOX_VERSION 4.3.12 ENV TCL_REPO_BASE http://tinycorelinux.net/5.x/x86 ENV TCZ_DEPS iptables \ iproute2 \ @@ -109,18 +108,6 @@ RUN cd /linux-kernel && \ # Prepare the ISO directory with the kernel RUN cp -v /linux-kernel/arch/x86_64/boot/bzImage /tmp/iso/boot/vmlinuz64 -# Build VBox guest additions -RUN mkdir -p /vboxguest && \ - cd /vboxguest && \ - curl -L -o vboxguest.iso http://download.virtualbox.org/virtualbox/${VBOX_VERSION}/VBoxGuestAdditions_${VBOX_VERSION}.iso && \ - 7z x vboxguest.iso -ir'!VBoxLinuxAdditions.run' && \ - sh VBoxLinuxAdditions.run --noexec --target . && \ - mkdir x86 && cd x86 && tar xvjf ../VBoxGuestAdditions-x86.tar.bz2 && cd .. && \ - mkdir amd64 && cd amd64 && tar xvjf ../VBoxGuestAdditions-amd64.tar.bz2 && cd .. && \ - cd amd64/src/vboxguest-${VBOX_VERSION} && KERN_DIR=/linux-kernel/ make && cd ../../.. && \ - cp amd64/src/vboxguest-${VBOX_VERSION}/*.ko $ROOTFS/lib/modules/$KERNEL_VERSION-tinycore64 && \ - mkdir -p $ROOTFS/sbin && cp x86/lib/VBoxGuestAdditions/mount.vboxsf $ROOTFS/sbin/ - # Download the rootfs, don't unpack it though: RUN curl -L -o /tcl_rootfs.gz $TCL_REPO_BASE/release/distribution_files/rootfs.gz @@ -132,13 +119,35 @@ RUN for dep in $TCZ_DEPS; do \ rm -f /tmp/$dep.tcz ;\ done -# Make sure that all the modules we might have added are recognized -RUN depmod -a -b $ROOTFS $KERNEL_VERSION-tinycore64 - # get generate_cert RUN curl -L -o $ROOTFS/usr/local/bin/generate_cert https://github.com/SvenDowideit/generate_cert/releases/download/0.1/generate_cert-0.1-linux-386/ && \ chmod +x $ROOTFS/usr/local/bin/generate_cert +# Build VBox guest additions +# For future reference, we have to use x86 versions of several of these bits because TCL doesn't support ELFCLASS64 +# (... and we can't use VBoxControl or VBoxService at all because of this) +ENV VBOX_VERSION 4.3.16 +RUN mkdir -p /vboxguest && \ + cd /vboxguest && \ + \ + curl -L -o vboxguest.iso http://download.virtualbox.org/virtualbox/${VBOX_VERSION}/VBoxGuestAdditions_${VBOX_VERSION}.iso && \ + 7z x vboxguest.iso -ir'!VBoxLinuxAdditions.run' && \ + rm vboxguest.iso && \ + \ + sh VBoxLinuxAdditions.run --noexec --target . && \ + mkdir amd64 && tar -C amd64 -xjf VBoxGuestAdditions-amd64.tar.bz2 && \ + mkdir x86 && tar -C x86 -xjf VBoxGuestAdditions-x86.tar.bz2 && \ + rm VBoxGuestAdditions*.tar.bz2 && \ + \ + KERN_DIR=/linux-kernel/ make -C amd64/src/vboxguest-${VBOX_VERSION} && \ + cp amd64/src/vboxguest-${VBOX_VERSION}/*.ko $ROOTFS/lib/modules/$KERNEL_VERSION-tinycore64/ && \ + \ + mkdir -p $ROOTFS/sbin && \ + cp x86/lib/VBoxGuestAdditions/mount.vboxsf $ROOTFS/sbin/ + +# Make sure that all the modules we might have added are recognized (especially VBox guest additions) +RUN depmod -a -b $ROOTFS $KERNEL_VERSION-tinycore64 + COPY VERSION $ROOTFS/etc/version RUN cp -v $ROOTFS/etc/version /tmp/iso/version diff --git a/README.md b/README.md index 665900c05..b741713e5 100644 --- a/README.md +++ b/README.md @@ -155,6 +155,40 @@ the "samba" container that refers to it by name. So, in this example, if you were on OS-X you now have /Volumes/data and /data in container being shared. You can change the paths as needed. +##### VirtualBox Guest Additions + +Alternatively, Boot2Docker includes the VirtualBox Guest Additions built in for +the express purpose of using VirtualBox folder sharing. + +The first of the following share names that exists (if any) will be +automatically mounted at the location specified: + +1. `Users` share at `/Users` +2. `/Users` share at `/Users` +3. `c/Users` share at `/c/Users` +4. `/c/Users` share at `/c/Users` +5. `c:/Users` share at `/c/Users` + +If some other path or share is desired, it can be mounted at run time by doing +something like: + +```console +$ mount -t vboxsf -o uid=1000,gid=50 your-other-share-name /some/mount/location +``` + +It is also important to note that in the future, the plan is to have any share +which is created in VirtualBox with the "automount" flag turned on be mounted +during boot at the directory of the share name (ie, a share named `home/jsmith` +would be automounted at `/home/jsmith`). + +In case it isn't already clear, the Linux host support here is currently hazy. +You can share your `/home` or `/home/jsmith` directory as `Users` or one of the +other supported automount locations listed above, but note that you will then +need to manually convert your `docker run -v /home/...:...` bind-mount host +paths accordingly (ie, `docker run -v /Users/...:...`). As noted in the +previous paragraph however, this is likely to change in the future as soon as a +more suitable/scalable solution is found and implemented. + #### Customize The `boot2docker` management tool allows you to customise many options from both diff --git a/rootfs/rootfs/bootscript.sh b/rootfs/rootfs/bootscript.sh index 2698e9f22..095c965f7 100755 --- a/rootfs/rootfs/bootscript.sh +++ b/rootfs/rootfs/bootscript.sh @@ -39,6 +39,9 @@ if grep -q '^docker:' /etc/passwd; then fi fi +# Automount Shared Folders (VirtualBox, etc.) +/etc/rc.d/automount-shares + # Configure SSHD /etc/rc.d/sshd diff --git a/rootfs/rootfs/etc/rc.d/automount-shares b/rootfs/rootfs/etc/rc.d/automount-shares new file mode 100755 index 000000000..60da99f46 --- /dev/null +++ b/rootfs/rootfs/etc/rc.d/automount-shares @@ -0,0 +1,45 @@ +#!/bin/sh +set -e + +# TODO add more magic like sshfs share setup here <3 + +# VirtualBox Guest Additions +# - this will bail quickly and gracefully if we're not in VBox +if modprobe vboxguest &> /dev/null && modprobe vboxsf &> /dev/null; then + mountOptions='defaults' + if grep -q '^docker:' /etc/passwd; then + mountOptions="${mountOptions},uid=$(id -u docker),gid=$(id -g docker)" + fi + + # try mounting "$name" (which defaults to "$dir") at "$dir", + # but quietly clean up empty directories if it fails + try_mount_share() { + dir="$1" + name="${2:-$dir}" + + mkdir -p "$dir" 2>/dev/null + if ! mount -t vboxsf -o "$mountOptions" "$name" "$dir" 2>/dev/null; then + rmdir "$dir" 2>/dev/null || true + while [ "$(dirname "$dir")" != "$dir" ]; do + dir="$(dirname "$dir")" + rmdir "$dir" 2>/dev/null || break + done + + return 1 + fi + + return 0 + } + + # bfirsh gets all the credit for this hacky workaround :) + try_mount_share /Users 'Users' \ + || try_mount_share /Users \ + || try_mount_share /c/Users 'c/Users' \ + || try_mount_share /c/Users \ + || try_mount_share /c/Users 'c:/Users' \ + || true + # TODO replace this whole hacky bit with VBoxService --only-automount + # (the problem with that being that we can't run VBoxService because the + # 32bit VBoxService won't work with the 64bit kernel modules, but the 64bit + # VBoxService won't work with our 32bit userspace; good times) +fi