Thursday, May 27, 2010

Creating New Partition and File System in Linux

Creating a new partition and file system, a.k.a formatting in Windows world is very easy. We can do that in just few clicks (right click, format, and select the file system). Creating a new partition and file system in Linux, however, is not that easy. Here I'm gonna show you how to do it.

You need to run these steps as root.
1. Run 'fdisk '
# fdisk /dev/sdb
If you're creating a new partition in the first SATA/SCSI disk, the device name will be /dev/sda, if it's a second SATA/SCSI disk, it'll be /dev/sdb and so on. If the device is the first master IDE disk, it'll be /dev/hda and so on.
2. Choose n to add a new partition.
3. Choose e for extended or p for primary.
4. Accept the default values for first and last cylinder if you wish to partition the whole disk.
5. Choose w to write the table to disk.
If suppose you've created the first partition in the second SATA/SCSI disk, you should be able to see that /dev/sdb1 has been created in your file system.
6. The next step is to create a file system on that partition. The command is 'mkfs -t '
# mkfs -t ext4 /dev/sdb1
The here can be ext2, ext3, ext4, etc. The here should be /dev/sdb1 and NOT /dev/sdb.
7. The last step is to mount this partition. To do that, execute 'mount -t '
# mkdir -p /mnt/newdisk
# mount -t ext4 /mnt/newdisk
To see if your partition has been mounted successfully. Run 'mount' or 'cat /etc/mtab'.
To mount it permanently, you need to create a new entry in the /etc/fstab as shown below.
/dev/sdb1            /mnt/newdisk         ext4       acl,user_xattr        1 2
The value last second option 1 specifies whether or not the file system should be dumped. 1 means dump. 0 means don't dump.
The value last option 2 specifies the order in which fsck should check the file system at reboot. For root partition, it should be 1, other partitions should be 2.

No comments:

Post a Comment