RAID and LVM Configuration Guide: How to create, expand, and manage RAID devices and logical volumes

Article directory

  • 1 Introduction
    • 1.1 What is RAID and LVM
    • 1.2 The role and advantages of RAID and LVM
  • 2. RAID configuration command: mdadm
    • 2.1 Install mdadm
    • 2.2 Create RAID device
      • 2.2.1 RAID 0
      • 2.2.2 RAID 1
      • 2.2.3 RAID 5
      • 2.2.4 RAID 10
    • 2.3 Add disk to RAID device
    • 2.4 Removing disks from RAID devices
    • 2.5 View and manage RAID devices
    • 2.6 Troubleshooting and recovery
  • 3. LVM configuration commands: pvcreate, vgcreate, lvcreate
    • 3.1 Install LVM tools
    • 3.2 Create a physical volume (Physical Volume)
    • 3.3 Create Volume Group
    • 3.4 Create a logical volume (Logical Volume)
    • 3.5 Expanding and shrinking logical volumes
    • 3.6 Delete logical volumes, volume groups and physical volumes
    • 3.7 View and manage LVM
  • 4. Practical application examples
    • 4.1 Case demonstration of using mdadm and LVM to create RAID and extend logical volumes
  • 5. Summary
    • 5.1 Application scenarios and summary of RAID and LVM
    • 5.2 Things to note when using RAID and LVM
  • Recommended Python boutique columns
    • Basic knowledge of python (0 basic introduction)
    • python crawler knowledge

1. Introduction

1.1 What is RAID and LVM

RAID (Redundant Array of Inexpensive Disks) is a disk array technology that combines multiple hard drives to improve performance, data redundancy and data protection capabilities. LVM (Logical Volume Manager) is a technology that abstracts the physical storage space on the hard disk into logical storage space and manages it uniformly.

1.2 The functions and advantages of RAID and LVM

The role of RAID is to improve data redundancy and read and write performance. Using RAID technology, multiple hard drives can be combined into a logical hard drive with better redundancy and read and write performance. The role of LVM is to abstract and manage physical storage space. Users can create, expand and shrink logical volumes through LVM, thereby using hard disk storage more flexibly.

2. RAID configuration command: mdadm

2.1 Install mdadm

In Ubuntu system, install mdadm through the following command:

sudo apt-get install mdadm

2.2 Create RAID device

2.2.1 RAID 0

# Create a RAID 0 device named md0, consisting of /dev/sdb and /dev/sdc
sudo mdadm --create /dev/md0 --level=0 --raid-devices=2 /dev/sdb /dev/sdc

# Check RAID device status
sudo mdadm --detail /dev/md0

# Format and mount the RAID device to the /mnt/raid0 directory
sudo mkfs.ext4 /dev/md0
sudo mkdir /mnt/raid0
sudo mount /dev/md0 /mnt/raid0

2.2.2 RAID 1

# Create a RAID 1 device named md1, consisting of /dev/sdd and /dev/sde
sudo mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sdd /dev/sde

# Check RAID device status
sudo mdadm --detail /dev/md1

# Format and mount the RAID device to the /mnt/raid1 directory
sudo mkfs.ext4 /dev/md1
sudo mkdir /mnt/raid1
sudo mount /dev/md1 /mnt/raid1

2.2.3 RAID 5

# Create a RAID 5 device named md2, consisting of /dev/sdf, /dev/sdg and /dev/sdh
sudo mdadm --create /dev/md2 --level=5 --raid-devices=3 /dev/sdf /dev/sdg /dev/sdh

# Check RAID device status
sudo mdadm --detail /dev/md2

# Format and mount the RAID device to the /mnt/raid5 directory
sudo mkfs.ext4 /dev/md2
sudo mkdir /mnt/raid5
sudo mount /dev/md2 /mnt/raid5

2.2.4 RAID 10

# Create a RAID 10 device named md3, consisting of /dev/sdi, /dev/sdj, /dev/sdk and /dev/sdl
sudo mdadm --create /dev/md3 --level=10 --raid-devices=4 /dev/sdi /dev/sdj /dev/sdk /dev/sdl

