Linux mount read only file system

How to mount a hard disk as read-only from the terminal

You do not mount /dev/sda , that refers to the entire disk. You mount /dev/sda1 or whatever partition you want.

Make a mount point, call it anything you like.

sudo mount -o ro /dev/sda1 /media/2tb 

When your done, you should unmount the disk

When mounting the filesystem read-only, some trouble may happen. The system may try to write into the device anyway and fail.

For that reason the noload flag may be used, to notify to the system that the disk is blocked.

The best solution I found was:

sudo mount -o ro,noload /dev/sda1 /media/2tb 

The manual of mount(8) explains this options as follows:

-r , —read-only

Mount the filesystem read-only. A synonym is -o ro .

Note that, depending on the filesystem type, state and kernel behavior, the system may still write to the device. For example, Ext3 or ext4 will replay its journal if the filesystem is dirty. To prevent this kind of write access, you may want to mount ext3 or ext4 filesystem with ro,noload mount options or set the block device to read-only mode, see command blockdev(8) .

[…]

norecovery / noload

Don’t load the journal on mounting. Note that if the filesystem was not unmounted cleanly, skipping the journal replay will lead to the filesystem containing inconsistencies that can lead to any number of problems.

Yes, when I was trying to mount a single disk from an old RAID 1 array, I was able to mount it only with nolaod option — sudo mount -o ro,noload /dev/md0 /mnt/disk1 once I have rebuilt the array with sudo mdadm —assemble —readonly /dev/md0 /dev/sda

I am plugging a USB connected drive into Ubuntu 12.04 and the system is mounting it automatically. In Terminal, if I just say mount it shows me the current info. I want to remount it read-only.

Extrapolated from man mount(8) :

sudo mount -o remount,ro /dev/sdb4 /media/HP_TOOLS 

Seemed to work nicely. Had to do it for each automounted partition.

Step 1: After connecting the disk to the machine, give the command below to see what it shows the disk as.

It will show the disk as /dev/sda or /dev/sdb with a partion table.

Disk /dev/sdb: 7.5 GiB, 8053063680 bytes, 15728640 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x0e0e8e70 Device Boot Start End Sectors Size Id Type /dev/sdb1 * 0 2902111 2902112 1.4G 0 Empty /dev/sdb2 2888004 2892739 4736 2.3M ef EFI (FAT-12/16/32) 

Step 2: Execute the command below to see where it is mounted. For example,

$ sudo df -HT Filesystem Type Size Used Avail Use% Mounted on udev devtmpfs 4.2G 0 4.2G 0% /dev tmpfs tmpfs 829M 10M 819M 2% /run /dev/mapper/ubuntu--vg-root ext4 484G 149G 311G 33% / tmpfs tmpfs 4.2G 20M 4.2G 1% /dev/shm tmpfs tmpfs 5.3M 4.1k 5.3M 1% /run/lock tmpfs tmpfs 4.2G 0 4.2G 0% /sys/fs/cgroup /dev/sda1 ext2 495M 111M 359M 24% /boot /dev/sdb1 iso9660 1.5G 1.5G 0 100% /media/username/Ubuntu 

Step 3: Finally execute the command below to remount it as an ro only.

sudo mount -o remount,ro /dev/sdb1 /media/username/Ubuntu 

Источник

Читайте также:  Узнать сколько свободного места линуксе

How to Change HDD State From Read-Only After Temporary Crash in Linux

announcement - icon

The Kubernetes ecosystem is huge and quite complex, so it’s easy to forget about costs when trying out all of the exciting tools.

To avoid overspending on your Kubernetes cluster, definitely have a look at the free K8s cost monitoring tool from the automation platform CAST AI. You can view your costs in real time, allocate them, calculate burn rates for projects, spot anomalies or spikes, and get insightful reports you can share with your team.

Connect your cluster and start monitoring your K8s costs right away:

1. Overview

