diff --git a/pkg/util/mount/mount_linux.go b/pkg/util/mount/mount_linux.go index dbb864cd479..c298c1ed036 100644 --- a/pkg/util/mount/mount_linux.go +++ b/pkg/util/mount/mount_linux.go @@ -511,7 +511,11 @@ func (mounter *SafeFormatAndMount) formatAndMount(source string, target string, } if fstype == "ext4" || fstype == "ext3" { - args = []string{"-F", source} + args = []string{ + "-F", // Force flag + "-m0", // Zero blocks reserved for super-user + source, + } } glog.Infof("Disk %q appears to be unformatted, attempting to format as type: %q with options: %v", source, fstype, args) _, err := mounter.Exec.Run("mkfs."+fstype, args...) diff --git a/pkg/util/mount/safe_format_and_mount_test.go b/pkg/util/mount/safe_format_and_mount_test.go index 20bfeb9f624..506126b300b 100644 --- a/pkg/util/mount/safe_format_and_mount_test.go +++ b/pkg/util/mount/safe_format_and_mount_test.go @@ -116,7 +116,7 @@ func TestSafeFormatAndMount(t *testing.T) { execScripts: []ExecArgs{ {"fsck", []string{"-a", "/dev/foo"}, "", nil}, {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}}, - {"mkfs.ext4", []string{"-F", "/dev/foo"}, "", fmt.Errorf("formatting failed")}, + {"mkfs.ext4", []string{"-F", "-m0", "/dev/foo"}, "", fmt.Errorf("formatting failed")}, }, expectedError: fmt.Errorf("formatting failed"), }, @@ -127,7 +127,7 @@ func TestSafeFormatAndMount(t *testing.T) { execScripts: []ExecArgs{ {"fsck", []string{"-a", "/dev/foo"}, "", nil}, {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}}, - {"mkfs.ext4", []string{"-F", "/dev/foo"}, "", nil}, + {"mkfs.ext4", []string{"-F", "-m0", "/dev/foo"}, "", nil}, }, expectedError: fmt.Errorf("Still cannot mount"), }, @@ -138,7 +138,7 @@ func TestSafeFormatAndMount(t *testing.T) { execScripts: []ExecArgs{ {"fsck", []string{"-a", "/dev/foo"}, "", nil}, {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}}, - {"mkfs.ext4", []string{"-F", "/dev/foo"}, "", nil}, + {"mkfs.ext4", []string{"-F", "-m0", "/dev/foo"}, "", nil}, }, expectedError: nil, }, @@ -149,7 +149,7 @@ func TestSafeFormatAndMount(t *testing.T) { execScripts: []ExecArgs{ {"fsck", []string{"-a", "/dev/foo"}, "", nil}, {"blkid", []string{"-p", "-s", "TYPE", "-s", "PTTYPE", "-o", "export", "/dev/foo"}, "", &fakeexec.FakeExitError{Status: 2}}, - {"mkfs.ext3", []string{"-F", "/dev/foo"}, "", nil}, + {"mkfs.ext3", []string{"-F", "-m0", "/dev/foo"}, "", nil}, }, expectedError: nil, },