服務器上加了一塊舊硬盤,打算格式化以後放點歷史數據,結果用fdisk 報錯:
/dev/sda1 isapparently in use by the system; will not make a filesystem here!
一般來說,這種情況是該盤已經被系統使用或者掛載到其他地方,使用mount 和df –lh確認,這個盤沒有使用。
在我之前整理過一篇類似的文章:
/dev/sdxx isapparently in use by the system; will not make a filesystem here! 解決方法 http://www.linuxidc.com/Linux/2013-04/83299.htm
在這篇文章裡是一個共享設備掛載到同一個2個不同的節點,但我這裡是一個設備掛載到一個服務器,所以情況和我們之前的不一樣。
Google了一下,說是受以前盤上遺留的RAID信息的影響,系統會根據殘留的信息自動發現raid,由於系統的自動識別,硬盤被虛擬地組建成了raid(即便沒有真實raid存在),這就提示磁盤正在被使用,硬盤無法格式化。
確認了一下:
[root@web1 ~]# dmraid -s
ERROR: ddf1: wrong # of devices in RAID set"ddf1_4035305a8680b02520202020202020209a33c30a3a354a45" [1/2] on/dev/sda
*** Group superset .ddf1_disks
--> *Inconsistent*Active Subset
name : ddf1_4035305a8680b02520202020202020209a33c30a3a354a45
size : 145051648
stride : 128
type : mirror
status : inconsistent
subsets: 0
devs : 1
spares : 0
[root@web1 mapper]# dmsetup status
ddf1_4035305a8680b02520202020202020209a33c30a3a354a45:0 145051651 linear
釋放對磁盤的使用可以使用如下方法:
1) dmsetup remove_all
[root@web1 mapper]# dmsetup remove_all
# dmsetup remove /dev/mapper/[device]
[root@web1 mapper]# dmsetup status
No devices found
2) 用dmraid來disableactive狀態:dmraid -a no
[root@web1 conf]# dmraid -a no
ERROR: ddf1: wrong # of devices in RAID set"ddf1_4035305a8680b02520202020202020209a33c30a3a354a45" [1/2] on/dev/sda
ERROR: device"ddf1_4035305a8680b02520202020202020209a33c30a3a354a45" could not befound
RAID set"ddf1_4035305a8680b02520202020202020209a33c30a3a354a45" is not active
[root@web1 conf]#
--驗證:
[root@web1 ~]# dmraid -s
ERROR: ddf1: wrong # of devices in RAID set"ddf1_4035305a8680b02520202020202020209a33c30a3a354a45" [1/2] on/dev/sda
*** Group superset .ddf1_disks
--> *Inconsistent*Subset
name : ddf1_4035305a8680b02520202020202020209a33c30a3a354a45
size : 145051648
stride : 128
type : mirror
status : inconsistent
subsets: 0
devs : 1
spares : 0
[root@web1 ~]#
釋放以後我們就可以對磁盤格式化,在進行掛載了。
但這樣在系統重啟之後,還是會識別到磁盤的RAID信息,依舊不能正常mount。嘗試清除磁盤上RAID的信息。
--使用dmraid –x:
[root@web1 ~]# dmraid -x
ERROR: ddf1: wrong # of devices in RAID set"ddf1_4035305a8680b02520202020202020209a33c30a3a354a45" [1/2] on/dev/sda
About to delete RAID setddf1_4035305a8680b02520202020202020209a33c30a3a354a45
WARNING: The metadata stored on theraidset(s) will not be accessible after deletion
Do you want to continue ? [y/n] :y
ERROR: Raid set deletion is notsupported in "ddf1" format
[root@web1 ~]#
--使用:dmraid -rE
[root@web1 mapper]# dmraid -rE
Do you really want to erase"ddf1" ondisk metadata on /dev/sda ? [y/n] :y
ERROR: ddf1: seeking device"/dev/sda" to 38070153641984
ERROR: writing metadata to /dev/sda, offset74355768832 sectors, size 0 bytes returned 0
ERROR: erasing ondisk metadata on /dev/sda
[root@web1 mapper]#
都不能成功清除,這樣即使我把mount信息添加到/etc/fstab裡,在啟動啟動之後,也不能正常mount。所以選擇了一種方法。
在/etc/rc.d/rc.local 文件中添加了如下信息:
dmraid -a no
sleep 5
mount /dev/sda1 /backup
這樣就可以自動掛載了。