How do I script mkfs asking "is entire device, not just one partition! Proceed anyway?"
I'm trying to create a script that formats an Amazon EC2 EBS volume, so I can mount it.
From the command-line, it looks like this:
> mkfs -q -t ext4 /dev/sdf
/dev/sdf is entire device, not just one partition!
Proceed anyway? (y,n)
(The command is correct; no need to create a partition table for my purpose)
My problem: because this command is supposed to be run in an automated script, I can't have that question on the terminal; nobody will be answering and the script will hang. How do I avoid this?
I tried:
> echo y | mkfs -q -t ext4 /dev/sdf
but that doesn't do the trick. The -q option makes no difference either.
Solution 1:
From the manpage:
-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.
So call mkfs.ext4
directly instead of via mkfs
, and add the -F
parameter to ignore this warning.
Solution 2:
expect
is what you're looking for. Try something like this:
#!/usr/bin/expect
spawn mkfs -q -t ext4 /dev/sdf
expect "/dev/sdf is entire device, not just one partition!\nProceed anyway? (y,n)"
send -- "y\r"
expect eof