Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
mkfs.ext4 over existing ext4
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 989

PostPosted: Wed Jul 16, 2014 12:52 am    Post subject: mkfs.ext4 over existing ext4 Reply with quote

Can anyone tell me how to avoid this prompt:

Code:
/dev/sdc2 contains a ext4 file system
Proceed anyway? (y|n)


When executing something like this in a script:

Code:
mkfs.ext4 -O ^has_journal /dev/sdc2
Back to top
View user's profile Send private message
vaxbrat
l33t
l33t


Joined: 05 Oct 2005
Posts: 731
Location: DC Burbs

PostPosted: Wed Jul 16, 2014 1:21 am    Post subject: Use the -Force Luke Reply with quote

Use -F to force the mkfs. This is also what you would do when clobbering an existing btrfs.
Back to top
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 989

PostPosted: Wed Jul 16, 2014 1:35 am    Post subject: Reply with quote

Well I'd rather only force in that one situation. Is that the only option for this?

Code:
-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.  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.
Back to top
View user's profile Send private message
The Doctor
Moderator
Moderator


Joined: 27 Jul 2010
Posts: 2574

PostPosted: Wed Jul 16, 2014 1:44 am    Post subject: Reply with quote

You could use a hack.
Code:
yes | <command>
Where <command> demands a yes/no response.

But this really doesn't seem like an ideal solution. Is there any reason why your script shouldn't ask the user if they are sure? Making a new file system doesn't strike me as a routine operation.
_________________
First things first, but not necessarily in that order.

Apologies if I take a while to respond. I'm currently working on the dematerialization circuit for my blue box.
Back to top
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 989

PostPosted: Wed Jul 16, 2014 3:26 pm    Post subject: Reply with quote

It's a script to create a filesystem on a USB stick and do some other stuff.

Can I do something to the existing ext4 filesystem right before running the mkfs command so mkfs doesn't detect it as ext4 and doesn't ask that question?
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 3383

PostPosted: Wed Jul 16, 2014 3:34 pm    Post subject: Reply with quote

How about use "dd" to write a bunch of zeros to the front of the partition? I know that there are spare superblocks, but I believe that in order to use one, you have to tell it exactly where to look. Wipe the front of the partition, and with no alternate superblock info it will assume it's not ext4.
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 989

PostPosted: Wed Jul 16, 2014 3:38 pm    Post subject: Reply with quote

Would you mind showing me the dd command for this?
Back to top
View user's profile Send private message
depontius
Advocate
Advocate


Joined: 05 May 2004
Posts: 3383

PostPosted: Wed Jul 16, 2014 3:58 pm    Post subject: Reply with quote

dd if=/dev/zero of=/dev/sdXX blocks=1k

I don't use the dd command often enough to be well-versed. Also, I have usually cut/pasted the command from some help text, when I've needed it. The biggest issue in what I wrote above is noT knowing how big a block is. But as long as it's "big enough" to kill the "ext4 identity", (primary superblock?) and not bigger than the device itself, you should be good. Deleting too much is just slower.

As an optimization, I'm sure the block size can be set, even though I don't see it on the man page at the moment. You could set the block size to a least-common-denominator for flash devices for best performance and write life.
_________________
.sigs waste space and bandwidth
Back to top
View user's profile Send private message
grant123
l33t
l33t


Joined: 23 Mar 2005
Posts: 989

PostPosted: Wed Jul 16, 2014 4:29 pm    Post subject: Reply with quote

Looks great, thank you depontius.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum