服务器上加了一块旧硬盘,打算格式化以后放点历史数据,结果用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
这样就可以自动挂载了。