Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #245829 > unrolled thread

Make Debian automount mount devices in read only

Started byCarles Pina i Estany <carles@pina.cat>
First post2022-03-03 10:10 +0100
Last post2022-03-04 00:30 +0100
Articles 5 — 3 participants

Back to article view | Back to linux.debian.user


Contents

  Make Debian automount mount devices in read only Carles Pina i Estany <carles@pina.cat> - 2022-03-03 10:10 +0100
    Re: Make Debian automount mount devices in read only Brian <ad44@cityscape.co.uk> - 2022-03-03 13:20 +0100
      Re: Make Debian automount mount devices in read only Carles Pina i Estany <carles@pina.cat> - 2022-03-03 14:40 +0100
    Re: Make Debian automount mount devices in read only David Wright <deblis@lionunicorn.co.uk> - 2022-03-03 17:00 +0100
      Re: Make Debian automount mount devices in read only Carles Pina i Estany <carles@pina.cat> - 2022-03-04 00:30 +0100

#245829 — Make Debian automount mount devices in read only

FromCarles Pina i Estany <carles@pina.cat>
Date2022-03-03 10:10 +0100
SubjectMake Debian automount mount devices in read only
Message-ID<DWPDb-5y9r-3@gated-at.bofh.it>
Hi,

My desktop computer (Debian 11.2) auto-mounts USB devices (hard disks,
etc.)

I would like the devices to be mounted in read only mode by default. I
will remount them in rw if I need to.

They are not in my /etc/fstab

I've been looking at udev configuration files, rules, etc. but I'm
unsure which is the best way to go.

Is anyone here a bit more familiar with udev, systemd, etc. let me know
of a good approach please? The current Debian (and for many versions)
worked so well for me that I haven't dealt with this kind of settings,
I don't know which is the right tool to setup or how they interact with
eachother in detail anymore :-)

Thank you!

-- 
Carles Pina i Estany
https://carles.pina.cat

[toc] | [next] | [standalone]


#245832

FromBrian <ad44@cityscape.co.uk>
Date2022-03-03 13:20 +0100
Message-ID<DWSB3-5A3A-5@gated-at.bofh.it>
In reply to#245829
On Thu 03 Mar 2022 at 10:00:09 +0100, Carles Pina i Estany wrote:

> 
> Hi,
> 
> My desktop computer (Debian 11.2) auto-mounts USB devices (hard disks,
> etc.)
> 
> I would like the devices to be mounted in read only mode by default. I
> will remount them in rw if I need to.
> 
> They are not in my /etc/fstab
> 
> I've been looking at udev configuration files, rules, etc. but I'm
> unsure which is the best way to go.
> 
> Is anyone here a bit more familiar with udev, systemd, etc. let me know
> of a good approach please? The current Debian (and for many versions)
> worked so well for me that I haven't dealt with this kind of settings,
> I don't know which is the right tool to setup or how they interact with
> eachother in detail anymore :-)

I have a USB stick containing audio files and in /etc/fstab there is

 LABEL=MUSIC-1  /media/MUSIC-1  vfat ro,gid=1000,fmask=0117,dmask=0007,noatime,noauto,user,x-systemd.automount,x-systemd.idle-timeout=5,x-systemd.device-timeout=1 0 0

Mounting takes place only when the decice is accessed.

  * x-systemd.automount: mounts /media/MUSIC-1 when a command wants
    to access it. 
  * systemd.idle-timeout: unmounts the partition a specified time
    period after the calling program ceases to access it.
  * noauto: causes /media/MUSIC-1 not to be mounted while the machine
    is booting.
  * x-systemd.device-timeout: configures how long systemd should wait
    when no device is plugged in or an incorrect device is found.

I haven't any idea how this fits in with having udisks on the system or
remounting a disk rw, or even how it fits your objectives.

-- 
Brian.

[toc] | [prev] | [next] | [standalone]


#245834

FromCarles Pina i Estany <carles@pina.cat>
Date2022-03-03 14:40 +0100
Message-ID<DWTQt-5AOC-7@gated-at.bofh.it>
In reply to#245832
Hi,

On Mar/03/2022, Brian wrote:
> On Thu 03 Mar 2022 at 10:00:09 +0100, Carles Pina i Estany wrote:
> 
> > 
> > Hi,
> > 
> > My desktop computer (Debian 11.2) auto-mounts USB devices (hard disks,
> > etc.)
> > 
> > I would like the devices to be mounted in read only mode by default. I
> > will remount them in rw if I need to.
> > 
> > They are not in my /etc/fstab
> > 
> > I've been looking at udev configuration files, rules, etc. but I'm
> > unsure which is the best way to go.
> > 
> > Is anyone here a bit more familiar with udev, systemd, etc. let me know
> > of a good approach please? The current Debian (and for many versions)
> > worked so well for me that I haven't dealt with this kind of settings,
> > I don't know which is the right tool to setup or how they interact with
> > eachother in detail anymore :-)
> 
> I have a USB stick containing audio files and in /etc/fstab there is
> 
>  LABEL=MUSIC-1  /media/MUSIC-1  vfat ro,gid=1000,fmask=0117,dmask=0007,noatime,noauto,user,x-systemd.automount,x-systemd.idle-timeout=5,x-systemd.device-timeout=1 0 0

Thanks!

> Mounting takes place only when the decice is accessed.

Ha! This is a bit different but interesting anyway. I didn't know that
it was possible to use x-systemd.* options in /etc/fstab

[...]

> I haven't any idea how this fits in with having udisks on the system or
> remounting a disk rw, or even how it fits your objectives.

For the remounting I'm not worried.

My use case is that I have about 10 or 15 hard disks that I want to
automount in ro because... I only need to read from them and I want to
avoid making accidental changes.

I expect that I don't need to change /etc/fstab with the UUID / LABEL of
each one.

I guess (untested) that I could do:
"
/dev/sdc1	/mnt/read-only	auto	ro,other_options	0 0
"

But I think that I would prefer to change the auto-mounter instead of
changing /etc/fstab and assume that they will come as sdc1 (plus some
have different partitions; and they have ext4, vfat and reiserfs for
what I remember but "auto" should be enough for this).

Thanks for the answer,

-- 
Carles Pina i Estany
https://carles.pina.cat

[toc] | [prev] | [next] | [standalone]


#245845

FromDavid Wright <deblis@lionunicorn.co.uk>
Date2022-03-03 17:00 +0100
Message-ID<DWW1Y-5CdK-1@gated-at.bofh.it>
In reply to#245829
On Thu 03 Mar 2022 at 10:00:09 (+0100), Carles Pina i Estany wrote:
> 
> My desktop computer (Debian 11.2) auto-mounts USB devices (hard disks,
> etc.)

That doesn't help a great deal because there are several automounters
available in Debian.

> I would like the devices to be mounted in read only mode by default. I
> will remount them in rw if I need to.
> 
> They are not in my /etc/fstab
> 
> I've been looking at udev configuration files, rules, etc. but I'm
> unsure which is the best way to go.
> 
> Is anyone here a bit more familiar with udev, systemd, etc. let me know
> of a good approach please? The current Debian (and for many versions)
> worked so well for me that I haven't dealt with this kind of settings,
> I don't know which is the right tool to setup or how they interact with
> eachother in detail anymore :-)

With Debian, I would guess that systemd is the way to go, because it's
probably best supported. You probably want to read pages such as:

https://www.freedesktop.org/software/systemd/man/systemd.automount.html
https://www.freedesktop.org/software/systemd/man/systemd.mount.html

(You should have local man copies, referring to the specific version
of systemd on Debian, not necessarily the latest.)

I've only used udev for creating mountpoints, as I don't believe
in automounting. I write my own rules files from scratch (man udev),
and there are copious examples in /lib/udev/rules.d/ to steal from.

As for the others, the wikis hint that you should probably leave them
alone, eg:

  AutoFs: "NB This information is likely outdated, usbmount does much
           of this automagically for most use cases."

  usbmount: USBmount is intended as a lightweight solution which is
            independent of a desktop environment. Users who like an
            icon to appear when an USB device is plugged in should
            use the pmount and hal packages instead. 

            Note (made in 2013): currently the author of the package
            is unable to maintain it and no one else has taken it on yet.

            For an appreciation of the present situation regarding
            usbmount development read this bug report and visit this
            repository. 

Of course if you use a DE then all bets are off because they may use
their own automounting scheme, qv, or something given above.

Cheers,
David.

[toc] | [prev] | [next] | [standalone]


#245860

FromCarles Pina i Estany <carles@pina.cat>
Date2022-03-04 00:30 +0100
Message-ID<DX33r-5GFj-1@gated-at.bofh.it>
In reply to#245845
Hi,

I'm providing more information and answering my own question (for my
laptop's installation).

On Mar/03/2022, David Wright wrote:
> On Thu 03 Mar 2022 at 10:00:09 (+0100), Carles Pina i Estany wrote:
> > 
> > My desktop computer (Debian 11.2) auto-mounts USB devices (hard disks,
> > etc.)
> 
> That doesn't help a great deal because there are several automounters
> available in Debian.

You are right - I thought that this was dealt only via systemd nowadays
(with applications using it).

> > I would like the devices to be mounted in read only mode by default. I
> > will remount them in rw if I need to.
> > 
> > They are not in my /etc/fstab
> > 
> > I've been looking at udev configuration files, rules, etc. but I'm
> > unsure which is the best way to go.
> > 
> > Is anyone here a bit more familiar with udev, systemd, etc. let me know
> > of a good approach please? The current Debian (and for many versions)
> > worked so well for me that I haven't dealt with this kind of settings,
> > I don't know which is the right tool to setup or how they interact with
> > eachother in detail anymore :-)
> 
> With Debian, I would guess that systemd is the way to go, because it's
> probably best supported. You probably want to read pages such as:
> 
> https://www.freedesktop.org/software/systemd/man/systemd.automount.html
> https://www.freedesktop.org/software/systemd/man/systemd.mount.html

Thanks for the pointers

[...]

> I've only used udev for creating mountpoints, as I don't believe

I've ended up using udev

> in automounting. I write my own rules files from scratch (man udev),
> and there are copious examples in /lib/udev/rules.d/ to steal from.

[...]

> Of course if you use a DE then all bets are off because they may use
> their own automounting scheme, qv, or something given above.

In this case I use a DE (lxde). I haven't properly dealt with all the
chain of events but the file manager pcmanfm is the one asking for the
password of the new device (if the device had one) or even just to open
the device.

pcmanfm seems to use gvfs and gvfs uses udev.

I ended up writing a new udev.d rule:
carles@pinux:~$ cat /etc/udev/rules.d/99-carles-read-only.rules 
ENV{UDISKS_MOUNT_OPTIONS_DEFAULTS}="ro,noexec"
carles@pinux:~$ 

This was found here:
http://storaged.org/doc/udisks2-api/latest/mount_options.html

Doing this the file system is mounted in ro which is what I wanted.

While searching for this information I've also found some ways to
execute hdparm -r1 on the device. I had used in the past hdparm -r0/-r1
for similar cases.

Anyway, tomorrow I can plug the hard disks and they will be read only by
default which is what I wanted.

Thanks and apologies for the lack of information in the initial email.
As I said, for many years, lxde just mounts the devices without any
problems and I lost touch with which systems are doing what in this
respect.

Cheers,

-- 
Carles Pina i Estany
https://carles.pina.cat

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web