Linux hard disk merge implementation code

  • 2020-11-25 07:49:05
  • OfStack

purpose

Combine two empty hard disks into "1 block" and mount to the specified directory to use all the space of 2 hard disks in one directory.

conditions

Hard disk 1 / dev/sdb Hard disk 2 / dev/sdc

methods

Create pv


pvcreate /dev/sdb  // The hard disk 1
pvcreate /dev/sdc  // The hard disk 2

Create vg


//vgcreate [ The custom LVM The name of the ] [ equipment ]
// Use the hard disk first 1 create vg:LVM
vgcreate LVM /dev/sdb

Extension vg


//vgextend [ The custom vg The name of the ] [ equipment ]  
// Use the hard disk 2 extension vg
vgextend LVM /dev/sdc

Create lv


//lvcreate -L[ Customize the partition size ] -n[ Customize the partition name ] [vg The name of the ]
//* The partition size cannot exceed the total disk capacity *
lvcreate -L5.0T -nDB_DATA LVM

Formatted partition


//mkfs -t [ The file system ] [ Partition location ]
mkfs -t ext4 /dev/LVM/DB_DATA

Mount the partition


//mount [ Partition location ] [ Directory address ]
mount /dev/LVM/DB_DATA /root/DB_DATA

Set startup load

Add the following line to the end of the /etc/fstab file.


/dev/LVM/DB_DATA /root/DB_DATA ext4 defaults 1 2

Related articles: