版本
[root@station mapper]# cat /proc/version
Linux version 3.10.0-123.el7.x86_64 (mockbuild@x86-017.build.eng.bos.redhat.com) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Mon May 5 11:16:57 EDT 2014
创建PV-VG-LV
1、查看磁盘
[root@station ~]# fdisk -l
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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
Disk label type: dos
Disk identifier: 0xb2e9457d
Device Boot Start End Blocks Id System
/dev/vdb1 2048 6293503 3145728 83 Linux
Disk /dev/mapper/rhce-iscsi_vol: 3217 MB, 3217031168 bytes, 6283264 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
Disk label type: dos
Disk identifier: 0xa65fd8a6
Device Boot Start End Blocks Id System
/dev/mapper/rhce-iscsi_vol1 8192 3489791 1740800 83 Linux
[root@station ~]#
2、磁盘分区
[root@station ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p):
Using default response p
Partition number (2-4, default 2):
First sector (6293504-20971519, default 6293504):
Using default value 6293504
Last sector, +sectors or +size{K,M,G} (6293504-20971519, default 20971519): +1G
Partition 2 of type Linux and of size 1 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@station ~]#
3、创建pv
[root@station ~]# pvcreate /dev/vdb2
Physical volume /dev/vdb2 not found
Device /dev/vdb2 not found (or ignored by filtering).
由于是刚创建的pv,信息没有同步,所以报错设备找不到
[root@station /]# partprobe
device-mapper: reload ioctl on rhce-iscsi_vol1 failed: Invalid argument
device-mapper: remove ioctl on rhce-iscsi_vol1 failed: No such device or address
[root@station /]# pvcreate /dev/vdb2
Physical volume "/dev/vdb2" successfully created
4、创建vg
[root@station mapper]# vgcreate vo_vg /dev/vdb2
Volume group "vo_vg" successfully created
5、创建lv
[root@station mapper]# lvcreate -L 200M -n vo_lv vo_vg
Logical volume "vo_lv" created
[root@station mapper]# ls -l
total 0
crw-------. 1 root root 10, 236 Jun 13 19:21 control
lrwxrwxrwx. 1 root root 7 Jun 13 22:22 rhce-iscsi_vol -> ../dm-0
lrwxrwxrwx. 1 root root 7 Jun 13 22:29 vo_vg-vo_lv -> ../dm-1
[root@station mapper]#
6、lv创建文件系统
[root@station mapper]# mkfs.ext4 /dev/mapper/vo_vg-vo_lv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33816576
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[root@station mapper]#
7、挂载文件系统
[root@station mapper]# mkdir /vo_lv
[root@station mapper]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May 7 01:22:57 2014
#
# 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
#
UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 / xfs defaults 1 1
/dev/mapper/vo_vg-vo_lv /vo_lv ext4 defaults 0 0
[root@station mapper]#
[root@station mapper]# mount -a
[root@station mapper]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.3G 6.8G 33% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 84K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/mapper/vo_vg-vo_lv 190M 1.6M 175M 1% /vo_lv
ext4文件系统LV扩容
8、查看需扩容lv的文件系统类型(ext4和xfs文件系统扩容不同,此处为ext4扩容方式)
[root@station mapper]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
vda
└─vda1 xfs 9bf6b9f7-92ad-441b-848e-0257cbb883d1 /
vdb
├─vdb1 LVM2_member CPb1VX-KaAB-MNLI-TcIB-XVt9-4UE5-LlaG2T
│ └─rhce-iscsi_vol
└─vdb2 LVM2_member MlOa9D-XH4d-n4Xn-Sief-t16B-0ktI-mqj11P
└─vo_vg-vo_lv ext4 eb51e7c8-5129-483d-b66e-de1da5692cf6 /vo_lv
也可用parted -l查看
[root@station mapper]# parted -l
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/vo_vg-vo_lv: 210MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags:
Number Start End Size File system Flags
1 0.00B 210MB 210MB ext4
9、查看lv所属的vg是否有空余空间
[root@station mapper]# lvdisplay
--- Logical volume ---
LV Path /dev/vo_vg/vo_lv
LV Name vo_lv
VG Name vo_vg
LV UUID 0nZkWe-Slw6-E6aa-TZic-1dJF-7JKm-NPrda1
LV Write Access read/write
LV Creation host, time station.domain1.example.com, 2020-06-13 22:29:12 +0800
LV Status available
# open 1
LV Size 200.00 MiB
Current LE 50
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 252:1
[root@station mapper]# vgdisplay vo_vg
--- Volume group ---
VG Name vo_vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 1020.00 MiB
PE Size 4.00 MiB
Total PE 255
Alloc PE / Size 50 / 200.00 MiB
Free PE / Size 205 / 820.00 MiB
VG UUID BgfZ4K-02hY-0u0o-R20D-L9tF-OpDT-qJI4CW
[root@station mapper]#
10、扩展前卸载设备和挂载点的关联
[root@station mapper]# umount /vo_lv
11、扩容lv,注意此处的300M为扩容后lv的总大小,不是添加300M。
[root@station mapper]# lvextend -L 300M -n /dev/vo_vg/vo_lv
Extending logical volume vo_lv to 300.00 MiB
Logical volume vo_lv successfully resized
[root@station mapper]#
12、检查硬盘完整性,并重置硬盘容量
[root@station mapper]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.3G 6.8G 33% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 84K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/mapper/vo_vg-vo_lv 190M 1.6M 175M 1% /vo_lv
注意如果没有umount挂载设备,检查硬盘完整性无法进行,生产中如需扩容最好umount之后进行,因为如果扩容过程中有数据读写,可能会有数据丢失会错误等现象。
[root@station mapper]# e2fsck /dev/vo_vg/vo_lv
e2fsck 1.42.9 (28-Dec-2013)
/dev/vo_vg/vo_lv is mounted.
e2fsck: Cannot continue, aborting.
[root@station mapper]# resize2fs /dev/vo_vg/vo_lv
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vo_vg/vo_lv is mounted on /vo_lv; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/vo_vg/vo_lv is now 307200 blocks long.
[root@station mapper]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.3G 6.8G 33% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 84K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/mapper/vo_vg-vo_lv 287M 2.1M 267M 1% /vo_lv
[root@station mapper]#
13、重新挂载硬盘设备并查看挂载状态
[root@station mapper]# mount -a
[root@station mapper]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 10G 3.3G 6.8G 33% /
devtmpfs 906M 0 906M 0% /dev
tmpfs 921M 84K 921M 1% /dev/shm
tmpfs 921M 17M 904M 2% /run
tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/mapper/vo_vg-vo_lv 287M 2.1M 267M 1% /vo_lv
[root@station mapper]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 11G 3.5G 7.3G 33% /
devtmpfs 950M 0 950M 0% /dev
tmpfs 966M 87k 966M 1% /dev/shm
tmpfs 966M 18M 948M 2% /run
tmpfs 966M 0 966M 0% /sys/fs/cgroup
/dev/mapper/vo_vg-vo_lv 301M 2.2M 280M 1% /vo_lv
[root@station mapper]#
14、LV的信息
[root@station mapper]# cd /dev/vo_vg
[root@station vo_vg]# ls
vo_lv
[root@station vo_vg]# ls -l
total 0
lrwxrwxrwx. 1 root root 7 Jun 13 22:51 vo_lv -> ../dm-1
[root@station vo_vg]# cd /dev/mapper
[root@station mapper]# ls -l
total 0
crw-------. 1 root root 10, 236 Jun 13 19:21 control
lrwxrwxrwx. 1 root root 7 Jun 13 22:39 rhce-iscsi_vol -> ../dm-0
lrwxrwxrwx. 1 root root 7 Jun 13 22:51 vo_vg-vo_lv -> ../dm-1
[root@station mapper]#