On Linux, it’s attainable to rapidly mount any file system as read-only straight by the terminal. Mounting file systems as read-only on the fly is a good way to forestall modifications, tampering and to general improve safety quickly.

Mount file systems as read-only

To start out the mounting course of, open up a terminal window by urgent Ctrl + Alt + T or Ctrl + Shift + T on the keyboard. From there, run the lsblk command to view all block units on your laptop.

lsblk

If in case you have loads of loop units (Snap packages) displaying up in lsblk, run lsblk -e 7 as an alternative to view linked file systems with out seeing loop units.

Look by the printout that the lsblk command reveals within the terminal to discover the partition identify you’re attempting to re-mount as root. On this information, we’ll use /dev/sda1. Yours might differ.

Be aware: having hassle discovering out the partition label of the file system you’d like to mount as read-only? Take a look at our information on how to discover exhausting drive data on Linux.

When you’ve decided the partition label, use the next command to mount the file system in read-only mode.

Be aware: the command beneath is an instance. Please change “/dev/sda1” beneath with the partition label you propose to mount in read-only mode on Linux.

sudo mount -r /dev/sda1 /location/to/mount/partition/

With the above command entered, your file system will mount as read-only, and it’ll not be attainable to tamper with the contents of the file system. It would keep in read-only mode until the following reboot.

Take away read-only mount

In case you’ve determined you need to take away read-only mode on the partition you’ve mounted with out rebooting, the remount command should be used.

Be aware: make sure to change “/dev/sda1” with the partition label for the file system you propose to re-mount as learn/write on Linux.

sudo mount -rw -o remount /dev/sda1 /location/to/mount/partition/

Assuming the command above runs efficiently the file system will now not be mounted in read-only mode.

Completely mount file systems as read-only

Placing a file system in read-only mode by the command-line is helpful for particular duties, however not adequate for long-term use. If you need explicit file systems on Linux to all the time be accessible in read-only mode, you have to specify it within the file system configuration file (fstab).

Again up your Fstab

Earlier than tinkering with the Fstab file on this information, you have to make a backup of the file. Making a backup will make sure that if one thing goes mistaken throughout enhancing, modifications made to the file can rapidly be undone.

To create a backup of the Fstab file, use the cp command beneath.

sudo cp /and so forth/fstab /and so forth/fstab.bak

Add in read-only mode completely

So as to add in read-only mode, open up the Fstab file within the Nano textual content editor. Remember the fact that enhancing this file should be performed with sudo or su as it’s a system file!

sudo nano -w /and so forth/fstab

Or

su - 

nano -w /and so forth/fstab

As soon as inside the Fstab file in Nano, search for the partition you’d like to change to read-only mode and transfer the cursor there with the Arrow keys.

Be aware: can’t discover the exhausting drive partition you need to change within the Fstab file? Open up a second terminal, run lsblk -f and match the UUID code that seems subsequent to the partition you’d like to edit within the lsblk output with the one in “/etc/fstab.”

2Q==

If you’ve discovered the road within the Fstab file, add within the read-only possibility to the file-system “ro” to the mount line. It ought to look comparable to the instance code beneath.

Be aware: the code beneath is simply an instance to get an thought of what the edit ought to seem like. Don’t copy and paste the code into Nano!

UUID=96E4E375E4E35651 /media/data-storage-windows ntfs defaults,ro 0 2

After making the edit to the Fstab file to make read-only everlasting, save the edits. Saving is finished by urgent Ctrl + O on the keyboard. Then, shut the textual content editor by urgent Ctrl + X.

Shut the terminal window and reboot your PC. If you log again in, the partition needs to be in read-only mode.

Take away read-only auto-mount

Need to do away with the read-only mode arrange within the Fstab file? Right here’s what to do. First, open up a terminal window and transfer it to the foundation account by utilizing sudo -s.

sudo -s

With the terminal window logged into the foundation account, transfer into the “/etc/” listing utilizing the CD command.

cd /and so forth

Delete the Fstab file with the read-only edits made to it utilizing the rm command.

rm fstab

Restore the “fstab.bak” file you made at first of this information with the mv command.

mv fstab.bak fstab

Shut the terminal window and restart your Linux PC. If you log again in, the read-only setting can be disabled.



Source link

Share.
Leave A Reply

Exit mobile version