-->

Creating a Filesystem On Linux

Before you can store data on the partition, you must format it with a filesystem so Linux can use it.

Creating a Filesystem On Linux
Creating a Filesystem On Linux

Each filesystem type uses its own command line program to format partitions. The Table below lists the utilities used for the different filesystems discussed in this articles.

Command Line Programs to Create Filesystems
Command Line Programs to Create Filesystems

Not all filesystem utilities are installed by default. To determine whether you have a particular filesystem utility, use the type command:

  1. $ type mkfs.ext4
  2. mkfs.ext4 is /sbin/mkfs.ext4
  3. $$
  4. type mkfs.btrfs
  5. -bash: type: mkfs.btrfs: not found
  6. $

The preceding example on an Ubuntu system shows that the mkfs.ext4 utility is available. However, the Btrfs utility is not. See Chapter 9 on how to install additional software and utilities on your Linux distribution.

Each filesystem utility command has lots of command line options that allow you to customize just how the filesystem is created in the partition. To see all the command line options available, use the man command to display the manual pages for the filesystem command (see Chapter 3). All the filesystem commands allow you to create a default filesystem with just the simple command with no options:

  1. $ sudo mkfs.ext4 /dev/sdb1
  2. [sudo] password for Christine:
  3. mke2fs 1.41.12 (17-May-2010)
  4. Filesystem label=
  5. OS type: Linux
  6. Block size=4096 (log=2)
  7. Fragment size=4096 (log=2)
  8. Stride=0 blocks, Stripe width=0 blocks
  9. 131648 inodes, 526120 blocks
  10. 26306 blocks (5.00%) reserved for the super user
  11. First data block=0
  12. Maximum filesystem blocks=541065216
  13. 17 block groups
  14. 32768 blocks per group, 32768 fragments per group
  15. 7744 inodes per group
  16. Superblock backups stored on blocks:
  17. 32768, 98304, 163840, 229376, 294912
  18. Writing inode tables: done
  19. Creating journal (16384 blocks): done
  20. Writing superblocks and filesystem accounting information: done
  21. This filesystem will be automatically checked every 23 mounts or
  22. 180 days, whichever comes first. Use tune2fs -c or -i to override.
  23. $

The new filesystem uses the ext4 filesystem type, which is a journaling filesystem in Linux. Notice that part of the creation process was to create the new journal.

After you create the filesystem for a partition, the next step is to mount it on a virtual directory mount point so you can store data in the new filesystem. You can mount the new filesystem anywhere in your virtual directory where you need the extra space.

  1. $ ls /mnt
  2. $$
  3. sudo mkdir /mnt/my_partition
  4. $$
  5. ls -al /mnt/my_partition/
  6. $$
  7. ls -dF /mnt/my_partition
  8. /mnt/my_partition/
  9. $$
  10. sudo mount -t ext4 /dev/sdb1 /mnt/my_partition
  11. $$
  12. ls -al /mnt/my_partition/
  13. total 24
  14. drwxr-xr-x. 3 root root 4096 Jun 11 09:53 .
  15. drwxr-xr-x. 3 root root 4096 Jun 11 09:58 ..
  16. drwx––. 2 root root 16384 Jun 11 09:53 lost+found
  17. $

The mkdir command (Chapter 3) creates the mount point in the virtual directory, and the mount command adds the new hard drive partition to the mount point. The -t option on the mount command indicates what filesystem type, ext4, you are mounting. Now you can save new files and folders on the new partition!

Note

This method of mounting a filesystem only temporarily mounts the filesystem. When you reboot your Linux system, the filesystem doesn’t automatically mount. To force Linux to automatically mount the new filesystem at boot time, add the new filesystem to the /etc/fstab file.

Now that the filesystem is mounted within the virtual directory system, it can start to be used on a regular basis. Unfortunately, with regular use comes the potential for serious problems, such as filesystem corruption. The next section looks at how to deal with these issues.


0 Response to "Creating a Filesystem On Linux"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel