Small House


NFS for Docker

Setup a NFS Server and Client on the Raspberry Pi

Reference and Links

Setup a NFS Server/Client on the RaspberryPi 3

Server Side (Manager Node) – Disks and Directories

With 5 nodes in docker swarm mode (i.e. 1 manager and 4 workers) and prepare the directory for shared volume in a manager node via NFS:

$ sudo mkdir -p /mnt/shared
$ sudo chown pi:pi /mnt/shared
$ sudo chmod 755 /mnt/shared

For demonstration, I will be using the same disk as my cluster, but if you have other disks that you would like to mount, mount them like the following:

$ sudo lsblk
$ sudo mount /dev/sda1 /mnt/shared
$ sudo chown -R pi:pi /mnt/shared/existing_dirs
$ sudo find /opt/nfs/existing_dirs/ -type d -exec chmod 755 {} \;
$ sudo find /opt/nfs/existing_dirs/ -type f -exec chmod 644 {} \;

If you mounted the disk, and you would like to mount the disk on boot, we need to add it to our /etc/fstab. We can get the disk by running either:

$ sudo lsblk
# or
$ sudo blkid

Populate the /etc/fstab with your disk info, it will look more or less like:

/dev/sda1 /mnt/shared ext4 defaults,noatime 0 0

Append rootdelay=10 after rootwait in /boot/cmdline.txt, then reboot for the changes to become active.

Setup the Server Side – Installing NFS Server

Install the NFS Server packages:

$ sudo apt install nfs-kernel-server nfs-common rpcbind -y

Configure the paths in /etc/exports, we need to uid gid for the user that owns permission that we need to pass to the NFS Client. To get that:

$ id pi
uid=1000(pi) gid=1000(pi)

Setup our path that we would like to be accessible via NFS:


If you would like to have open access:

/opt/nfs *(rw,all_squash,no_hide,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)

Export the config, enable the services on boot and start NFS:

$ sudo exportfs -ra
$ showmount -e
$ sudo systemctl enable rpcbind
$ sudo systemctl enable nfs-kernel-server
$ sudo systemctl enable nfs-common
$ sudo systemctl start rpcbind
$ sudo systemctl start nfs-kernel-server
$ sudo systemctl start nfs-common

Setup the NFS Client

On the client install the NFS Client packages:

$ sudo apt install nfs-common -y

Create the mountpoint of choice and change the ownership:

$ sudo chown pi:pi /mnt

Setup the /etc/idmapd.conf to match the user:

Nobody-User = pi
Nobody-Group = pi

Mount the NFS Share to your local mount point:

$ sudo mount /mnt

Enable mount on boot via /etc/fstab: /mnt nfs rw 0 0

Emergency Mode in PI

想把USB手指組成比較大的Docker Volume,挂载信息寫入到了 /etc/fstab 中。發現Pi是無法進入系统,屏幕上出現现如下錯誤:

you are in emergency mode. after logging in, type "journalctl -xb" to view system logs, "systemctl reboot" to reboot, "systemctl default" or ^d to try again to boot into default mode.

cannot open access to console, the root account is locked.
see sulogin(8) man page for more details.

press enter to continue.


根据以下文章,大概是fstab信息有問題,導致 /boot 分區和根目錄無法正常加載。於是在/boot/cmdline.txt 加入 init=/bin/sh 尾部以進入root環境。

先/boot分 區 重新挂載 :

mount -o remount,rw /dev/mmcblk0p1 /boot

提示boot分區并未加載 。用 ls /boot 查看,空空如也。於是先挂載 : mount /dev/mmcblk0p1 /boot ,再次用 ls 查看,OK問题解决。

接着重新挂載 根目錄 : mount -o remount,rw /dev/mmcblk0p2 / 。根目錄可寫後,編輯 /etc/fstab 文件,將引起問题的挂載點註釋掉。

然後執行 exec /sbin/init 重新啟動系统,才正常進入系統。

最後才把 /boot/cmdline.txt 文件中的 init=/bin/sh 删除,避免下次又進入root環境。





碼頭工(Docker)軟件及用蜂群(Swarm)管理軟件形成電腦叢集(Cluster).一如其名.在電腦核心(kernel)及硬件下, 碼頭工(Docker)是把一份碼頭檔(Dockerfile)及其他說明檔,按客戶要求提供共用的資源(例如基本系統版本,端口等環境資料)去建造(built)鏡象(image),再放進貨櫃箱(Container),當要使用時便按要求的大小(Scale)提供電腦服務(Services)而蜂群(Swarm)是由管理節點(Manager Node)分配工作及由工蜂節點(Worker Node)去完成. 在分配工作或工作其間有問題,便會再次在節點上提供服務.