Chapter 3. Creating XFS Filesystems

This chapter discusses the following:


Caution: When you create a filesystem, all files already on the disk partition or logical volume are destroyed.


Making a Filesystem

Use the following procedure to make an XFS filesystem:

  1. Review Chapter 2, “Planning an XFS Filesystem” to verify that you are ready to begin this procedure.

  2. Identify the device name of the partition or logical volume where you plan to create the filesystem. This is the value of partition in the examples below. For simplicity, the examples in this chapter use an example partition name of /dev/sdc1. (For more information about partitioning, see the parted(8) man page.)

  3. If the disk partition is already mounted, unmount it:

    # umount partition


    Caution: Any data that is on the disk partition is destroyed.

    For example:

    # umount /dev/sdc1

  4. Use the mkfs.xfs(8) command to make the filesystem. See the following examples:

  5. Make a mount directory:

    # mkdir -p mountdir 

    mountdir is the directory to be mounted. For example:

    # mkdir -p /mnt/scratch_space

  6. Mount the filesystem on the mount directory:

    # mount partition mountdir 

    For example:

    # mount /dev/sdc1 /mnt/scratch_space

  7. To configure the system so that the new filesystem is automatically mounted when the system is booted, add the following line to the file /etc/fstab:

    partition mountdir xfs defaults 0 0

    For example:

    /dev/sdc1 /mnt/scratch_space xfs defaults 0 0

mkfs.xfs Using the Defaults

If you are making a filesystem on a disk partition or on a logical volume that does not have a log subvolume and want to use the default values for block size and log size, use the following command to create the new XFS filesystem:

# mkfs.xfs partition

The following example shows the command line to create an XFS filesystem using the defaults and system output:

# mkfs.xfs /dev/sdc1
meta-data=/dev/sdc1 isize=256    agcount=18, agsize=1048576 blks
data     =                       bsize=4096   blocks=17921788, imaxpct=25
         =                       sunit=0      swidth=0 blks, unwritten=0
naming   =version 2              bsize=4096  
log      =internal log           bsize=4096   blocks=2187, version=1
         =                       sunit=0 blks
realtime =none                   extsz=65536  blocks=0, rtextents=0

mkfs.xfs Specifying Block and Log Size of Internal Log

If you are making a filesystem on a disk partition or on a logical volume that does not have a log subvolume and want to specify the block size and log size, use the following mkfs.xfs command to create the new XFS filesystem:

# mkfs.xfs -b size=blocksize -l size=logsize partition 

blocksize is the filesystem block size (see “Choosing the Filesystem Block Size” in Chapter 2), logsize is the size of the area dedicated to log records (see “Choosing the Log Type and Size” in Chapter 2), and partition is the device name or logical volume. The default values are 4-KB blocks and a 1000-block log.

The following example shows the command line used to create an XFS filesystem and the system output. The filesystem has a 10-MB internal log and a block size of 1 KB and is on the partition /dev/dsk/dks0d4s7 .

# mkfs.xfs -b size=1k -l size=10m /dev/sdc1
meta-data=/dev/sdc1 isize=256    agcount=18, agsize=4194304 blks
data     =                       bsize=1024   blocks=71687152, imaxpct=25
         =                       sunit=0      swidth=0 blks, unwritten=0
naming   =version 2              bsize=4096  
log      =internal log           bsize=1024   blocks=10240, version=1
         =                       sunit=0 blks
realtime =none                   extsz=65536  blocks=0, rtextents=0

mkfs.xfs for a Logical Volume with a Log Subvolume

If you are making a filesystem on a logical volume that has a log subvolume (for an external log), use the following mkfs.xfs command to make the new XFS filesystem:

# mkfs.xfs -l logdev=device,size=blocksize partition

For example, to make a filesystem on partition /dev/sdc1 , with an external log on the entire device /dev/sdh , whose size is 65536 filesystem blocks, enter the following:

# mkfs.xfs -l logdev=/dev/sdh,size=65536b /dev/sdc1
meta-data=/dev/sdc1              isize=256    agcount=4, agsize=76433916
blks
         =                       sectsz=512   attr=2
data     =                       bsize=4096   blocks=305735663,
imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =/dev/sdh               bsize=4096   blocks=65536, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

mkfs.xfs for a Directory Block Size Larger than Filesystem Block Size

If you are making a filesystem with a directory block size that is larger than the filesystem block size, use the following mkfs.xfs command to create the new XFS filesystem:

# mkfs.xfs -b size=blocksize -n size=dirblocksize  partition 

dirblocksize is the directory block size (see “Choosing the Filesystem Directory Block Size ” in Chapter 2).

For example:

# mkfs.xfs -b size=2k -n size=4k /dev/sdc1
meta-data=/dev/sdc1              isize=256    agcount=4,
agsize=152867832 blks
         =                       sectsz=512   attr=2
data     =                       bsize=2048   blocks=611471327,
imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=2048   blocks=298569, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Growing a Filesystem

To grow an existing XFS filesystem, increase the available disk space and use the xfs_growfs(8) command. The filesystem must be mounted to be grown. The existing contents of the filesystem are undisturbed, and the added space becomes available for additional file storage.

Growing an XFS filesystem is supported on XVM volumes. You must first grow the XVM volume before growing the XFS filesystem. For information on XVM volumes, see the XVM Volume Manager Administrator's Guide.

The following example grows a filesystem mounted at /mnt :

# xfs_growfs /mnt
meta-data=/mnt                   isize=256    agcount=30, agsize=262144 blks
data     =                       bsize=4096   blocks=7680000, imaxpct=25
         =                       sunit=0      swidth=0 blks, unwritten=0
naming   =version 2              bsize=4096  
log      =internal               bsize=4096   blocks=1200 version=1
         =                       sunit=0 blks
realtime =none                   extsz=65536  blocks=0, rtextents=0
data blocks changed from 7680000 to 17921788