[SOLVED] How to make USB stick readonly - to prevent from accidental overwrite.
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to make USB stick readonly - to prevent from accidental overwrite.
I got a usb stick preinstalled with win os image that i keep. I made a wrong move and destroyed the usb stick, it is no longer able to install win7.
Hence i would like to make it readonly so that that won't happen in future.
I know how to make it in windows os.. but i have not find way to do it in linux.
After much searching around, only found this.
Is this the method ? Is there any other method ?
A quick google search for your question turns up a LOT of responses.
Really ? I must have entered wrong search key.. because i have being searching multiple times.
The result was always in Windows os method. = diskpart method
and fix usb readonly problem (instead of making it readonly),
never one that uses linux to make usbstick readonly.
The
Code:
$sudo hdparm -r1 /dev/sdc
method was the only one i got from digging around in linux forum, even then, i think there is other method, something like attribute change, but i am not sure if it is suitable .
Can you give me the keyword that you search which you said got plenty of result ? I often don't know what keyword to search, hence poor usable result
After some more reading, i think the conclusion is, unless it is a sdcard with lock switch, there is no way to make usbstick readonly, because any partitioning or formating will destroy the "readonly" data in usbstick.
I have always wondered why USB sticks don't have a hardware "write protect" switch. I cheerfully would pay another 3¢ for such a very-useful thing ...
Hell, floppy disks always had one ...
However, so far as I know, unless you are using a stick that does have one, there's no way to actually prevent your data from being overwritten. (Which, to me, is absolutely stupid ...)
Last edited by sundialsvcs; 06-02-2021 at 08:03 PM.
They used to exist, I had at least one. A quick search turned up a 16G USB3 with a switch on Amazon, so they are still being offered. If your data are that valuable, put up with the extra cost.
The full size SD cards had the write protect switch, and as has already been stated some USB sticks do.
My search was for "how to write protect a flash drive" which turned up about 46 million results. I did not of course dig any deeper, although the first several had interesting summaries.
The full size SD cards had the write protect switch, and as has already been stated some USB sticks do.
My search was for "how to write protect a flash drive" which turned up about 46 million results. I did not of course dig any deeper, although the first several had interesting summaries.
I checked out your search on google.. the top 2 results are all in windows os method. The next result is "how to format write protected usb stick" or similar stuff.. lol.. Not what i am looking for.
Anyway, Since i know the TRUTH about write protection.. i won't bother to proceed anymore.
Thanks all for info.
CLose thread
You want to ensure that device is always mounted read only. There are a few means of achieving this, dependent on how the device is mounted, but in terms of accidentally wrecking it with dd, the only precaution against that is to take more care.
Anyway, Since i know the TRUTH about write protection.. i won't bother to proceed anymore.
No, you still don't know. You can mount any usb in read only mode - if you wish. There are at least two ways to do that:
1. configure your system to ensure device is automatically mounted in read only mode (post above)
2. write a simple script to lock/unlock that [any?] device any time you wish. That means you can change the mount from read/write to readonly mode (or back) with a click.
I'd try testdisk on it to see if you can recover the data.
Thank you for your suggestion. I regret for not thinking of "recovering data" this path.. I have tried to locate another window image and already dd it onto the usbstick .. now need to know if this image is safe to use or not.
Weird: Why is it read-only when i just dd into it ? How to know what protection mechanism is used ?
I want to umount it first and remount it to another folder, but i keep getting this: Bash crashed. what does that mean ? is it terminal is accessing the device ?
How to umount it in this case ?
Code:
$ sudo umount /dev/sdd
umount: /run/media/usbstick: target is busy.
$ fuser -mki /dev/sdd
/dev/sdd: 140805c
Kill process 140805 ? (y/N) y
Warning: Program '/bin/bash' crashed.
fuser -k will kill the process which uses the given resource. That's why it is crashed.
Bash is not a terminal, but a shell, which is usually running inside terminal windows, but can be executed independently from any terminal.
It just seems weird to me that every USB stick does not have these, "quite routinely." Were designers really trying that hard to save a couple of pennies?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.