# Check RAID device status
sudo mdadm --detail /dev/md3

# Format and mount the RAID device to the /mnt/raid10 directory
sudo mkfs.ext4 /dev/md3
sudo mkdir /mnt/raid10
sudo mount /dev/md3 /mnt/raid10

2.3 Add disk to RAID device

# Add /dev/sdd disk to md0 device
sudo mdadm --add /dev/md0 /dev/sdd

# Check RAID device status
sudo mdadm --detail /dev/md0

2.4 Removing disks from RAID devices

# Delete /dev/sdb from the md0 device
sudo mdadm --fail /dev/md0 /dev/sdb
sudo mdadm --remove /dev/md0 /dev/sdb

# Check RAID device status
sudo mdadm --detail /dev/md0

2.5 View and manage RAID devices

# View the status of all RAID devices
sudo mdadm --detail --scan

# Uninstall RAID device
sudo umount /dev/md0

# Stop RAID device
sudo mdadm --stop /dev/md0

2.6 Fault handling and recovery

When a RAID device fails, it can be processed and recovered through the following commands:

# Check RAID device status
sudo mdadm --detail /dev/md0

# Replace the failed disk
sudo mdadm --manage /dev/md0 --remove /dev/sdb
sudo mdadm --manage /dev/md0 --add /dev/sdb1

3. LVM configuration commands: pvcreate, vgcreate, lvcreate

3.1 Install LVM tools

In Ubuntu system, install the LVM tool through the following command:

sudo apt-get install lvm2

3.2 Create a physical volume (Physical Volume)

# Create a physical volume on /dev/sdb
sudo pvcreate /dev/sdb

3.3 Create Volume Group

# Add the physical volume /dev/sdb to the volume group named vg0
sudo vgcreate vg0 /dev/sdb

3.4 Create Logical Volume

# Create a logical volume named lv0 in the vg0 volume group with a size of 10G
sudo lvcreate -L 10G -n lv0 vg0

# Format and mount the logical volume to the /mnt/lv0 directory
sudo mkfs.ext4 /dev/vg0/lv0
sudo mkdir /mnt/lv0
sudo mount /dev/vg0/lv0 /mnt/lv0

3.5 Expanding and shrinking logical volumes

# Expand the lv0 logical volume to 20G
sudo lvextend -L 20G /dev/vg0/lv0

# Update file system size
sudo resize2fs /dev/vg0/lv0

# Reduce the lv0 logical volume to 15G
sudo umount /mnt/lv0
sudo e2fsck -f /dev/vg0/lv0
sudo resize2fs /dev/vg0/lv0 15G
sudo lvreduce -L 15G /dev/vg0/lv0
sudo mount /dev/vg0/lv0 /mnt/lv0

3.6 Delete logical volumes, volume groups and physical volumes

# Delete logical volume lv0
sudo umount /mnt/lv0
sudo lvremove /dev/vg0/lv0

# Delete volume group vg0
sudo vgremove vg0

# Delete physical volume /dev/sdb
sudo pvremove /dev/sdb

3.7 View and manage LVM

# View volume group vg0 information
sudo vgdisplay vg0

# View logical volume lv0 information
sudo lvdisplay /dev/vg0/lv0

4. Practical application examples

4.1 Case demonstration of using mdadm and LVM to create RAID and extended logical volumes

In the Ubuntu system, create a RAID 5 device named raid_lv and logical volume lv0 with the following command:

# Create a RAID 5 device named md0, consisting of /dev/sdb, /dev/sdc and /dev/sdd
sudo mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb /dev/sdc /dev/sdd

# Create physical volume /dev/md0
sudo pvcreate /dev/md0

# Add the physical volume to the vg0 volume group
sudo vgcreate vg0 /dev/md0

#Create logical volume lv0 in vg0 volume group with a size of 10G
sudo lvcreate -L 10G -n lv0 vg0

# Format and mount the logical volume to the /mnt/lv0 directory
sudo mkfs.ext4 /dev/vg0/lv0
sudo mkdir /mnt/lv0
sudo mount /dev/vg0/lv0 /mnt/lv0

Later, when expansion is needed, you can use the following command to expand the lv0 logical volume to 20G:

sudo lvextend -L 20G /dev/vg0/lv0
sudo resize2fs /dev/vg0/lv0

5. Summary

5.1 Application scenarios and summary of RAID and LVM

RAID can improve data redundancy and read and write performance on multiple hard disks and is one of the commonly used technologies in servers; LVM can abstract and manage the physical storage space on hard disks and support convenient expansion and reduction. It is also a common technology on servers. One of the common techniques.

5.2 Things to note when using RAID and LVM

When using RAID and LVM, you need to pay attention to hardware compatibility, as well as the impact of data redundancy, performance, and storage expansion brought by RAID and LVM. In actual applications, it is recommended to make backups and tests in advance to ensure the correctness and stability of RAID and LVM.

Python boutique column recommendations

Basic knowledge of python (0 basic introduction)

[Basic knowledge of python] 0.print() function
[Basic knowledge of python] 1. Data types, data applications, data conversion
[Basic knowledge of python] 2.if conditional judgment and conditional nesting
[Basic knowledge of python] 3.input() function
[Basic knowledge of python] 4. Lists and dictionaries
[Basic knowledge of python] 5. for loop and while loop
[Basic knowledge of python] 6. Boolean values and four statements (break, continue, pass, else)
[Basic knowledge of python] 7. Practical operation-Using Python to implement the “Text PK” game (1)
[Basic knowledge of python] 7. Practical operation-Using Python to implement the “Text PK” game (2)
[Basic Knowledge of Python] 8. Programming Thinking: How to Solve Problems – Thinking
[Basic knowledge of python] 9. Definition and calling of functions
[Basic knowledge of python] 10. Writing programs with functions – Practical operation
[Basic knowledge of python] 10. Use Python to implement the rock-paper-scissors game-Function Practical Operation
[Basic knowledge of python] 11. How to debug – Common error reasons and troubleshooting ideas – Thinking
[Basic knowledge of python] 12. Classes and objects (1)
[Basic knowledge of python] 12. Classes and objects (2)
[Basic knowledge of python] 13. Classes and objects (3)
[Basic knowledge of python] 13. Classes and objects (4)
[Basic knowledge of python] 14. Construction of library management system (practical operation of classes and objects)
[Python basics] 15. Coding basics
[Basic knowledge of python] 16. Basics and operations of file reading and writing
[Basic Knowledge of Python] 16. Python Implementation of “Ancient Poetry Dictation Questions” (File Reading, Writing and Coding – Practical Operation)
[Basic knowledge of python] 17. The concept of modules and how to introduce them
[Basic knowledge of python] 18. Practical operation-using python to automatically send mass emails
[Basic knowledge of python] 19. Product thinking and the use of flow charts – Thinking
[Basic Knowledge of Python] 20. Python Implementation of “What to Eat for Lunch” (Product Thinking – Practical Operation)
[Basic knowledge of python] 21. The correct way to open efficiently and lazily – graduation chapter
[Python file processing] Reading, processing and writing of CSV files
[python file processing] Excel automatic processing (using openpyxl)
[python file processing]-excel format processing

Python crawler knowledge

[python crawler] 1. Basic knowledge of crawlers
[python crawler] 2. Basic knowledge of web pages
[python crawler] 3. First experience with crawlers (BeautifulSoup analysis)
[python crawler] 4. Practical crawler operation (dish crawling)
[python crawler] 5. Practical crawler operation (lyrics crawling)
[python crawler] 6. Practical crawler operation (requesting data with parameters)
[python crawler] 7. Where is the crawled data stored?
[python crawler] 8. Review the past and learn the new
[python crawler] 9. Log in with cookies (cookies)
[python crawler] 10. Command the browser to work automatically (selenium)
[python crawler] 11. Let the crawler report to you on time
[python crawler] 12. Build your crawler army
[python crawler] 13. What to eat without getting fat (crawler practical exercise)
[python crawler] 14. Scrapy framework explanation
[python crawler] 15.Scrapy framework practice (crawling popular positions)
[python crawler] 16. Summary and review of crawler knowledge points