8

I have a secondary partition with a broken Windows installation on my hard drive. I no longer need Windows, but I still have some files that I need there.

The partition remained mounted when my Windows system crashed, so I can only mount it as read only using this command:

sudo mount -o ro /dev/sda2 /media/Windows

Is there a way to execute this command during the boot process? I can't seem to execute this command without a sudo privilege.

3
  • It's totally unclear what you're trying to achieve. Please give us more details why you need it mounted during the boot, not afterwards. If you simply need it mounted - place it into /etc/fstab
    – V_Pavel
    Commented Jul 20, 2015 at 8:44
  • I'm just trying to avoid typing that command over and over again every time I start the system. Sorry, I thought that this would be easy to assume from the current content.
    – r3bl
    Commented Jul 20, 2015 at 11:29
  • it was too easy, so I assumed there was some hidden pithole :) @embik already answered your question with my suggestion to use "/etc/fstab" file for auto-mount
    – V_Pavel
    Commented Jul 20, 2015 at 15:31

3 Answers 3

7

You don't need to run this as a command during boot, you can achieve read-only mounting via the file /etc/fstab. /etc/fstab contains all filesystems that should be mounted upon boot and that's exactly what you want. It's also possible to add the mount options (for example, ro for read-only) to an /etc/fstab entry.

The additional line you need to add to the file (for example, via sudo nano /etc/fstab) looks like this:

/dev/sda2 /media/Windows ntfs ro 0 2

If you're interested in a cleaner way of creating that line, you'll need the UUID of your partition - The /dev/sdx allocation may change if you're adding different disks or even USB media (most likely it does not, nonetheless you're safer with using the UUID). To display the partition's UUID, run sudo blkid /dev/sda2 and change the line you have to match this syntax:

UUID=<UUID for /dev/sda2> /media/Windows ntfs ro 0 2

After saving the file, run sudo mount -a to make sure your partition is mounted properly (unmount the partition before to make sure it really works).

1

I have multiple partitions that I wanted mounted automatically: I have set that with the 'Disks' tool (gnome-disk-utility) present in the default repos.

  • Select the drive you want and access its mount options after clicking the small gears button

  • Un-check the 'automatic mount', enable 'mount at startup' and set the mount point:

enter image description here

The mount point changes also when one of the options under 'Identify as' menu is changed. I have found most convenient the 'Identify as' option that has the form 'LABEL=Label-of-your-drive'.

Labels can be easily edited

0

I had a slightly different need, I wanted to mount partition at the graphical session start and following the gvfs schema. To be clearer I wanted the partition to be mounted like its icon had been clicked in Files.

In order to do that I created a simple shell script mount-data-partition.sh with content:

#!/bin/sh
gio mount --device=/dev/<my partition device>

put it into a path that is in my login shell (in my case the default bash) PATH, opened System Settings > Applications > Startup and finally added a custom command using just the name of the script mount-data-partition.sh.

This does correctly mount the device at the gvfs default /media/{username}/{label} path and the mount can be unmounted from Files.

You could use fstab and add a rule for the same mount point but it would be fixed and not depending on the label (or the user). Also Files would not be able to umount it without authentication.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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