Reference: https://zhuanlan.zhihu.com/p/456193585
Step one: View disk information
View existing physical volume information
pvdisplay
If the logical volume management system tool is not installed
apt install lvm2 ## I use Ubuntu
View disk partitions
fdisk -l
I want to use the following two SSDs to mount to the same directory.
Results of the:
Disk /dev/nvme0n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors Disk model: Samsung SSD 970 EVO Plus 500GB Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sdb: 447.14 GiB, 480113590272 bytes, 937721856 sectors Disk model: SanDisk SSD PLUS Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
Step 2: Create a new physical volume
Data will be deleted! ! !
Create a new physical volume
pvcreate /dev/nvme0n1 /dev/sdb
View existing physical volume information
pvdisplay
Results of the:
root@my-desktop:/home/lo# pvcreate /dev/nvme0n1 /dev/sdb WARNING: ext4 signature detected on /dev/nvme0n1 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/nvme0n1. WARNING: ext4 signature detected on /dev/sdb at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sdb. Physical volume "/dev/nvme0n1" successfully created. Physical volume "/dev/sdb" successfully created. root@my-desktop:/home/lo# pvdisplay "/dev/nvme0n1" is a new physical volume of "465.76 GiB" --- NEW Physical volume --- PV Name /dev/nvme0n1 VG Name PV Size 465.76 GiB Allocable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID xKbpen-bqCr-9c2G-1WVt-Uxa0-AsBN-nvkGvC "/dev/sdb" is a new physical volume of "447.14 GiB" --- NEW Physical volume --- PV Name /dev/sdb VG Name PV Size 447.14 GiB Allocable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 5GVMe5-5bN5-QIcM-TXcZ-wIdP-YJCO-p53AoC
Step 3: Create a new volume group
Create a new volume group work_vg, which contains the physical volumes /dev/nvme0n1 and /dev/sdb
Create a new physical volume
vgcreate work_vg /dev/nvme0n1 /dev/sdb
View existing physical volume information
pvdisplay
Results of the:
root@my-desktop:/home/lo# vgcreate work_vg /dev/nvme0n1 /dev/sdb Volume group "work_vg" successfully created root@my-desktop:/home/lo# pvdisplay --- Physical volume --- PV Name /dev/nvme0n1 VG Name work_vg PV Size 465.76 GiB / not usable 4.02 MiB Allocable yes PE Size 4.00 MiB Total PE 119234 Free PE 119234 Allocated PE 0 PV UUID xKbpen-bqCr-9c2G-1WVt-Uxa0-AsBN-nvkGvC --- Physical volume --- PV Name /dev/sdb VG Name work_vg PV Size 447.14 GiB / not usable 4.00 MiB Allocable yes PE Size 4.00 MiB Total PE 114467 Free PE 114467 Allocated PE 0 PV UUID 5GVMe5-5bN5-QIcM-TXcZ-wIdP-YJCO-p53AoC
Step 4: Create a new logical volume
Create a new logical volume
lvcreate -n work_lv -l 100%FREE work_vg
View disk partitions
fdisk -l
Results of the:
root@my-desktop:/home/lo# lvcreate -n work_lv -l 100%FREE work_vg Logical volume "work_lv" created. root@my-desktop:/home/lo# fdisk -l Disk /dev/nvme0n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors Disk model: Samsung SSD 970 EVO Plus 500GB Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sdb: 447.14 GiB, 480113590272 bytes, 937721856 sectors Disk model: SanDisk SSD PLUS Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/work_vg-work_lv: 912.92 GiB, 980213039104 bytes, 1914478592 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
Step 5: Format partition ext4
mkfs.ext4 /dev/mapper/work_vg-work_lv
Results of the:
root@my-desktop:/home/lo# mkfs.ext4 /dev/mapper/work_vg-work_lv mke2fs 1.45.5 (07-Jan-2020) Discarding device blocks: done Creating filesystem with 239309824 4k blocks and 59834368 inodes Filesystem UUID: b828e1cc-a6b1-4005-bf55-c05971bfafe7 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848 Allocating group tables: done Writing inode tables: done Creating journal (262144 blocks): done Writing superblocks and filesystem accounting information: done
Step 6: Mount to directory
mount /dev/mapper/work_vg-work_lv /media/lo/work
Check
df -h
Results of the:
root@my-desktop:/media/lo/work# df -h Filesystem Size Used Avail Use% Mounted on udev 16G 0 16G 0% /dev tmpfs 3.2G 2.0M 3.2G 1% /run /dev/sda1 1.8T 26G 1.7T 2% / tmpfs 16G 0 16G 0% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/loop1 128K 128K 0 100% /snap/bare/5 /dev/loop0 56M 56M 0 100% /snap/core18/2128 /dev/loop2 56M 56M 0 100% /snap/core18/2253 /dev/loop3 62M 62M 0 100% /snap/core20/1270 /dev/loop5 219M 219M 0 100% /snap/gnome-3-34-1804/72 /dev/loop4 219M 219M 0 100% /snap/gnome-3-34-1804/77 /dev/loop6 248M 248M 0 100% /snap/gnome-3-38-2004/87 /dev/loop8 66M 66M 0 100% /snap/gtk-common-themes/1519 /dev/loop7 51M 51M 0 100% /snap/snap-store/547 /dev/loop10 44M 44M 0 100% /snap/snapd/14295 /dev/loop9 66M 66M 0 100% /snap/gtk-common-themes/1515 /dev/loop11 55M 55M 0 100% /snap/snap-store/558 /dev/loop12 43M 43M 0 100% /snap/snapd/14066 /dev/nvme1n1p8 71G 26G 42G 38% /home /dev/nvme1n1p1 196M 112M 85M 57% /boot/efi tmpfs 3.2G 60K 3.2G 1% /run/user/1000 /dev/mapper/work_vg-work_lv 898G 77M 852G 1% /media/lo/work