@@ -10,14 +10,11 @@ import (
1010
1111// MakeFS formats the imageFile as a filesystem of the specified type,
1212// populating it with the contents of the directory at sourcePath.
13- // Recognized filesystem types are "ext2", "ext3", "ext4", and "btrfs ".
13+ // Recognized filesystem types are "btrfs", " ext2", "ext3", "ext4", and "xfs ".
1414// Note that krun's init is currently hard-wired to assume "ext4".
1515// Returns the stdout, stderr, and any error returned by the mkfs command.
1616func MakeFS (sourcePath , imageFile , filesystem string ) (string , string , error ) {
1717 var stdout , stderr strings.Builder
18- // N.B. mkfs.xfs can accept a protofile via its -p option, but the
19- // protofile format doesn't allow us to supply timestamp information or
20- // specify that files are hard linked
2118 switch filesystem {
2219 case "ext2" , "ext3" , "ext4" :
2320 logrus .Debugf ("mkfs -t %s --rootdir %q %q" , filesystem , sourcePath , imageFile )
@@ -33,6 +30,16 @@ func MakeFS(sourcePath, imageFile, filesystem string) (string, string, error) {
3330 cmd .Stderr = & stderr
3431 err := cmd .Run ()
3532 return stdout .String (), stderr .String (), err
33+ case "xfs" :
34+ // N.B. -p treating directories as source for the filesystem contents only
35+ // available in xfsprogs-6.17.0 or later; before that, it only accepts prototype
36+ // files
37+ logrus .Debugf ("mkfs -t %s -p %q %q" , filesystem , sourcePath , imageFile )
38+ cmd := exec .Command ("mkfs" , "-t" , filesystem , "-p" , sourcePath , imageFile )
39+ cmd .Stdout = & stdout
40+ cmd .Stderr = & stderr
41+ err := cmd .Run ()
42+ return stdout .String (), stderr .String (), err
3643 }
3744 return "" , "" , fmt .Errorf ("don't know how to make a %q filesystem with contents" , filesystem )
3845}
0 commit comments