Skip to content

Instantly share code, notes, and snippets.

@rasheedamir
Forked from pantelis/coreos-windows-share.sh
Last active September 23, 2016 09:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rasheedamir/b9f4cae2e118b8c8935e45805935c169 to your computer and use it in GitHub Desktop.
Save rasheedamir/b9f4cae2e118b8c8935e45805935c169 to your computer and use it in GitHub Desktop.
Mount Windows share drives on CoreOS
# WARNING - THIS IN NOT a SHELL SCRIPT - JUST a LIST of COMMANDS
# based on https://github.com/coreos/coreos-overlay/issues/595 with links updated
# Build cifs-utils in a container and copy it into /tmp on the host.
$docker run -t -i -v /tmp:/host_tmp fedora /bin/bash
# On the container bash prompt
yum groupinstall -y "Development Tools" "Development Libraries"
yum install -y tar
yum install -y bzip2
curl https://download.samba.org/pub/linux-cifs/cifs-utils/cifs-utils-6.3.tar.bz2 | bunzip2 -c - | tar -xvf -
cd cifs-utils-6.3/
./configure && make
cp mount.cifs /host_tmp/
exit
#back at the host
$ sudo mkdir /mnt/foo
$ sudo /tmp/mount.cifs //198.51.100.23/foo /mnt/foo -o domain=zzz,username=xxx,password=yyy
$ mount | grep /mnt/foo
@rasheedamir
Copy link
Author

Mounting NAS/Cifs

Mounting a cifs share is not natively supported in CoreOS but there is a pretty easy workaround to allow the host system to mount NAS shares. You will use a container to build the mount.cfis module and then copy it to the CoreOS system

On the CoreOS system run the following to download and drop in to a Fedora container:
docker run -t -i -v /tmp:/host_tmp fedora /bin/bash

Once you are in the container you will want to run the following to build the cifs utility
dnf groupinstall -y "Development Tools" "Development Libraries"
dnf install -y tar
dnf install -y bzip2
curl https://ftp.samba.org/pub/linux-cifs/cifs-utils/cifs-utils-6.4.tar.bz2 | bunzip2 -c - | tar -xvf -
cd cifs-utils-6.4/
./configure && make
cp mount.cifs /host_tmp/

Now that the mount.cifs file has been copied to the host machine you can exit the docker container by issuing the 'exit' command or pressing 'ctrl+d'. When you are back in the CoreOS system you can mount the CIFS share with the following command:
/tmp/mount.cifs //nasXXX.service.softlayer.com/USERNAME -o username=USERNAME,password=PASSWORD /path/to/mount

@rasheedamir
Copy link
Author

Workaround we came up with is to manually mount the fileshare in the cloud-init. So our cloud-init looks like this now:

- name: cifsmount.service
  command: start
  enable: false
  content: |
    [Unit]
    Description=Copy CIFS mount
    After=network.target

    [Service]
    Type=oneshot
    RemainAfterExit=yes
    TimeoutStartSec=0
    ExecStartPre = -/usr/bin/mkdir -p /opt/sbin
    ExecStart=/bin/sh -c "rm -fr /opt/sbin && rsync -a /usr/sbin/ /opt/sbin/ && /usr/bin/docker run -v /opt/sbin:/target so0k/mount.cifs_copy /target && mount --bind /opt/sbin/ /usr/sbin/ && mount -t cifs //<storage_account>.file.core.windows.net/<fileshare> /mnt/azure -o vers=2.1,username=<storage_account>,password=<storage_account_key>,dir_mode=0777,file_mode=0777"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment