alpine虚拟机上安装nfs server

安装virtualbox

1
sudo pacman -S virtualbox virtualbox-host-modules-arch

如果碰到:

1
2
3
4
5
6
WARNING: The vboxdrv kernel module is not loaded. Either there is no module available for the current kernel 
(4.13.12-1-ARCH) or it failed to load. Please recompile the kernel module and install it by 

sudo /sbin/vboxconfig

You will not be able to start VMs until this problem is fixed.

安装linux-headers
参考:
archWiki: VirtualBox
Can’t run virtualbox. ‘sudo /sbin/vboxconfig’ error

下载安装alpine镜像

下载Virtual Alpine ISO,新建虚拟机,在Storage选项卡中,单击IDE Secondary Master旁蓝色光驱图标,选择刚下载的iso文件
选择iso文件
setup-alpine启动配置向导,安装模式填sys
重点:安装完成后不要reboot,关闭虚拟机窗口选择”shutdown”,从刚刚的光驱中移除alpine iso文件,然后重新启动虚拟机
参考:
Installation
Install Alpine on VirtualBox

设置虚拟机和宿主机网络互通

然后在虚拟机中用命令ip addr查看网络
ip addr
一般是eth0 inet后面的地址,虚拟机和宿主机互ping都能通

安装nfs并启动

参考:
Setting up a nfs-server

1
2
3
apk add nfs-utils
rc-update add nfs
rc-status

/etc/exports:

1
/nfs  *(rw,sync,no_root_squash,no_subtree_check)

不要加fsid=0选项,否则会出现:

1
2
mount.nfs: mount(2): No such file or directory
mount.nfs: mounting 192.168.0.167:/root failed, reason given by server: No such file or directory
1
2
3
4
5
# 创建共享目录和文件
mkdir /nfs
touch /nfs/a
# 启动nfs server
rc-service nfs start

然后在宿主机上挂载nfs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
[fc@arch test]$ sudo mount -o nfsvers=4 -v 192.168.0.167:/nfs /home/fc/workspace/nfs
mount.nfs: timeout set for Mon Aug  5 13:53:55 2019
mount.nfs: trying text-based options 'vers=4.2,addr=192.168.0.167,clientaddr=192.168.0.159'
[fc@arch test]$ ls ~/workspace/nfs
ls: cannot open directory '/home/fc/workspace/nfs': Permission denied
[fc@arch test]$ sudo ls -la ~/workspace/nfs
total 12
drwx------  2 root root  4096 Aug  2 21:20 .
drwxr-xr-x 22 fc   users 4096 Aug  5 11:09 ..
-rw-------  1 root root   951 Aug  2 21:29 .ash_history
-rw-r--r--  1 root root     0 Aug  2 21:20 a
科学上网
go snippets
comments powered by Disqus