Linux 同一目录挂载两块磁盘
目录
收起
第一步:查看磁盘信息
第二步:新建物理卷
第三步:新建卷组
第四步:新建逻辑卷
第五步:格式化分区 ext4
第六步:挂载到目录
第七步:自动挂载
第八步:更改挂载点的用户
备份磁盘数据!
备份磁盘数据!
备份磁盘数据!
备份磁盘数据!
备份磁盘数据!
备份磁盘数据!
重要的事情说三遍。
第一步:查看磁盘信息
# 查看现有物理卷信息
pvdisplay
# 如果没有安装逻辑卷管理系统工具
apt install lvm2 ## 我用的 Ubuntu
# 查看磁盘分区
fdisk -l
我要用以下两块 SSD 来挂载到同一目录。
执行结果:
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
第二步:新建物理卷
数据会被删除!!!数据会被删除!!!
# 新建物理卷
pvcreate /dev/nvme0n1 /dev/sdb
# 查看现有物理卷信息
pvdisplay
执行结果:
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
Allocatable 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
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 5GVMe5-5bN5-QIcM-TXcZ-wIdP-YJCO-p53AoC
第三步:新建卷组
新建卷组 work_vg ,该卷组包含了物理卷 /dev/nvme0n1 和 /dev/sdb
# 新建物理卷
vgcreate work_vg /dev/nvme0n1 /dev/sdb
# 查看现有物理卷信息
pvdisplay
执行结果:
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
Allocatable 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
Allocatable yes
PE Size 4.00 MiB
Total PE 114467
Free PE 114467
Allocated PE 0
PV UUID 5GVMe5-5bN5-QIcM-TXcZ-wIdP-YJCO-p53AoC
第四步:新建逻辑卷
# 新建逻辑卷
lvcreate -n work_lv -l 100%FREE work_vg
# 查看磁盘分区
fdisk -l
执行结果:
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
第五步:格式化分区 ext4
mkfs.ext4 /dev/mapper/work_vg-work_lv
执行结果:
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
第六步:挂载到目录
mount /dev/mapper/work_vg-work_lv /media/lo/work
# 查看
df -h
执行结果:
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
第七步:自动挂载
在/etc/fstab
末尾添加挂载信息,实现自动挂载:
# /media/lo/work is on /dev/mapper/work_vg-work_lv
# This is a Logical Volume containing two SSD
# SanDisk SSD 480GB and Samsung SSD 500GB
# Physical Volume: /dev/nvme0n1 and /dev/sdb are created
# Volume Group work_vg is created
# Logical Volume work_lv is created
/dev/mapper/work_vg-work_lv /media/lo/work ext4 defaults 0 0
第八步:更改挂载点的用户
sudo chown -R lo:lo /media/lo/work