ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Linux: Creating a Filesystem

    IT Discussion
    linux sam linux administration ext4 xfs mkfs
    3
    8
    3.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • scottalanmillerS
      scottalanmiller
      last edited by

      As with any operating system, in Linux we have block devices, create partitions, optionally apply a logical volume manager and on top of all of that we format to a filesystem which we use to store our files. In Linux we do this using the mkfs command.

      In normal day to day operations, we will do nearly all work with the ETX4 and the XFS filesystems. But the mkfs command will support many options. We can use the mkfs command directly but how it is done in Linux is a bit odd, but easy. There are actually a large number of commands that start with "mkfs" and end in the name of the filesystem that we want to use. Each of these is not actually a command per se but is actually a symbolic link to one central command. But that's unnecessary to know to use it.

      Using tab completion, in Linux Mint in this example, we can type in "mkfs." and hit tab and see all of the available format commands available to us on the existing system:

      $ mkfs.
      mkfs.bfs       mkfs.ext2      mkfs.ext4      mkfs.fat       mkfs.hfsplus   mkfs.minix     mkfs.ntfs      mkfs.vfat
      mkfs.cramfs    mkfs.ext3      mkfs.ext4dev   mkfs.hfs       mkfs.jfs       mkfs.msdos     mkfs.reiserfs  mkfs.xfs
      

      That is a few, to be sure. Of those, however, we really only are going to care about a few in the "real world." For normal usage mkfs.xfs, mkfs.ext4 and mkfs.ntfs are the only ones that we are ever likely to use and the last one there would be extremely rare desktop compatibility use cases. Most of these options are legacy and would only exist for research, education or legacy compatibility purposes. The one exception would be mkfs.jfs, but with the power, support and robustness of XFS today, there is little, if any, call to use IBM's JFS filesystem. Note: BFS is not synonimous with BtrFS. The mkfs.bfs command creates an SCO BFS filesystem, not a BtrFS filesystem.

      If we have created a new partition from our earlier lesson, let's say that it is /dev/vda2 and we want to format it as XFS, this is all that we need to do:

      mkfs.xfs /dev/vda2
      

      That's it. Filesystem specific format command and the block device that we want to format.

      If we had a /dev/sdb1 device and wanted to use the latest Linux Extended Filesystem (EXT4) filesystem, we would do this:

      mkfs.ext4 /dev/sdb1
      

      For nearly all use cases, this is all that is needed. There are advanced flags available for individual filesystems to allow for detailed tuning such as adjusting block and cluster sizes, relocating meta data and such. But these are rarely used as the defaults are very good and require a lot of careful consideration. We will not cover them here and likely you will not need to use them. If you do, you will want to be consulting documentation at the time of doing so as these are not routine commands. For 99% of use cases, the standard command is sufficient.

      Once the mkfs command completes, we now have a fully formatted disk or partition, but it is not yet mounted. So it will not be displayed by the df command at this time.

      Part of a series on Linux Systems Administration by Scott Alan Miller

      1 Reply Last reply Reply Quote 2
      • thwrT
        thwr
        last edited by thwr

        Good article, just missing two things here: ext2 or even FAT32/vfat on /boot is still quite common, mkswap is also important

        scottalanmillerS 2 Replies Last reply Reply Quote 0
        • scottalanmillerS
          scottalanmiller @thwr
          last edited by

          @thwr said in Linux: Creating a Filesystem:

          Good article, just missing two things here: ext2 or even FAT32/vfat on /boot is still quite common, mkswap is also important

          mkswap will be covered separately. It's not quite a filesystem, exactly. EXT2 and vFAT have been dropped from use on /boot on current generation systems. That's a vestige now. Was still common in the RHEL 5 / CentOS 5 era, but has been some time now.

          thwrT 1 Reply Last reply Reply Quote 1
          • scottalanmillerS
            scottalanmiller @thwr
            last edited by

            @thwr said in Linux: Creating a Filesystem:

            Good article, just missing two things here...

            If you check the main article, you can see placeholders for a lot of where content will be. Memory management doesn't have a ToC created yet, but it will be coming.

            thwrT 1 Reply Last reply Reply Quote 0
            • thwrT
              thwr @scottalanmiller
              last edited by

              @scottalanmiller said in Linux: Creating a Filesystem:

              @thwr said in Linux: Creating a Filesystem:

              Good article, just missing two things here: ext2 or even FAT32/vfat on /boot is still quite common, mkswap is also important

              mkswap will be covered separately. It's not quite a filesystem, exactly. EXT2 and vFAT have been dropped from use on /boot on current generation systems. That's a vestige now. Was still common in the RHEL 5 / CentOS 5 era, but has been some time now.

              You are right, but a popular distro using vfat on /boot is Debian-based Raspbian for example.

              1 Reply Last reply Reply Quote 0
              • thwrT
                thwr @scottalanmiller
                last edited by

                @scottalanmiller said in Linux: Creating a Filesystem:

                @thwr said in Linux: Creating a Filesystem:

                Good article, just missing two things here...

                If you check the main article, you can see placeholders for a lot of where content will be. Memory management doesn't have a ToC created yet, but it will be coming.

                great, thanks

                1 Reply Last reply Reply Quote 0
                • DashrenderD
                  Dashrender
                  last edited by

                  I'm assuming LVM will be covered separately - I'm trying to understand what it's purpose is versus just using mkfs.

                  scottalanmillerS 1 Reply Last reply Reply Quote 0
                  • scottalanmillerS
                    scottalanmiller @Dashrender
                    last edited by

                    @Dashrender said in Linux: Creating a Filesystem:

                    I'm assuming LVM will be covered separately - I'm trying to understand what it's purpose is versus just using mkfs.

                    It will be. And it is unrelated. mkfs and lvm do totally different things. Neither replaces the other in any way.

                    1 Reply Last reply Reply Quote 2
                    • 1 / 1
                    • First post
                      Last post