Format And Mount local2: Difference between revisions

From DISI
Jump to navigation Jump to search
No edit summary
 
(One intermediate revision by the same user not shown)
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


'''Initialize the block devices'''
2. Initialize the block devices
* pvcreate <drive1> <drive2> <...> ...
pvcreate <drive1> <drive2> <...> ...
** Example: pvcreate /dev/sdb /dev/sdc /dev/sdd
example: pvcreate /dev/sdb /dev/sdc /dev/sdd


'''To double check PV'''
3. To double check PV
* pvdisplay
pvdisplay
* pvscan
pvscan
* pvs
pvs


'''After PV, create a Volume Group (VG)'''
4. After PV, create a Volume Group (VG)
* vgcreate <name of volume> <drive1> <drive2> <...> ...
vgcreate <name of volume> <drive1> <drive2> <...> ...
** Example: vgcreate soft2 /dev/sdb /dev/sdc /dev/sdd
example: vgcreate soft2 /dev/sdb /dev/sdc /dev/sdd


'''To double check VG'''
5. To double check VG
* vgs <VG name>
vgs <VG name>
* vgdisplay <VG name>
vgdisplay <VG name>


''' After VG, create a Logical Volume (LV) '''
6. After VG, create a Logical Volume (LV)
* lvcreate <options> <name of LV> <VG Name>
lvcreate <options> <name of LV> <VG Name>
** Example: lvcreate -l 100%FREE -n soft_lv soft2  
example: lvcreate -l 100%FREE -n soft_lv soft2  
***-l is for storage space in percent, 100%FREE means use all space in VG
"-l" is for storage space in percent, 100%FREE means use all space in VG
***-n is for name of LV
"-n" is for name of LV


''' Double Check LV '''
7. Double Check LV
* lvs /dev/<VG NAME>/<LV NAME>
lvs /dev/<VG NAME>/<LV NAME>
* lvdisplay /dev/<VG NAME>/<LV NAME>
lvdisplay /dev/<VG NAME>/<LV NAME>
* lvscan
lvscan


'''Last step, create a File System'''
8. Create a File System
* mkfs.ext4 <options> /dev/<VG NAME>/<LV NAME>
mkfs.ext4 <options> /dev/<VG NAME>/<LV NAME>
* Example: mkfs.ext4 /dev/soft2/soft_lv
example: mkfs.ext4 /dev/soft2/soft_lv


''' It's time to mount '''
9. Make the directory:
Make the directory first:
mkdir <somewhere>
* mkdir <somewhere>
example: mkdir /export/soft2
** Example: mkdir /export/soft2
 
* mount /dev/<VG NAME>/<LV NAME> <somewhere>
10. Mount permanently:
** Example: mount /dev/soft2/soft_lv /export/soft2/
vim /etc/fstab
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


== Partition Disk ==
11. Lastly, mount all
* https://www.techotopia.com/index.php/Adding_a_New_Disk_Drive_to_a_CentOS_System
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

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