Linux "mkfs.btrfs" Command Line Options and Examples
create a btrfs filesystem

mkfs.btrfs is used to create the btrfs filesystem on a single or multiple devices. <device> is typically a block device but can be a file-backed image as well.


Usage:

mkfs.btrfs [options] [...]






Command Line Options:

-b|--byte-count
Specify the size of the filesystem. If this option is not used, then mkfs.btrfs uses the entire device space for the filesystem.
mkfs.btrfs -b|--byte-count ...
-d|--data
Specify the profile for the data block groups. Valid values are raid0, raid1, raid5, raid6, raid10 or single or dup (case doesnot matter).See DUP PROFILES ON A SINGLE DEVICE for more.
mkfs.btrfs -d|--data ...
-m|--metadata
Specify the profile for the metadata block groups. Valid values are raid0, raid1, raid5, raid6, raid10, single or dup, (case doesnot matter).A single device filesystem will default to DUP, unless a SSD is detected. Then it will default to single. The detection is basedon the value of /sys/block/DEV/queue/rotational, where DEV is the short name of the device.Note that the rotational status can be arbitrarily set by the underlying block device driver and may not reflect the true status(network block device, memory-backed SCSI devices etc). Use the options --data/--metadata to avoid confusion.See DUP PROFILES ON A SINGLE DEVICE for more details.
mkfs.btrfs -m|--metadata ...
-M|--mixed
Normally the data and metadata block groups are isolated. The mixed mode will remove the isolation and store both types in thesame block group type. This helps to utilize the free space regardless of the purpose and is suitable for small devices. Theseparate allocation of block groups leads to a situation where the space is reserved for the other block group type, is notavailable for allocation and can lead to ENOSPC state.The recommended size for the mixed mode is for filesystems less than 1GiB. The soft recommendation is to use it for filesystemssmaller than 5GiB. The mixed mode may lead to degraded performance on larger filesystems, but is otherwise usable, even onmultiple devices.The nodesize and sectorsize must be equal, and the block group types must match.Noteversions up to 4.2.x forced the mixed mode for devices smaller than 1GiB. This has been removed in 4.3+ as it caused someusability issues.
mkfs.btrfs -M|--mixed ...
-l|--leafsize
Alias for --nodesize. Deprecated.
mkfs.btrfs -l|--leafsize ...
-n|--nodesize
Specify the nodesize, the tree block size in which btrfs stores metadata. The default value is 16KiB (16384) or the page size,whichever is bigger. Must be a multiple of the sectorsize and a power of 2, but not larger than 64KiB (65536). Leafsize alwaysequals nodesize and the options are aliases.Smaller node size increases fragmentation but leads to taller b-trees which in turn leads to lower locking contention. Highernode sizes give better packing and less fragmentation at the cost of more expensive memory operations while updating the metadatablocks.Noteversions up to 3.11 set the nodesize to 4k.
mkfs.btrfs -n|--nodesize ...
-s|--sectorsize
Specify the sectorsize, the minimum data block allocation unit.The default value is the page size and is autodetected. If the sectorsize differs from the page size, the created filesystem maynot be mountable by the kernel. Therefore it is not recommended to use this option unless you are going to mount it on a systemwith the appropriate page size.
mkfs.btrfs -s|--sectorsize ...
-L|--label
Specify a label for the filesystem. The string should be less than 256 bytes and must not contain newline characters.
mkfs.btrfs -L|--label ...
-K|--nodiscard
Do not perform whole device TRIM operation on devices that are capable of that. This does not affect discard/trim operation whenthe filesystem is mounted. Please see the mount option discard for that in btrfs(5).
mkfs.btrfs -K|--nodiscard ...
-r|--rootdir
Populate the toplevel subvolume with files from rootdir. This does not require root permissions to write the new files or tomount the filesystem.NoteThis option may enlarge the image or file to ensure it’s big enough to contain the files from rootdir. Since version 4.14.1the filesystem size is not minimized. Please see option --shrink if you need that functionality.
mkfs.btrfs -r|--rootdir ...
--shrink
Shrink the filesystem to its minimal size, only works with --rootdir option.If the destination is a regular file, this option will also truncate the file to the minimal size. Otherwise it will reduce thefilesystem available space. Extra space will not be usable unless the filesystem is mounted and resized using btrfs filesystemresize.Noteprior to version 4.14.1, the shrinking was done automatically.
mkfs.btrfs --shrink ...
-O|--features
A list of filesystem features turned on at mkfs time. Not all features are supported by old kernels. To disable a feature, prefixit with ^.See section FILESYSTEM FEATURES for more details. To see all available features that mkfs.btrfs supports run:mkfs.btrfs -O list-all
mkfs.btrfs -O|--features ...
-f|--force
Forcibly overwrite the block devices when an existing filesystem is detected. By default, mkfs.btrfs will utilize libblkid tocheck for any known filesystem on the devices. Alternatively you can use the wipefs utility to clear the devices.
mkfs.btrfs -f|--force ...
-q|--quiet
Print only error or warning messages. Options --features or --help are unaffected.
mkfs.btrfs -q|--quiet ...
-U|--uuid
Create the filesystem with the given UUID. The UUID must not exist on any filesystem currently present.
mkfs.btrfs -U|--uuid ...
-V|--version
Print the mkfs.btrfs version and exit.
mkfs.btrfs -V|--version ...
-A|--alloc-start
deprecated, will be removed (An option to help debugging chunk allocator.) Specify the (physical) offset from the start of thedevice at which allocations start. The default value is zero.SIZE UNITSThe default unit is byte. All size parameters accept suffixes in the 1024 base. The recognized suffixes are: k, m, g, t, p, e, bothuppercase and lowercase.MULTIPLE DEVICESBefore mounting a multiple device filesystem, the kernel module must know the association of the block devices that are attached tothe filesystem UUID.There is typically no action needed from the user. On a system that utilizes a udev-like daemon, any new block device isautomatically registered. The rules call btrfs device scan.The same command can be used to trigger the device scanning if the btrfs kernel module is reloaded (naturally all previousinformation about the device registration is lost).Another possibility is to use the mount options device to specify the list of devices to scan at the time of mount.# mount -o device=/dev/sdb,device=/dev/sdc /dev/sda /mntNotethat this means only scanning, if the devices do not exist in the system, mount will fail anyway. This can happen on systemswithout initramfs/initrd and root partition created with RAID1/10/5/6 profiles. The mount action can happen before all blockdevices are discovered. The waiting is usually done on the initramfs/initrd systems.As of kernel 4.14, RAID5/6 is still considered experimental and shouldn’t be employed for production use.FILESYSTEM FEATURESFeatures that can be enabled during creation time. See also btrfs(5) section FILESYSTEM FEATURES.mixed-bg(kernel support since 2.6.37)mixed data and metadata block groups, also set by option --mixedextref(default since btrfs-progs 3.12, kernel support since 3.7)increased hardlink limit per file in a directory to 65536, older kernels supported a varying number of hardlinks depending on thesum of all file name sizes that can be stored into one metadata blockraid56(kernel support since 3.9)extended format for RAID5/6, also enabled if raid5 or raid6 block groups are selectedskinny-metadata(default since btrfs-progs 3.18, kernel support since 3.10)reduced-size metadata for extent references, saves a few percent of metadatano-holes(kernel support since 3.14)improved representation of file extents where holes are not explicitly stored as an extent, saves a few percent of metadata ifsparse files are usedBLOCK GROUPS, CHUNKS, RAIDThe highlevel organizational units of a filesystem are block groups of three types: data, metadata and system.DATAstore data blocks and nothing elseMETADATAstore internal metadata in b-trees, can store file data if they fit into the inline limitSYSTEMstore structures that describe the mapping between the physical devices and the linear logical space representing the filesystemOther terms commonly used:block group, chunka logical range of space of a given profile, stores data, metadata or both; sometimes the terms are used interchangeablyA typical size of metadata block group is 256MiB (filesystem smaller than 50GiB) and 1GiB (larger than 50GiB), for data it’s1GiB. The system block group size is a few megabytes.RAIDa block group profile type that utilizes RAID-like features on multiple devices: striping, mirroring, parityprofilewhen used in connection with block groups refers to the allocation strategy and constraints, see the section PROFILES for moredetailsPROFILESThere are the following block group types available:┌────────┬────────────────────────────────────┬────────────────────┐│ │ │ ││Profile │ Redundancy │ Min/max devices ││ ├──────────────┬────────┬────────────┤ ││ │ │ │ │ ││ │ Copies │ Parity │ Striping │ │├────────┼──────────────┼────────┼────────────┼────────────────────┤│ │ │ │ │ ││single │ 1 │ │ │ 1/any │├────────┼──────────────┼────────┼────────────┼────────────────────┤│ │ │ │ │ ││ DUP │ 2 / 1 device │ │ │ 1/any (see note 1) │├────────┼──────────────┼────────┼────────────┼────────────────────┤│ │ │ │ │ ││ RAID0 │ │ │ 1 to N │ 2/any │├────────┼──────────────┼────────┼────────────┼────────────────────┤│ │ │ │ │ ││ RAID1 │ 2 │ │ │ 2/any │├────────┼──────────────┼────────┼────────────┼────────────────────┤│ │ │ │ │ ││RAID10 │ 2 │ │ 1 to N │ 4/any │├────────┼──────────────┼────────┼────────────┼────────────────────┤│ │ │ │ │ ││ RAID5 │ 1 │ 1 │ 2 to N - 1 │ 2/any (see note 2) │├────────┼──────────────┼────────┼────────────┼────────────────────┤│ │ │ │ │ ││ RAID6 │ 1 │ 2 │ 3 to N - 2 │ 3/any (see note 3) │└────────┴──────────────┴────────┴────────────┴────────────────────┘WarningIt’s not recommended to build btrfs with RAID0/1/10/5/6 profiles on partitions from the same device. Neither redundancy norperformance will be improved.Note 1: DUP may exist on more than 1 device if it starts on a single device and another one is added. Since version 4.5.1, mkfs.btrfswill let you create DUP on multiple devices.Note 2: It’s not recommended to use 2 devices with RAID5. In that case, parity stripe will contain the same data as the data stripe,making RAID5 degraded to RAID1 with more overhead.Note 3: It’s also not recommended to use 3 devices with RAID6, unless you want to get effectively 3 copies in a RAID1-like manner(but not exactly that). N-copies RAID1 is not implemented.DUP PROFILES ON A SINGLE DEVICEThe mkfs utility will let the user create a filesystem with profiles that write the logical blocks to 2 physical locations. Whetherthere are really 2 physical copies highly depends on the underlying device type.For example, a SSD drive can remap the blocks internally to a single copy—thus deduplicating them. This negates the purpose ofincreased redundancy and just wastes filesystem space without providing the expected level of redundancy.The duplicated data/metadata may still be useful to statistically improve the chances on a device that might perform some internaloptimizations. The actual details are not usually disclosed by vendors. For example we could expect that not all blocks getdeduplicated. This will provide a non-zero probability of recovery compared to a zero chance if the single profile is used. The usershould make the tradeoff decision. The deduplication in SSDs is thought to be widely available so the reason behind the mkfs defaultis to not give a false sense of redundancy.As another example, the widely used USB flash or SD cards use a translation layer between the logical and physical view of thedevice. The data lifetime may be affected by frequent plugging. The memory cells could get damaged, hopefully not destroying bothcopies of particular data in case of DUP.The wear levelling techniques can also lead to reduced redundancy, even if the device does not do any deduplication. The controllersmay put data written in a short timespan into the same physical storage unit (cell, block etc). In case this unit dies, both copiesare lost. BTRFS does not add any artificial delay between metadata writes.The traditional rotational hard drives usually fail at the sector level.In any case, a device that starts to misbehave and repairs from the DUP copy should be replaced! DUP is not backup.KNOWN ISSUESSMALL FILESYSTEMS AND LARGE NODESIZEThe combination of small filesystem size and large nodesize is not recommended in general and can lead to various ENOSPC-relatedissues during mount time or runtime.Since mixed block group creation is optional, we allow small filesystem instances with differing values for sectorsize and nodesizeto be created and could end up in the following situation:# mkfs.btrfs -f -n 65536 /dev/loop0btrfs-progs v3.19-rc2-405-g976307cSee http://btrfs.wiki.kernel.org for more information.Performing full device TRIM (512.00MiB) ...Label: (null)UUID: 49fab72e-0c8b-466b-a3ca-d1bfe56475f0Node size: 65536Sector size: 4096Filesystem size: 512.00MiBBlock group profiles:Data: single 8.00MiBMetadata: DUP 40.00MiBSystem: DUP 12.00MiBSSD detected: noIncompat features: extref, skinny-metadataNumber of devices: 1Devices:ID SIZE PATH1 512.00MiB /dev/loop0# mount /dev/loop0 /mnt/mount: mount /dev/loop0 on /mnt failed: No space left on deviceThe ENOSPC occurs during the creation of the UUID tree. This is caused by large metadata blocks and space reservation strategy thatallocates more than can fit into the filesystem.AVAILABILITYmkfs.btrfs is part of btrfs-progs. Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for further details.
mkfs.btrfs -A|--alloc-start ...