Skip to content

Commit

Permalink
Update VBox Additions code with some minor changes (especially for ca…
Browse files Browse the repository at this point in the history
…che-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).
  • Loading branch information
tianon committed Sep 15, 2014
1 parent 4f648a6 commit 1bf1671
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 16 deletions.
41 changes: 25 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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`).

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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 1bf1671

Please sign in to comment.