Skip to content
This repository has been archived by the owner on Jan 1, 2021. It is now read-only.

VirtualBox Guest Additions #534

Merged
merged 2 commits into from Sep 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 27 additions & 1 deletion Dockerfile
Expand Up @@ -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
Expand Down Expand Up @@ -122,6 +123,31 @@ RUN for dep in $TCZ_DEPS; do \
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

Expand Down
34 changes: 34 additions & 0 deletions README.md
Expand Up @@ -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`).

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


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
Expand Down
3 changes: 3 additions & 0 deletions rootfs/rootfs/bootscript.sh
Expand Up @@ -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

Expand Down
45 changes: 45 additions & 0 deletions 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