本帖最后由 larry 于 2023-4-20 15:00 编辑
You can configure your Debian system to automatically mount USB drives when they are inserted using the udev and systemd rules. Here's a step-by-step guide:
1、Install udev and systemd (if not already installed):
- sudo apt-get update
- sudo apt-get install udev systemd
复制代码
2、Create a udev rule:
Create a new udev rule file:
- sudo nano /etc/udev/rules.d/99-automount-usb.rules
复制代码
Add the following content to the file:
- ACTION=="add", KERNEL=="sd*[!0-9]|sr*", ENV{DEVTYPE}=="partition", ENV{ID_FS_TYPE}!="", ENV{ID_FS_TYPE}!="swap", RUN+="/bin/systemd-mount --no-block --automount=yes --collect $env{DEVNAME} /media/$env{DEVNAME}"
- ACTION=="remove", KERNEL=="sd*[!0-9]|sr*", ENV{DEVTYPE}=="partition", RUN+="/bin/systemd-mount --umount $env{DEVNAME}"
复制代码
Save and exit the file (Ctrl+X, Y, Enter).
3、Reload udev rules:
- sudo udevadm control --reload-rules
复制代码
4、Create a mount point directory:
5、Test the setup:
Insert a USB drive and check if it's mounted automatically under /media. You can use the df -h command to list all mounted filesystems.
Notes:
- The above configuration mounts USB drives to /media/<device-name>. You can change the mount point by editing the udev rule file.
- This setup assumes that your USB drive uses a supported filesystem, such as FAT32, NTFS, or ext4. If your drive uses a different filesystem, you might need to install additional packages to enable support for that filesystem.
- To unmount a USB drive, you can use the umount /media/<device-name> command before you remove it from the system.
|