How to create new partition in linux system step by step guide with practical examples


How to create new partition in linux system step by step guide with practical examples

In this article we learn how to create a new partition as per your requirement and how to update the created partition of the linux system.

It is very essential task for a system administrator to manage the user data. If you required additional hard drive to store  data we have to add the additional hdd and  create a new partition for it. If we don’t aware about the operation when we delete a partition there is a chance to lost the user data.

Verify the partition list before creation a new partition

When we are going to create a new partition as per our requirement we have to view the partition table before do this. To view the partition table we execute the below command.

#fdisk –l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000ef612

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        1045     7875584   8e  Linux LVM

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Here we have two partitions which are /dev/sda1 and /dev/sda2.we add new  hdd  and that is /dev/sdb and we create a new partition on this disk.



Create a new partition


we add new  hdd  and that is /dev/sdb and we create a new partition on this disk.
To create a new partition we execute the below command .

[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x48bf2abc.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): 57M

Command (m for help): P

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x48bf2abc

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1           8       64228+  83  Linux

Command (m for help): W
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

How to create new partition in linux system step by step guide with practical examples
How to create new partition in linux system step by step guide with practical examples


First we need to  press “n” key to create new partition. After that we define the partition size, then press “p” key to print the table and finally we press ”w” key to save the table.

To update partition table after creating a new partition


After creating a new partition we need to update the partition table to update the partition table without reboot the system we use “partprobe” command.

After that we format the new partition and mount the the partition to access the partition to store data.

[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.43-WIP (20-Jun-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
16064 inodes, 64228 blocks
3211 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=65798144
8 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Now we create test directory to mount /dev/sdb1 partition. To do this we executes below commands.

[root@localhost ~]# mkdir /test
 [root@localhost ~]# mount /dev/sdb1 /test
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      6.5G  3.2G  3.0G  52% /
tmpfs                 244M     0  244M   0% /dev/shm
/dev/sda1             477M   72M  376M  17% /boot
/dev/sdb1              57M  1.3M   52M   3% /test

To mount permanently we need to entry in /etc/fstab .


SHARE

Admin

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment