Thursday, November 22, 2012

How to Creating Partition table on linux using fdisk

I will create two partitions, the first one for data and one for swap, for data I would use 8 GB. while the remaining 500 MB for the swap. let's get started: D I need to know, where is my disk attached, there is a lot way to know, where is my device attached, but here i use my way :D
# dmesg | grep blocks:
   sd 2:0:0:0: [sda] 41943040 512-byte logical blocks: (21.4 GB/20.0 GiB)
   sd 3:0:0:0: [sdb] 16777216 512-byte logical blocks: (8.58 GB/8.00 GiB)
Or
# cat /proc/partitions
   major minor  #blocks  name
   8        0   20971520 sda
   8        1   10240000 sda1
   8        2    1024000 sda2
   8        3    9706496 sda3
   8       16    8388608 sdb
Or
# fdisk -l
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 Disk /dev/sdb doesn't contain a valid partition table
Oke, i know my new disk attached to /dev/sdb and i can start creating partititon table on my new disk with following step :
# fdisk /dev/sdb

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

Start creating first partition, which contains 8GB  data and 500 MB swap
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): +8000MB 

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

Choosing swap file type for partition number 2
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap / Solaris)
Write all what you done :D
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
Check what you done :D
# fdisk -l /dev/sdb
Device Boot      Start        End      Blocks   Id  System
/dev/sdb1           1         974     7823623+  83  Linux
/dev/sdb2         975        1044      562275   82  Linux swap / Solaris
Done

No comments: