While formatting a USB disk which was mounted in write-protected mode we are getting the below error:

fdisk: Unable to write /dev/sdg: Bad file descriptor

 

Solution

 

1. The disk in this example is /dev/sxx. Disable read-only mode on the USB disk first. Make sure hdparm is installed, then run the following command:

# hdparm -r0 /dev/sxx

 

2. Make sure the util-linux package is installed, and then wipe out the file system.

# wipefs --all /dev/sxx --force

 

3. Make a new parttion on the disk using fdisk:

# fdisk -cu /dev/sxx

 

then ‘d‘ to delete and ‘w‘ to write.

 

4. The disk is now ready to be formatted. To format the disk with the ext4 file system, the following command can be used:

# hdparm -r0 /dev/sxx

 

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $131.99 a month.

Was this answer helpful?

Still stuck? Open a ticket