This is Ubuntu server 11.10.

/dev/sdb is not mounted (see outputs below) and is not used by any process that I can see. Its not used for swap as well. This is a 2nd IDE drive in the server, connected to the secondary IDE and set up in hardware raid as array 2.

I cannot mount the drive as I get a complaint it might already be in use. I did run fdisk, deleted all the previous partitions and created a single primary one.

root@sargent:/home/harel# fdisk -l /dev/sdb

Disk /dev/sdb: 122.9 GB, 122942324736 bytes
226 heads, 63 sectors/track, 16864 cylinders, total 240121728 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00083711

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   240121727   120059840   83  Linux

root@sargent:/home/harel# mkfs -t ext4 /dev/sdb
mke2fs 1.41.14 (22-Dec-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
/dev/sdb is apparently in use by the system; will not make a filesystem here!

root@sargent:/home/harel# cat /proc/swaps 
Filename                Type        Size    Used    Priority
/dev/sda5                               partition   2619388 0   -1

root@sargent:/home/harel# mount
/dev/sda1 on / type ext4 (rw,errors=remount-ro)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
  • You said the drive is part of a RAID array - as long as that array is active, you may not be able to access (e.g. format) the individual drives directly.
    – cyberx86
    Jan 2, 2012 at 22:01
  • Its two separate arrays though. Array 1 is a 40GB drive with Ubuntu etc., and the other drive is set as Array 2. How can I refer to it then?
    – Harel
    Jan 2, 2012 at 22:10
  • 1
    You say 'this is the second drive... setup as array 2'. An array is made of more than one disk (you can't have a 1 drive array). If you have two arrays, you should have (at least) 4 disks. You should be able to refer to the arrays (each collection of disks), but not the individual disks themselves, while they are part of an active array. (Perhaps I am misunderstanding your scenario?)
    – cyberx86
    Jan 2, 2012 at 22:19
  • It turns out that in my scenario the 2nd Raid array was set wrong in the raid configuration software. I rebuilt the array and it then mounted correctly. This is an old Fujistu server and although I understand your point regrding 1 drive arrays, it does let me set it up as such. I think its because the IDE drives only have the raid interface to connect to so it doubles up as an IDE interface (just a guess). So, thanks. Your comment about the arrays prompted me to check the bios config.
    – Harel
    Jan 2, 2012 at 22:55

8 Answers 8


Check your partitioning once again, but without specifying /dev/sda:

# fdisk -l

Then if you find in output something like /dev/md0, - it means that you have got sw array, and disk that you're trying to format contains metadata of that array.

In this case:

# umount /dev/md0
# mdadm --stop /dev/md0

Clear superblock of disk:

# mdadm --zero-superblock /dev/sdb

Remove array

# mdadm --remove /dev/md0

No you can work with your drive.


/dev/sdb is in use because there are partitions on it that the OS is aware of. If you want to create a filesystem on it (a bad idea, because it is rarely done so will confuse administrators, and it will make it difficult to do any kind of splitting or resizing), first remove the existing partition with fdisk. If you want to create a filesystem on the sole partition /dev/sdb1 (this is what you should do, since there is no benefit to using the disk directly), then say what you mean: mkfs /dev/sdb1.


You get this error message because /dev/sdb has a partition (i.e. /dev/sdb1) and the mkfs call would also overwrite all or parts of your partition table. In the worst case, your file system wouldn't be usable then. Or you 'just' loose a partition table you might still need. Since the partition device files and the actual on disk partition table should tell the same story, they are arguably 'in use' by the kernel.

Thus, the simple rule is: if you want to create your filesystem on the whole disk device then make sure all partitions are deleted before. For example:

# ls /dev/sdb*
/dev/sdb /dev/sdb1
# sfdisk --delete /dev/sdb
# sfdisk --list /dev/sdb
# ls /dev/sdb*

Usually, the partitioning tool takes care of notifying the kernel to update its partition device files. But sometimes (e.g. for loopback devices) it may be necessary to explicitly remove them (after the partition table is removed), e.g. via partx -dv mydev and/or kpartx -dv mydev.

Note that a previous kpartx -av mydev may create the partition devices as /dev/mapper/mydev* instead of /dev/mydev*. When they are present then mkfs complains in the same way.


This is an old post but I encountered the same problem when I tried to create a filesystem to one of my hard drives. The system complains and says

> [root@MASTER ~]# mkfs.ext4 -L squid_cache -m2 /dev/sdc1
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdc1 is apparently in use by the system; will not make a filesystem here!

The commands:

  • fuser
  • lsof

did not yield anything useful. Here's what I did to find the cause of the problem. I went to the /etc directory and searched for any files that mentioned the drive sdc. The first 'find' did not find anything, so I expanded the search to include the next layer below and that did find the offender

> [root@MASTER etc]# find  ./* -maxdepth 1 -type f -execdir grep -l sdc '{}' +                                                                                             

I know those files are being used by targetcli (iSCSI backend), so once I detached that storage and re-run the mkfs command, the same command ran without any issue.

Hope this helps.

  • While I found 3 similar files with this command, you failed to show how you removed them, and thus your answer is useless to me and I have to try to find a different solution. Jun 2, 2022 at 17:48
  • So I shared ways on how to find the offending file(s) and you said you found 3 similar files. Then you added that I failed to show on how to remove them. To me, that sounds you lack the fundamental knowldege of file operations in linux but instead you blamed me for your inability. Haven't heard of 'rm' or 'find ... -delete' commands? Next time, pls be more appreciative for the information you found for free.
    – oogway
    Jun 7, 2022 at 4:49
  • Duh, anyone knows how to just do rm -rf, the dangerous server-destroyer command. But what are these files, how did they get here, and what are the consequences of removing them? You talked about some iSCSI backend and I don't have any idea what you're talking about, I don't use that, you said something about unmounting something. I'm not just going to rm -rf files that I don't even know what they are, and if it could break my filesystem. I'm not going to recklessly delete unknown files like an idiot. Jun 7, 2022 at 21:10
  • And in any case, I solved it on my own by moving all the data that I needed to another drive and then just formatting the drive by deleting the partition and recreating the partition. Your answer did not help at all. Jun 7, 2022 at 21:13

In my case sudo umount /dev/sdb worked.

  • Didn't work for me. It's already unmounted but yet command still throws same error. Jun 2, 2022 at 17:49

None of these answers are helpful in my case. I tried to format the first partition (/dev/sda1) not the whole drive, which is how the command 'mkfs.ext4' is supposed to be used. But I get an error that the system is using it.
In my system, i installed Ubuntu 20.04 Desktop on a NVMe disk (/dev/sdb), and I also added a HDD to the system (which is now /dev/sda). In the GUI there's a utility called Disk, which used to have a "switch" to allow me to mount/unmount the HDD, but now the switch is missing! But, there shouldn't be ANYTHING running on that disk. This whole problem started because I want to store video files from surveillance cameras on that 2 TB HDD, and I wanted to access it remotely to be able to view the files. So, I needed to map and mount the partition such that the system could write files to it, but a user could stream files from it to view over a LAN. But first, I need to format it. And for some reason, I can't. I've tried both GUI and CLI methods--both get that "in use" error, but earlier today it wasn't even mounted (that's how I know about the GUI switch).


sudo dd if=/dev/urandom of=/dev/sdb bs=1M status=progress

This command will delete the metadata and digital signatures which is even caused by Intel VROC (virtual raid on CPU), but takes more time depending on the size of hard disk.

  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Dec 15, 2021 at 9:21
  • This overwrites the whole drive with random data. I feel bad for anyone who mindlessly copies your command and destroys their hard drive. Jun 2, 2022 at 17:50

Try completely wiping the Hard Drive first with:

sudo dc3dd wipe=/dev/sdb

Make sure to choose the correct drive.

  • 1
    This is terrible advice. Beside using a rarely available program, it's also completely unnecessary and should only ever be done if you know exactly what you are doing. See Gilles' answer and the comments instead.
    – Sven
    Aug 28, 2017 at 7:32

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.