Linux: Remount as read write or read only – ro rw
Imagine this:
You stuck in a USB drive, you go in to try and write something or delete something and it says its read only filesystem. You type mount and notice the “ro” directive. Do you go and unmount and mount again? Nah.. Just remount.
There are 2 ways.
1) Remount all of the mounts of that device
2) Remount a specific mount of that device
To remount as readonly or readwrite every mount of the device
SYNTAX:
mount -o ro,remount [device]
mount -o rw,remount [device]
To remount a mounted partition as readonly
mount -o ro,remount /dev/sdb1
mount -o rw,remount /dev/sdb1
Even if you have several mounts of the same thing, they will all remount as readonly or readwrite
Also note that you dont have to specify the target only the device
———————-
To remount as readonly or readwrite only one mount of a device
SYNTAX:
mount -o ro,remount [destination folder]
mount -o rw,remount [destination folder]
To remount a specific mount folder and not every mount do this
mount -o rw,remount /media/USB_FLASH_1
Complications (METHOD UNSTABLE):
When you do the above method to only remount as readwrite or readonly a specific destination folder, well every mount that happened after the specified mount will get changed as well.
After doing some test this proved to be unstable… Sometimes only the destination folder would remount properly, and other times all of the destination folders would remount the same way
———————-
EXAMPLE:
I put in a usb sdcard and it was mounted like this
# mount
..snip..
/dev/sdb1 on /media/USB_FLASH_1 type vfat (ro,noatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,shortname=winnt,utf8,flush,errors=remount-ro)
/dev/sdb1 on /run/nfs4/media/USB_FLASH_1 type vfat (ro,noatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,shortname=winnt,utf8,flush,errors=remount-ro)
So I made it readwrite like this
# mount -o rw,remount /dev/sdb1
Now look at what mount says
# mount
..snip..
/dev/sdb1 on /media/USB_FLASH_1 type vfat (rw,noatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,shortname=winnt,utf8,flush,errors=remount-ro)
/dev/sdb1 on /run/nfs4/media/USB_FLASH_1 type vfat (rw,noatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,shortname=winnt,utf8,flush,errors=remount-ro)
Now lets make the /media/USB_FLASH_1 readonly (this is where the complication comes in, well hopefully it doesnt)
# mount -o ro,remount /run/nfs4/media/USB_FLASH_1
Verify
# mount
..snip..
/dev/sdb1 on /media/USB_FLASH_1 type vfat (rw,noatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,shortname=winnt,utf8,flush,errors=remount-ro)
/dev/sdb1 on /run/nfs4/media/USB_FLASH_1 type vfat (ro,noatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,shortname=winnt,utf8,flush,errors=remount-ro)
—-
(so here looks like it worked, and the complication didn’t happen)
What is this complication?
So in the previous command if the result of this command:
# mount -o ro,remount /run/nfs4/media/USB_FLASH_1
would of been (notice how both changed to ro, instead of just one… hence the complication)
# mount
..snip..
/dev/sdb1 on /media/USB_FLASH_1 type vfat (ro,noatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,shortname=winnt,utf8,flush,errors=remount-ro)
/dev/sdb1 on /run/nfs4/media/USB_FLASH_1 type vfat (ro,noatime,fmask=0000,dmask=0000,allow_utime=0022,codepage=cp437,iocharset=iso8859-1,shortname=winnt,utf8,
By: KBoss