How to automount usb external hardisks in ubuntu server 12.04?
Solution 1
When an USB devices is plugged in it gets probed. If you have a modern Linux distributen then the udev rules get triggered. (See /etc/udev/rules.d
& /lib/udev/rules.d
).
You can use those rules to run a script. That script can then read the drives label and take a specific action based on that (e.g. if the label is 'backup_drive_1` then rsync /data to that drive).
However: I have not tried that myself. All I have atm is an interest into how to do that and a few handy links. (in my case the goal was to resync a mdadm mirror to an specific USB drive).
Regardless, these links may set you on the right path, and maybe someone will post a ready made answer.
- http://reactivated.net/writing_udev_rules.html#external-run
- https://unix.stackexchange.com/questions/5623/what-happens-when-a-usb-drive-is-plugged-in
- http://ubuntuforums.org/showthread.php?t=168221
- https://stackoverflow.com/questions/469243/how-can-i-listen-for-usb-device-inserted-events-in-linux-in-python
Solution 2
You should just be able to add them to /etc/fstab
UUID=your-uuid-goes-here /where-to-mount-goes-here ext4 defaults 0 2
NTFS example:
UUID=your-uuid-goes-here /where-to-mount-goes-here ntfs-3g defaults,auto,umask=000,users,rw 0
Related videos on Youtube
rf2632
Updated on September 18, 2022Comments
-
rf2632 over 1 year
How can I automount USB HDs ? I installed usbmount but seems not working. Here below a few details:
sudo fdisk -lu:
Disk /dev/sda: 20.4 GB, 20416757760 bytes 255 heads, 63 sectors/track, 2482 cylinders, total 39876480 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000859fe Device Boot Start End Blocks Id System /dev/sda1 * 2048 38238207 19118080 83 Linux /dev/sda2 38240254 39874559 817153 5 Extended /dev/sda5 38240256 39874559 817152 82 Linux swap / Solaris Disk /dev/sdb: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0000d617 Device Boot Start End Blocks Id System /dev/sdb1 * 2048 972597247 486297600 83 Linux /dev/sdb2 972599294 976771071 2085889 5 Extended /dev/sdb5 972599296 976771071 2085888 82 Linux swap / Solaris Disk /dev/sdc: 40.0 GB, 40020664320 bytes 255 heads, 63 sectors/track, 4865 cylinders, total 78165360 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x43ba43ba Device Boot Start End Blocks Id System /dev/sdc1 * 63 78140159 39070048+ 7 HPFS/NTFS/exFAT Disk /dev/sdd: 1000.2 GB, 1000204886016 bytes 255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000c85ff Device Boot Start End Blocks Id System /dev/sdd1 63 1953520064 976760001 7 HPFS/NTFS/exFAT Disk /dev/sde: 1500.3 GB, 1500301910016 bytes 255 heads, 63 sectors/track, 182401 cylinders, total 2930277168 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x48686a76 Device Boot Start End Blocks Id System /dev/sde1 63 2930272064 1465136001 7 HPFS/NTFS/exFAT
sudo blkid:
/dev/sda1: UUID="70d2b83a-1b0a-4c5d-b6ff-89d187b4c96a" TYPE="ext4" /dev/sda5: UUID="444db037-76b9-4a53-b357-ab5ae1764044" TYPE="swap" /dev/sdb1: LABEL="500GB" UUID="7c0f92c4-3428-4e0a-b724-abe13229224c" TYPE="ext4" /dev/sdb5: UUID="370e0ecf-3190-4fe8-92d3-13cb1fedecb1" TYPE="swap" /dev/sdc1: LABEL="admin_only" UUID="528b53ef-15ac-4a2d-ad97-425af3a61995" TYPE="ext4" /dev/sdd1: LABEL="Hitachi" UUID="e7f30f9f-2d42-4222-bce3-4b58d65c26e3" SEC_TYPE="ext2" TYPE="ext3" /dev/sde1: LABEL="Toshiba" UUID="5c61d0bd-eb41-4a8e-aa4e-b6db05d1b43e" SEC_TYPE="ext2" TYPE="ext3"
mount:
/dev/sda1 on / type ext4 (rw,errors=remount-ro) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) none on /sys/fs/fuse/connections type fusectl (rw) none on /sys/kernel/debug type debugfs (rw) none on /sys/kernel/security type securityfs (rw) udev on /dev type devtmpfs (rw,mode=0755) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) none on /run/shm type tmpfs (rw,nosuid,nodev)
Thank you!
-
Gus E over 10 yearsTake a look at this thread: superuser.com/questions/53978/…
-