HowTo: Formatting Linux Filesystem
A typical Linux system
usually has at least three separate partitions. They are labelled /, /boot, and swap.
The / (pronounced root) is the parent of the directory structure.
/boot is where the system kernel and map files reside.
The swap partition is used when parts of memory need to be moved to the hard drive because of over-commitment. This is called being swapped out to disk.
The following are usually on separate partitions:
/: It is the parent directory
/boot: The boot and map files are located in here
(swap): It signifies the swap space
The following are traditionally on a separate partition, but do not have to be:
/home
/tmp
/etc
/var
------------------------
device: It refers to the entire disk. For example, the first SCSI disk is normally named
/dev/sda.
partition: It is the device name followed by a number. The first SCSI partition would
be /dev/sda1.
filesystem: It defines the type of filesystem being used. Some examples are ext2,
ext3, ext4, vfat, and xfs.
mount point: It is the directory that points to the partition. The /etc/fstab file
contains a table showing mount points and the partitions they are associated with.
This file, which is created by a system installer such an Anaconda, can be manually
edited by the superuser to add or delete devices and mounts.
The boot partition is where the operating system kernel and other startup files are located.
Here is a description of the files found in /boot:
The fdisk program is used to manipulate the disk partition table.
The mkfs program will destroy any data currently residing in the partition.
Be sure to unmount the partition before proceeding.
The fsck program if used incorrectly, can corrupt the data currently residing on the partition.
The device must be unmounted before running the command.
LVM for Linux allows one to manage disks or arrays of disks as one large pool of storage.
An LVM consists of one or more physical volumes along with one or more logical volumes.
Directories such as /root and /home for example, are located in a logical volume. Several
commands exist to manage the LVM. Some operate on physical volumes, some operate
on logical volumes, and some on both.
The following list can be used as a quick
----------------------
Let’s see all the physical volumes on the system:
pvdisplay
Now let’s scan the disks:
pvscan
Then, display the attributes of the volume groups:
vgdisplay
We report information about volume groups:
vgs
The disks for all the volume groups are then scanned:
vgscan
Then the attributes for the logical volume (this one gets used a lot) need to be displayed:
lvdisplay
----------------------
Formatting Linux filesystem is an essential task for sysadmin and may required for many reasons such as installing a new disk on server. If you want to expand file system or you just add a new hard disk drive or create separate partitions for security and performance reasons. Whatever may be your reason(s) all file system creating involves creations of superblock, inode and other filesystem metadata structure. Fortunately, Linux comes with mkfs command to format filesystem. It is used to build a Linux file system on a device, usually a hard disk partition. General syntax of mkfs is as follows:
mkfs -t filetype /dev/DEVICE
OR
mkfs.ext3 /dev/DEVICE
OR
mkfs.ext4 /dev/DEVICE
Sample outputs:
usually has at least three separate partitions. They are labelled /, /boot, and swap.
The / (pronounced root) is the parent of the directory structure.
/boot is where the system kernel and map files reside.
The swap partition is used when parts of memory need to be moved to the hard drive because of over-commitment. This is called being swapped out to disk.
The following are usually on separate partitions:
/: It is the parent directory
/boot: The boot and map files are located in here
(swap): It signifies the swap space
The following are traditionally on a separate partition, but do not have to be:
/home
/tmp
/etc
/var
------------------------
device: It refers to the entire disk. For example, the first SCSI disk is normally named
/dev/sda.
partition: It is the device name followed by a number. The first SCSI partition would
be /dev/sda1.
filesystem: It defines the type of filesystem being used. Some examples are ext2,
ext3, ext4, vfat, and xfs.
mount point: It is the directory that points to the partition. The /etc/fstab file
contains a table showing mount points and the partitions they are associated with.
This file, which is created by a system installer such an Anaconda, can be manually
edited by the superuser to add or delete devices and mounts.
The boot partition is where the operating system kernel and other startup files are located.
Here is a description of the files found in /boot:
The fdisk program is used to manipulate the disk partition table.
The mkfs program will destroy any data currently residing in the partition.
Be sure to unmount the partition before proceeding.
The fsck program if used incorrectly, can corrupt the data currently residing on the partition.
The device must be unmounted before running the command.
LVM for Linux allows one to manage disks or arrays of disks as one large pool of storage.
An LVM consists of one or more physical volumes along with one or more logical volumes.
Directories such as /root and /home for example, are located in a logical volume. Several
commands exist to manage the LVM. Some operate on physical volumes, some operate
on logical volumes, and some on both.
The following list can be used as a quick
----------------------
Let’s see all the physical volumes on the system:
pvdisplay
Now let’s scan the disks:
pvscan
Then, display the attributes of the volume groups:
vgdisplay
We report information about volume groups:
vgs
The disks for all the volume groups are then scanned:
vgscan
Then the attributes for the logical volume (this one gets used a lot) need to be displayed:
lvdisplay
----------------------
Formatting Linux filesystem is an essential task for sysadmin and may required for many reasons such as installing a new disk on server. If you want to expand file system or you just add a new hard disk drive or create separate partitions for security and performance reasons. Whatever may be your reason(s) all file system creating involves creations of superblock, inode and other filesystem metadata structure. Fortunately, Linux comes with mkfs command to format filesystem. It is used to build a Linux file system on a device, usually a hard disk partition. General syntax of mkfs is as follows:
mkfs -t filetype /dev/DEVICE
OR
mkfs.ext3 /dev/DEVICE
OR
mkfs.ext4 /dev/DEVICE
- -t filetype : File system type, it can be ext3, ext2, etc4, vfat etc
- /dev/DEVICE : Your device name i.e. partition /dev/hda1 or /dev/sda1 etc.
An example
Suppose you would like to format /dev/hda5 with ext3 file system.
Warning: The first task is to allocate disk space for Linux. You will need to set up a partitioning scheme for your hard disk using a program called fdisk command.
Step #1 Create the new filesystem with following command (first login in as a root user)
# mkfs.ext3 /dev/sda5
Sample outputs:
mke2fs 1.35 (28-Feb-2004) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 30120 inodes, 120456 blocks 6022 blocks (5.00%) reserved for the super user First data block=1 15 block groups 8192 blocks per group, 8192 fragments per group 2008 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 38 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Step # 2: Create mount point directory for the file system
# mkdir /datadisk1
Step # 3: Mount the new file system
# mount /dev/sda5 /datadisk1
Step # 4: Finally make sure file system /dev/hda5 automatically mounted at /datadisk1 mount point after system reboots. You need to add partition to /etc/fstab file. Use text editor such as vi to add following entry
# vi /etc/fstab
Add/append following entry to file:
/dev/sda5 /datadisk1 ext3 defaults 0 2
Where,
- /dev/sda5 : File system or parition name
- /datadisk1 : Mount point
- ext3 : File system type
- defaults : Mount options (Read man page of mount command for all options)
- 0 : Indicates whether you need to include or exclude this filesystem from dump command backup. Zero means this filesystem does not required dump.
- 2 : It is used by the fsck program to determine the order in which filesystem checks are done at reboot time. The root (/) filesystem should be specified with a #1, and otherfilesystems should have a # 2 value.
Save file and exit to shell prompt. For more information see mkfs(8) page.
Comments
Post a Comment