Thursday, January 17, 2013

Creating new disk Logical Volume Manager Linux

Purpose: This tutorial gives some basic commands to work with Logical Volume Manager in Linux to create a new logical disk. Logical Volume Manage allows you to manage disks group logically separating the logical volume from the physical disk set. This make extending logical drives easy.

Video Demo:

Steps to create a new logical volume:
1. Partition the disk device
  fdisk –l
  fdisk -u /dev/<device>
  n = new
  p = primary partition
  1 for first partition
  default = beginning of disk
  default = end of disk
  w = write
  fdisk –l
2. Create the physical disk drive
  pvcreate /dev/<partition_name>
3. Verify the new physical name
  pvdisplay
4. Create a volume group with the new physical disk name
  vgcreate <volume_group_name> /dev/<partition_name> 
5. Verify the volume group
  vgdisplay
6. Divide volume group into logical volume groups
  lvcreate -L <logical_volume_size>G --name <logical_volume_name> <volume_group_name>
7. Verify Logical Volume groups
  lvdisplay
8. Format Disk
  mkfs.ext4 /dev/<partition_name>/<logical_volume_name>
9. Make disk mountable for boot
  # if this is disk will always be attached add it to fstab
  #vi /etc/fstab
  #/dev/<partition_name>/<logical_volume_name> /<directory_name> ext3   defaults   0 0
  # if this disk will only be used this session just mount the disk directly
  # mount  /dev/<partition_name>/<logical_volume_name> /<directory_name>
  # if this disk will be moved from system to system mount it using /etc/rc.d/rc.local
  # This method will error the drive on the machine on boot if the disk
  # is not attached but will not require a linux boot repair.
  # vi /etc/rc.d/rc.local
  # mount  /dev/<partition_name>/<logical_volume_name> /<directory_name>
10. mount disk
  mkdir /<directory_name> –p
  mount /<directory_name>
  cd <directory_name>
  df -h

Example:
1. Partition the disk device
  fdisk –l
  fdisk -u /dev/sdb
  n = new
  p = primary partition
  1 for first partition
  default = beginning of disk
  default = end of disk
  w = write
  fdisk –l
2. Create the physical disk drive
  pvcreate /dev/sdb1
3. Verify the new physical name
  pvdisplay
4. Create a volume group with the new physical disk name
  vgcreate softwarevg /dev/sdb1 
5. Verify the volume group
  vgdisplay
6. Divide volume group into logical volume groups
  lvcreate -L 79G –-name softwarelv softwarevg
7. Verify Logical Volume groups
  lvdisplay
8. Format Disk
  mkfs.ext4 /dev/softwarevg/softwarelv
9. Make disk mountable for boot
  # if this is disk will always be attached add it to fstab
  #vi /etc/fstab
  #/dev/softwarevg/softwarelv /software ext3   defaults   0 0
  # if this disk will only be used this session just mount the disk directly
  # mount  /dev/softwarevg/softwarelv /software
  # if this disk will be moved from system to system mount it using /etc/rc.d/rc.local
  # This method will error the drive on the machine on boot if the disk
  # is not attached but will not require a linux boot repair.
  # vi /etc/rc.d/rc.local
  # mount  /dev/softwarevg/softwarelv /software
10. mount disk
  mkdir /software –p
  mount /software
  cd /software
  df –h