2

As far as I know, to mount something at boot you need to edit fstab.

I need to add / remove disks from fstab automatically (this is a script, not me personally). This script identifies disks by their UUID. Is there an utility to do this ?

As for the interests: editing fstab by using a text editor is just for manual changes. Doing it in a script requires to write a parser for the format ; maybe someone already took the time to write it ? Also such an utility would be able to prevent some errors by checking for them for example...

8
  • 1
    Could you describe what kind of modification you need to do exactly? I don't know if there's a general purpose fstab managing tool, but for specific tasks it would be easy to script that with e.g. sed, awk or just bash.
    – Byte Commander
    Jan 2, 2017 at 15:49
  • Well, adding / removing mount points is enough - by removing I do not mean "removing the last", but "removing mount point of disk with specified UUID". Also, for a file this important, I prefer serious solutions instead of hacks (no offsense, but I find sed / awk to be unreadable). I could use Python or C++ if needed (but obviously needing to code it is not an answer !)
    – Synxis
    Jan 2, 2017 at 15:56
  • The issue is that adding a drive to fstab has many options. In such a case, there is not much to win to script it, since the command to run the script would equally require the option to set many options. You could however easily automate adding entries to fstab (since you can easily make a script to do anything when a new mount or anything occurs), but you would still need to set the options in advance. Jan 2, 2017 at 16:01
  • Adding is not that obvious; echo ... >> /etc/fstab is not sufficient as we should also check the mount is not already added (and other verifications). What's more, removing a mount is not straightforward. That's why a cli would be hugely beneficial... I can hardcode some of the mount options in the script (ex UUID or filesystem).
    – Synxis
    Jan 2, 2017 at 16:08
  • I might be missing something, but if you have the uuid, then simply remove the corresponding line? Jan 2, 2017 at 16:12

1 Answer 1

0

There doesn't seem to be a command-line utility, so I finally went with a python script : there is a python fstab module developed by Canonical, although it is old and need some love (the API is crude). That avoided redoing the whole parser from scratch.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .