Total Pageviews

Translate

September 13, 2015

How to make partitions using "fdisk" command in linux

by 4hathacker  |  in System Administration at  3:33 AM

Step 1 : Check partitions by this command 

[root@4hathacker Desktop]# fdisk -cul

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0xed10b684

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    31789055    15893504    c  W95 FAT32 (LBA)
/dev/sda2   *    31791104    32507903      358400    7  HPFS/NTFS
/dev/sda3        32507904   242228069   104860083    7  HPFS/NTFS
/dev/sda4       242228073   976766975   367269451+   f  W95 Ext'd (LBA)
Partition 4 does not start on physical sector boundary.
/dev/sda5       242228136   705349889   231560877    7  HPFS/NTFS
/dev/sda6       705353728   706377727      512000   83  Linux
/dev/sda7       706379776   962379775   128000000   83  Linux
/dev/sda8       962381824   968689663     3153920   82  Linux swap / Solaris
step 2 : See, what is name of your device like /dev/sda or /dev/vda or /dev/sdb 
Step 3 : See other information by the " df " command  ; It will show ,where your  devices are mounted .

[root@4hathacker Desktop]# df -hT
Filesystem     Type   Size  Used Avail Use% Mounted on
/dev/sda7      ext4   121G   74G   41G  65% /
tmpfs          tmpfs  1.9G   84K  1.9G   1% /dev/shm
/dev/sda6      ext4   477M   35M  417M   8% /boot
Step 4 : My device name is /dev/sda , so i will use it .
 Note : when you run "fdisk /dev/sda" command then you are going in the fdisk's command line.
 
[root@4hathacker Desktop]# fdisk /dev/sda

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

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):

Note : these are the fdisk commands which we will use.

Command (m for help): help
h: unknown command
Command action
   a   toggle a bootable flag
   b   edit bsd disk label
   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 disk label
   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)

Command (m for help):

Step 5 : Now i am making a partition ; use these keywords to make partitions :
1)       p   print the partition table  
2)       n   add a new partition

see added partiton by using "p" . If you see right then save and close by the "w" ,otherwise use "q" to close without saving . These two close :
1)       q   quit without saving changes
2)       w  quit with saving changes OR write table to disk and exit

 Now we have done with making of partitions.

***Note *** : These partitions will work after reboot . If you want to use it at live time then please use this command :
for rhel6  use "partx -a /dev/sda "
for rhel7 use "partprobe "
And check by "cat /proc/partitions" .


To use this partition: Format this partion and then mount  OR permanent mount .

[root@4hathacker Desktop]# mkfs.ext4 /dev/sda8

***Note*** : To make it permanent , make it entry in "/etc/fstab" 
[root@4hathacker Desktop]# mkdir /media/xyz
[root@4hathacker Desktop]# gedit /etc/fstab

Add this line in  /etc/fstab (here /dev/sda8 is my partition name and /media/xyz is my mount point)

/dev/sda8 /media/xyz  ext4  defaults  0  0 

And then always use "mount   -a" to check ; if no error then you are right.

Troubleshooting

1) In fdisk command line, use "d" to delete partition .
 2) In fdisk command line, use   "l"  to list known partition types.

*****NOTE***** 
In order for more queries please comment below:

0 comments:

Like Our Facebook Page

Nitin Sharma's DEV Profile
Proudly Designed by 4hathacker.