Difference between revisions of "Format And Mount local2"

From DISI
Jump to navigation Jump to search
 
Line 10: Line 10:
 
*print. (to confirm)
 
*print. (to confirm)
 
*quit
 
*quit
 
  
 
== Mount storage disks using LVM ==
 
== Mount storage disks using LVM ==
 
Reference guide: '''https://www.thegeekdiary.com/redhat-centos-a-beginners-guide-to-lvm-logical-volume-manager/'''
 
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)'''
+
1. Scan devices to be used as physical volumes (PV)
* lvmdiskscan
+
lvmdiskscan
 +
 
 +
2. Initialize the block devices
 +
pvcreate <drive1> <drive2> <...> ...
 +
example: pvcreate /dev/sdb /dev/sdc /dev/sdd
  
'''Initialize the block devices'''
+
3. To double check PV
* pvcreate <drive1> <drive2> <...> ...
+
pvdisplay
** Example: pvcreate /dev/sdb /dev/sdc /dev/sdd
+
pvscan
 +
pvs
  
'''To double check PV'''
+
4. After PV, create a Volume Group (VG)
* pvdisplay
+
vgcreate <name of volume> <drive1> <drive2> <...> ...
* pvscan
+
example: vgcreate soft2 /dev/sdb /dev/sdc /dev/sdd
* pvs
 
  
'''After PV, create a Volume Group (VG)'''
+
5. To double check VG
* vgcreate <name of volume> <drive1> <drive2> <...> ...
+
vgs <VG name>
** Example: vgcreate soft2 /dev/sdb /dev/sdc /dev/sdd
+
vgdisplay <VG name>
  
'''To double check VG'''
+
6. After VG, create a Logical Volume (LV)
* vgs <VG name>
+
lvcreate <options> <name of LV> <VG Name>
* vgdisplay <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
  
''' After VG, create a Logical Volume (LV) '''
+
7. Double Check LV
* lvcreate <options> <name of LV> <VG Name>
+
lvs /dev/<VG NAME>/<LV NAME>
** Example: lvcreate -l 100%FREE -n soft_lv soft2
+
lvdisplay /dev/<VG NAME>/<LV NAME>
***-l is for storage space in percent, 100%FREE means use all space in VG
+
lvscan
***-n is for name of LV
 
  
''' Double Check LV '''
+
8. Create a File System
* lvs /dev/<VG NAME>/<LV NAME>
+
mkfs.ext4 <options> /dev/<VG NAME>/<LV NAME>
* lvdisplay /dev/<VG NAME>/<LV NAME>
+
example: mkfs.ext4 /dev/soft2/soft_lv
* lvscan
 
  
'''Last step, create a File System'''
+
9. Make the directory:
* mkfs.ext4 <options> /dev/<VG NAME>/<LV NAME>
+
mkdir <somewhere>
* Example: mkfs.ext4 /dev/soft2/soft_lv
+
example: mkdir /export/soft2
  
''' It's time to mount '''
+
10. Mount permanently:
Make the directory first:
+
vim /etc/fstab
* 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>
 
  /dev/<VG NAME>/<LV NAME>      <somewhere>      <type of file system>      <mount options>      <dump>        <fsck>
 
  example:
 
  example:
 
  /dev/soft2/soft_lv /export/soft2 ext4 defaults 1 2
 
  /dev/soft2/soft_lv /export/soft2 ext4 defaults 1 2
 +
 +
11. Lastly, mount all
 +
mount -a
 +
 +
== RAID1 with LVM on fresh drives ==
 +
1. Check which disk will act as the mirror
 +
fdisk -l
 +
 +
2. Create physical volumes of the drives
 +
pvcreate <disk> <disk> <disk>
 +
example: pvcreate /dev/sdz /dev/sdaa
 +
 +
3. Create a volume group for these drives
 +
vgcreate <name> <disk1> <disk2>
 +
example: vgcreate local2 /dev/sdz /dev/sdaa
 +
 +
4. Create a logical volume with "-m1" flag to say mirror/raid1
 +
lvcreate -l <how much of disk to use in percent> -m1 -n <name> <volume_group>
 +
example: lvcreate -l 100%FREE -m1 -n local2_lv local2
 +
 +
5. Mount permanently:
 +
vim /etc/fstab
 +
/dev/<VG NAME>/<LV NAME>      <somewhere>      <type of file system>      <mount options>      <dump>        <fsck>
 +
example:
 +
/dev/local2/local2_lv  /local2        ext4    defaults        1      2
 +
 +
6. Lastly, mount all
 +
mount -a
  
 
== RAID1 with LVM on an existing used logical volume ==
 
== RAID1 with LVM on an existing used logical volume ==
Line 73: Line 98:
 
If ''' PV /dev/sdd1  VG local2          lvm2 [<7.28 TiB / 0 free] ''' then do
 
If ''' PV /dev/sdd1  VG local2          lvm2 [<7.28 TiB / 0 free] ''' then do
 
  lvreduce -l -1 --resizefs /dev/<volume_group>/<logical_volume>
 
  lvreduce -l -1 --resizefs /dev/<volume_group>/<logical_volume>
  for example : lvreduce -l -1 --resizefs /dev/local2/zinc_lv
+
  example : lvreduce -l -1 --resizefs /dev/local2/zinc_lv
  
  
Line 82: Line 107:
 
3. Extend the disk to volume group
 
3. Extend the disk to volume group
 
  vgextend <volume_group> /dev/<disk>
 
  vgextend <volume_group> /dev/<disk>
  for example: vgextend local2 /dev/sdc
+
  example: vgextend local2 /dev/sdc
 
To remove extension:
 
To remove extension:
 
  vgreduce <volume_group> /dev/<disk>
 
  vgreduce <volume_group> /dev/<disk>
  for example: vgreduce local2 /dev/sdc
+
  example: vgreduce local2 /dev/sdc
  
  
 
4. Convert current working logical volume to RAID1 and assign mirror
 
4. Convert current working logical volume to RAID1 and assign mirror
 
  lvconvert -m1 /dev/<volume_group>/<logical_volume> /dev/<disk>
 
  lvconvert -m1 /dev/<volume_group>/<logical_volume> /dev/<disk>
  for example: lvconvert -m1 /dev/local2/zinc_lv /dev/sdc
+
  example: lvconvert -m1 /dev/local2/zinc_lv /dev/sdc
  
 
5. It should say it was successful, to check syncing progress
 
5. It should say it was successful, to check syncing progress
 
  lvs -a -o +devices
 
  lvs -a -o +devices

Latest revision as of 20:35, 1 April 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/

1. Scan devices to be used as physical volumes (PV)

lvmdiskscan

2. Initialize the block devices

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

3. To double check PV

pvdisplay
pvscan
pvs

4. After PV, create a Volume Group (VG)

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

5. To double check VG

vgs <VG name>
vgdisplay <VG name>

6. 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

7. Double Check LV

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

8. Create a File System

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

9. Make the directory:

mkdir <somewhere>
example: mkdir /export/soft2

10. Mount permanently:

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

11. Lastly, mount all

mount -a

RAID1 with LVM on fresh drives

1. Check which disk will act as the mirror

fdisk -l

2. Create physical volumes of the drives

pvcreate <disk> <disk> <disk>
example: pvcreate /dev/sdz /dev/sdaa

3. Create a volume group for these drives

vgcreate <name> <disk1> <disk2>
example: vgcreate local2 /dev/sdz /dev/sdaa

4. Create a logical volume with "-m1" flag to say mirror/raid1

lvcreate -l <how much of disk to use in percent> -m1 -n <name> <volume_group>
example: lvcreate -l 100%FREE -m1 -n local2_lv local2

5. Mount permanently:

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

6. Lastly, mount all

mount -a

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>
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>
example: vgextend local2 /dev/sdc

To remove extension:

vgreduce <volume_group> /dev/<disk>
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>
example: lvconvert -m1 /dev/local2/zinc_lv /dev/sdc

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

lvs -a -o +devices