Read-only is a file system property that permits users to read or copy stored data but not write new information or edit the data. Alternatively, we can identify a Hard Disk Drive (HDD) in a read-only state as a write-protected device.

Usually, a write-protected disk shows the read-only filesystem error message on any attempt to modify its content. This error indicates that the system mounts the target drive’s file system in read-only mode. Hence, we cannot write to or alter its content.

The following conditions can corrupt or set an HDD in read-only mode:

  • Unexpected power loss
  • System crashes
  • Unsafe removal of the drive
  • Bootable disks
  • Absence of write permissions

In this tutorial, we’ll explain how to change the HDD state from read-only after a temporary crash in Linux.

2. Locate the Drive

The first step to fixing a read-only error is to locate the HDD mount point. To locate a drive, we can run the mount command and pass it through grep. The grep command helps to filter the output and highlight the argument given to it:

$ mount | grep /dev/ devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000) /dev/sda5 on / type ext4 (rw,relatime,errors=remount-ro) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev,inode64) hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M) mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime) /dev/sda1 on /boot/efi type vfat (rw,relatime,fmask=0077,dmask=0077,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro) /dev/fuse on /run/user/1000/doc type fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000) /dev/sdb4 on /media/chris/writable type ext4 (rw,nosuid,nodev,relatime,uhelper=udisks2) /dev/sdb1 on /media/chris/Ubuntu-Server 22.04 LTS amd64 type iso9660 (ro,nosuid,nodev,relatime,nojoliet,check=s,map=n,blocksize=2048,uid=1000,gid=1000,dmode=500,fmode=400,iocharset=utf8,uhelper=udisks2) 

Generally, SATA device names follow the pattern /dev/sd[a-z], while NVMe device names have the pattern /dev/nvme6n8.

From the output, we can identify the read-only devices with ro as the initial attribute in the parentheses. Similarly, rw indicates a device mounted as read/write. Also, the output of the mount command shows the mount point of each HDD partition.

The drive /dev/sdb1 mounted on /media/chris/Ubuntu-Server 22.04 LTS amd64 is a read-only device.

Читайте также:  Vmware общая папка windows linux

3. Restore Write Permission

To determine the permissions on a drive, we can use the ls command with the -l option and the device name. The following command lists the disk and its permissions:

$ ls -l /dev/sdb1 brw-r----- 1 root disk 8, 17 Jul 22 11:34 /dev/sdb1

Accordingly, with appropriate remount flags, the mount command can quickly repair a read-only error. To illustrate, let’s execute the following line of command to remount the drive:

$ sudo mount -o remount,uid=1000,gid=1000,rw /dev/sdb1 . 

The -o flag allows the mount command to use a comma-separated list of options. The ensuing are the roles of the comma-separated options in the command:

  • remount – remounts the drive over the same mount point with the same previous options
  • uid=1000 – makes the user with id=1000 the owner of the drive
  • gid=1000 – assigns the group with id=1000 as the group owner of the drive
  • rw – mounts the drive as read/write
  • /dev/sdb1 – indicates the name of the device

The values of these options come from the output of the previous mount command in section 2.

However, this quick-fix does not work for all HDD crash situations. For example, the mount command gives the following output when the command fails:

$ sudo mount -o remount,uid=1000,gid=1000,rw /dev/sdb1 mount: /media/chris/Ubuntu-Server 22.04 LTS amd64: cannot remount /dev/sdb1 read-write, is write-protected.

If the remounting command does not fix the error, then we can proceed to repair the file system on the drive.

4. Fix Read-Only HDD

Again, different cases of HDD crashes can render its file system read-only. The procedure to fix such a device requires that we:

  1. Unmount the drive
  2. Check and repair the file system
  3. Remount the drive
  4. Reboot the system

4.1. Unmount Drive

The umount command unmounts an HDD from its mount point. It takes the mount point of the drive as an attribute. Again, we recall that we can use the mount command to locate devices mounted as read-only. The following command unmounts /dev/sdb1:

