开发者社区> 问答> 正文

systemd启动的程序调用mount函数无法挂载设计

我的程序代码如下:

include

include

include

using namespace std;
int main()
{

    printf("start to mount ****** \n");
    int ret;
    ret = mount("/dev/sdc", "/mnt/test", "ext4", 0, NULL);
    if(ret != 0) {
            printf("mount failed\n");
            throw;
    }else {
            printf("mount successful");
    }
    sleep(1000000);

}

我通过 g++ test.cc -o mount-test -g 生成可执行文件 mount-test.
如果我在终端直接输入 ./mount-test 运行程序, 则可将/dev/sdc成功挂载到/mnt/test。
如果我通过systemd启动mount-test程序, systemd的脚本如下:
[root@localhost system]# cat mount-test.service
[Unit]
Description=mount test service
After=network.target
[Service]
ExecStart=/root/mount-test
PrivateTmp=true
[Install]
WantedBy=multi-user.target
我运行 systemctl start mount-test , 服务起来后,没有抛出异常, mount函数返回值正确,但是设备却没有挂载上。

展开
收起
jicheng 2018-06-14 11:34:10 3530 0
1 条回答
写回答
取消 提交回答
  • sudo mount -t ntfs /dev/you/ntfs/partition /mnt/somewhere /dev/you/ntfs/partition may bee /dev/sda1 etc.

    答案来源于网络

    2019-09-25 21:01:45
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
PV timer for KVM 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载

相关实验场景

更多