Hi. I am running 32 bit Ubuntu 18.04.2 LTS, Gnome 3.28.2. I have inherited a 2GB USB drive which has 2 partitions. One of those partitions has a folder which is locked (there is no physical switch present) and read-only. I wish to reformat the whole drive with FAT32 and erase all the files present. How do I do that please? I have looked on the net in various places but I have not had any success as yet. Thanks in advance.
Andrew
I would try using GParted. It should allow you to wipe all partitions and reformat the whole drive.
Gparted has always worked for me also.
Thanks Guys for your responses. I have tried GParted this afternoon and unfortunately it did not work. The problem seems to be the read-only permissions which I canât alter.
I tried âsudo chmod 666 /dev/ sdYâ where âsdYâ is the device assignment for the USB drive, which is supposed to allow R & W peermissions but that did not work either. Any further ideas?
your drive should be listed in /etc/mtab and that should give you an idea if it is mounted read-only (ro). if not there might just be an issue with the drive.
if it is read-only, you could try remounting it like in @Akitoâs description below. or there is more info about remounting as read/write in the askubuntu link below that.
You need to make sure the drive hasnât been mounted before trying to delete any partitions. If it has been mounted, then open a terminal to unmount it (sudo umount /{path to mounted partition(s)}.
When none of the partitions on the drive are mounted, GParted should allow you to delete them and reformat the space as you please.
Try this one:
Rightclick the usb-stick and unmount.
Go the the terminal and launch it, type:
sudo chown -R username:username /mnt/your stick name and Enter
Reformat the stick/partition
Or try at the command line (make sure youâre using the correct device!).
e.g. sudo fdisk -l (to list connected mass storage devices - and their partitions).
Letâs assume your â/â - main Linux O/S disk is on /dev/sda (and /dev/sda1, 2 etc).
So the USB you want to nuke might be /dev/sdb (donât take my word for it though! VERIFY! And after verifying, VERIFY again )
sudo fdisk /dev/sdb - and delete the partition(s).
sample session (i.e. first off list drives and partitions):
sudo fdisk -l
(below is the one Iâm âwipingâ the partition off) :
Disk /dev/sdb: 7.2 GiB, 7731314688 bytes, 15100224 sectors
Disk model: Trans-It Drive
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x22fb6a74
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 15099903 15097856 7.2G 7 HPFS/NTFS/exFAT
â°â⤠sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.33.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
â (âpâ will print partitions)
Command (m for help): p
Disk /dev/sdb: 7.2 GiB, 7731314688 bytes, 15100224 sectors
Disk model: Trans-It Drive
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x22fb6a74
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 15099903 15097856 7.2G 7 HPFS/NTFS/exFAT
â (âdâ will delete partitions - in this case thereâs only one so I pressed âenterâ for default of â1â - if youâve got several, you might have to select 2, or 3 etc)
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): p
Disk /dev/sdb: 7.2 GiB, 7731314688 bytes, 15100224 sectors
Disk model: Trans-It Drive
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x22fb6a74
â (then I pressed âwâ to write the changes - then âqâ to quit - donât worry about the message âFailed to remove partitionâ - itâs lying to you - this probably happened because the stick got automounted when I inserted it) :
Command (m for help): w
The partition table has been altered.
Failed to remove partition 1 from system: Device or resource busy
The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.
sudo fdisk -l
(snip snip)
Disk /dev/sdb: 7.2 GiB, 7731314688 bytes, 15100224 sectors
Disk model: Trans-It Drive
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x22fb6a74
(note - thereâs no longer â/dev/sdb1 * 2048 15099903 15097856 7.2G 7 HPFS/NTFS/exFATâ showing)
Now it would probably be a good idea to eject / safely remove the device⌠plug it in again and run âsudo fdisk -lââŚ
Now you could run fdisk again on it and create a new partition - or - use gparted (probably easier - but not for me - I find the CLI infiinitely easier than GUI).
I went back and created a new Linux (83) partition with âdefaultsâ - i.e. : in âsudo fdisk /dev/sdbâ - I just pressed ânâ for new, then enter, enter, enter (to use the whole device with defaults) then âwâ to write changes⌠Then I also ejected it again, and re-inserted itâŚ
Then :
mkfs.ext4 /dev/sdb1
â°â⤠sudo fdisk -l /dev/sdb
Disk /dev/sdb: 7.2 GiB, 7731314688 bytes, 15100224 sectors
Disk model: Trans-It Drive
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x22fb6a74
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 15100223 15098176 7.2G 83 Linux
Never be complacent - always verify⌠I do this stuff all the time, almost with my eyes closed, when provisioning Linux servers - however - I still do make mistakes occasionally and fdisk the wrong device, but thankfully Iâve never done it on a production server (I sometimes get complacent when Iâm doing stuff on a home server)âŚ
Too many suggestions already give for you.
As last alternative: Try to format in a PC with Windows.
Any a can solve. Win 7, 8, or 10.
Again, thank you to you all for suggestions to try and solve this difficulty. At the moment, I am learning how to use the terminal and navigate my way through the file heirarchy. I started using Dan Trippâs suggestion because I was imitating his typing; however after entering the command: w enter, a message appeared:
fdisk: failed to write disk label:operation not permitted.
Disk label type is: dos
And so I could not get any further with that one.
cordx suggested seeing if my drive was in /etc/mtab and if it was mounted read-only. What do I type in the terminal to do that please?
Am I right in thinking for gparted to delete a partition the drive needs to be unmounted?
Will try the other methods and report back. Thanks again
Andrew
cat /etc/mtab
will print out the contents of your mtab in the terminal. there will be a lot of info printed out. my three usbâs are at the very bottom so hopefully the drive you are looking for will be as well.
for example, my 4 gb usb is listed as:
/dev/sdcX /media/myusername/vol_work vfat rw,nosuid,nodev,relatime,uid=1000,gid=1000,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro 0 0
the part you are interested in is just after the filesystem type (vfat in this case) where mine says rw (read/write), you are looking to see if yours says ro (read only).
I can only think that you didnât use sudo⌠make sure nobody (e.g. you) doesnât have a file manager (e.g. nautilus) session looking at the mounted drive, or - a shell session in the mount point directory (check all your terminal sessions, close any you donât need, make sure youâre in â~â - i.e. $HOME - âcd ~
â).
âsudo fdisk /dev/[device
]â shouldnât care whether itâs mounted, but might barf if a user has a âsessionâ looking at the mount pointâŚ
I donât usually use youtube for software tech support or recommend it - but his might help you :
Hi Guys: Thanks for the suggestions. Here is some promised feedback of how I am getting on. I âcat /etc/mtabâ my usb drive and yes it is ro. I then used the method in the youtube video Daniel suggested and it indicated it had changed the ro to rw. However when coming to format the disk, the files were still present.
While using GParted on the usb disk, it was written the File system was fat 16, status : unmounted; Path: /dev/sdd1
Warning
Cantât open /dev/sd11: No such file or directory
Cannot initialise â::â
label: Cannot initialise drive
Canât open /devsdd1: No such file or directory
Cannot initialise â::â
fsck.fat4.1 (2017-01-24)
open: No such file or directory
Unable to read the contents of this filesystem!
Because of this some operations may be unavailable.
The cause might be missing software package.
The following list of software packages is required for fat 16 filesystem support: dosfstools, mtools
Does this suggest I need to install added software to read the filesystem before it can be altered?
I have also tried using Windows to format the usb but it did not.
Will keep trying the above suggestions.
Andrew
What do you mean? After formatting?
Try:
WARNING: the -f option allows usage on a mounted drive, so be absolutely sure you select the correct drive.
You can remove the f
option, if you manage to dismount the target drive.
sudo badblocks -svf /dev/sdd -o badblocks1.log
You also may add the w
option, since you donât care to keep the files on the drive. Adding the w
option usually overwrites all files on the target drive.
After I tried formatting the USB drive with GParted, I got the warning message above in my previous post which to me indicated the drive had not been formatted.
I then checked to see if the files in the locked folder had gone; but they had not.
It seems to me because I did not create the locked folder I need to either change the ownership or override the write protection. I will continue trying the above suggestions. Thanks again for your help.
Andrew
Another phenomenon that could explain this is that you try to mount
the stick with the wrong file system. E.g. I once mounted a ZFS enabled disk as NTFS and it showed some old data from before I enabled ZFS on it. The data was, as expected, still on the HDD, but it just became visible after deletion because of using the wrong file system when mounting the medium.
A post was split to a new topic: How to enable read-write permissions on a USB flash drive
Use the Gparted and delete the partition.
After make other with the system files intended: ext4, reiserFS, ntfs âŚegcâŚ
Done !
@ Sheli
Very sorry I entered in this thread very late. I have suggestion to make. Please open" Disks" from Menu Dash and you will find your Pen drive listed in the left side⌠Select it And Press Ctl+F. After that right click on the USB icon on the destop and you will have Format Menu as context Menu. Click it anf format will start. I found it working in Linux Mint 19.2.
Thank you again to everyone who has tried to solve this problem. I have tried ubhatâs suggestion but that has not worked either. I have used Gparted to delete the partition and the locked files are still there. I shall keep trying because this has become a challenge and perhaps all of us could learn something from this.