# fdisk -l 查看挂上去的第二块硬盘的格式和大小
# pvcreate /dev/sdb 让新添加的硬盘设备支持LVM逻辑卷管理器技术
# vgcreate storage /dev/sdb
# vgdisplay 把新加的硬盘设备都加入到storage卷组中,然后查看下卷组的状态
* 需要注意下切割单位的问题,在LVM逻辑卷管理器对LV逻辑卷的切割上面有两种计量单位,第一种是常见以-L参数来以容量单位为对象,例如使用`-L 204800M` 或者 `-L 200G` 来生成一个大小为200G的逻辑卷,还可以使用-l参数来指定要使用PE基本单元的个数,默认每个PE的大小为4M;
# lvcreate -n vo -L 198G storage 这里分出来198G是为了预留一定量的空间,以防万一数据写满磁盘维护不便
# mkfs.ext4 /dev/storage/vo 把生成好的逻辑卷格式化后挂载使用
# mkdir -p /disk 创建挂载分区
# mount /dev/storage/vo /disk 进行挂载
# df -h 查看挂载状态,并写入到配置文件永久生效
# echo "/dev/storage/vo /disk ext4 defaults 0 0" >> /etc/fstab
后期维护可能需要:
如果想扩容逻辑卷大小:
# umount /disk
逻辑卷vo扩展至300G:
# lvextend -L 300G /dev/storage/vo 这里需要特别注意,需要根据自己的服务器环境预留一定大小的空间,FreeSpace太小容易造成空间不足,建议预留1-2G空间
检查磁盘完整性,重置硬盘容量
# e2fsck -f /dev/storage/vo
# resize2fs /dev/storage/vo
重新挂载硬盘设备并查看挂载状态:
# mount -a
# df -h
一次扩展磁盘的实例:
[root@localhost dev]# fdisk -l
磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000ae4fe
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 62914559 30944256 8e Linux LVM
磁盘 /dev/sdb:214.7 GB, 214748364800 字节,419430400 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/cl-root:23.1 GB, 23093837824 字节,45105152 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/cl-swap:8589 MB, 8589934592 字节,16777216 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@localhost dev]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@localhost dev]# vgcreate storage /dev/sdb
Volume group "storage" successfully created
[root@localhost dev]# vgdisplay
--- Volume group ---
VG Name cl
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 29.51 GiB
PE Size 4.00 MiB
Total PE 7554
Alloc PE / Size 7554 / 29.51 GiB
Free PE / Size 0 / 0
VG UUID oOQBEf-XtWA-y14D-TbmO-wNnM-zvEp-lTrAJg
--- Volume group ---
VG Name storage
System ID
Format lvm2
Metadata Areas 1
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 1
Act PV 1
VG Size 200.00 GiB
PE Size 4.00 MiB
Total PE 51199
Alloc PE / Size 0 / 0
Free PE / Size 51199 / 200.00 GiB
VG UUID EkUQoQ-e1Gf-Ct5H-nVEA-c6Qf-nzpq-3BwUX0
[root@localhost dev]# lvcreate -n vo -l 200 storage
Logical volume "vo" created.
[root@localhost dev]# lvdisply
-bash: lvdisply: 未找到命令
[root@localhost dev]# lvdisplay
--- Logical volume ---
LV Path /dev/cl/swap
LV Name swap
VG Name cl
LV UUID 9jBpcd-bXEg-DQK0-cYYF-J8xj-tqLo-QXXDFM
LV Write Access read/write
LV Creation host, time localhost, 2017-10-11 17:22:29 +0800
LV Status available
# open 2
LV Size 8.00 GiB
Current LE 2048
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/cl/root
LV Name root
VG Name cl
LV UUID T1jL7u-sYgf-koSa-y0dp-O4RL-yZMe-01GqcV
LV Write Access read/write
LV Creation host, time localhost, 2017-10-11 17:22:29 +0800
LV Status available
# open 1
LV Size 21.51 GiB
Current LE 5506
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/storage/vo
LV Name vo
VG Name storage
LV UUID FTkp2Y-e4pH-fajp-0Iw3-QR4w-TgbD-wqFpUR
LV Write Access read/write
LV Creation host, time localhost, 2017-10-11 17:35:00 +0800
LV Status available
# open 0
LV Size 800.00 MiB
Current LE 200
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
[root@localhost dev]# mkfs.ext4 /dev/storage/vo
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
51296 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
7328 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@localhost dev]# cd /
[root@localhost /]# mkdir -p /disk
[root@localhost /]# ls
bin boot dev disk etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[root@localhost /]# mount /dev/storage/vo /disk
[root@localhost /]# df -hl
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl-root 22G 1021M 21G 5% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 497M 132M 366M 27% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/storage-vo 772M 1.6M 714M 1% /disk
[root@localhost /]# echo "/dev/storage/vo /disk ext4 defaults 0 0" >> /etc/fstab
[root@localhost /]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Oct 11 17:22:30 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/cl-root / xfs defaults 0 0
UUID=3b9f4067-8fb0-4d8c-b1cf-4c93ae5e18d3 /boot xfs defaults 0 0
/dev/mapper/cl-swap swap swap defaults 0 0
/dev/storage/vo /disk ext4 defaults 0 0
[root@localhost /]# ^C
[root@localhost /]# df -hl
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl-root 22G 1021M 21G 5% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 497M 132M 366M 27% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/storage-vo 772M 1.6M 714M 1% /disk
[root@localhost /]# umount /disk
[root@localhost /]# lvextend -L 199G /dev/storage/vo
Size of logical volume storage/vo changed from 800.00 MiB (200 extents) to 199.00 GiB (50944 extents).
Logical volume storage/vo successfully resized.
[root@localhost /]# e2fsck -f /dev/storage/vo
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/storage/vo: 11/51296 files (0.0% non-contiguous), 7726/204800 blocks
[root@localhost /]# resize2fs /dev/storage/vo
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/storage/vo to 52166656 (4k) blocks.
The filesystem on /dev/storage/vo is now 52166656 blocks long.
[root@localhost /]# mount -a
[root@localhost /]# df -hl
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/cl-root 22G 1021M 21G 5% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.5M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 497M 132M 366M 27% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/storage-vo 197G 4.5M 187G 1% /disk
[root@localhost /]# fdisk -l
磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000ae4fe
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 62914559 30944256 8e Linux LVM
磁盘 /dev/sdb:214.7 GB, 214748364800 字节,419430400 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/cl-root:23.1 GB, 23093837824 字节,45105152 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/cl-swap:8589 MB, 8589934592 字节,16777216 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/storage-vo:213.7 GB, 213674622976 字节,417333248 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节