Automatic say yes to make ext3 file system on disk with mkfs.ext3
I am working on a script where I make a ext3 filesystem on a disk, the problem is that the script ask user to either say yes or no:
root@ubuntu:/home/school# mkfs.ext3 /dev/sdc
mke2fs 1.42 (29-Nov-2011)
/dev/sdc is entire device, not just one partition!
Proceed anyway? (y,n)
I have tried to put -y before mkfs and after sdc but that didnt work. Do anyone have any solutions to do this without user interaction?
You should probably not make a filesystem on an entire disk. Instead, you should make it on a partition on the disk (which would be something like /dev/sdc1
rather than /dev/sdc
). If you don't already have a partition you can make that first. The partition can (essentially) be the size of the whole disk, if you like. Even when you only want one partition on the disk, you still need to actually make the partition. Many utilities and applications (and people!) will not work, or will behave strangely, if your filesystems are not on partitions.
If you really know what you are doing and you're sure you want to make a filesystem that is not part of any partition, you can do make mkfs.ext3
do this without prompting the user, by using the -F
flag. This is almost always preferable to simulating interactive input with a pipe (it's simpler, more self-documenting, and what if something unexpected happens and the question is something else, like the device already being mounted?). On the other hand, in some situations (with some utilities) you may find you have to pipe y
or yes
to a utility, so it's a good technique to be aware of.
From the description of the -F
flag in man mkfs.ext3
:
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. In order to force mke2fs to create a filesystem even if the filesystem appears to be in use or is mounted (a truly dangerous thing to do), this option must be specified twice.
So, you can use mkfs.ext3 -F /dev/sdc
.
But, to reiterate, you should probably not do this at all because filesystems should almost always be created on a partition.
There is no -y
option for mkfs.ext3
, you can check by readin its manual page (man mkfs.ext3
). However, there is a program called yes
that is specifically designed to do what you want:
NAME
yes - output a string repeatedly until killed
So, you could run:
yes | mkfs.ext3 /dev/sdc
However, bear in mind that you are attempting to create a filesystem on the entire device instead of on a single partition and this is probably not what you want to do. You should first create a partition on the disk and then create a filesystem on that partition.