Subscribe For Free Updates!

We'll not spam mate! We promise.

Monday, 29 September 2014

How to create new file system in Linux



Hello Friend's, In this session i am going to tall you how to create New File System in Linux.



***************Creatation of File system *****************
These are the basic step's before creating the FS.
1- Identity device
2- Partition device
3- Make file system
4- Label file system
5- Create a entry in /etc/fstab
6- Mount new file system
***************************************************


Linux File System






Step:1 Check the file system type and size
[root@trash3can/]# df -HTP
Filesystem    Type     Size   Used  Avail Use% Mounted on
/dev/sda1     ext3     8.2G   5.8G   2.0G  75% /
/dev/sda2     ext3     2.1G    37M   1.9G   2% /swap
tmpfs        tmpfs     531M      0   531M   0% /dev/shm

Step:2 To check the device (hda , sda) by using fdisk.check the new partition

[root@trash3can/]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1020     8193118+  83  Linux
/dev/sda2            1021        1275     2048287+  83  Linux


Note : here deive is sda

Step:3
[root@trash3can/]# fdisk /dev/sda
The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
press n to add a new partition
Command (m for help): n
   e   extended
   p   primary partition (1-4)
press p for primary partition p
Partition number (1-4): 3
First cylinder (1276-1305, default 1276):
Using default value 1276
Last cylinder or +size or +sizeM or +sizeK (1276-1305, default 1305):
Using default value 1305
p   print the partition table
Command (m for help): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1020     8193118+  83  Linux
/dev/sda2            1021        1275     2048287+  83  Linux
/dev/sda3            1276        1305      240975   83  Linux
w-write table to disk and exit
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

[root@trash3can/]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1020     8193118+  83  Linux
/dev/sda2            1021        1275     2048287+  83  Linux
/dev/sda3            1276        1305      240975   83  Linux


Step:4 while writing the partition table , the kernel encountered an error , and requested a reboot.This is normal , but unneccessary.View the contents of /proc/partitions
re
[root@trash3can/]# cat /proc/partitions
major minor  #blocks  name
   8     0   10485760 sda
   8     1    8193118 sda1
   8     2    2048287 sda2
The table will only reflect the original partitions.Execute partprobe and then again review /proc/partitions
[root@trash3can/]# partprobe
[root@trash3can/]# cat /proc/partitions
major minor  #blocks  name
   8     0   10485760 sda
   8     1    8193118 sda1
   8     2    2048287 sda2
   8     3     240975 sda3

Now you can see that kernel table is updated after running the partprobe command.Now you can see the sda3 partition.

Partprobe- reinitializes the kernel's in memory version of partitions table.

Step:5  Create an ext3 file system on the new partition and assign the label opt.

L - for file system labeling

File system labeling creates a layer of abstraction that allows you to identify filesystem by a unique label rather than the device name.

[root@trash3can/]# mkfs.ext3 -L opt /dev/sda3
mke2fs 1.39 (29-May-2006)
Filesystem label=opt
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
60480 inodes, 240972 blocks
12048 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
30 block groups
8192 blocks per group, 8192 fragments per group
2016 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729, 204801, 221185
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


Step:6 To see the file system lebel use blkid
[root@trash3can/]# blkid |grep opt
/dev/sda3: LABEL="opt" UUID="a2d2889b-6864-499a-a09c-2c2d55eb8f7d" SEC_TYPE="ext2" TYPE="ext3"
[root@trash3can/]# blkid
[root@trash3can~]# blkid
/dev/sda2: LABEL="/swap" UUID="301e794b-c712-4f29-8303-9411d470f97e" TYPE="ext3"
/dev/sda1: LABEL="/" UUID="d3bfad6c-da66-4db4-9217-023cd4119e24" TYPE="ext3"
/dev/cdrom: LABEL="RHEL/5.3 i386 DVD" TYPE="iso9660"
/dev/sda3: LABEL="/opt/" UUID="a2d2889b-6864-499a-a09c-2c2d55eb8f7d" TYPE="ext3"


Step:7 by using  e2label we can see the label
[root@trash3can~]# e2label /dev/sda3
/opt/

Step:8 Mount /opt/ directory by using mount command
[root@trash3can/]# mount LABEL=opt /opt/

Step:9 Make a permanent  in /etc/fstab
[root@trash3can/]# vim /etc/fstab
device name           mount point      file system type      options        dump-frequency     fsck_order
LABEL=opt               /opt               ext3                     defaults        0                        0

or
/dev/sda3

Step:9 mount -a command to mount the new file system under /opt
[root@trash3can/]# mount -a
Note : mount -a command to check the /etc/fstab and mount the new file system.This also checks for errors that might prevent your system from booting properly.



Step:11 Reboot the system to verify that the file system is automatically mounted after boot with df-HTP command

[root@trash3can/]# df -HTP
Filesystem    Type     Size   Used  Avail Use% Mounted on
/dev/sda1     ext3     8.2G   5.8G   2.0G  75% /
/dev/sda2     ext3     2.1G    37M   1.9G   2% /swap
tmpfs        tmpfs     531M      0   531M   0% /dev/shm
/dev/sda3     ext3     239M   6.4M   221M   3% /opt





Socializer Widget By trash3can
SOCIALIZE IT →
SHARE IT →

2 comments:

  1. "How to create a new file system" is a bit misleading.. EXT4 and XFS are examples of file systems, your instructions are merely informing the reader of how to create a new partition and format it. Also, there is no need to copy /etc/passwd to the new partition.

    ReplyDelete
    Replies
    1. I appreciate that you give time to read my post and thanx for your information, i agree with you there is no need to copy passwd file, so i removed the the same, apart from this every thing seems fine, On my Step:5 i created ext3 file system which is older file system but still in use,

      Delete