我正在为Beagle Bone开发板构建一个Linux系统。我已经编译了vanilla内核,并使用busybox
构建了基本的根文件系统。系统通过U-boot引导,而rootfs
位于Linux PC上,并通过NFS进行导出:
/path/to/rootfs 10.42.0.17(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
U-boot的
bootargs
如下:bootargs console=ttyO0,115200n8 root=/dev/nfs rw nfsroot=${serverip}:/path/to/rootfs,v3,tcp ip=dhcp
当我尝试让非root用户使用su
时,遇到了问题。为了解决这个问题,网络上的人建议为busybox
二进制文件设置suid
位。
$ sudo chmod u+s busybox
并进行验证:
$ ls -la
...
-rwsr-xr-x 1 myuser myuser 1882976 Jan 13 21:47 busybox
...
$ stat -c "%a %n" busybox
4755 busybox
出现了一些问题。内核正在启动,所有通常的消息都会显示,但它在结束时卡住了,没有显示任何login
行。以下是引导序列的最后几行:
[ 3.776185] IP-Config: Complete:
[ 3.779656] device=eth0, hwaddr=c8:a0:30:c5:80:e9, ipaddr=10.42.0.17, mask=255.255.255.0, gw=10.42.0.1
[ 3.789877] host=10.42.0.17, domain=, nis-domain=(none)
[ 3.795822] bootserver=10.42.0.1, rootserver=10.42.0.1, rootpath=
[ 3.802492] nameserver0=10.42.0.1
[ 3.871575] VFS: Mounted root (nfs filesystem) on device 0:15.
[ 3.879903] devtmpfs: mounted
[ 3.883713] Freeing unused kernel memory: 380K (c07ef000 - c084e000)
如果去掉该标志,事情会恢复正常:
....
[ 3.862291] Freeing unused kernel memory: 380K (c07ef000 - c084e000)
10.42.0.17 login:
如果在Beagle Bone板子上的运行shell中设置标志,执行
chmod
后,shell会立即停止响应。我怀疑这与NFS导出rootfs的方式有关,但这只是一个猜测,因此需要一个合格的解释和可能的解决方案。