askvity

How to Remove Read Only from USB in Linux?

Published in Linux USB Troubleshooting 6 mins read

Yes, you can remove the read-only status from a USB drive in Linux, often by identifying the device and repairing filesystem errors or adjusting mount options.

Experiencing a USB drive stuck in read-only mode on Linux can be frustrating, preventing you from writing, deleting, or modifying files. This issue can arise from various causes, including filesystem errors, physical write-protection switches, or incorrect software permissions and mount options. Fortunately, you can often resolve this using standard Linux command-line tools.

Here's a step-by-step guide to troubleshoot and remove the read-only attribute from your USB drive.

1. Identify Your USB Drive

The first crucial step is to correctly identify your USB device to avoid accidentally affecting other drives. As referenced, you can use terminal commands like lsblk or fdisk -l for this purpose.

Insert your USB drive into your computer and open your terminal application.

  • Using lsblk:

    lsblk

    This command lists block devices in a tree format. Look for your USB drive based on its SIZE or NAME. It will likely appear as /dev/sdb, /dev/sdc, or similar. The partitions on it will be listed as /dev/sdb1, /dev/sdb2, etc.

  • Using fdisk -l:

    sudo fdisk -l

    This command lists partition tables. You'll need root privileges (sudo). Scroll through the output and find your USB drive by its size and partition information. It will also be listed as /dev/sdb, /dev/sdc, etc.

Important: Note the device identifier (e.g., /dev/sdb). Replace /dev/sdb with the correct device identifier for your USB drive in all subsequent commands. Using the wrong device path can lead to data loss on other drives.

2. Check for a Hardware Write-Protection Switch

Some USB drives, especially older ones or SD card adapters, have a small physical switch on the side that enables hardware write protection.

  • Inspect your USB drive or SD card adapter carefully.
  • If a switch is present, ensure it is in the "unlocked" or "write-enabled" position.
  • Remove and re-insert the drive after changing the switch position.

3. Repair Filesystem Errors

A common reason for a drive becoming read-only in Linux is detected filesystem errors. The system mounts the drive in read-only mode to prevent further corruption. The reference implies this fix by mentioning "Follow the prompts to fix any errors that are found."

You can use the fsck (filesystem check) utility to scan and repair the filesystem. Before running fsck, ensure the partition is UNMOUNTED.

  • Unmount the USB partition(s):
    Find the mount point(s) using mount or df -h. For example, if /dev/sdb1 is mounted at /media/user/USBNAME, unmount it:

    sudo umount /dev/sdb1
    # Or if you know the mount point:
    # sudo umount /media/user/USBNAME

    If the drive has multiple partitions (e.g., /dev/sdb1, /dev/sdb2), unmount all of them. If umount fails, you might need to forcefully unmount:

    sudo umount -l /dev/sdb1 # -l for lazy unmount
  • Run fsck to check and repair:
    The exact command depends on the filesystem type (FAT32, exFAT, NTFS, ext4, etc.). You can often determine the filesystem type using lsblk -f after identifying the drive.

    • For FAT32 or exFAT (common on USB drives):
      sudo fsck.fat -a /dev/sdb1 # Replace /dev/sdb1 with your partition identifier
      # Or for exFAT:
      # sudo fsck.exfat -a /dev/sdb1

      The -a flag automatically attempts to fix errors.

    • For NTFS (common on drives used with Windows):
      sudo ntfsfix /dev/sdb1 # Replace /dev/sdb1

      ntfsfix is a utility specifically for NTFS. It's a basic repair tool and flags the partition for a more thorough check the next time Windows is booted.

    • For ext4 (less common on USB drives shared with Windows, but possible):
      sudo fsck.ext4 -f /dev/sdb1 # Replace /dev/sdb1

      The -f flag forces a check even if the filesystem seems clean.

    Note: Run fsck on the partition (e.g., /dev/sdb1), not the whole disk (/dev/sdb).

  • After running fsck, remove and re-insert the USB drive, then try writing to it.

4. Check and Fix Permissions

Sometimes, the issue might be file or directory permissions on the drive, especially if it was previously used with root privileges or a different user.

  • Mount the drive.
  • Navigate to the mount point in the terminal.
  • Check permissions:
    ls -l
  • If necessary, change ownership to your user:
    sudo chown -R your_username:your_username /path/to/your/usb/mountpoint

    Replace your_username and /path/to/your/usb/mountpoint.

  • If necessary, adjust file permissions (be cautious with this):
    sudo chmod -R u+rw /path/to/your/usb/mountpoint # Gives owner read/write

5. Check Mount Options and Remount

Your USB drive might have been accidentally mounted with read-only permissions.

  • Check the current mount options:
    mount | grep /dev/sdb1 # Replace /dev/sdb1

    Look for ro (read-only) in the output. If you see rw (read-write), this is not the issue.

  • If it's mounted read-only (ro), unmount it (as shown in step 3) and remount it manually with read-write options:
    sudo mount -o rw /dev/sdb1 /path/to/your/usb/mountpoint

    Replace /dev/sdb1 and /path/to/your/usb/mountpoint. Often, simply unmounting and re-inserting the drive will make the system remount it correctly if the underlying issue (like filesystem errors) is resolved.

6. Consider Physical Damage

If none of the above steps work, the USB drive may be physically damaged or failing, causing it to default to a read-only state to protect existing data. In this case, data recovery might be possible, but the drive may not be usable for writing anymore.

By systematically checking for hardware switches, repairing filesystem errors using tools like fsck (as suggested by the reference's mention of fixing errors), and verifying permissions and mount options, you can often restore write access to your USB drive in Linux.

Related Articles