Skip to content

Commit 83fd8c2

Browse files
committed
Merge pull request boot2docker#534 from tianon/vbox-guest-additions
VirtualBox Guest Additions
2 parents 3afd3a6 + 1bf1671 commit 83fd8c2

File tree

4 files changed

+109
-1
lines changed

4 files changed

+109
-1
lines changed

Dockerfile

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ RUN apt-get update && apt-get -y install unzip \
1515
xorriso \
1616
syslinux \
1717
automake \
18-
pkg-config
18+
pkg-config \
19+
p7zip-full
1920

2021
ENV KERNEL_VERSION 3.16.1
2122
ENV AUFS_BRANCH aufs3.16
@@ -122,6 +123,31 @@ RUN for dep in $TCZ_DEPS; do \
122123
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/ && \
123124
chmod +x $ROOTFS/usr/local/bin/generate_cert
124125

126+
# Build VBox guest additions
127+
# For future reference, we have to use x86 versions of several of these bits because TCL doesn't support ELFCLASS64
128+
# (... and we can't use VBoxControl or VBoxService at all because of this)
129+
ENV VBOX_VERSION 4.3.16
130+
RUN mkdir -p /vboxguest && \
131+
cd /vboxguest && \
132+
\
133+
curl -L -o vboxguest.iso http://download.virtualbox.org/virtualbox/${VBOX_VERSION}/VBoxGuestAdditions_${VBOX_VERSION}.iso && \
134+
7z x vboxguest.iso -ir'!VBoxLinuxAdditions.run' && \
135+
rm vboxguest.iso && \
136+
\
137+
sh VBoxLinuxAdditions.run --noexec --target . && \
138+
mkdir amd64 && tar -C amd64 -xjf VBoxGuestAdditions-amd64.tar.bz2 && \
139+
mkdir x86 && tar -C x86 -xjf VBoxGuestAdditions-x86.tar.bz2 && \
140+
rm VBoxGuestAdditions*.tar.bz2 && \
141+
\
142+
KERN_DIR=/linux-kernel/ make -C amd64/src/vboxguest-${VBOX_VERSION} && \
143+
cp amd64/src/vboxguest-${VBOX_VERSION}/*.ko $ROOTFS/lib/modules/$KERNEL_VERSION-tinycore64/ && \
144+
\
145+
mkdir -p $ROOTFS/sbin && \
146+
cp x86/lib/VBoxGuestAdditions/mount.vboxsf $ROOTFS/sbin/
147+
148+
# Make sure that all the modules we might have added are recognized (especially VBox guest additions)
149+
RUN depmod -a -b $ROOTFS $KERNEL_VERSION-tinycore64
150+
125151
COPY VERSION $ROOTFS/etc/version
126152
RUN cp -v $ROOTFS/etc/version /tmp/iso/version
127153

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,40 @@ the "samba" container that refers to it by name. So, in this example, if you
155155
were on OS-X you now have /Volumes/data and /data in container being shared. You
156156
can change the paths as needed.
157157

158+
##### VirtualBox Guest Additions
159+
160+
Alternatively, Boot2Docker includes the VirtualBox Guest Additions built in for
161+
the express purpose of using VirtualBox folder sharing.
162+
163+
The first of the following share names that exists (if any) will be
164+
automatically mounted at the location specified:
165+
166+
1. `Users` share at `/Users`
167+
2. `/Users` share at `/Users`
168+
3. `c/Users` share at `/c/Users`
169+
4. `/c/Users` share at `/c/Users`
170+
5. `c:/Users` share at `/c/Users`
171+
172+
If some other path or share is desired, it can be mounted at run time by doing
173+
something like:
174+
175+
```console
176+
$ mount -t vboxsf -o uid=1000,gid=50 your-other-share-name /some/mount/location
177+
```
178+
179+
It is also important to note that in the future, the plan is to have any share
180+
which is created in VirtualBox with the "automount" flag turned on be mounted
181+
during boot at the directory of the share name (ie, a share named `home/jsmith`
182+
would be automounted at `/home/jsmith`).
183+
184+
In case it isn't already clear, the Linux host support here is currently hazy.
185+
You can share your `/home` or `/home/jsmith` directory as `Users` or one of the
186+
other supported automount locations listed above, but note that you will then
187+
need to manually convert your `docker run -v /home/...:...` bind-mount host
188+
paths accordingly (ie, `docker run -v /Users/...:...`). As noted in the
189+
previous paragraph however, this is likely to change in the future as soon as a
190+
more suitable/scalable solution is found and implemented.
191+
158192
#### Customize
159193

160194
The `boot2docker` management tool allows you to customise many options from both

rootfs/rootfs/bootscript.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ if grep -q '^docker:' /etc/passwd; then
3939
fi
4040
fi
4141

42+
# Automount Shared Folders (VirtualBox, etc.)
43+
/etc/rc.d/automount-shares
44+
4245
# Configure SSHD
4346
/etc/rc.d/sshd
4447

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# TODO add more magic like sshfs share setup here <3
5+
6+
# VirtualBox Guest Additions
7+
# - this will bail quickly and gracefully if we're not in VBox
8+
if modprobe vboxguest &> /dev/null && modprobe vboxsf &> /dev/null; then
9+
mountOptions='defaults'
10+
if grep -q '^docker:' /etc/passwd; then
11+
mountOptions="${mountOptions},uid=$(id -u docker),gid=$(id -g docker)"
12+
fi
13+
14+
# try mounting "$name" (which defaults to "$dir") at "$dir",
15+
# but quietly clean up empty directories if it fails
16+
try_mount_share() {
17+
dir="$1"
18+
name="${2:-$dir}"
19+
20+
mkdir -p "$dir" 2>/dev/null
21+
if ! mount -t vboxsf -o "$mountOptions" "$name" "$dir" 2>/dev/null; then
22+
rmdir "$dir" 2>/dev/null || true
23+
while [ "$(dirname "$dir")" != "$dir" ]; do
24+
dir="$(dirname "$dir")"
25+
rmdir "$dir" 2>/dev/null || break
26+
done
27+
28+
return 1
29+
fi
30+
31+
return 0
32+
}
33+
34+
# bfirsh gets all the credit for this hacky workaround :)
35+
try_mount_share /Users 'Users' \
36+
|| try_mount_share /Users \
37+
|| try_mount_share /c/Users 'c/Users' \
38+
|| try_mount_share /c/Users \
39+
|| try_mount_share /c/Users 'c:/Users' \
40+
|| true
41+
# TODO replace this whole hacky bit with VBoxService --only-automount
42+
# (the problem with that being that we can't run VBoxService because the
43+
# 32bit VBoxService won't work with the 64bit kernel modules, but the 64bit
44+
# VBoxService won't work with our 32bit userspace; good times)
45+
fi

0 commit comments

Comments
 (0)