• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Unable to format drive - "is apparently in use by the system"

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Automata

Destroyer of Empires and Use
Joined
May 15, 2006
If you found this page through a search, please see post #9 for a fix!

------


Hello all,

I've been working on this issue for almost a solid day and I can't figure out how to format a single partition. It is almost silly since it is easy, but I can't seem to get it to go through. If I issue the following command, I get this:

Code:
[root@thideras-main ~]# mkfs.ext4 /dev/sda3
mke2fs 1.41.12 (17-May-2010)
/dev/sda3 is apparently in use by the system; will not make a filesystem here!
Searching the internet comes up with a few solutions, such as a RAID device running or the drive is being mounted. The issue is, neither of these are true and the partition isn't being mounted at all. Here is what I'm seeing on my side for information:

mount
Code:
[root@thideras-main ~]# mountftp://thideras@
/dev/mapper/vg_thiderasmain-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sdb1 on /boot type ext4 (rw)
/dev/mapper/vg_thiderasmain-lv_home on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
gvfs-fuse-daemon on /home/thideras/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=thideras)
umount /dev/sda3
Code:
[root@thideras-main ~]# umount /dev/sda3
umount: /dev/sda3: not mounted
lvdisplay
Code:
[root@thideras-main ~]# lvdisplay
  /dev/md125: read failed after 0 of 4096 at 0: Input/output error
  --- Logical volume ---
  LV Name                /dev/vg_thiderasmain/lv_root
  VG Name                vg_thiderasmain
  LV UUID                xxxxxxx-xxxxxxx-xxxxxxx-xxxxxxx
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             1600
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Name                /dev/vg_thiderasmain/lv_home
  VG Name                vg_thiderasmain
  LV UUID                xxxxxxx-xxxxxxx-xxxxxxx-xxxxxxx
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                58.94 GiB
  Current LE             1886
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
   
  --- Logical volume ---
  LV Name                /dev/vg_thiderasmain/lv_swap
  VG Name                vg_thiderasmain
  LV UUID                xxxxxxx-xxxxxxx-xxxxxxx-xxxxxxx
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                9.81 GiB
  Current LE             314
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
fdisk -l
Code:
[root@thideras-main ~]# fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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: 0xb7d4408b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *       16065      224909      104422+   7  HPFS/NTFS
/dev/sda2          224910   615980294   307877692+   7  HPFS/NTFS
/dev/sda3       615981056  1953523711   668771328   83  Linux

Disk /dev/sdb: 128.0 GB, 128035676160 bytes
255 heads, 63 sectors/track, 15566 cylinders, total 250069680 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: 0xb09031cc

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     1026047      512000   83  Linux
/dev/sdb2         1026048   250068991   124521472   8e  Linux LVM

Disk /dev/dm-0: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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: 0x00000000

Disk /dev/dm-0 doesn't contain a valid partition table

Disk /dev/dm-1: 10.5 GB, 10536091648 bytes
255 heads, 63 sectors/track, 1280 cylinders, total 20578304 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: 0x00000000

Disk /dev/dm-1 doesn't contain a valid partition table

Disk /dev/dm-2: 63.3 GB, 63283658752 bytes
255 heads, 63 sectors/track, 7693 cylinders, total 123600896 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: 0x00000000

Disk /dev/dm-2 doesn't contain a valid partition table
mdadm --detail --scan
Code:
[root@thideras-main ~]# mdadm --detail --scan
ARRAY /dev/md127 metadata=imsm UUID=d399cac8:be79920b:43eab79d:e93761b1
mdadm: cannot open /dev/md/RAID0_0: No such file or directory
lvs
Code:
[root@thideras-main ~]# lvs
  /dev/md125: read failed after 0 of 4096 at 0: Input/output error
  LV      VG              Attr   LSize  Origin Snap%  Move Log Copy%  Convert
  lv_home vg_thiderasmain -wi-ao 58.94g                                      
  lv_root vg_thiderasmain -wi-ao 50.00g                                      
  lv_swap vg_thiderasmain -wi-ao  9.81g
I can't seem to find why it thinks the drive is being used. I even tried this in single user mode and got the same message. I know that I can fire up a live disk and do this without issue, but I know there is a way to do it without resorting to that. I've gone through well over five pages of Google search results and have turned up empty handed. The partition is currently unformatted and not used by the operating system at all. Here is how the drive is being partitioned:

gparted_inusebysystem.png


I'm unable to perform this format with command line utilities (preferred) or UI based one such as GParted. I'm able to delete /dev/sda3 then create it all at once, but it still gives the same error.

"/dev/sda1" is the Windows 7 recovery partition.
"/dev/sda2" is the actual Windows 7 partition
"/dev/sda3" will be the Linux EXT4 partition, once I can format it.
 
Last edited:
I did that and then tried to format, same thing.

Code:
[root@thideras-main ~]# hdparm -z /dev/sda

/dev/sda:
 re-reading partition table
[root@thideras-main ~]# mkfs.ext4 /dev/sda3
mke2fs 1.41.12 (17-May-2010)
/dev/sda3 is apparently in use by the system; will not make a filesystem here!
 
