0

I got a USB drive which is probably corrupted by some virus in windows. So, I tried formatting it by plugging it into an linux system. I used fdisk and gparted to try and delete all partitions and format the drive using fdisk. But I get the following errors: Errors

Looking at the partition table of the disk, I noticed something very strange.

Partition Table

The drive is only around 4GB in size, but the some of the partitions are as large as 1TB. What I concluded was that, fdisk could not write new partition table as it could not delete the existing partition tables probably because the starting point of the first partition itself is from a value(778,135,908) higher than that of the total sectors available(7,897,087).

So, is there anyway to change the start/end of the each partitions manually? so that I can finally clean format the drive and remove the virus.

2 Answers 2

1

You were on the right track but the partition table was corrupted. So, the first step is to create a new one (a DOS one in this example).

I assume your disk is /dev/sdx, please check this, because the next steps will erase the whole selected disk once you write to it (you have to explicitely ask fdisk to do it though).

$ sudo fdisk /dev/sdx 

There are many commands, you can type m to see them.

  • Create a new DOS partition table by typing oenter
  • Create a new partition typing nenter, set it to primary penter and accept all default values. That will create a Linux partition that fills the disk.
  • Type wenter to finish fdisk and write the changes to disk (this is the moment the disk is written to).

You are almost there, a sane partition table and a single partition. You need to create the filesystem on that partition and you will be all set:

$ sudo mkfs -t ext4 /dev/sdx 
2
  • dev/sdc: close device failed: Input/output error This is what I get when I write changes from the first step. Commented Jun 14, 2020 at 7:20
  • 1
    And what do the last couple of lines of sudo dmesg show when that happens? It might be a hardware issue after all. Commented Jun 14, 2020 at 15:25
0

Your screenshots say "disklabel type: dos", meaning MBR. The MBR is just the first 512 bytes of the drive, which can be manually overwritten with, say, dd.

But if you want to erase the entire drive and start over, an easy way to do that is

cat /dev/zero > /dev/sdc 

which completely zeros out the contents of the drive that /dev/sdc refers to. Then you should be able to (remove and reattach the drive and) reformat with the standard tools

5
  • Zeroing the whole drive looks like overkill, just erasing the MBR and partition would be enough. Commented Jun 13, 2020 at 17:07
  • and dd with a reasonably big block size is faster Commented Jun 13, 2020 at 20:02
  • definitely (to both of you)! this was an oversimplified answer that intentionally didn't go into detail on dd as a "quick get it working again". A more thorough answer that describes dd with explanation of good options would definitely be nice too Commented Jun 13, 2020 at 20:14
  • @fox I understand it. Following your advice, and seeing the OP had actually tried fdisk I added another answer. Commented Jun 14, 2020 at 0:24
  • I tried running sudo bash -c 'cat /dev/zero > /dev/sdc' and the command seems to be stuck however, I checked the disk activity using iotop it showed that cat /dev/zero is using write speeds upto 3MB/s. Commented Jun 14, 2020 at 7:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.