However, we cannot unmount the root file system on which the device is running. Hence, let’s ensure to boot from an external bootable device when aiming to fix a system HDD. Next, let’s check and repair the file system on the device.

4.2. Check and Repair File System

The fsck program checks and repairs one or more Linux file systems. With the following fsck command and the device name attribute, we can check and repair the file system on the faulty drive:

$ sudo fsck /dev/sdb1 fsck from util-linux 2.34 e2fsck 1.44.1 (23-Jul-2022) second_disk: clean 54/81280 files, 149903/325096 blocks

However, if we do not supply a device to the command, it will check file systems in the /etc/fstab file serially.

4.3. Remount Drive

After repair, we have to remount the device to a new mount point. To remount the HDD, we’ll:

  1. Create a new mount point
  2. Mount the drive to the new mount point
  3. Write the changes in the /etc/fstab file

To illustrate, let’s create a new mount point:

Further, the following command mounts the HDD to the new mount point:

$ sudo mount -o rw,uid=1000,gid=1000,user,exec,umask=003,blksize=4096 /dev/sdb1/media/HDdevice

In addition, here’s a rundown of what’s going on in the command:

  • user – permits any user to mount the HDD
  • exec – allows for the execution of binaries
  • umask=003 – assigns rwxrwxr– permissions to directories and files in the device
  • /media/HDdevice – indicates the name of the hard disk
  • blksize=4096 – assigns block size of 4096 to the drive
Читайте также:  Где настройки сети линукс

Lastly, let’s write the changes in the /etc/fstab file. It ensures our changes remain intact on system startup. First, let’s create a backup of the /etc/fstab file to safeguard its content:

$ sudo cp /etc/fstab /etc/fstab.bak

Secondly, using the nano text editor, let’s write the following changes in the /etc/fstab file:

$ sudo nano /etc/fstab . # line for mounting the Hddevice UUID=D04A-0AE4 /media/HDdevice exfat rw,uid=1000,gid=1000,user,exec,umask=003,blksize=4096 0 0

Then, let’s press Ctrl+X, Y, and Enter to save and close the file.

4.4. Reboot the System

To confirm our changes, let’s restart the system with the shutdown command. The following shutdown command, along with the –r flag, restarts the system:

Consequently, the shutdown command sends a signal to stop all running processes and unmount devices safely before shutdown.

5. Conclusion

In this article, we learned how we could change a device state from read-only after a temporary crash in Linux. Also, we’ve seen alternative programs that solve similar problems at each step in the repair process.

Источник

How to Fix Read Only File System Error on Ubuntu

Install Telegram on Rocky Linux 9 3

The “Read-only file system…” error is a file system-related error. This could happen in many circumstances for various causes. In this article, we will discuss how to fix read only file system error on Ubuntu.

A filesystem is a grouping of data (files and directories) kept on a storage device in Linux. The filesystem is used by your operating system to report the physical location and positioning of the files. The files would appear as invisible or random bits without the filesystem.

Each file system also has its own permissions, which control which users or groups can read and write files. The “Read-only file system” problem on Ubuntu will be fixed with this guide.

How to Fix Read Only File System Error on Ubuntu

read-only file system for Ubuntu

By default, Ubuntu has a read-only file system. It implies that the user cannot change or remove files from the system. It helps to safeguard system data and folders and stop unintentional removals. Linux distribution Ubuntu uses the read-only ShrinkFS file system.

This file system saves disk space. It can be used to keep executables, configuration files, and other information that shouldn’t be changed by the user. Linux distribution Ubuntu comes included with a read-only file system. The “Btrfs” file system aims to increase performance and dependability.

The read-only file system cannot be removed using rm.

An error warning will appear if you attempt to delete a read-only file system while the machine is running. It is thus because you cannot delete the file system, which is a component of the computer’s main operating system.

Источник

Оцените статью
Adblock
detector