3

I'm trying to use 24.10 Oracular Orial and I have an external USB hard drive which I have tried partitioning as MBR, and I also later tried as GPT. Both cases, I created just 1 partition with fdisk. In the case of MBR, I made the partition primary. I did this through terminal by running lsblk. This shows me that /dev/sdb is the disk I'll be targeting.

sudo umount /dev/sdb
sudo fdisk /dev/sdb

I started by either creating a gpt, or an MBR table by either typing g, and pressing enter, or typing o, and pressing enter.

Then I made a new partition by pressing n, and then enter, and accepting all default values. (I want the partition to extend to the entire capassity of the disk, all 2TB.)

Then I wrote the changes by typing w, and pressing enter.

Back at my prompt, I then am running

sudo mkfs.ext4 /dev/sdb

Once done, I close the terminal, then unplug the drive from USB, then plug it back in after about 20 seconds. Here's where the issue then starts. The drive is not mounted to the desktop, nor is it mounted under /media/chris as it should be like any other drive I've plugged in.

This isn't happening if I use mkfs.exfat. It only seems to happen with mkfs.ext4. Ext4 is the only time it won't automount.

I looked with journalctl -u udisks2 /dev/sdb, everything looks fine. dmesg isn't showing anything out of the ordenary either, aside just that the drive isn't being attempted to mount.

If I manually run

udisksctl mount -b /dev/sdb

That works even if the file system is Ext4. But, as soon as I either reboot, or unplug the drive, then plug it back in, it again no longer automounts.

After unplugging, then replugging it in, I can confirm that lsblk absolutely shows the drive correctly with the correct file system, partition layout etcetera.

Also, fdisk -l is showing the disk correctly. It's simply just not mounting on its own.

Once manually mounted with udisksctl, I ran ls -ld /media/chris/Storage (Storage is what I labeled the file system), and it looks like the permissions and ownership of the drive are all correct as well as the actual virtual mountpoint.

When I look in /etc/fstab, I see no entries for /dev/sdb of any sort, but I guess that kinda makes sense, as I don't think Ubuntu adds entries automatically to that file when hotplugging external storage media, does it?

I tried adding udisks_allow_external_ext4=true below the last line of /etc/udisks2/udisks2.conf, then restarting the service

sudo systemctl restart udisks2

Which didn't give me any error or any output when I did so, so I assume it worked. However, even then, after unplugging and replugging in the drive, no good.

I'm just totally at a loss. This is absolutely bonkers crazy! You'd think, if exfat was automounting, then there's absolutely no reason why ext4 wouldn't.

What in the world am I missing! I've been at this all day trying to figure this out, and am no closer to finding an answer than when I started.

muru
  • 207,228

3 Answers3

0

This can be due to policy restriction from Ubuntu, it prevent the automatic mounting of external drives like ext4 by default for security reason.

Lets allow it in `olkit

first open in your favorite editor /etc/polkit-1/localauthority/50-local.d/10-mount-ext4.pkla

and put this inside:

[Allow user chris to mount ext4 filesystems on external drives]
Identity=unix-user:chris
Action=org.freedesktop.udisks2.filesystem-mount-system
ResultAny=yes
ResultInactive=yes
ResultActive=yes

save and restart Polkit with sudo systemctl restart polkit or simply reboot, then unplug and replug your USB drive and it should work.

muru
  • 207,228
Saxtheowl
  • 2,394
  • 2
  • 12
  • 22
0

Try this:

Plug in the USB drive

Open a terminal.

Run in it:

sudo apt update
sudo apt install --reinstall gparted
sudo gparted

From Gparted select the USB drive

Unmount it, if it is mounted.

Create a new GPT partition table

Create a partition in the unpartitioned space, ext4 file system.

Apply the changes

Close Gparted

Close the terminal.

Unmount the drive with umount

Open a terminal

Run in it

sudo umount /dev/sdb1 (if your drive is sdb)

Plug it in and see if it automatically mounts to /media/user/?????

If it still doesn't mount, try the following:

Open a terminal.

Run in it:

sudo nano /etc/fstab

Without touching any of its content, add the line at the end (adapt it to your device and desired mounting location)

  /dev/sdb1   /media/user/MiDisco     auto     noauto,x-systemd.automount     0 2

noauto: It means that it will not attempt to mount at boot, where the disk may not be present.

Save the file. Ctrl + O

Close nano. Ctrl + X

Run in terminal:

 sudo systemctl daemon-reload
 sudo systemctl restart remote-fs.target
 sudo systemctl restart local-fs.target

Close the terminal.

kyodake
  • 17,808
0

I faced the same problem, and traced it to the udev rule at /usr/lib/udev/rules.d/64-ext4.rules:

# Don't let udisks automount ext4 filesystems without even asking a user.
# This doesn't eliminate filesystems as an attack surface; it only prevents
# evil maid attacks when all sessions are locked.
#
# According to http://storaged.org/doc/udisks2-api/latest/udisks.8.html,
# supplying UDISKS_AUTO=0 here changes the HintAuto property of the block
# device abstraction to mean "do not automatically start" (e.g. mount).
SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="ext2|ext3|ext4|ext4dev|jbd", ENV{UDISKS_AUTO}="0"

This file comes from this patch on the e2fsprogs upstream mailing list.

The best solution to the issue (without compromising security too much) would probably be to explicitly list the partitions you want in a custom rules file, e.g. in /etc/udev/rules.d/65-ext4-automount.rules (beware the 65, we want it to execute after the baked-in rule):

SUBSYSTEM=="block", ENV{ID_FS_UUID}=="2aefc5e0-0fad-4650-bc37-994a918a75f5" ENV{UDISKS_AUTO}="1"

However, if for some reason you really want your desktop to automount any random ext4 stick, you can instead use that rule:

SUBSYSTEM=="block", ENV{ID_FS_TYPE}=="ext4", ENV{UDISKS_AUTO}="1"

However, I'd strongly advise to use the first approach instead.