Thursday, August 18, 2011

How to partitions in a hard disk using fdisk

Listing Details of the Hard Disks

[root@RHEL01 ~]# fdisk -l Disk /dev/sda: 999.6 GB, 999653638144 bytes 255 heads, 63 sectors/track, 121534 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 64 514048+ 83 Linux /dev/sda2 65 12812 102398310 83 Linux /dev/sda3 12813 19186 51199155 82 Linux swap / Solaris /dev/sda4 19187 121534 822110310 5 Extended /dev/sda5 19187 25560 51199123+ 83 Linux /dev/sda6 25561 121534 770911123+ 83 Linux Disk /dev/sdb: 999.6 GB, 999653638144 bytes 255 heads, 63 sectors/track, 121534 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 1 121534 976221823+ 83 Linux

Creating a Partition
For this purpose we need to find out which hard disk that we are going to partitioned. keep in mind that IDE hard disks can be seen as hda, hdb, hdc, etc., as well as SATA or SCSI can be seen as sda, sdb, sdc, etc,.

List your devices.
ll /dev/sd* brw-rw----. 1 root disk 8, 0 Aug 18 18:40 /dev/sda brw-rw----. 1 root disk 8, 1 Aug 18 18:40 /dev/sda1 brw-rw----. 1 root disk 8, 2 Aug 18 18:40 /dev/sda2 brw-rw----. 1 root disk 8, 16 Aug 18 18:40 /dev/sdb brw-rw----. 1 root disk 8, 32 Aug 18 18:40 /dev/sdc brw-rw----. 1 root disk 8, 48 Aug 18 18:40 /dev/sdd

Syntax:
fdisk <device>

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

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
t change a partition's system id
w write the new partition table and exit

Here we are going to make 4GB partition as first partition. Then 512MB swap space. Then extended partition of  3.5G which has 2GB and 1.5GB. at last we change the partition type (id) to 82 which is Linux swap. The write all to disk and exit.

There are some limitations when it comes to working with partitions. You can have only four partitions to a physical disk—with one exception. If you want to make more than the four, you need to create three primary partitions and one extended partition, although the primary partitions aren’t required for extended partition creation. The extended partition can then hold 11 logical partitions (5–16) on it.

[root@RHEL01 ~]# 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: 0x000896f3 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): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-1044, default 1044): +4G Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (524-1044, default 524): Using default value 524 Last cylinder, +cylinders or +size{K,M,G} (524-1044, default 1044): +512M Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 3 First cylinder (590-1044, default 590): Using default value 590 Last cylinder, +cylinders or +size{K,M,G} (590-1044, default 1044): Using default value 1044 Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (590-1044, default 590): Using default value 590 Last cylinder, +cylinders or +size{K,M,G} (590-1044, default 1044): +2G Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (852-1044, default 852): Using default value 852 Last cylinder, +cylinders or +size{K,M,G} (852-1044, default 1044): Using default value 1044 Command (m for help): t Partition number (1-6): 2 Hex code (type L to list codes): 82 Changed system type of partition 2 to 82 (Linux swap / Solaris) 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: 0x000896f3 Device Boot Start End Blocks Id System /dev/sdb1 1 523 4200966 83 Linux /dev/sdb2 524 589 530145 82 Linux swap / Solaris /dev/sdb3 590 1044 3654787+ 5 Extended /dev/sdb5 590 851 2104483+ 83 Linux /dev/sdb6 852 1044 1550241 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@RHEL01i sahan]#

Now task is completed and it need to be informed to the OS correctly. The Linux command for this is partprobe (inform the OS and kernel of partition table changes).  man partprobe will give you more details.
 SYNOPSIS:
       partprobe [-d] [-s] [devices...]
partprobe /dev/hdb
You can not found any out put here, it just informed the new partition table to OS.

No comments:

Post a Comment

MABM

Demo: Create MBAM 2.5 users and groups in Active Directory Domain Services Configure MBAM 2.5 Roles for the instance of SQL Server ...