10

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.

4
  • 4
    Perhaps you don't feel you need a partition table, but is there any reason why you should not have a partition table?
    – bahamat
    Aug 2, 2012 at 5:08
  • 2
    More things that can go wrong. Note my question is really a shell question, not a partition table question. Aug 2, 2012 at 5:09
  • You're claim that "more things can go wrong" is completely baseless. It sounds like you're using your fear and misunderstanding to fuel your bad decisions.
    – bahamat
    Aug 2, 2012 at 5:40
  • 4
    Look, bahamat, I'm just talking about myself. I know that if I have to do two things instead of one, my likelihood of screwing up goes up. Maybe it's different for you, but none of this is the subject of this question at all anyway. #troll Aug 2, 2012 at 21:58

2 Answers 2

18

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.

1
  • Why wouldn't it make sense, according to the man page, to create a file system on the unpartitioned device? May 2, 2021 at 20:56
3

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
2
  • What does expect do differently than reading from stdin? Aug 2, 2012 at 5:30
  • if there's another warning it won't send y
    – mekb
    Jan 31, 2022 at 22:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .