Linux automount usb hdd

Detect and mount devices

I upgraded Ubuntu today and everything works smooth except that Ubuntu doesn’t detect any other storage devices. My / and /home partitions work fine, but my other partitions are just not detected. I wouldn’t mind, except the same problem goes with USB sticks. When I plug in a USB stick, the light goes on, but the computer detects nothing. Just to be clear, my mouse and keyboard are connected via USB and work fine. Any idea how to solve this issue? None of the suggestions I found on the internet have any effect.

Just to make sure I got this, this is stand-alone Ubuntu not in virtual machine, right? Run sudo fdisk -l in terminal and post the output.

In case of latest portable HDDs they could be mounted again once they left not connected for few hours(>6h). Observed this in Transcend and Seagate 2TB Expansion

6 Answers 6

Solution 1: Try the Disks program (if you run Ubuntu with a GUI).

(check that the gnome-disk-utility package is installed) (make sure that udisks2 package is installed)

Hit SUPER A to open the Application Lens and type Disks in the Search Applications field.

( SUPER is probably the key with the Windows icon.)

In Disks you can play with the automount options. .

Disks Program

You have to click on the little icon with the two gears and choose ‘Edit Mount Options’.

Mount Options

Solution 2: Using the CLI (for a headless installation)

Step 1. Check the blockdevices and the file systems that are assigned to those block devices.

lsblk

Here you see the blokdevice sdb with partition /sdb1. But it’s not mounted. There’s no file assigned to it.

Step 2. What kind of device is sdb?

lshw

So the USB stick — the block device /sdb — has the logical name /dev/sdb. And the FAT32 filesystem on that stick has the logical name /dev/sdb1.

Step 3. Mounting the USB-stick

We will mount /dev/sdb1 to /media/usbstick

sudo mkdir /media/usbstick sudo mount -t vfat /dev/sdb1 /media/usbstick 

Read the manpage of mount for other options.

lsblk 2

Yes, we can see that the filesystem on the USB stick is mounted to /media/usbstick

Addendum : if there are no logical names like /dev/sdb, you should first create them. See this information about setting up and controling loop devices with the losetup command

Читайте также:  Не устанавливается linux nvidia

I like this post a whole lot actually, lsblk looks like a great program. Too bad it doesnt come with ubuntu

sudo lsusb will tell you what USB devices Linux detects. Whether a USB storage device mounts, or is detected, are separate issues. sudo lsusb -v will give verbose output, possibly more information than you want if the OS truly doesn’t recognize the device.

Alternatively, you could compare the lists of devices in /dev before and after plugging in the USB device. There are many ways to do it; I would probably just use:

This will give you a number of recognized devices. Doing it before and after plugging in a device will tell you if the OS assigned the device in /dev/ .

Another option would be to look at what is happening in dmesg when you plug in the USB device. dmesg may tell you things like how a device failed.

If the USB device you are having trouble mounting, is on the lsusb list, then you can try mounting the device. At this point it would be good to know the filesystem type. sudo fdisk -l will tell you the filesystem type, in the form of an ID. You may have to look up the ID number. There are lots of references online for that. Once you know the device listing, that is, /dev/hda1 and the filesystem type you can try to mount the device manualy with the mount command.

sudo mount /dev/hda1 /home/user/Desktop/whereEver 

You may have to make sure the location you want to mount the device on exists. If the OS recognizes the file system, then mount might just work if the file system is not a native file system type; you may have to specify flags for mounting.

Post back your output from dmesg (not all of it, only from around when the USB device is plugged in), and sudo lsusb .

You may find Linux / UNIX: Device files helpful if trying to determine device type.

I am writing this assuming all your unrecognized devices are block type devices. There are many ways to approach this type of problem and many possible solutions. More specific information is needed to provide a solution.

There are also many GUI applications that can do the same thing. You might try looking for the plugged-in hardware in the «Disk Utility».

Читайте также:  Установка vs code astra linux

Источник

How do I automount usb drives in Linux (Debian)?

With every new release the way to automount USB drives in Linux seems to change (fortunately I’m using Debian, so I’m only losing a few days on this every 2 years). We used to have usbmount, udisks, udisks2, udisks-glue, pmount, custom udev rules, and I’m probably forgetting many more. (A quick look shows that at least a thing named afuse seems to exist, but is not documented too well). None of these work anymore (for me at least). What is the «current» way to automount USB drives in Debian? I used the following udev rule, but since updating from stretch to buster this stopped working:

SUBSYSTEM=="usb", DRIVERS=="usb-storage", ACTION=="add", \ RUN+="mkdir /media/usb%n; mount -o gid=plugdev,umask=002,fmask=111,users /dev/%k%n /media/usb%n" 

Also: what is the stable solution to do this, that will reliably work even after updating to a new release, that I probably missed?

3 Answers 3

You can create systemd.mount and systemd.automount unit files. Here is an example:

To mount /dev/sdb1 under /mnt/mountpoint , create a mnt-mountpoint.mount file:

sudo nano /etc/systemd/system/mnt-mountpoint.mount 

Note: The name of the unit file should be dir-sub-dir.mount extracted from the mount point /dir/sub-dir (if you need to mount the device under /media/mountpoint the name will be media-mountpoint.mount )

Then paste the following lines:

[Unit] Description=Mount sdb1 [Mount] What=/dev/disk/by-uuid/UUID_here Where=/mnt/mountpoint Type=auto Options=defaults [Install] WantedBy=multi-user.target 

Use blkid to replace the UUID_here with the uuid of /dev/sdb1 .

Create the mnt-mountpoint.automount file:

sudo nano /etc/systemd/system/mnt-mountpoint.automount 

To contain the following lines:

[Unit] Description=Automount usb [Automount] Where=/mnt/mountpoint [Install] WantedBy=multi-user.target 

Attach your USB then enable and start the units:

sudo systemctl daemon-reload sudo systemctl enable --now mnt-mountpoint.mount mnt-mountpoint.automount 

Thanks for your answer. This is for mounting a particular device on a particular mount point (which can be solved by a litteral one-liner in /etc/fstab ). My question was about how to automount generic USB devices in the smallest available /media/usbN directory.

Update[2022-03-06]: Just apt install udisks2 should give you usb automounting.

I researched (reverse) package dependencies in Debian of nautilus, udisks2 and libglib2.0-bin (which contains the gio binary). Based on this and on Archlinux Udisks page I now believe:

  • The state of the art for the thing that actually does the mounting is udisks2. The next best thing to automounting is udisksctl unmount -b /dev/$DEVICE .
  • On a «standard» Debian Gnome installation, nautilus is controlling the icons on the Desktop. When an USB drive gets plugged in, an icon gets shown for the drive but the drive only gets mounted on click on the icon.
  • The best choice for minimal desktops for usb automounting is probably udiskie.
Читайте также:  Intel celeron j1900 linux

I added a user systemd service to start udiskie:

[Unit] Description=Udiskie automount daemon [Install] WantedBy=graphical-session.target [Service] ExecStart=/usr/bin/udiskie --verbose --use-udisks2 --automount --no-config --notify --tray --appindicator 

This worked great for me. If you want to have the mounts user-accessible, add this » [Service] User=user Group=plugdev » above ExecStart . Also add a file » /etc/polkit-1/localauthority/50-local.d/10-udiskie.pkla » with the contents: » [udisks] Identity=unix-group:plugdev Action=org.freedesktop.udisks.* ResultAny=yes [udisks2] Identity=unix-group:plugdev Action=org.freedesktop.udisks2.* ResultAny=yes «

Seems like the —use-udisks2 option doesn’t exist anymore, so it should be removed from the ExecStart command (tested on Ubuntu 21.10).

Same issue happened to me after upgrade from Stretch to Buster (headless Raspberry Pi Zero W). In my case, I am using /etc/fstab , so systemd automatically generates mount units from it. All my disks are specified in fstab, and they were automatically mounted on hot plugin just fine in Stretch. It all stopped working in Buster. (The disks would mount fine on reboot, though.)

The culprit of the problem, it seems, was the change in new systemd version:

 * The .device units generated by systemd-fstab-generator and other generators do not automatically pull in the corresponding .mount unit as a Wants= dependency. This means that simply plugging in the device will not cause the mount unit to be started automatically. But please note that the mount unit may be started for other reasons, in particular if it is part of local-fs.target, and any unit which (transitively) depends on local-fs.target is started. 

I verified it with systemctl show my-mount.mount command: the device was missing in the WantedBy= list, there was only local-fs.target . (While on Stretch there was local-fs.target and the correspondent dev-sdaX.device , both were listed.) As a result, when the disk was inserted, it did not trigger my-mount.mount unit to start.

So the solution which worked for me was creating the new udev rule that triggers local-fs.target each time the new disk is inserted:

$ cat /etc/udev/rules.d/98-usb-disk-mount.rules ACTION=="add", KERNEL=="sd?9", SUBSYSTEM=="block", RUN+="/bin/systemctl start local-fs.target" 

(Note: the systemctl start local-fs.target command is recommended way to trigger fstab disks mount in systemd manual.)

Источник

Оцените статью
Adblock
detector