Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
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 '12 at 5:08
    
More things that can go wrong. Note my question is really a shell question, not a partition table question. –  Johannes Ernst Aug 2 '12 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 '12 at 5:40
1  
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 –  Johannes Ernst Aug 2 '12 at 21:58

2 Answers 2

up vote 4 down vote accepted

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.

share|improve this answer

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
share|improve this answer
    
What does expect do differently than reading from stdin? –  Johannes Ernst Aug 2 '12 at 5:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.