Wednesday, January 6, 2016

Using newly attached HDD




To detect and create a new partition after assigning a new HDD to the Linux server:

Note:
If the newly attached HDD is not visible in 'fdisk -l' command output, you need to rescan the drive.

Run below commands:
# echo "1" > /sys/class/scsi_host/host*/scan

Now check the 'fdisk -l' command output.

1. Identify the newly assigned HD:
# fdisk -l | grep '^Disk'

Assuming that the newly assigned disk is 'sdd'.

2. Now create a new partition:
# fdisk /dev/sdd

press 'p' for printing partition table.
> p

Initially, it will not show anything as there is no partition on '/dev/sdd'.

3. press 'n' to create new partition.
> Command (m for help): n
> Command action
   e   extended
   p   primary partition (1-4)
> p
> Partition number (1-4): 1
> First cylinder (1-621, default 1):<RETURN>
> Using default value 1
> Last cylinder or +size or +sizeM or +sizeK (1-621, default 621):

Note: The partition no will be '1' if you are creating the first ever partition on that HDD.

4. Now press 't' for partition table type and code
> t
Hex code (type L to list codes): L

Give table type to "83" for creating Linux type filesystem.
Give table type to "8e" for creating Linux-LVM type filesystem.

5. Now check again the partition table:
> p

example:
   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         130     1044193+  8e  Linux LVM


6. Press 'w' to save the whole work:
> w

7. Run command to let the kernel know about this newly created partition.
# partprobe

8. Now, as you have created the partition in LVM mode, you need to make the LV on it.
For that:
# pvcreate /dev/sdd1

Check PV information:
# pvs

9. Now create VG on created 2 PVs:
# vgcreate vg01 /dev/sdd1

If there are two HDDs, to use two HDDs for one VG:
# vgcreate vg01 /dev/sdd1 /dev/sde1

Check with the command:
# vgs

10. Now create LV on created VG:
First check the PE value of VG:
# vgdisplay vg01 | grep PE
 Free  PE / Size       564 / 2.20 GiB

Now create the LV:
# lvcreate -l 564 vg01 -n lv01

Check the LV:
# lvs

11. Format the partition (based on other partitons filesystem in the server):

To make the filesystem of 'ext2' type:
# mkfs.ext2 /dev/vg01/lv01

OR
To make the filesystem of 'ext3' type:
# mkfs.ext3 /dev/vg01/lv01

OR
To make the filesystem of 'ext4' type:
# mkfs.ext4 /dev/vg01/lv01


12. Create mountpoint:
# mkdir /oracle3

and then mount the partition:
# mount /dev/vg01/lv01 /oracle3

13. To make it permanent, edit the fstab file:
# cp /etc/fstab /tmp/fstab_orig

# vim /etc/fstab
/dev/mapper/vg01-lv01 /oracle1 ext3 defaults        1 2


No comments:

Post a Comment