Tuesday, August 3, 2010

How to partition a linux drive or raw disk?

Here are the steps those I followed :

servername : abc
New device attached : /dev/sdc //You'll view it by executing fdisk -l command.

Example :

====
root@abc [~]# fdisk -l

Disk /dev/sda: 251.0 GB, 251059544064 bytes
255 heads, 63 sectors/track, 30522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 274 2096482+ 82 Linux swap / Solaris
/dev/sda3 275 30522 242967060 83 Linux

Disk /dev/sdb: 251.0 GB, 251059544064 bytes
255 heads, 63 sectors/track, 30522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System

Disk /dev/sdc: 251.0 GB, 251000193024 bytes
255 heads, 63 sectors/track, 30515 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn't contain a valid partition table
root@abc [~]#
====

Steps to partition the disk :

=======
1.
root@sbc[/]#fdisk /dev/sdc
Command (m for help): d
Selected partition 4

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-30515, default 1): //press enter
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-30515, default 30515): //press enter
Using default value 30515

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Note : /dev/sdc1 has created here.
============

2.
root@abc [~]# mkfs.ext3 /dev/sdc1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
30654464 inodes, 61277926 blocks
3063896 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
1871 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: 547/1871
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
root@abc [~]#
---------------------------------

3.
mkdir /disk2
# mount /dev/sdc1 /disk2
# df -H
# vi /etc/fstab

Append as follows:

/dev/sdc1 /disk2 ext3 defaults 1 2
============


Task: Label the partition

You can label the partition using e2label. For example, if you want to labelthe new partition /backup, enter
# e2label /dev/sdb1 /backup
You can use label name insted of partition name to mount disk using /etc/fstab:

LABEL=/backup /disk2 ext3 defaults 1 2
========

That's it try :)

No comments:

Post a Comment