What happens if you format the drive fat32 in windows and then try to format the disc to something else in linux.

I have noticed that every once in a while windows will grab the MBR/partition table and not unlock them. I have had similar problems while trying to mount a partition but I have never tried to format them (or bumped into this while formatting)

I would also try formatting from a livecd
 
I'll try doing that now. Didn't think about Windows doing this.
 
Live disk did not work and formatting it in Windows first did not. Time to bring out the big guns.
 
Oops, I accidently the drive.

Code:
[root@thideras-main ~]# dd if=/dev/zero of=/dev/sda bs=1024000
^C5911+0 records in
5911+0 records out
6052864000 bytes (6.1 GB) copied, 48.3848 s, 125 MB/s
Yay, progress.

Code:
[root@thideras-main ~]# fdisk /dev/sda
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xf60e7488.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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: 0xf60e7488

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4, default 1): 1
First sector (2048-1953525167, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1953525167, default 1953525167): 
Using default value 1953525167

Command (m for help): p

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 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: 0xf60e7488

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048  1953525167   976761560   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@thideras-main ~]# mkfs.ext4 /dev/sda1
mke2fs 1.41.12 (17-May-2010)
/dev/sda1 is apparently in use by the system; will not make a filesystem here!
DENIED. I wiped the whole damn disk and I get the same thing.
 
Even after completely wiping the drive clean of any information and restarting before I create a partition, I can't format it.

I have a completely empty drive and I can't do it.
 
Well, I figured it out. After trying hundreds of different commands. I found out that it thought this device was in a RAID array and keeping the drive open.

Code:
[root@thideras-main block]# mdadm --detail /dev/md127
/dev/md127:
        Version : imsm
     Raid Level : container
  Total Devices : 1

Working Devices : 1


           UUID : d399cac8:be79920b:43eab79d:e93761b1
  Member Arrays :

    Number   Major   Minor   RaidDevice

       0       8       16        -        /dev/sdb
So, I did:

Code:
[root@thideras-main block]# mdadm --remove /dev/md125
[root@thideras-main block]# mdadm --remove /dev/md127
[root@thideras-main block]# mdadm --detail
mdadm: No devices given.
[root@thideras-main block]# mdadm --stop /dev/md125
mdadm: stopped /dev/md125
[root@thideras-main block]# mdadm --stop /dev/md127
mdadm: stopped /dev/md127
Then, I won.

Code:
[root@thideras-main block]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
61054976 inodes, 244190390 blocks
12209519 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
7453 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000, 214990848

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
So, if you find this page via Google and have this issue:

Make sure the partition isn't mounted.
Make sure the partition or drive is not in a RAID array.
Stop any MDADM devices that are not legitimate and remove them.
This should allow you do work with the drives.

It took me a long time to find this information and to piece it together, so I really hope this helps someone. If you are reading this issue and this information does not help, create an account and respond here.
 
If the system is starting up a RAID using one of your partitions, that is because it sees what looks like RAID metadata on the drive. Once you stop the RAID, you can zero the superblock using the command e.g.
Code:
mdadm --zero-superblock /dev/sdb1
(if /dev/sdb1 was the device incorporated into a RAID.) The command should be repeated until it reports that it finds no superblock as more than one can be stored in the partition. In certain conditions, it can also be stored in the drive itself (/dev/sdb in the example above.)
 
I already fixed the issue. :-/

Once I saw the drive was actually in a RAID, I knew what to do. I have experience with MDADM, I just thought that /dev/md125 and /dev/md127 were my operating system drive for some reason.
 
Good morning everyone,

Since your page is the first on google when I entered the following query:
/dev/sda is apparently in use by the system; will not make a filesystem here!

I tought I would complete the page with the information that helped me since I had no raid configured. I was trying to redo the layout of my disk on ubuntu and got that message ( using a liveCD ). Turns out that ubuntu detected a swap partition on that disk and deceided to use it. All I had to do was:

sudo swapoff -a

Then I was able to work the drive.
 
Good information, thanks for stopping by and posting. :)
 
If the system is starting up a RAID using one of your partitions, that is because it sees what looks like RAID metadata on the drive. Once you stop the RAID, you can zero the superblock using the command e.g.
Code:
mdadm --zero-superblock /dev/sdb1
(if /dev/sdb1 was the device incorporated into a RAID.) The command should be repeated until it reports that it finds no superblock as more than one can be stored in the partition. In certain conditions, it can also be stored in the drive itself (/dev/sdb in the example above.)

I really appreciate this article and comments regarding wiping the super blocks. Thanks a bunch for sharing this info.
-Greg
 
Hi
Below are the commands I checked, all were fine but still I am unable to format fs on /dev/sdb

fdisk -l /dev/sdb

Disk /dev/sdb: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes <-----
I/O size (minimum/optimal): 4096 bytes / 4096 bytes <----
Disk identifier: 0x276fa738


mkfs.ext3 /dev/sdb
mke2fs 1.41.12 (17-May-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!


mount
/dev/mapper/vg_foxc5-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg_foxc5-lv_home on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)


There aren't any md devices started on my system.

[root@foxc5 ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_foxc5
PV Size 232.40 GiB / not usable 2.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 59493
Free PE 0
Allocated PE 59493
PV UUID jNhKj7-3BXg-OMjK-aukW-dPbe-nPmX-UYku1p

[root@foxc5 ~]# lvdisplay
--- Logical volume ---
LV Name /dev/vg_foxc5/lv_root
VG Name vg_foxc5
LV UUID NR33vf-qFTI-OVgw-VPNm-LlXd-ojrk-t3Kldg
LV Write Access read/write
LV Status available
# open 1
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Name /dev/vg_foxc5/lv_home
VG Name vg_foxc5
LV UUID HsV643-DUcU-omVu-GPdk-JVB5-6KNw-0veuKE
LV Write Access read/write
LV Status available
# open 1
LV Size 160.75 GiB
Current LE 41153
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:2

--- Logical volume ---
LV Name /dev/vg_foxc5/lv_swap
VG Name vg_foxc5
LV UUID WivbJA-5Smi-iBKp-hBFt-gbnT-9Anz-1rGoZj
LV Write Access read/write
LV Status available
# open 0
LV Size 21.64 GiB
Current LE 5540
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

[root@foxc5 ~]# vgdisplay
--- Volume group ---
VG Name vg_foxc5
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 232.39 GiB
PE Size 4.00 MiB
Total PE 59493
Alloc PE / Size 59493 / 232.39 GiB
Free PE / Size 0 / 0
VG UUID 9KxnGi-qgsT-HaD7-ap9j-hH5N-NEjS-f93Cs0


=======================================================

cat /sys/block/sdb/device/block/sdb/queue/physical_block_size
4096
[root@foxc5 ~]# cat /sys/block/sdb/device/block/sdb/queue/logical_block_size
512


cat /sys/block/sdb/device/model
ST500DM002-1BD14

Is it because of Physical Sector size, that I am unable to make fs here, or is it because of un-allignment of logical/physical sector size.

I tried every thing mentioned in above threads but was not able to get it done. :(
 
Are you sure it isn't in a mdadm RAID array? I noticed that is the one thing you didn't check.
 
Yes, it isn't in mdadm RAID array, I checked that too

mdadm --detail /dev/md*
mdadm: cannot open /dev/md*: No such file or directory

But I think I got that, it is being used by another driver, in fdisk -l it showed
/dev/mvsablk_0 which is being created on top of /dev/sdb

after destroying that, I was able to create fs :) Sorry for bothering you.
 
No problem and I'm glad you got it figured out. I'd like to note that "mdadm --detail /dev/md*" didn't run correctly, as noted by the error. It literally searched for "/dev/md*" instead of replacing it with all the objects in the list.
 
Last edited:
Seems I am having a similar issue and here are my reports.

Code:
root@server1 [~]# lvmdiskscan
  /dev/ram0    [      16.00 MiB]
  /dev/root    [     922.66 GiB]
  /dev/ram1    [      16.00 MiB]
  /dev/sda1    [     250.00 MiB]
  /dev/vg/swap [       7.84 GiB]
  /dev/ram2    [      16.00 MiB]
  /dev/vg/tmp  [       1.00 GiB]
  /dev/ram3    [      16.00 MiB]
  /dev/ram4    [      16.00 MiB]
  /dev/ram5    [      16.00 MiB]
  /dev/ram6    [      16.00 MiB]
  /dev/ram7    [      16.00 MiB]
  /dev/ram8    [      16.00 MiB]
  /dev/ram9    [      16.00 MiB]
  /dev/ram10   [      16.00 MiB]
  /dev/ram11   [      16.00 MiB]
  /dev/ram12   [      16.00 MiB]
  /dev/ram13   [      16.00 MiB]
  /dev/ram14   [      16.00 MiB]
  /dev/ram15   [      16.00 MiB]
  /dev/sdb1    [     931.51 GiB] LVM physical volume
  3 disks
  17 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume

Code:
root@server1 [~]# fdisk -l /dev/sdb

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
81 heads, 63 sectors/track, 382818 cylinders
Units = cylinders of 5103 * 512 = 2612736 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001674d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      382819   976761560   83  Linux

Code:
root@server1 [~]# mdadm --detail /dev/md127
mdadm: cannot open /dev/md127: No such file or directory

Code:
root@server1 [~]# fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 31 sectors/track, 247125 cylinders
Units = cylinders of 7905 * 512 = 4047360 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0003d3c1

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          66      256000   83  Linux

Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
81 heads, 63 sectors/track, 382818 cylinders
Units = cylinders of 5103 * 512 = 2612736 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001674d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      382819   976761560   83  Linux

Disk /dev/mapper/vg-root: 990.7 GB, 990694604800 bytes
255 heads, 63 sectors/track, 120445 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg-swap: 8422 MB, 8422162432 bytes
255 heads, 63 sectors/track, 1023 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg-tmp: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Code:
root@server1 [~]# /sbin/mkfs.ext4 -L /home2 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
/dev/sdb1 is apparently in use by the system; will not make a filesystem here!

I am not sure what else I can do.
 
Back