Wednesday, May 11, 2011

Detecting new hard disk ,creating partition,formating a partition,creating mount point point for storage purpose on linux platform

Detecting new hard disk ,creating partition,formating a partition,creating mount point point for storage,Using the mount point for storage on linux platform :
-------------------------------------------------------------------------------------
For becoming a best DBA we should have sound knowledge of operating system.The below experiment will be very useful for creating partition on linux ,formating the partition and mounting the disk for our storage purpose.

I got the 50 GB hard disk from my system admin,Now I want to use this hard disk for
storing backup of Database files.before doing I need to do the below steps:

Pre-requistics step:
--------------------

For detecting hard disk in linux server you need to reboot.We can do as follows:
[root@testNODE ~]# shutdown -r now
Broadcast message from root (pts/0) (Wed Apr 20 01:23:45 2009).

The system is going down for reboot NOW!

Note: 'reboot' command is also used.
----
Once ther server is up you can detect your hard disk as follows:

[root@testNODE ~]# fdisk -l =>This is for checking disk in linux.

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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 4633 36700492+ 83 Linux
/dev/sda3 4634 5482 6819592+ 83 Linux
/dev/sda4 5483 7832 18876375 5 Extended
/dev/sda5 5483 6265 6289416 82 Linux swap / Solaris
/dev/sda6 6266 7030 6144831 83 Linux
/dev/sda7 7031 7683 5245191 83 Linux

Disk /dev/sdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 4981 40009851 83 Linux
/dev/sdb2 4982 5221 1927800 83 Linux

Disk /dev/sdc: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdc doesn't contain a valid partition table

So here is my new hard disk '/dev/sdc'.I will create a valid partition for this disk.For creating a valid partition we need to follow below steps:

Step 1: Use the command 'fdisk' as follows:
-------


[root@testNODE ~]# fdisk /dev/sdc
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.

The number of cylinders for this disk is set to 6527.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Step 2: To get help for various partition options use 'm' option
-------


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)

Step 3:As seen above 'n' is used to create a new partition,'e' for extended
---------
partition,'1' is the primary partition used 'w' is for writing to disk


Command (m for help): n =>For creating new partition
Command action
e extended
p primary partition (1-4)
p =>For primary partition
Partition number (1-4): 1
First cylinder (1-6527, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-6527, default 6527):
=>Above you can specify size as +5G,+10G,...if you want to create 2 or more partition,I want to create only 1 partition of size 50G(default value of cylinder)
so I have not given any values.

Command (m for help): p =>for print of partitions which are created.

Disk /dev/sdc: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdc1 1 6080 48837568+ 83 Linux

Command (m for help): w =>for writing and saving the partition
The partition table has been altered!

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

So our partition is created with 50GB of space.

Step 4: Check the filesystems types available
-------


[root@testNODE ~]# cat /etc/filesystems =>Gives types of filesystem available in OS
ext3
ext2
nodev proc
nodev devpts
iso9660
vfat
hfs
hfsplus

Step 5:Our attached hard disk is created with extended based filesystem i.e ext3
------


[root@testNODE ~]# fdisk -l /dev/sdc =>For checking the partition

Disk /dev/sdc: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdc1 1 6080 48837568+ 83 Linux

So,as you see above we created one partition with size 50GB.

Step 6:Format your partition before mounting
------


a)Check your filesystem with 'e2fsck':
-------------------------------------------


[root@testNODE /]# e2fsck -b 8193 /dev/sdc
e2fsck 1.39 (29-May-2006)
e2fsck: Bad magic number in super-block while trying to open /dev/sdc

The superblock could not be read or does not describe a correct ext2
filesystem. If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193

From the above error I came to know the partition is not formated,Now for formating use 'mke2fs' for formating extended
filesystem.

[root@testNODE /]# e2fsck -b 8193 /dev/sdc1 =>For filesystem check i.e extended here
e2fsck 1.39 (29-May-2006)
e2fsck: Bad magic number in super-block while trying to open /dev/sdc1

The superblock could not be read or does not describe a correct ext2
filesystem. If the device is valid and it really contains an ext2
filesystem (and not swap or ufs or something else), then the superblock
is corrupt, and you might try running e2fsck with an alternate superblock:
e2fsck -b 8193

Note 1:'e2fsck' is used to check a Linux ext2/ext3 file system.
Note 2: 'fsck' is used to check and repair a Linux file system

b)Format your partition with 'mke2fs'
------------------------------------------------


[root@testNODE /]# sudo file -s /dev/sdc1
/dev/sdc1: x86 boot sector
[root@testNODE /]# sudo mke2fs -S /dev/sdc1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
6553600 inodes, 13107024 blocks
655351 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
400 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

Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

[root@testNODE /]# sudo mke2fs -j /dev/sdc1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
6553600 inodes, 13107024 blocks
655351 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
400 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

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

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.


Below are very important notes based on above experiment:
-------------------------------------------------------------


Note 1:'mke2fs' is used to format the extended filesystem.
-------


Note 2:In 'mke2fs' -S option is a very good option as it Write superblock and group descriptors only.
-------
This is useful if all of the superblock and backup superblocks are corrupted, and a last-ditch recovery method is desired. It causes mke2fs to
reinitialize the superblock and group descriptors, while not touching the inode table and the
block and inode bitmaps.

Note 3:'mkfs' is used to build a Linux file system on a device, usually a hard disk partition. filesystem is the device name (e.g. /dev/hda1, /dev/sdb2). blocks is the number of blocks to be used for the file system.
The exit code returned by mkfs is 0 on success and 1 on failure.

Note 4=>'mke2f' -j=>Create the filesystem with an ext3 journal (given the size of the filesystem)

=> So our extended filesystem is formated.

Step 7: Make an entry in /etc/fstab to detect a mount point even after re-boot.
--------


vi /etc/fstab
=>Add the below line.

/dev/sdc1 /u05 ext3 defaults 1 2


Step 8: Mount the filesystem.
-------

Create a directory for mounting as follows:
[root@testNODE /]# mkdir /u05

Once the directory is created we can use this for mounting purpose.
We have to use the 'mount' command to mount a disk with the option as given below.

[root@testNODE /]# mount -t ext3 /dev/sdc1 /u05
=>The above command is for mounting the partition
Here: -t=>is used to indicate the file system type
ext3=>is the filesystem type i.e extended as per entry in the /etc/fstab
/dev/sdc1=>raw disk partition used for mounting
/u05=>Directory used for mounting

[root@testNODE /]# df -h =>For checking the mount point you have created and diskspace utilization.
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 5.7G 4.0G 1.5G 73% /
/dev/sda7 4.9G 4.1G 515M 90% /u01
/dev/sda3 6.3G 1.7G 4.3G 29% /u03
/dev/sda2 34G 32G 719M 98% /u02
/dev/sda1 487M 17M 445M 4% /boot
tmpfs 2.0G 1.4G 641M 68% /dev/shm
/dev/sdb1 38G 34G 2.1G 95% /u04
/dev/sdc1 50G 180M 47G 1% /u05

Let us do filesystem check now after mounting:

[root@testNODE /]# e2fsck -b 8193 /dev/sdc
e2fsck 1.39 (29-May-2006)
e2fsck: Device or resource busy while trying to open /dev/sdc
Filesystem mounted or opened exclusively by another program?

As you see above our raw disk mounted and ready to use.

Step 9:Granting ownership and permission to 'Oracle' user
-------

Once the directory is mounted now let us grant the ownership to 'Oracle' user so that this disk can be used
for various purposes by 'Oracle' owner.

[root@testNODE u05]# chown oracle:oinstall /u05
[root@testNODE u05]# chmod -R 775 /u05

Here:
chown:Granting ownership to operating system user 'Oracle'.
chmod:Granting permission to operating system user 'Oracle'.


Step 10: Login to 'Oracle' user to verify:
--------


[oracle@testNODE u05]$ mkdir TEST
[oracle@testNODE u05]$ cd TEST
[oracle@testNODE TEST]$ touch test1
[oracle@testNODE TEST]$ ls -altr
total 8
drwxrwxr-x 4 oracle oinstall 4096 May 11 17:21 ..
-rw-r--r-- 1 oracle dba 0 May 11 17:22 test1
drwxr-xr-x 2 oracle dba 4096 May 11 17:22 .

Note:'touch' command is used to create an empty file in linux(unix) for creating empty file with 0 byte size'
----

So our directory '/u05' is ready for use.My friends keep on saying me they need more on unix from DBA's point of view.This is just a basic experiment.

Hope it helps.

Best regards,

Rafi.

No comments:

Post a Comment