关于启动执行脚本的问题
Tofloor
poster avatar
zxszx4
deepin
2016-05-10 20:43
Author
我想每次开机自动执行挂载网络共享的命令,放在/etc/rc.local下的话,执行过程报错说找不到目标主机,于是我觉得应该放在后面的步骤里,于是放在了用户目录下.bashrc里面,但是问题出现是执行mount命令的话没有权限,有没有哪位给个解决办法,能够让我开机自动挂载网络共享?

Reply Favorite View the author
All Replies
avatar
shdyeu
deepin
2016-05-10 22:26
#1
真的不错的,学习了呢
Reply View the author
avatar
MattD
deepin
2016-05-10 22:38
#2
/etc/rc.local里面的脚本是在init过程最后才执行的,这时候网络服务应该早就启动了才对,除非你的网络环境是需要手动连接的,如PPPoE。
用户级的脚本,如果权限不够的话,有两种方法可以安全提权:
1、在脚本里需要提权的命令前面加上以下内容,-S参数会把前面的内容作为标准输入进行读取,从而不需要人工输入密码。
  1. echo "password" | sudo -S mount XXX
Copy the Code
2、在sudoer里面把mount命令设为不需要提权。但是需要注意,根据你的目标文件系统,mount会实际调用mount.foo。例如对于ntfs,需要改为/sbin/mount.ntfs等。
  1. USERNAME ALL=(ALL) NOPASSWD: /path/to/mount
Copy the Code


Reply View the author
Comments
ArthurDeepin
2016-05-10 23:42
赞 1
avatar
zxszx4
deepin
2016-05-10 23:09
#3
https://bbs.deepin.org/post/39357
/etc/rc.local里面的脚本是在init过程最后才执行的,这时候网络服务应该早就启动了才对,除非你的网络环境 ...

感谢,我都忘了还有这个了。
Reply View the author
avatar
Island
deepin
2016-05-10 23:50
#4
还可以放到systemd启动
Reply View the author
avatar
much1988
deepin
2016-05-11 06:13
#5
不都是在 fstab 里面进行mount 吗?
楼主不够专业啊。
Reply View the author
avatar
MattD
deepin
2016-05-11 06:29
#6
https://bbs.deepin.org/post/39357
不都是在 fstab 里面进行mount 吗?
楼主不够专业啊。

你不太了解Linux启动和初始化过程吧……
fstab的读取是紧接着在initramfs里面执行switch_root以后发生的。在这之前,会先在initramfs的临时/环境里面,根据bootloader传递的root=XXX参数找到real root,并挂载到/mnt,接着执行switch_root切换为真正的/,并执行/sbin/init。
执行完/sbin/init以后,才开始读取fstab,并根据设置挂载其中的文件系统。而在这个阶段,网络服务都还没启动呢,你怎么挂载网络共享文件夹?







    来自:Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0  (zh-CN)
    ——2016/5/10 下午10:29:19
    Reply View the author
    avatar
    much1988
    deepin
    2016-05-11 06:31
    #7
    https://bbs.deepin.org/post/39357
    你不太了解Linux启动和初始化过程吧……
    fstab的读取是紧接着在initramfs里面执行switch_root以后发生的 ...

    不科学,为啥我能挂载
    Reply View the author
    avatar
    MattD
    deepin
    2016-05-11 06:50
    #8
    https://bbs.deepin.org/post/39357
    不科学,为啥我能挂载

    samba或者nfs服务会调用fstab内容的(没记错的话),而且你的网络应该属于自动连接的类型,所以开机就可用。但是LZ的看起来不是,所以写入fstab也会无效。
    不过我倒是真心忘了fstab这个东西,感谢提醒。







      来自:Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Firefox/46.0  (zh-CN)
      ——2016/5/10 下午10:50:27
      Reply View the author
      avatar
      much1988
      deepin
      2016-05-11 06:52
      #9
      https://bbs.deepin.org/post/39357
      samba或者nfs服务会调用fstab内容的(没记错的话),而且你的网络应该属于自动连接的类型,所以开机就可 ...

      有空读源码,再多多讨教。
      Reply View the author