t 改变分区类型为8e
[root@localhost ~]# pvcreate /dev/sdb1
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created.
[root@localhost ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created.
[root@localhost ~]# pvcreate /dev/sdb3
WARNING: xfs signature detected on /dev/sdb3 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sdb3.
Physical volume "/dev/sdb3" successfully created.
[root@localhost ~]# pvs //更加直观的显示
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 --- 1.00g 1.00g
/dev/sdb2 lvm2 --- 1.00g 1.00g
/dev/sdb3 lvm2 --- 1.00g 1.00g
[root@localhost ~]# pvdisplay
"/dev/sdb2" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb2
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID v51GO2-WNkf-AlSO-i3HX-3AJ0-UIec-SRvpOx
"/dev/sdb3" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb3
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID nuWhUG-K8jv-c8Ka-3UD4-TDkC-qcQJ-3iZcjw
"/dev/sdb1" is a new physical volume of "1.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 1.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID b81FIf-CfsJ-zLnm-Jrsv-Dsk7-JN7b-1PdS2W
[root@localhost ~]# pvremove /dev/sdb2
Labels on physical volume "/dev/sdb2" successfully wiped
[root@localhost ~]# pvchange -x n /dev/sdb1 #禁止分配指定物理卷上的PE
Physical volume "/dev/sdb1" changed
1 physical volume changed / 0 physical volumes not changed
[root@localhost ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2
Volume group "vg1" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 0 0 wz--n- 1.99g 1.99g
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 2
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 2
Act PV 2
VG Size 1.99 GiB
PE Size 4.00 MiB
Total PE 510
Alloc PE / Size 0 / 0
Free PE / Size 510 / 1.99 GiB
VG UUID kUuExp-cQi4-tikr-t51M-WSDC-KmKw-36rxYe
[root@localhost ~]# vgremove vg1
Volume group "vg1" successfully removed
[root@localhost ~]# lvcreate -L 100M -n lv1 vg1
Logical volume "lv1" created.
[root@localhost ~]# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
若格式化xfs文件系统,在后续的扩容或缩容会受到一定的影响
- 挂载磁盘
- mount命令,挂载磁盘
- 格式:mount /dev/vg1/lv1 /mnt/ 挂载到 /mnt/ 目录下
[root@localhost ~]# mount /dev/vg1/lv1 /mnt/
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 1.3G 17G 7% /
devtmpfs 483M 0 483M 0% /dev
tmpfs 493M 0 493M 0% /dev/shm
tmpfs 493M 6.8M 486M 2% /run
tmpfs 493M 0 493M 0% /sys/fs/cgroup
/dev/sda1 197M 109M 88M 56% /boot
tmpfs 99M 0 99M 0% /run/user/0
/dev/mapper/vg1-lv1 93M 1.6M 85M 2% /mnt
[root@localhost ~]#
这里会发现,明明mount的是/dev/vg1/lv1这个文件,显示的却是/dev/mapper/vg1-lv1 这个文件,下面会看到它们指向的是同一个文件 /dm-0 文件
[root@hf-01 ~]# ls -l /dev/vg1/lv1
lrwxrwxrwx. 1 root root 7 11月 7 05:33 /dev/vg1/lv1 -> ../dm-0
[root@hf-01 ~]# ls -l /dev/mapper/vg1-lv1
lrwxrwxrwx. 1 root root 7 11月 7 05:33 /dev/mapper/vg1-lv1 -> ../dm-0
[root@hf-01 ~]#
[root@hf-01 ~]# mkdir /mnt/1212
[root@hf-01 ~]# touch /mnt/23.txt
[root@hf-01 ~]# echo "11111111" > /mnt/23.txt
[root@hf-01 ~]#
[root@hf-01 ~]# umount /mnt/
[root@hf-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 2.4G 16G 14% /
devtmpfs 489M 0 489M 0% /dev
tmpfs 494M 0 494M 0% /dev/shm
tmpfs 494M 6.7M 487M 2% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/sda1 197M 75M 123M 38% /boot
[root@hf-01 ~]# lvresize -L 200M /dev/vg1/lv1 重新设置逻辑卷的大小
Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).
Logical volume vg1/lv1 successfully resized.
[root@hf-01 ~]# e2fsck -f /dev/vg1/lv1 检查磁盘错误
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 13/25688 files (7.7% non-contiguous), 8899/102400 blocks
[root@hf-01 ~]# resize2fs /dev/vg1/lv1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 204800 blocks long.
[root@hf-01 ~]# !mount 重新挂载
mount /dev/vg1/lv1 /mnt/
[root@hf-01 ~]# df -h 这里会看到/dev/mapper/vg1-lv1扩容后,容量增加了
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 2.4G 16G 14% /
devtmpfs 489M 0 489M 0% /dev
tmpfs 494M 0 494M 0% /dev/shm
tmpfs 494M 6.7M 487M 2% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/sda1 197M 75M 123M 38% /boot
/dev/mapper/vg1-lv1 190M 1.6M 175M 1% /mnt
[root@hf-01 ~]# ls /mnt/ 这里会看到之前的文件,目录依旧存在,并没有随着扩容而消失
1212 23.txt lost+found
[root@hf-01 ~]# cat /mnt/23.txt
11111111
扩容后,会发现之前的文件依旧存在,没有受到任何的影响
(但是上述例子只是针对ext4文件系统的)
- 缩减逻辑卷(xfs不支持)
- 先umount
- e2fsck -f /dev/vg1/lv1 检查磁盘错误(ext)
- resize2fs /dev/vg1/lv1 100M 更新逻辑卷信息(ext)
- lvresize -L 100M /dev/vg1/lv1 重新设置卷的大小
[root@hf-01 ~]# !umount
umount /mnt/
[root@hf-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 2.4G 16G 14% /
devtmpfs 489M 0 489M 0% /dev
tmpfs 494M 0 494M 0% /dev/shm
tmpfs 494M 6.7M 487M 2% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/sda1 197M 75M 123M 38% /boot
[root@hf-01 ~]# e2fsck -f /dev/vg1/lv1
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/vg1/lv1: 13/49400 files (7.7% non-contiguous), 11887/204800 blocks
[root@hf-01 ~]# resize2fs /dev/vg1/lv1 100M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg1/lv1 to 102400 (1k) blocks.
The filesystem on /dev/vg1/lv1 is now 102400 blocks long.
[root@hf-01 ~]# lvresize -L 100M /dev/vg1/lv1
WARNING: Reducing active logical volume to 100.00 MiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg1/lv1? [y/n]: y //这里会提示是否操作,有可能会导致文件的损坏?
Size of logical volume vg1/lv1 changed from 200.00 MiB (50 extents) to 100.00 MiB (25 extents).
Logical volume vg1/lv1 successfully resized.
[root@hf-01 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 100.00m
[root@hf-01 ~]# !mount
mount /dev/vg1/lv1 /mnt/
[root@hf-01 ~]# ls /mnt/ 会看到缩容后,并不影响文件的存在
1212 23.txt lost+found
在xfs文件系统扩容的时候,不需要卸载,可直接扩容
xfs文件系统扩容,几大步骤:
[root@hf-01 ~]# !umount 先取消挂载
umount /mnt/
[root@hf-01 ~]# mkfs.xfs -f /dev/vg1/lv1 格式化成xfs文件系统
meta-data=/dev/vg1/lv1 isize=256 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@hf-01 ~]# !mount 再次挂载
mount /dev/vg1/lv1 /mnt/
[root@hf-01 ~]# ls /mnt/ 这里会看到之前的文件目录不存在了
[root@hf-01 ~]# touch /mnt/233.txt
[root@hf-01 ~]# echo "aaa" > !$
echo "aaa" > /mnt/233.txt
[root@hf-01 ~]# cat !$
cat /mnt/233.txt
aaa
[root@hf-01 ~]# lvs 查看逻辑卷大小
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-ao---- 100.00m
[root@hf-01 ~]# lvresize -L 300M /dev/vg1/lv1 扩容到300M(这里不需要先卸载,直接扩容)
Size of logical volume vg1/lv1 changed from 100.00 MiB (25 extents) to 300.00 MiB (75 extents).
Logical volume vg1/lv1 successfully resized.
[root@hf-01 ~]# lvs 会发现逻辑卷扩容到300M
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-ao---- 300.00m
[root@hf-01 ~]# df -h 但是查看的时候,看看到还是100M(还需执行命令)
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 2.4G 16G 14% /
devtmpfs 489M 0 489M 0% /dev
tmpfs 494M 0 494M 0% /dev/shm
tmpfs 494M 6.7M 487M 2% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/sda1 197M 75M 123M 38% /boot
/dev/mapper/vg1-lv1 97M 5.2M 92M 6% /mnt
[root@hf-01 ~]# xfs_growfs /dev/vg1/lv1 执行这条运行,xfs文件系统才是成功扩容
meta-data=/dev/mapper/vg1-lv1 isize=256 agcount=4, agsize=6400 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=25600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=853, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 25600 to 76800
[root@hf-01 ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 18G 2.4G 16G 14% /
devtmpfs 489M 0 489M 0% /dev
tmpfs 494M 0 494M 0% /dev/shm
tmpfs 494M 6.7M 487M 2% /run
tmpfs 494M 0 494M 0% /sys/fs/cgroup
/dev/sda1 197M 75M 123M 38% /boot
/dev/mapper/vg1-lv1 297M 5.5M 292M 2% /mnt
扩展卷组
(逻辑卷扩容最大化就是到卷组这么大)
实验(这里的物理卷已设置好,就只的从第三步开始)
[root@hf-01 ~]# vgextend vg1 /dev/sdb3
Volume group "vg1" successfully extended
[root@hf-01 ~]# vgs //这里出现小于号或者等于都不碍事的,有可能在分区和扩容过程中,会有一点点小误差
VG #PV #LV #SN Attr VSize VFree
vg1 3 1 0 wz--n- <2.99g <2.70g
先扩容卷组,再扩容逻辑卷