Wednesday, 18 January 2017

Read-only file system Error In Pendrive

The Dreaded Issue


Often you come across errors in linux with storage devices and the one of the most common and dreaded one is the following one
Read-only file system

Here are a few google search suggestions that pop up the moment you begin typing read-only filesystem.

  1. Fedora pen drive read-only
  2. pen drive read-only Ubuntu
  3. pen drive read-only Problem



I have seen people using several distros constantly complaining due to this issue.
Some of the most reputed forums offer horrible fixes to this issue. The solutions offered by these forums are often over complicated.

We will look into two simple approaches to this problem.


  1. The Naive Method
  2. And Geek Method


The Geek Method is hell lot a faster and looks really cool , or rather should I say geeky.

The Reason

This issue normally occurs when the pendrive is plugged out from the system without unmounting.

Why don't Windows Users face this problem?


Windows by default uses some kind of a protection mechanism to prevent this from happening, allowing you to plug-out devices without safely removing them. 

However this protection comes at a cost. This reduces the transfer speed when using the storage devices. 
This option can however be changed and this safety protection mechanism can be disabled.

Linux on the other hand assumes that you are not noobs and know the fact that storage devices need to be unmounted before pulling them out and offers you better transfer speeds instead.

Naive Method


Whenever you have a problem with any kind of storage device this method will always work.

  1. First Take a Backup
  2. Create a New Partition Table
  3. Create a New Partition
  4. Again Place your Data Back into the Storage Device
This method has been tested by several times and works flawlessly across all platforms including Android.

Linux 


In Linux you can do all these operations using the terminal or I suggest use gparted.

In case you don't have it installed, I suggest you install it right away.

Gparted Installation


  • Ubuntu 16.04 and above
sudo apt install gparted

  • Ubuntu 14.04 and distros with apt-get
sudo apt-get install gparted

  • Fedora
yum install gparted

How to use gparted?


When you launch gparted  , it will ask for the sudo password for scanning all the devices.
When prompted enter the password for the same.

Read-only file system Error In Pendrive
Authentication Prompt



Select the device you want to work with using using drop down menu on the right top corner.

Read-only file system Error In Pendrive
Gparted Interface

Unmount it 

Read-only file system Error In Pendrive
How to umnount Device Gparted!
Once unmounted click on Device on the Menu and select create new Partition option.

Next create a new partition on the device using a file system type of your choice

  1. NTFS: If you are planing to use it on Windows as well as Linux. And have large files to store
  2. FAT32: If you are planing to use it on Multiple Platforms . Widely supported
  3. Ext 2/3/4: If you are using it only for Linux. Ext4 will be unnecessary though as in most cases you shouldn't require a journaling file system for portable device
Eject the Pen drive and reinsert it you should be good to go.

The Geeky Method


This is the best looking solution. Its faster and not that complicated

  • sudo su
Obtain superuser permission. 
  • df - Th
To list all the devices and their storage capacities in human readable format. 
Additional Info:This command was explored in this blog post.

  • Identify the storage device from this output.
Assume that is /dev/sdd1
  • umount /dev/sdd1
  • dosfck /dev/sdd1
Unmount and file system check

Remove the storage device and reinsert. You should be able to write and modify the contents of the storage device.


Terminal Output for Reference


super@super-PI945GCM:~$ sudo su
[sudo] password for super: 
root@super-PI945GCM:/home/super# df - Th
df: -: No such file or directory
df: Th: No such file or directory
root@super-PI945GCM:/home/super# df -Th
Filesystem     Type      Size  Used Avail Use% Mounted on
udev           devtmpfs  1.2G     0  1.2G   0% /dev
tmpfs          tmpfs     250M  7.5M  243M   3% /run
/dev/sda1      ext4       71G   39G   29G  57% /
tmpfs          tmpfs     1.3G  256K  1.3G   1% /dev/shm
tmpfs          tmpfs     5.0M  4.0K  5.0M   1% /run/lock
tmpfs          tmpfs     1.3G     0  1.3G   0% /sys/fs/cgroup
tmpfs          tmpfs     250M   64K  250M   1% /run/user/1000
/dev/sdb5      fuseblk   932G  930G  1.9G 100% /media/super/Abhishek
/dev/sdd1      vfat       29G   16K   29G   1% /media/super/SANDISK
root@super-PI945GCM:/home/super# umount /dev/sdd1
root@super-PI945GCM:/home/super# dosfsck /dev/sdd1
fsck.fat 3.0.28 (2015-05-16)
/dev/sdd1: 1 files, 1/1875947 clusters
root@super-PI945GCM:/home/super# 


Restarting the Computer


If you still get a read-only error on your pendrive I recommend trying restarting your computer on Linux.  This is because the changes in the partition table of the pendrive are not reflected in the kernel. 









No comments:

Post a Comment