LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 06-02-2021, 12:03 PM   #1
andrewysk
Member
 
Registered: Mar 2020
Posts: 797

Rep: Reputation: Disabled
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 ?
Code:
$ sudo hdparm -r1 /dev/sdc
Thanks
 
Old 06-02-2021, 12:07 PM   #2
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
A quick google search for your question turns up a LOT of responses.
 
Old 06-02-2021, 05:18 PM   #3
andrewysk
Member
 
Registered: Mar 2020
Posts: 797

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by computersavvy View Post
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

Last edited by andrewysk; 06-02-2021 at 05:19 PM.
 
Old 06-02-2021, 05:43 PM   #4
andrewysk
Member
 
Registered: Mar 2020
Posts: 797

Original Poster
Rep: Reputation: Disabled
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.
 
Old 06-02-2021, 07:41 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 22,010

Rep: Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629Reputation: 3629
I'd try testdisk on it to see if you can recover the data.
 
Old 06-02-2021, 08:00 PM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
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.
 
Old 06-02-2021, 09:13 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,147

Rep: Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124Reputation: 4124
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.
 
1 members found this post helpful.
Old 06-02-2021, 09:20 PM   #8
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
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.
 
Old 06-03-2021, 01:59 AM   #9
andrewysk
Member
 
Registered: Mar 2020
Posts: 797

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by sundialsvcs View Post
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 ...
Same feeling here too.

This one got a lock switch. Cost 32 euro instead of normal 7 euro. crazy
Code:
amazon
Kanguru FlashBlu30 USB-Speicherstick, USB 3.0, 16 GB, Blau
Marke: Kanguru
Jetzt: 	32,08 €

Last edited by andrewysk; 06-03-2021 at 02:02 AM.
 
Old 06-03-2021, 02:07 AM   #10
andrewysk
Member
 
Registered: Mar 2020
Posts: 797

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by computersavvy View Post
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
 
Old 06-03-2021, 02:15 AM   #11
cynwulf
Senior Member
 
Registered: Apr 2005
Posts: 2,727

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
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.
 
Old 06-03-2021, 02:28 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,997

Rep: Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338
Quote:
Originally Posted by andrewysk View Post
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.
 
Old 06-03-2021, 02:47 AM   #13
andrewysk
Member
 
Registered: Mar 2020
Posts: 797

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jefro View Post
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 ?
Code:
$ sudo mount -o rw /dev/sdd /run/media/usbstick/
mount: /run/media/usbstick: WARNING: source write-protected, mounted read-only.
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.
 
Old 06-03-2021, 02:52 AM   #14
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,997

Rep: Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338Reputation: 7338
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.
 
Old 06-03-2021, 09:00 AM   #15
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,679
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
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?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Accidental File Overwrite icorey2014 Linux - Newbie 6 03-18-2014 06:51 PM
Accidental overwrite of .bashrc with different script. AceOfSpade Ubuntu 2 01-24-2011 09:28 AM
-bash: HISTSIZE: readonly variable -bash: HISTFILESIZE: readonly variable deathsfriend99 Linux - Newbie 4 12-08-2009 12:51 PM
Difference between Readonly Filesystem and Mounting filesystem as readonly bluepenguine Linux - Newbie 1 06-19-2009 01:26 AM
safety script prevent accidental rm -rf GATTACA Programming 4 10-29-2007 02:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration