2

So my USB containing a Live Linux booting environment got semi-corrupted. It seems to be booting, but the EFI partition got corrupt, because of Windows failing to write to it. So I thought why not use Linux for that.

Is it possible to format a Kali USB running Live Kali?

If so, then how? I tried unmounting with umount and using mkfs.ntfs on the usb, but it said it's an device and not a partition and it didn't continue.

P.S Windows throws a could not set sectors to null error on the USB drive if I try to use the diskpart command clean after selecting a disk.

Error code is 5@0101000F (Windows internal error code from Event Viewer)

My commands:

  sudo umount /dev/sdb 
  sudo mkfs.ntfs /dev/sdb 
  sudo mkfs.ntfs /dev/sdb1
  • Please can you provide some hard examples of what you're trying to do. (For example, rather than "I tried... using mkfs.ntfs on the usb" tell us the actual command you used.) – roaima Sep 14 '19 at 14:27
  • 1
    @GAD3R yes that's what it says. I tried to specify /dev/sdb1 without avail. – Sir Muffington Sep 14 '19 at 14:27
  • @GAD3R the partition seems to be corrupt, so selecting it is not really an option. – Sir Muffington Sep 14 '19 at 14:34
  • Thank you for adding the commands. What output did you get from each one? – roaima Sep 14 '19 at 14:52
4

Q: Is it possible to format a Kali USB running Live Kali?

A: Yes.

If your partitioning tools have problems, you should unmount all partitions,

sudo umount /dev/sdx?

where x is the device letter (for example b, but check that you select the correct letter). The questionmark is a wild card for a character, for example 1, 2, 3, ...

Then you can overwrite the first mibibyte of the drive with zeros. You can do that with dd, but it is risky, and you should doublecheck that you select the correct device letter x),

sudo dd if=/dev/zero of=/dev/sdx bs=1024 count=1024

After that most partitioníng tools should work, gparted, parted, fdisk ...

If you want more details and/or graphical tools, see this link (showing also how to identify hardware problems) and this link.

1

First of all:

P.S Windows throws a could not set sectors to null error on the USB drive if I try to use the diskpart command clean after selecting a disk.

This sounds really more like a hardware problem in which case reformatting the partition won't completely solve your problem. Your best bet is to backup all data you can read and replace that drive.

That being said: can you format a USB drive from a live USB boot? Yes, of course you can! First thing you need is to know which partition to format:

In Linux hard drives (and USB storage) is represented by files in /dev. For PCs these are mostly the files /dev/sdX with /dev/sda being your primary drive, /dev/sdb your secondary etc. The partitions on these drives are represented as separate files with the number added to the file name, i.e. /dev/sda2 being your second partition on the primary drive etc.

I tried unmounting with umount and using mkfs.ntfs on the usb, but it said it's an device and not a partition and it didn't continue. [...]

My commands:

  sudo umount /dev/sdb 
  sudo mkfs.ntfs /dev/sdb 
  sudo mkfs.ntfs /dev/sdb1

So before formatting you should ensure that the respective partition is unmounted and then you can use mkfs.* on it:

  sudo umount /dev/sdb1
  sudo mkfs.ntfs /dev/sdb1

But be careful: EFI partitions usually need to be FAT32 formatted. Also if you want to use it to boot (Windows) from it, you'll probably need to reinstall the bootloader afterwards.

A simpler tool for formatting drives would be the graphical gparted which is included in most modern live Linux systems.

In any case you'll have to umount the partition first - which may not be possible if the live system is still using it which is the case when booting from the exact devices you're planing to format. Possible solutions to this:

  • use another USB stick to boot from
  • many live systems support a toram boot option which will load the whole system into RAM and release the drive afterwards

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.