How do I script mkfs asking "is entire device, not just one partition! Proceed anyway?"

32,403

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
Share:
32,403

Related videos on Youtube

William Nyqvister
Author by

William Nyqvister

Technologist & entrepreneur.

Updated on September 18, 2022

Comments

  • William Nyqvister
    William Nyqvister over 1 year

    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.

    • bahamat
      bahamat almost 12 years
      Perhaps you don't feel you need a partition table, but is there any reason why you should not have a partition table?
    • William Nyqvister
      William Nyqvister almost 12 years
      More things that can go wrong. Note my question is really a shell question, not a partition table question.
    • bahamat
      bahamat almost 12 years
      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.
    • William Nyqvister
      William Nyqvister almost 12 years
      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
  • William Nyqvister
    William Nyqvister almost 12 years
    What does expect do differently than reading from stdin?
  • Matthias Braun
    Matthias Braun about 3 years
    Why wouldn't it make sense, according to the man page, to create a file system on the unpartitioned device?
  • mekb
    mekb over 2 years
    if there's another warning it won't send y