Difference between revisions of "Format And Mount local2"

From DISI
Jump to navigation Jump to search
Line 62: Line 62:
 
  /dev/soft2/soft_lv /export/soft2 ext4 defaults 1 2
 
  /dev/soft2/soft_lv /export/soft2 ext4 defaults 1 2
  
== Partition Disk ==
+
== RAID1 with LVM on an existing used logical volume ==
* https://www.techotopia.com/index.php/Adding_a_New_Disk_Drive_to_a_CentOS_System
+
'''Before starting, make sure that the disk that will mirror data is the same size or bigger than the drive being mirrored.'''
 +
 
 +
1. Check if the volume has free space for lvm logs. Mirror will fail if no free space available.
 +
pvscan
 +
example output:
 +
  PV /dev/sda2  VG centos          lvm2 [<222.57 GiB / 0    free]
 +
  PV /dev/sdb1  VG centos          lvm2 [<223.57 GiB / 0    free]
 +
  PV /dev/sdd1  VG local2          lvm2 [<7.28 TiB / <5.03 GiB free]
 +
If ''' PV /dev/sdd1  VG local2          lvm2 [<7.28 TiB / 0 free] ''' then do
 +
lvreduce -l -1 --resizefs /dev/<volume_group>/<logical_volume>
 +
for example : lvreduce -l -1 --resizefs /dev/local2/zinc_lv
 +
 
 +
 
 +
2. Check which disk will act as the mirror
 +
fdisk -l
 +
 
 +
 
 +
3. Extend the disk to volume group
 +
vgextend <volume_group> /dev/<disk>
 +
for example: vgextend local2 /dev/sdc
 +
To remove extension:
 +
vgreduce <volume_group> /dev/<disk>
 +
for example: vgreduce local2 /dev/sdc
 +
 
 +
 
 +
4. Convert current working logical volume to RAID1 and assign mirror
 +
lvconvert -m1 /dev/<volume_group>/<logical_volume> /dev/<disk>
 +
for example: lvconvert -m1 /dev/local2/zinc_lv /dev/sdc
 +
 
 +
5. It should say it was successful, to check syncing progress
 +
lvs -a -o +devices

Revision as of 23:13, 26 March 2021

Format Disk

Do these commands as root:

  • fdisk -l
    • Find disks/RAID disks to format
  • parted
  • print
  • mklabel gpt
  • mkpart logical 0GB 9995GB. (based on what we read in result of print above)
  • print. (to confirm)
  • quit


Mount storage disks using LVM

Reference guide: https://www.thegeekdiary.com/redhat-centos-a-beginners-guide-to-lvm-logical-volume-manager/

Scan devices to be used as physical volumes (PV)

  • lvmdiskscan

Initialize the block devices

  • pvcreate <drive1> <drive2> <...> ...
    • Example: pvcreate /dev/sdb /dev/sdc /dev/sdd

To double check PV

  • pvdisplay
  • pvscan
  • pvs

After PV, create a Volume Group (VG)

  • vgcreate <name of volume> <drive1> <drive2> <...> ...
    • Example: vgcreate soft2 /dev/sdb /dev/sdc /dev/sdd

To double check VG

  • vgs <VG name>
  • vgdisplay <VG name>

After VG, create a Logical Volume (LV)

  • lvcreate <options> <name of LV> <VG Name>
    • Example: lvcreate -l 100%FREE -n soft_lv soft2
      • -l is for storage space in percent, 100%FREE means use all space in VG
      • -n is for name of LV

Double Check LV

  • lvs /dev/<VG NAME>/<LV NAME>
  • lvdisplay /dev/<VG NAME>/<LV NAME>
  • lvscan

Last step, create a File System

  • mkfs.ext4 <options> /dev/<VG NAME>/<LV NAME>
  • Example: mkfs.ext4 /dev/soft2/soft_lv

It's time to mount Make the directory first:

  • mkdir <somewhere>
    • Example: mkdir /export/soft2
  • mount /dev/<VG NAME>/<LV NAME> <somewhere>
    • Example: mount /dev/soft2/soft_lv /export/soft2/

Make it permanent by editing fstab:

  • vim /etc/fstab
/dev/<VG NAME>/<LV NAME>      <somewhere>       <type of file system>      <mount options>      <dump>         <fsck>
example:
/dev/soft2/soft_lv	/export/soft2	ext4	defaults	1	2

RAID1 with LVM on an existing used logical volume

Before starting, make sure that the disk that will mirror data is the same size or bigger than the drive being mirrored.

1. Check if the volume has free space for lvm logs. Mirror will fail if no free space available.

pvscan
example output:
 PV /dev/sda2   VG centos          lvm2 [<222.57 GiB / 0    free]
 PV /dev/sdb1   VG centos          lvm2 [<223.57 GiB / 0    free]
 PV /dev/sdd1   VG local2          lvm2 [<7.28 TiB / <5.03 GiB free]

If PV /dev/sdd1 VG local2 lvm2 [<7.28 TiB / 0 free] then do

lvreduce -l -1 --resizefs /dev/<volume_group>/<logical_volume>
for example : lvreduce -l -1 --resizefs /dev/local2/zinc_lv


2. Check which disk will act as the mirror

fdisk -l


3. Extend the disk to volume group

vgextend <volume_group> /dev/<disk>
for example: vgextend local2 /dev/sdc

To remove extension:

vgreduce <volume_group> /dev/<disk>
for example: vgreduce local2 /dev/sdc


4. Convert current working logical volume to RAID1 and assign mirror

lvconvert -m1 /dev/<volume_group>/<logical_volume> /dev/<disk>
for example: lvconvert -m1 /dev/local2/zinc_lv /dev/sdc

5. It should say it was successful, to check syncing progress

lvs -a -o +devices