树莓派插入U盘自动拷贝系统日志到U盘

Posted aricc

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了树莓派插入U盘自动拷贝系统日志到U盘相关的知识,希望对你有一定的参考价值。

sudo nano /lib/systemd/system/systemd-udevd.service

首先,打开上面的文件,将后7行注释掉,否则udev规则会触发执行,但会返回失败。

修改后如下:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=udev Kernel Device Manager
Documentation=man:systemd-udevd.service(8) man:udev(7)
DefaultDependencies=no
Wants=systemd-udevd-control.socket systemd-udevd-kernel.socket
After=systemd-udevd-control.socket systemd-udevd-kernel.socket systemd-sysusers.service
Before=sysinit.target
ConditionPathIsReadWrite=/sys

[Service]
Type=notify
OOMScoreAdjust=-1000
Sockets=systemd-udevd-control.socket systemd-udevd-kernel.socket
Restart=always
RestartSec=0
ExecStart=/lib/systemd/systemd-udevd
#KillMode=mixed
#WatchdogSec=3min
#TasksMax=infinity
#MountFlags=slave
#MemoryDenyWriteExecute=yes
#RestrictRealtime=yes
#RestrictAddressFamilies=AF_UNIX AF_NETLINK AF_INET AF_INET6

  在/etc/udev/rules.d/目录下新建规则文件98-logcopy.rules 

内容如下:

KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"

# Import FS infos
IMPORTprogram="/sbin/blkid -o udev -p %N"

# Get a label if present, otherwise specify one
ENVID_FS_LABEL!="", ENVdir_name="%EID_FS_LABEL"
ENVID_FS_LABEL=="", ENVdir_name="usbhd-%k"

# Global mount options
ACTION=="add", ENVmount_options="relatime"

# Filesystem-specific mount options
ACTION=="add", ENVID_FS_TYPE=="vfat|ntfs", ENVmount_options="$envmount_options,utf8,gid=100,umask=002"

# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%Edir_name", RUN+="/bin/mount -o $envmount_options /dev/%k /media/%Edir_name" RUN+="/bin/cp -r /opt/trash/logs /media/%Edir_name"

# Clean up after removal
ACTION=="remove", ENVdir_name!="", RUN+="/bin/umount -l /media/%Edir_name", RUN+="/bin/rmdir /media/%Edir_name"

# Exit
LABEL="media_by_label_auto_mount_end"

 

以上是关于树莓派插入U盘自动拷贝系统日志到U盘的主要内容,如果未能解决你的问题,请参考以下文章

树莓派3B—完全u盘启动系统

ubuntu怎样保存日志到U盘

树莓派更改启动为u盘

请教各位,树莓派U盘启动如何呃?谁有u-boot哈

树莓派用U盘安装系统

树莓派挂载exfat和ntfs格式硬盘优盘