 Learn about Linux in practice  1. Overview
We commonly use USB flash drives, also known as sticks, to transfer files, store backups, or create bootable media. As a Linux user, there are times we may encounter an issue where the USB stick mounts as read-only, preventing us from editing, copying, or deleting files. This might happen due to filesystem errors, hardware failure, improper unmounting, or permission issues.
In this tutorial, we’ll explain why USB sticks could mount as read-only, how to identify this as an issue, and ways to resolve it.
2. Why USB Sticks Mount as Read-Only
When we insert a USB stick into a Linux system, the kernel usually detects and mounts it automatically. Often, any desktop environment also enables quick access to the mount. In some cases, if something goes wrong in the process or the system detects any problems, it may mount the USB stick as read-only as the only option, or to prevent further damage.
In this section, we look at some of the most common causes for this.
2.1. Filesystem Errors
Linux relies on filesystem drivers and integrity checks to mount drives safely. If the kernel detects any problems, it may mount the USB stick as read-only to prevent further damage.
This often occurs when we haven’t properly ejected that USB stick in the past.
2.2. Mount Options
When the system or a user mounts the USB stick using the ro option, either manually or through /etc/fstab, the mount is read-only.
While this is an implicit configuration, it may be an unwanted side-effect of other processes.
2.3. Hardware Settings
Some USB sticks have a physical write-protect switch as a feature. When enabled, the storage hardware itself prevents any write operation.
The Linux kernel detects this flag and mounts the device in read-only mode.
2.4. Failing or Low-Quality USB Stick
When the memory of a USB stick starts to degrade, the internal controller may force the device into read-only mode to prevent data loss.
This is common for flash storage, as any failure there usually indicates further issues are imminent and, unlike some magnetic storage failures, flash burnouts are final.
3. How to Check if a USB Stick Is Mounted as Read-Only
To remedy an undesired read-only USB stick mount, we need to check whether that is indeed the case.
3.1. Using the mount Command
The mount command shows how the system currently mounts storage devices, including their mount options. We can use it to verify whether it has mounted the USB stick in read-only (ro) or read-write (rw) mode:
$ mount | grep /dev/sd
/dev/sdb5 on / type ext4 (rw,relatime,errors=remount-ro)
/dev/sdb5 on /var/snap/firefox/common/host-hunspell type ext4 (ro,noexec,noatime,errors=remount-ro)
/dev/sda1 on /mnt/MyUSB type exfat (ro,relatime,fmask=0022,dmask=0022,iocharset=utf8)
This command filters the list of mounted devices and only shows entries related to block storage, such as USB, solid state, and hard disk drives. In the output, /dev/sda1 represents the USB stick, which contains ro in its options, indicating that the system mounted it in read-only mode. On the same line, /mnt/MyUSB represents the mounting point.
3.2. Attempt USB Stick Write
To diagnose, we can try to create a file on the USB storage:
$ touch /mnt/MyUSB/contacts.txt
touch: cannot touch 'contacts.txt': Read-only file system
As expected, the output indicates the USB stick is mounted in read-only mode.
4. Fixing USB Read-Only Issues
Once we confirm the USB stick is mounted or always mounts as read-only, we can attempt to troubleshoot and resolve the issue.
4.1. Remount the USB Stick as Read-Write
Sometimes, a USB stick can be mounted as read-only by the system due to the default system behaviour, previous errors, or incorrect mount options that include the read-only (ro) flag. In such cases, we can try to remount the USB stick manually with write permissions.
First, we need to find the mount point:
$ df -h | grep /dev/sd
/dev/sdb5 73G 61G 8.1G 89% /
/dev/sda1 7.6G 6.6G 951M 88% /mnt/MyUSB
This output shows the USB stick /dev/sda1 is at /mnt/MyUSB.
Next, we remount the USB stick with the read-write flag:
$ sudo mount -o remount,rw /dev/sda1 /mnt/MyUSB
This command remounts /dev/sda1 with read-write permissions. To explain, the -o flag specifies mount options, while remount instructs the system to remount an already-mounted filesystem without unmounting it, and rw remounts the filesystem as read-write.
Finally, let’s verify if the system has remounted the USB stick with read-write permissions:
$ mount | grep /dev/sd
/dev/sdb5 on / type ext4 (rw,relatime,errors=remount-ro)
/dev/sdb5 on /var/snap/firefox/common/host-hunspell type ext4 (ro,noexec,noatime,errors=remount-ro)
/dev/sda1 on /mnt/MyUSB type exfat (rw,relatime,fmask=0022,dmask=0022,iocharset=utf8,errors=remount-ro)
From the output, we can see /dev/sda1 has an rw flag, indicating that the system successfully remounted the USB stick with read-write permissions.
4.2. Check for a Physical Write-Protect Switch
Some USB sticks, especially older ones, come with a physical write-protect switch that prevents data deletion or modification by locking the USB stick in read-only mode. When we enable the switch, we cannot write to the USB stick regardless of the operating system or permissions.
The switch is located on the side or bottom of the USB stick, and it signals the operating system to mount the device as read-only when enabled. However, in this state, we can view and copy files from the USB stick, but we can’t create, edit, or delete them.
To disable the write-protect switch, we usually need to remove the USB stick from the computer and toggle a switch to the side labeled unlock or rw.
Lastly, let’s test to see if we now have write permissions on the USB stick by attempting to create a file:
$ sudo touch /mnt/MyUSB/passwords.txt
If no errors occur and the file is created successfully, this means the read-only mode was probably due to the hardware write-protect switch.
4.3. Run Filesystem Check
Filesystem corruption often causes a USB stick to mount as read-only. This can occur if we remove the USB stick without unmounting it or if a power failure causes an interruption.
To fix filesystem errors, we use the fsck command.
First, we need to unmount the USB stick:
$ sudo umount /dev/sda1
Here, we replace /dev/sda1 with the name of the USB stick.
Next, let’s check the USB stick for filesystem corruption. Since we’re using an exFAT-formatted USB stick, we employ fsck.exfat:
$ sudo fsck.exfat /dev/sda1
The above command checks and attempts to repair any filesystem errors on /dev/sda1. In case of an error or prompt, we can follow the instructions to fix issues.
Once the scan completes without errors, we can remount the USB stick:
$ sudo mount /dev/sda1 /mnt/MyUSB
Here, we mount the /dev/sda1 filesystem to the /mnt/MyUSB directory, enabling us to access its contents from there.
Now, to verify whether the issue is resolved, we can try creating a file on the USB stick:
$ sudo touch /mnt/MyUSB/contacts.txt
In this example, /mnt/MyUSB represents the mounting point of the USB stick. If the file is created successfully, the USB stick is now writable. However, if the USB stick is still mounted as read-only, we can try the next solution.
4.4. Replace a Failing USB Stick
If none of the above solutions work and the USB stick still mounts as read-only, it could indicate hardware failure. USB flash memory supports a limited number of write cycles, and once it reaches this limit, controllers may switch the device to read-only mode to prevent data loss.
Let’s see some of the common signs of a failing USB stick:
- the system repeatedly mounts the USB stick as read-only
- the USB stick shows 0 bytes free even though it has space available
- the system no longer recognizes the USB stick
- when we try to perform file operations such as copy, delete, or create, we get input-output errors
In this case, the best option is to copy any available data off the USB stick and replace it with a more reliable one.
5. Conclusion
In this article, we discussed reasons why a USB stick may be mounted as read-only and how to identify and fix the issue.
By understanding the common causes of this issue, we can take the right steps to fix USB stick read-only issues. The post How to Fix USB Sticks Mounted as Read-Only first appeared on Baeldung on Linux.
Content mobilized by FeedBlitz RSS Services, the premium FeedBurner alternative. |