#415 Issue closed: mkfs -t btrfs missing force mode

Labels: bug

gdha opened issue at 2014-05-23 12:45:

I found an issue with mkfs -t btrfs:

--- usr/share/rear/layout/prepare/GNU/Linux/13_include_filesystem_code.sh.orig
+++ usr/share/rear/layout/prepare/GNU/Linux/13_include_filesystem_code.sh
@@ -94,7 +94,11 @@ EOF
 cat >> $LAYOUT_CODE <<EOF
 LogPrint "Creating $fstype-filesystem $mp on $device"
 # if $device is already mounted, skip
-mount | grep -q $device || mkfs -t $fstype $device
+# mkfs.btrfs needs an explicit '-f' (same as mkfs.xfs) to
+# force overwrite when an existing filesystem is detected
+# otherwise "rear recover" fails here with an error
+# see https://bugzilla.novell.com/show_bug.cgi?id=878870
+mount | grep -q $device || mkfs -t $fstype -f $device
 EOF
             if [ -n "$label" ] ; then
                 echo "mount | grep -q $device || btrfs filesystem label $device $label >&2" >> $LAYOUT_CODE

Details:

I think when rear creates filesystems it must be enforced to do that
even when an existing filesystem is detected.

Some mkfs.* tools need an explicit '-f' to do that
but for other mkfs.* tools '-f' has a different meaning
so that a careful case by case implementation is needed.

Currently on my system the mkfs.* man pages show:

# for f in /sbin/mkfs.* ; do m=$( basename $f ) ; \
 echo $m ; man -7 $m | tr -s ' ' | grep -A2 -- '^ -f' ; \
 echo ================================ ; done | fold -s -w70 | grep -v '^$'

mkfs.bfs
================================
mkfs.btrfs
 -f, --force
 Force overwrite when an existing filesystem is detected on the
device. By default, mkfs.btrfs will not write to the device if it
suspects that there is
 a filesystem or partition table on the device already.
================================
mkfs.cramfs
================================
mkfs.ext2
 -f fragment-size
 Specify the size of fragments in bytes.
================================
mkfs.ext3
 -f fragment-size
 Specify the size of fragments in bytes.
================================
mkfs.ext4
 -f fragment-size
 Specify the size of fragments in bytes.
================================
mkfs.minix
================================
mkfs.msdos
 -f number-of-FATs
 Specify the number of file allocation tables in the filesystem. The
default is 2. Currently the Linux MS-DOS filesystem does not support
more than 2 FATs.
================================
mkfs.reiserfs
 -f Forces mkreiserfs to continue even when the device is the whole
disk, looks mounted, or is not a block device. If -f is specified
more than once, it
 allows the user to avoid asking for confirmation.
================================
mkfs.xfs
 -f Force overwrite when an existing filesystem is detected on the
device. By default, mkfs.xfs will not write to the device if it
suspects that there is a
 filesystem or partition table on the device already.
================================
------------------------------------------------------------------------------

This means only for btrfs and xfs an explicit '-f' in
/usr/share/rear/layout/prepare/GNU/Linux/13_include_filesystem_code.sh
is needed. For xfs it is already there, only for btrfs it is missing:
-------------------------------------------------------------------------------
    case $fstype in
...
        xfs)
cat >> $LAYOUT_CODE <<EOF
LogPrint "Creating $fstype-filesystem $mp on $device"
mkfs.xfs -f  $device
EOF
...
        btrfs)
cat >> $LAYOUT_CODE <<EOF
LogPrint "Creating $fstype-filesystem $mp on $device"
# if $device is already mounted, skip
mount | grep -q $device || mkfs -t $fstype $device
EOF

Kind Regards
Johannes Meixner

gdha commented at 2014-06-04 09:30:

rear-1.16.1 should have the btrfs --force fix on board.

FlyinFistOfJuda commented at 2015-02-12 10:03:

Hi i'm on Debian 7.8 with rear 1.16.1-git201502062115.
Recover run fails with mkfs.btrfs: invalid option -- 'f' . Also, --force is invalid. (Btrfs Btrfs v0.19)

gdha commented at 2015-02-12 10:18:

@FlyinFistOfJuda could you show the option: mkfs.btrfs --help ?

FlyinFistOfJuda commented at 2015-02-12 13:25:

Well, even help is no option. :)
Here's the output on the running system:

mkfs.btrfs: unrecognized option '--help'

usage: mkfs.btrfs [options] dev [ dev ... ]

options:

     -A --alloc-start the offset to start the FS

     -b --byte-count total number of bytes in the FS

     -d --data data profile, raid0, raid1, raid10 or single

     -l --leafsize size of btree leaves

     -L --label set a label

     -m --metadata metadata profile, values like data profile

     -M --mixed mix metadata and data together

     -n --nodesize size of btree nodes

     -s --sectorsize min block allocation

     -r --rootdir the source directory

Btrfs Btrfs v0.19

Anyway, didn't want to file a support request. Idea was to comment that with rear 1.16.1 there's still a problem with usage of force regarding the bug.

gdha commented at 2015-02-12 14:43:

@FlyinFistOfJuda as such this not an issue with rear but with the version of btrfs you are using (quite old). The man page of mkfs.btrfs shows all options (more then what you listed)

FlyinFistOfJuda commented at 2015-02-12 15:03:

Yes, just also figured that out. An outdated man-page reflected my output. Thanks for clarification.


[Export of Github issue for rear/rear.]