Tuesday 11 October 2011

Create Linux Partition -- Add New HDD to Linux


[root@Grid-DB ~]# fdisk -l

Disk /dev/xvda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start    End   Blocks   Id System
/dev/xvda1   *       1     16   128488+  83 Linux
/dev/xvda2          17     408  3148740  82 Linux swap / Solaris
/dev/xvda3         409    1044  5108670  83 Linux

Disk /dev/xvdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/xvdb doesn't contain a valid partition table
7. Create a primary partition on the device identified above.

[root@Grid-DB ~]# fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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 or +size or +sizeM or +sizeK (1-1044, default 1044):
Using default value 1044

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

Calling ioctl() to re-read partition table.
Syncing disks.
8. Add a filesystem to the new partition.

[root@Grid-DB ~]# mkfs -t ext3 /dev/xvdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1048576 inodes, 2096474 blocks
104823 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 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

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

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@Grid-DB ~]#
Then add the necessary commands to the /etc/fstab file before issuing the mount command to mount the new device as shown below. 
[root@Grid-DB ~]# vi /etc/fstab

LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
LABEL=SWAP-xvda2        swap                    swap    defaults        0 0
/dev/xvdb1              /u01                    ext3    defaults        1 1

[root@Grid-DB ~]# mkdir /u01
[root@Grid-DB ~]# mount /u01
[root@Grid-DB ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda3            4.8G  2.5G  2.1G  55% /
/dev/xvda1            122M   13M  104M  11% /boot
tmpfs                 1.1G     0  1.1G   0% /dev/shm
/dev/xvdb1            7.9G  147M  7.4G   2% /u01

No comments: