Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  21] [ 0]  / answers: 1 / hits: 34847  / 1 Year ago, sun, february 5, 2023, 12:46:53

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?


More From » bash

 Answers
2

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.


[#26724] Monday, February 6, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ongdiligenc

Total Points: 452
Total Questions: 111
Total Answers: 107

Location: Ukraine
Member since Sun, Dec 13, 2020
3 Years ago
ongdiligenc questions
Wed, Apr 13, 22, 10:34, 2 Years ago
Tue, Jun 7, 22, 00:54, 2 Years ago
Sat, Aug 7, 21, 00:37, 3 Years ago
Sat, May 22, 21, 03:06, 3 Years ago
Tue, Mar 1, 22, 10:05, 2 Years ago
;