How do I make a drive write-protected or read-only in linux?

6,471

Solution 1

You can create an entry for this partition in /etc/fstab and specify it read-only( ro ).
It will automatically mount your partition (unless noauto is specified) as read-only when you start your system.

General format of /etc/fstab file is:

file_system   mount_point   type  options     dump  pass  


Suppose your Windows partition in /dev/sad1 and you want to automatically mount is on /media/Windows (with read-only permission) .

  • open /etc/fstab in gedit using gksudo gedit /etc/fstab
  • Now append following lines in it

    #Mount Windows partition as read-only
    /dev/sda1  /media/Windows   ntfs  ro,suid,dev,noexec,auto,user,async  0 0
    


Note: If you want to prevent the auto mounting of partition during boot, you can replace auto option with noauto.


For more detail, see Community Help Wiki

Solution 2

@g_p answer should suffice most of the time.

Otherwise, you can hide you partition as shown here: https://askubuntu.com/a/562948/16395

If you want, you could even go further and completely hide the disk from the kernel (if it's a normal SATA disk), using the boot parameter libata.force=X.XX:disable.

You can see detailed instruction here: https://askubuntu.com/a/387261/16395 and also here: https://unix.stackexchange.com/questions/102648/how-to-tell-linux-kernel-3-0-to-completely-ignore-a-failing-disk (since 14.04 the option is in stock kernel, so you simply need to add the command-line options).

Share:
6,471

Related videos on Youtube

Quantum88
Author by

Quantum88

Updated on September 18, 2022

Comments

  • Quantum88
    Quantum88 over 1 year

    I have installed Ubuntu on my machine, I have Windows on a small ssd and I would like that ssd not visible, read-only, or write-protected while I am using linux as I do not want any mistakes to mess up that drive...

    • yuvi
      yuvi about 9 years
      Can you edit your post with the output of df -h?