我如何编写 mkfs 脚本询问“是整个设备,而不仅仅是一个分区!仍然继续?”

Joh*_*nst 10 linux bash amazon-ec2

我正在尝试创建一个格式化 Amazon EC2 EBS 卷的脚本,以便我可以挂载它。

从命令行看,它看起来像这样:

> mkfs -q -t ext4 /dev/sdf
/dev/sdf is entire device, not just one partition!
Proceed anyway? (y,n) 
Run Code Online (Sandbox Code Playgroud)

(命令是正确的;不需要为我的目的创建分区表)

我的问题:因为这个命令应该在一个自动化脚本中运行,所以我不能在终端上问这个问题;没有人会接听,脚本将挂起。我如何避免这种情况?

我试过:

> echo y | mkfs -q -t ext4 /dev/sdf
Run Code Online (Sandbox Code Playgroud)

但这并不能解决问题。-q 选项也没有区别。

mgo*_*ven 16

联机帮助页

   -F     Force mke2fs to create a filesystem, even if the specified device is not a partition on a block special device, or  if  other
          parameters do not make sense.
Run Code Online (Sandbox Code Playgroud)

所以mkfs.ext4直接调用而不是 via mkfs,并添加-F参数以忽略此警告。