0

I have a partition structure as follows:

/dev/sdc1 => Partition 1 ( My OS. [ Linux flavour ] )
/dev/sdc2 => Partition 2 ( This contents some data. )
/dev/sdc3 => Partition 3 ( This also contents some data. )
/dev/sdc4 => Partition 4 ( I want this as a deciding partition. )

I am trying to mount partition 2 or partition 3 dynamically depending on the file present in partition 4.

For example:- Partition 2 will be mounted if partition 4 consists of a file named two. Partition 3 will be mounted if partition 4 consists of a file named three.

Note:- This partition will never be mounted together i.e. if Partition 2 is mounted partition 3 will be not be mounted until partition 2 is unmounted. Thus I can use a common directory for both partitions.

As I have systemd available on my os I can write a startup script which can read from partition 4 and mount the appropriate partition at boot and write the partition record into /etc/fstab.

But according to my understanding fstab is critical file and if any failure happens or fstab get's corrupt it's going to stop the system from booting.

Question:

Now what I am trying to achieve is can I add an entry in fstab which will read dynamically partition 4 and add the entry for partition 2 or partition 3 depending on the file that exists in the partition 4.

  • I don't think you can do that, I would do it with a script – darxmurf May 8 at 10:58
  • Yes after searching for some time I also came up with the same conclusion. – Sharvin Shah May 8 at 17:36
0

The solution should be systemd-based, you do NOT have to edit /etc/fstab with systemd, why would you ? You just mount the partition, depending on the factors you have outlined, and leave it at that.

I do not understand why you would want to edit /etc/fstab if systemd can mount what you need. Do note that systemd will refuse to boot if an entry in /etc/fstab is not available. This entails that on systems with systemd, /etc/fstab should only be used for boot-essential static file systems.

1

But according to my understanding fstab is critical file and if any failure happens or fstab get's corrupt it's going to stop the system from booting.

Right.

Now what I am trying to achieve is can I add an entry in fstab which will read dynamically partition 4 and add the entry for partition 2 or partition 3 depending on the file that exists in the partition 4.

With the proper commands and access rights, you can actually write into any file, including /etc/fstab.

What will happen if you try to do so is that anything you write into fstab will be written there WAY AFTER the OS has read it and mounted the appropriate filesystems.

  • At best, your changes have no effect.
  • At worst, any error or typo you made in your /etc/fstab edits will actually "pop out" on the next reboot (which will be REALLY bad news on a shared machine, or on a machine with decent uptime as you possibly won't remember tampering with /etc/fstab)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.