Thursday, May 5, 2011

Partition with fdisk


fdisk is started by typing (as root) fdisk device at the command prompt. device might be something like /dev/hda or /dev/sda.
To check the list of devices available type fdisk -l
The basic fdisk commands you need are:
p – Print the partition table.
n – Create a new partition.
d – Delete a partition.
q – Quit without saving changes.
a – Make a partition bootable.
w – Write the new partition table and exit.
Changes you make to the partition table do not take effect until you issue the write (w) command. Here is a sample partition table:

 
Disk /dev/sdb: 64 heads, 63 sectors, 621 cylinders
Units = cylinders of 4032 * 512 bytes
 
   Device Boot    Start       End    Blocks   Id  System
/dev/sdb1   *         1       184    370912+  83  Linux
/dev/sdb2           185       368    370944   83  Linux
/dev/sdb3           369       552    370944   83  Linux
/dev/sdb4           553       621    139104   82  Linux swap

Now here is how to partition a USB Drive for example:
1.      Type: fdisk /dev/sda or fdisk /dev/sdb (whatever may be your drive; to be sure which one is your drive just enter the USB Stick and check in the /dev, you will see a new device sda or sdb or sdc etc. is shown which was not there before inserting the stick.)
2.      Type: p to print the partition table of this device.
Command (m for help): p
 
Disk /dev/sdb: 64 heads, 63 sectors, 621 cylinders
Units = cylinders of 4032 * 512 bytes

3.      Now to create new partition type: n
        Command (m for help): n
        Command action
           e   extended
           p   primary partition (1-4)
Type: p for primary partition, and then do the following:
Partition number (1-4): 1
First cylinder (1-621, default 1) :<ENTER>
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-621, default 621):+384M
+384 – This is the size of the partition in MB; give whatever size you want.
4.      Next to set up the partition for swap, just create another partition the same way:
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (197-621, default 197):
Using default value 197
Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): +128M
2 more partitions can be created the same way.
5.      Make the first partition bootable:
Command (m for help): a
Partition number (1-4): 1

6.      Make second partition of type swap:
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)      
Command (m for help): p

7.      Finally issue a write command w to write the partition on to the disk. Without this command the changes will not be retained.


No comments:

Post a Comment