[Solved] Creating unformatted partition

I needed to create a un-formatted partition of X MB on a disk dont want it from GUI but from command line not sure what should be specified for fdisk

Please provide OS information first. Commands and options for fdisk utility varies from OS to OS. Here's what I would do on a RHEL system to create 30MB partition! :wink:

[root@testserv-sl6 ~]# 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): 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)

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: 0x00092e03

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         244     1953125   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2             244         487     1952768   83  Linux
Partition 2 does not end on cylinder boundary.
/dev/sdb3             487         730     1952768   83  Linux
Partition 3 does not end on cylinder boundary.
/dev/sdb4             730        1045     2529280   83  Linux

Command (m for help): d
Partition number (1-4): 1

Command (m for help): d
Partition number (1-4): 2

Command (m for help): d
Partition number (1-4): 3

Command (m for help): d
Selected partition 4

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: 0x00092e03

   Device Boot      Start         End      Blocks   Id  System

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): 1
Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +30M

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: 0x00092e03

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1           5       40131    5  Primary

Command (m for help): w

Ok i forgot that fdisk only creates the partition as un-formatted then you have to use mke2fs to create partition.

In anyways can this automated I mean can all these options be specified via script i'm asking since its a interactive process.Would like to avoid expect script here.

parted has a command line mode that can be scripted.

Thanks parted just meets my requirements