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.
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.
Not all filesystem utilities are installed by default. To determine whether you have a particular filesystem utility, use the type command:
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 |
Not all filesystem utilities are installed by default. To determine whether you have a particular filesystem utility, use the type command:
- $ type mkfs.ext4
- mkfs.ext4 is /sbin/mkfs.ext4
- $$
- type mkfs.btrfs
- -bash: type: mkfs.btrfs: not found
- $
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:
- $ sudo mkfs.ext4 /dev/sdb1
- [sudo] password for Christine:
- mke2fs 1.41.12 (17-May-2010)
- Filesystem label=
- OS type: Linux
- Block size=4096 (log=2)
- Fragment size=4096 (log=2)
- Stride=0 blocks, Stripe width=0 blocks
- 131648 inodes, 526120 blocks
- 26306 blocks (5.00%) reserved for the super user
- First data block=0
- Maximum filesystem blocks=541065216
- 17 block groups
- 32768 blocks per group, 32768 fragments per group
- 7744 inodes per group
- Superblock backups stored on blocks:
- 32768, 98304, 163840, 229376, 294912
- Writing inode tables: done
- Creating journal (16384 blocks): done
- Writing superblocks and filesystem accounting information: done
- This filesystem will be automatically checked every 23 mounts or
- 180 days, whichever comes first. Use tune2fs -c or -i to override.
- $
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.
- $ ls /mnt
- $$
- sudo mkdir /mnt/my_partition
- $$
- ls -al /mnt/my_partition/
- $$
- ls -dF /mnt/my_partition
- /mnt/my_partition/
- $$
- sudo mount -t ext4 /dev/sdb1 /mnt/my_partition
- $$
- ls -al /mnt/my_partition/
- total 24
- drwxr-xr-x. 3 root root 4096 Jun 11 09:53 .
- drwxr-xr-x. 3 root root 4096 Jun 11 09:58 ..
- drwx––. 2 root root 16384 Jun 11 09:53 lost+found
- $
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