首先安装命令:
yum install -y lvm2
使用
parted -l
查看当前硬盘的信息,出来的结果类似:
警告: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。
错误: /dev/sr0: unrecognised disk label
Model: QEMU QEMU DVD-ROM (scsi)
Disk /dev/sr0: 432kB
Sector size (logical/physical): 2048B/2048B
Partition Table: unknown
Disk Flags:
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
1 1049kB 21.5GB 21.5GB primary xfs 启动
错误: /dev/vdb: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
错误: /dev/vdc: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdc: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
错误: /dev/vdd: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdd: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
错误: /dev/sr0: unrecognised disk label
Model: QEMU QEMU DVD-ROM (scsi)
Disk /dev/sr0: 432kB
Sector size (logical/physical): 2048B/2048B
Partition Table: unknown
Disk Flags:
Model: Virtio Block Device (virtblk)
Disk /dev/vda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system 标志
1 1049kB 21.5GB 21.5GB primary xfs 启动
错误: /dev/vdb: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
错误: /dev/vdc: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdc: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
错误: /dev/vdd: unrecognised disk label
Model: Virtio Block Device (virtblk)
Disk /dev/vdd: 537GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags:
使用
pvcreate /dev/vdb /dev/vdc /dev/vdd
创建,注意,这里面的”/dev/vdb”, “/dev/vdc”, “/dev/vdd” 就是前面看到信息的内容。
输出如下表示成功:
Physical volume "/dev/vdb" successfully created
Physical volume "/dev/vdc" successfully created
Physical volume "/dev/vdd" successfully created
Physical volume "/dev/vdc" successfully created
Physical volume "/dev/vdd" successfully created
执行
pvscan
输出:
PV /dev/vdd lvm2 [500.00 GiB]
PV /dev/vdb lvm2 [500.00 GiB]
PV /dev/vdc lvm2 [500.00 GiB]
Total: 3 [1.46 TiB] / in use: 0 [0 ] / in no VG: 3 [1.46 TiB]
PV /dev/vdb lvm2 [500.00 GiB]
PV /dev/vdc lvm2 [500.00 GiB]
Total: 3 [1.46 TiB] / in use: 0 [0 ] / in no VG: 3 [1.46 TiB]
执行
vgcreate sata /dev/vdb /dev/vdc /dev/vdd
输出:
Volume group "sata" successfully created
PS:vgcreate 后的 sata 是一个名称,可以自己起,后面的3个参数是之前对应的盘符路径,按实际情况写。
执行
vgdisplay
看下结果:
--- Volume group ---
VG Name sata
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 1.46 TiB
PE Size 4.00 MiB
Total PE 383997
Alloc PE / Size 0 / 0
Free PE / Size 383997 / 1.46 TiB
VG UUID C0PTEh-erdY-7gh3-fTAb-mwsE-3fMk-J8Tg5e
VG Name sata
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 1.46 TiB
PE Size 4.00 MiB
Total PE 383997
Alloc PE / Size 0 / 0
Free PE / Size 383997 / 1.46 TiB
VG UUID C0PTEh-erdY-7gh3-fTAb-mwsE-3fMk-J8Tg5e
然后执行
lvcreate -l 383997 -n data sata
创建一个整个大盘,如果不要一次性全部创建,则可以用“L”参数。
其中 data 表示一个名称, sata 是之前创建的 VG Name,会输出:
Logical volume "data" created.
表示创建成功。
执行
lvscan
输出如下:
ACTIVE '/dev/sata/data' [1.46 TiB] inherit
执行
mkfs.xfs /dev/sata/data
创建 XFS 格式的盘到 /dev/sata/data 上,输出如下:
meta-data=/dev/sata/data isize=256 agcount=4, agsize=98303232 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=393212928, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=191998, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=393212928, imaxpct=5
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=191998, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
执行
blkid /dev/sata/data
查看新盘的UUID,复制下来下面要用,比如我的是:
/dev/sata/data: UUID="e54fa05f-dc2f-460b-a573-e2817adf9f7b" TYPE="xfs"
编辑文件
vim /etc/fstab
, 加入内容:
UUID=e54fa05f-dc2f-460b-a573-e2817adf9f7b /data xfs noatime,nobarrier 0 0
其中
/data
表示你要挂载的目录,加上 noatime 可以提高盘的性能(如果根目录的没有noatime,也可以加上,加上后记得执行
mount -o remount /
生效),完整内容如下:
UUID=6001f930-2d2b-4e57-b55b-3fde13756c7d / xfs defaults,noatime 0 0
UUID=e54fa05f-dc2f-460b-a573-e2817adf9f7b /data xfs noatime,nobarrier 0 0
UUID=e54fa05f-dc2f-460b-a573-e2817adf9f7b /data xfs noatime,nobarrier 0 0
注意,UUID应该对应自己的盘符名称。
执行
mkdir /data
mount -a
mount -a
这样就把盘挂到了 /data 目录了,可
df -lh
看下:
文件系统 容量 已用 可用 已用% 挂载点
/dev/vda1 20G 2.4G 18G 12% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.4M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
tmpfs 783M 0 783M 0% /run/user/0
/dev/mapper/sata-data 1.5T 33M 1.5T 1% /data
/dev/vda1 20G 2.4G 18G 12% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.4M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
tmpfs 783M 0 783M 0% /run/user/0
/dev/mapper/sata-data 1.5T 33M 1.5T 1% /data
这样就把3块500G的硬盘挂载到1个1.5T的 /data 目录了