Unable to remove the files from an usb drive (neither by dd /dev/zero nor by rm -r)
Solution 1
You only zeroed the first 4kb of the partition. Usually all file systems keep a few unused blocks at the start of their partition in order to give space to boot loaders that might be installed on the partition itself. I think that at least 16 blocks are always kept unused.
You copied, with dd
, a file system of type ISO 9660, so you have 2048 bytes blocks.
ISO 9660 reserve about 32kb for boot loaders, as explained here: http://wiki.osdev.org/ISO_9660#System_Area
So, in order to really delete the content of the partition, you may need to delete at least the first 1Mb.
Solution 2
You may try remounting the drive with read-write flag. Something like following should work.
# mount -o remount,rw /dev/sdb1 /media/alex/ARCH_201404
Related videos on Youtube
Incerteza
Updated on September 18, 2022Comments
-
Incerteza over 1 year
I have a flash usb drive and up till now it has worked well. Recently I recorded iso to it using dd. Now I want to delete it.
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT ....... sdb 8:16 1 14.6G 0 disk └─sdb1 8:17 1 14.5G 0 part /media/alex/ARCH_201404 sr0 11:0 1 1024M 0 rom $ mount /dev/sdb1 on /media/alex/ARCH_201404 type iso9660 (ro,nosuid,nodev,uid=1000,gid=1000,iocharset=utf8,mode=0400,dmode=0500,uhelper=udisks2)
When I did this
$ sudo dd ibs=4096 count=1 if=/dev/zero of=/dev/sdb1 1+0 records in 8+0 records out 4096 bytes (4.1 kB) copied, 0.00053675 s, 7.6 MB/s
it seemed to succeed but when I explored the usb flash all the files were still there. When did this:
sudo rm -r /media/alex/ARCH_201404/*
and I got the error:
.................. rm: cannot remove ‘/media/alex/ARCH_201404/loader/entries/uefi-shell-v1-x86_64.conf’: Read-only file system rm: cannot remove ‘/media/alex/ARCH_201404/loader/entries/uefi-shell-v2-x86_64.conf’: Read-only file system rm: cannot remove ‘/media/alex/ARCH_201404/loader/loader.conf’: Read-only file system .....................
What can I do about it?
-
Mat about 10 yearsUnmout the drive before you
dd
anything to it! Now you need to reformat it (after you've unmounted it if you can). -
Avinash Raj about 10 yearsdrive is mounted in readonly mode, please remount it in readwrite mode, so that you can be able to remove files from that.
-
eppesuig about 10 years@AvinashRaj the file system cannot be mounted in read/write since its type is iso9660. This file system is always in read only.
-
-
mikeserv about 10 years@Alex - this guy is correct. I didn't realize it, but I guess specified only 4kb when I meant 4mb. With
dd
you can just usebs=4M
orbs=$((4*1024*1024))
. Thanks, eppesuig. By the way - this is the reason I suggested you zero out the iso partition table in the first place. They're a pain on usb. -
eppesuig about 10 yearsThis cannot work: iso9660 is a read-only file system type.
-
shantanoo about 10 yearsYes that correct. One can recreate the iso9660 fs using 'mkisofs' command.