1 samba共享
apt install samba
vi /etc/samba/smb.conf
[share]
comment = share
browseable = yes
path = /share
guest ok = no
read only = no
smbpasswd -a admin
systemctl restart smbd
systemctl enable smbd
2 udev自动挂载
SUBSYSTEM!="block", KERNEL!="sd*|sr*|mmc*", GOTO="exit"
# check for special partitions we dont want mount
IMPORT{builtin}="blkid"
ENV{ID_FS_LABEL}=="EFI|BOOT|Recovery|RECOVERY|SETTINGS|boot|root0|share0", GOTO="exit"
# /dev/sd* with partitions/disk and filesystems only
KERNEL=="sd*", ENV{DEVTYPE}=="partition|disk", ENV{ID_FS_USAGE}=="filesystem", GOTO="harddisk"
GOTO="exit"
# mount or umount for hdds
LABEL="harddisk"
ACTION=="add", RUN+="/usr/bin/usb_mount /dev/%k"
ACTION=="remove", RUN+="/usr/bin/usb_umount /dev/%k"
GOTO="exit"
# Exit
LABEL="exit"
3 挂载和同步脚本
#!/bin/bash
LABLE=$(blkid $1|awk '{print $2}'|cut -d'"' -f2)
FSTYPE=$(blkid $1|awk '{print $4}'|cut -d'"' -f2)
MOUNT_POINT=/media/$LABLE
MOUNT_OPTIONS="rw,sync,uid=1000,gid=1000,iocharset=utf8"
SHARE_DIR=/share
#mount
mkdir -p $MOUNT_POINT
mount -t $FSTYPE -o $MOUNT_OPTIONS $1 $MOUNT_POINT
sleep 2
#rsync
rsync -trulv $MOUNT_POINT/ $SHARE_DIR
rsync -trulv $SHARE_DIR/ $MOUNT_POINT
4 卸载脚本
#!/bin/bash
LABLE=$(blkid $1|awk '{print $2}'|cut -d'"' -f2)
FSTYPE=$(blkid $1|awk '{print $4}'|cut -d'"' -f2)
MOUNT_POINT=/media/$LABLE
MOUNT_OPTIONS="rw,sync,uid=1000,gid=1000,iocharset=utf8"
SHARE_DIR=/share
mkdir -p $MOUNT_POINT
mount -t $FSTYPE -o $MOUNT_OPTIONS $1 $MOUNT_POINT
sleep 2
#rsync
rsync -trulv $MOUNT_POINT/ $SHARE_DIR
rsync -trulv $SHARE_DIR/ $MOUNT_POINT