ottomatica/slim

How to mount filesystems

blissdev opened this issue · 8 comments

Are there any guides on usage especially regarding mounts? I'm interested in setting up a development environment using slim and hyperkit, but I need to mount my code in a performant manner. Any other tips or writeups out there? This may be the wrong place to ask, feel free to point me in a different direction.

Yes, this is very possible. We’ve had this working in our embedded ansible server (Baker) for virtualbox and hyper-kit. Will create a demo Dockerfile with this working.

The basic idea for virtualbox is up and running. Requires a few steps, with pointers to line in Dockerfile or init: https://github.com/ottomatica/slim-images/tree/master/alpine3.8-vbox-mount

  • Need to add virtualbox-guest-modules-virt to kernel layer in order to get right kernel modules.

  • Need to add virtualbox-guest-additions to main layer.

  • Need to mount share in init:

    modprobe vboxsf 
    mkdir -p /shared
    mount.vboxsf -o uid=1000,gid=1000 vbox-share-0 /shared
    

Now, can access shared folder (set to / of host-system by virtualbox-provider).

$ slim build alpine3.8-vbox-mount
$ slim run m0 alpine3.8-vbox-mount
...
Executing VBoxManage sharedfolder add m0 --name "vbox-share-0" --hostpath "/" 
....
nanobox:~# ls /shared/Users/cjparnin/projects/slim-images/
README.md               alpine3.8-kubernetes    alpine3.9-runc-ansible  ubuntu16.04-kubernetes
alpine3.8-datascience   alpine3.8-vbox-mount    docs                    ubuntu16.04-simple

Hyperkit, is going to be a bit more "gnarly".

Ok, proof-of-concept for hyperkit shared folders for @blissdev:
image

First, build this image in the slim-images repo.

slim build slim-images/alpine3.8-9p-mount

The main difference is that you just add steps to mount the 9p network filesystem in the init script.

# 9p
mkdir -p /shared
modprobe 9pnet_virtio
mount -t 9p -o trans=virtio shared /shared 

However, the real difference is how you run hyperkit (see run.sh).

a) You need to pass a unix socket that will be used for 9p protocol.
b) You need a 9p filesystem server running.

I've provided a proof of concept script that does this. It will boot up this image directly in hyperkit.

cd slim-images/alpine3.8-9p-mount/scripts/ && ./run.sh 
...
nanobox:~# ls /shared/
Applications               home
Library                    installer.failurerequests
Network                    net
System                     opt
Users                      private

At some point, we can migrate some of this leg work into slim.

@chrisparnin Wow, thank you so much for putting this together! I was initially thinking that hyperkit may provide a better experience, but from your perspective what do you think is the better option? Will hyperkit be lighter weight? Any advice?

Honestly, this is probably something that would best be answered with longer term experimentation.

My use cases tends to center around being able to quickly spin up VMs, doing some local testing for infrastructure scripts, and throwing them away. For this, VirtualBox, isn't so bad, and actually can be ready just as fast as hyperkit. Hyperkit might be better for compute heavy tasks, but it is also pretty rough around the edges when it comes to other features.

Guess I'll have to experiment, thanks again! :)

Slim will now automatically mount / at /host and cwd (ie the directory where you run the slim run command) at /slim within the VM. This automounting can be disabled by passing the --nosync option in the slim run command.

Closing issue since we now support sync by default. Can revisit any problems with new issue. Thanks!