admin 管理员组

文章数量: 887016

一、插入磁盘自动挂载 

1、udev 工具安装 

#执行命令查看是否已经安装过 ;

 systemctl status udev

#没安装执行 命令 安装 

apt install udev

#启动udev 

systemctl start udev

#设置开机自启动 
systemctl enable udev

2、rules 规则文件配置

在目录/etc/udev/rules.d/ 增加文件99-local.rules     文件名建议使用99 开通 数字大排到后面执行 不容易出问题 (文件给默认权限就可以  777 会报错)

文件录入下面代码 

KERNEL=="sd[a-z]*[0-9]", SUBSYSTEMS=="usb", ACTION=="add", RUN+="/bin/systemctl start usb-mount@%k.service"

KERNEL=="sd[a-z]*[0-9]", SUBSYSTEMS=="usb", ACTION=="remove", RUN+="/bin/systemctl stop usb-mount@%k.service"

KERNEL=="mmcblk0p[0-9]", SUBSYSTEMS=="block", ACTION=="add", RUN+="/bin/systemctl start usb-mount@%k.service"

KERNEL=="mmcblk0p[0-9]", SUBSYSTEMS=="block", ACTION=="remove", RUN+="/bin/systemctl stop usb-mount@%k.service"

3、service 文件配置 

在目录 /usr/lib/systemd/system/usb-mount@.service  增加文件  

文件录入下面代码 

[Unit]
Description=Mount USB Drive on %i
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/usr/local/bin/usb-mount.sh add %i
ExecStop=/usr/local/bin/usb-mount.sh remove %i

4、挂载脚本配置

在目录 /usr/local/bin/usb-mount.sh  增加文件 (脚本设置一下777)

文件录入下面代码 

#!/usr/bin/env bash
## Modify by Sumn255@gmail
# If you are executing this script in cron with a restricted environment,
# modify the shebang to specify appropriate path; /bin/bash in most distros.
# And, also if you aren't comfortable using(abuse?) env command.

# This script is based on https://serverfault/a/767079 posted
# by Mike Blackwell, modified to our needs. Credits to the author.

# This script is called from systemd unit file to mount or unmount
# a USB drive.

PATH="$PATH:/usr/bin:/usr/local/bin:/usr/sbin:/usr/local/sbin:/bin:/sbin"
log="logger -t usb-mount.sh -s "

usage()
{
    ${log} "Usage: $0 {add|remove} device_name (e.g. sdb1)"
    exit 1
}

if [[ $# -ne 2 ]]; then
    usage
fi

ACTION=$1
DEVBASE=$2
DEVICE="/dev/${DEVBASE}"
#MIN_SIZE=1000 #1G

# See if this drive is already mounted, and if so where
MOUNT_POINT=$(mount | grep ${DEVICE} | awk '{ print $3 }')

DEV_LABEL=""

do_mount()
{
    if [[ -n ${MOUNT_POINT} ]]; then
        ${log} "Warning: ${DEVICE} is already mounted at ${MOUNT_POINT}"
        exit 1
    fi

    # Get info for this drive: $ID_FS_LABEL and $ID_FS_TYPE
    eval $(blkid -o udev ${DEVICE} | grep -i -e "ID_FS_LABEL" -e "ID_FS_TYPE")

    #format to ext4
    #if [[ ${DEVBASE} == sda1 && ${ID_FS_TYPE} != "ext4" ]]; then
    #    PART_SIZE=$(parted ${DEVICE} --script unit mb print|grep ${DEVICE}|awk '{ print $3|"sed 's/MB//'" }')
    #    if [[ ${PART_SIZE} -gt ${MIN_SIZE} ]];then
	   # ${log} "mount disk space ${PART_SIZE}MB"
    #    else
    #        ${log} "Space too small! only ${PART_SIZE}MB"
    #exit -1
    #    fi
    #fi
    
    # Figure out a mount point to use
    LABEL=${DEVBASE}
    if grep -q " /mnt/${LABEL} " /etc/mtab; then
        # Already in use, make a unique one
        LABEL+="-${DEVBASE}"
    fi
    DEV_LABEL="${LABEL}"

    # Use the device name in case the drive doesn't have label
    #if [ -z ${DEV_LABEL} ]; then
    #    DEV_LABEL="${DEVBASE}"
    #fi

    MOUNT_POINT="/mnt/${DEV_LABEL}"

    ${log} "Mount point: ${MOUNT_POINT}"

    mkdir -p ${MOUNT_POINT}

    # Global mount options
    OPTS="rw,relatime"

    # File system type specific mount options
    #if [[ ${ID_FS_TYPE} == "vfat" ]]; then
    #    OPTS+=",users,gid=100,umask=000,shortname=mixed,utf8=1,flush"
    #fi
    
    #check fs
    if [[ ${ID_FS_TYPE} == "ext4" ]];then
        fsck.ext4 ${DEVICE} -y
    fi
    
    if ! mount -o ${OPTS} ${DEVICE} ${MOUNT_POINT}; then
        ${log} "Error mounting ${DEVICE} (status = $?)"
        rmdir "${MOUNT_POINT}"
        exit 1
    else
        # Track the mounted drives
        echo "${MOUNT_POINT}:${DEVBASE}" | cat >> "/var/log/usb-mount.track" 
    fi

    ${log} "Mounted ${DEVICE} at ${MOUNT_POINT}"
    
    #PATH_PRE="/dev/sd"
    #if [[ ${DEVICE} == ${PATH_PRE}[a-z]1 ]];then
    #    #systemctl restart ttnode@${DEV_LABEL}.service
    #/usr/local/bin/ttnode -p /mnt/${DEV_LABEL}
    #    ${log} "Start Worker"
    #fi
}

do_unmount()
{
    if [[ -z ${MOUNT_POINT} ]]; then
        ${log} "Warning: ${DEVICE} is not mounted"
    else
        umount -l ${DEVICE}
	${log} "Unmounted ${DEVICE} from ${MOUNT_POINT}"
        /bin/rmdir "${MOUNT_POINT}"
        sed -i.bak "\@${MOUNT_POINT}@d" /var/log/usb-mount.track
	#docker stop $(docker ps -a -q)
    fi


}

case "${ACTION}" in
    add)
        do_mount
        ;;
    remove)
        do_unmount
        ;;
    *)
        usage
        ;;
esac

按上述4步配置完成重启 插入硬盘试试 ;

二、 docker 安装 

1、跟换源 (不跟换下载包会很慢 )

把文件备注一下 /etc/apt/sources.list 

修改文件内容 

以下是清华源 其他源可以参考下面帖子

Armbian安装后更换国内源_armbian换源-CSDN博客

deb https://mirrors.tuna.tsinghua.edu/debian/ bullseye main contrib non-free
#deb-src https://mirrors.tuna.tsinghua.edu/debian/ bullseye main contrib non-free

deb https://mirrors.tuna.tsinghua.edu/debian/ bullseye-updates main contrib non-free
#deb-src https://mirrors.tuna.tsinghua.edu/debian/ bullseye-updates main contrib non-free

deb https://mirrors.tuna.tsinghua.edu/debian/ bullseye-backports main contrib non-free
#deb-src https://mirrors.tuna.tsinghua.edu/debian/ bullseye-backports main contrib non-free

deb https://mirrors.tuna.tsinghua.edu/debian-security/ bullseye-security main contrib non-free
#deb-src https://mirrors.tuna.tsinghua.edu/debian-security/ bullseye-security main contrib non-free

2、更新 依赖 

 apt-get update


3、安装

apt install docker.io

本文标签: 磁盘 Armbian docker