首先建2分区
[root@localhost ~]# partx -d /dev/sdb
error deleting partition 4: BLKPG: No such device or address error deleting partitions 7-256: BLKPG: No such device or address
[root@localhost ~]# partx -a /dev/sdb 同步分区表也可以使用partprobe来刷新分区,力度没有partx大
[root@localhost ~]# cat /proc/partitions 这里面会显示我们当前系统的分区
major minor
#blocks name
8 0 41943040 sda 8 1 307200 sda1 8 2 4161536 sda2 8 3 37473280 sda3 8 16 8388608 sdb 8 17 204800 sdb1 8 18 204800 sdb2 8 19 1024 sdb3 8 21 307200 sdb5 8 22 102400 sdb6
[root@localhost ~]# pvcreate /dev/sdb5
Writing physical volume data to disk "/dev/sdb5"
Physical volume "/dev/sdb5" successfully created
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb5 lvm2 a-- 300.00m 300.00m
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb5 lvm2 a-- 300.00m 300.00m
[root@localhost ~]# pvdisplay
"/dev/sdb5" is a new physical volume of "300.00 MiB"
--- NEW Physical volume ---
PV Name /dev/sdb5
VG Name
PV Size 300.00 MiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 4YtDA6-RKEC-Nnh0-u2Qg-fSjv-q9bK-TaHsZJ
[root@localhost ~]# vgcreate vg0 /dev/sdb5
Volume group "vg0" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 1 0 0 wz--n- 296.00m 296.00m
[root@localhost ~]# lvcreate -L 100M -n lv0 /dev/vg0
Logical volume "lv0" created
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
lv0 vg0 -wi-a--- 100.00m
逻辑卷的扩展
比如当前的lv不够用了,我们得扩展,怎么办?
[root@localhost ~]# lvextend -L +30M /dev/vg0/lv0
Rounding size to boundary between physical extents: 32.00 MiB
Extending logical volume lv0 to 132.00 MiB
Logical volume lv0 successfully resized
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
lv0 vg0 -wi-a--- 132.00m
or
[root@localhost ~]# lvextend -L 200M /dev/vg0/lv0
Extending logical volume lv0 to 200.00 MiB
Logical volume lv0 successfully resized
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Copy% Convert
lv0 vg0 -wi-a--- 200.00m
如果我们的卷组不够用了怎么办?
[root@localhost ~]# pvcreate /dev/sdb6
Writing physical volume data to disk "/dev/sdb6"
Physical volume "/dev/sdb6" successfully created
[root@localhost ~]# vgextend /dev/sdb6
Please enter a physical volume path
Run `vgextend --help' for more information.
[root@localhost ~]# vgextend /dev/sdb6 /dev/vg0
Volume group "sdb6" not found
[root@localhost ~]# vgextend vg0 /dev/sdb6
Volume group "vg0" successfully extended
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 1 0 wz--n- 392.00m 192.00m
下面我们来玩在线拉伸就是在线扩展,还不损坏文件系统
[root@localhost ~]# mkfs.ext4 /dev/vg0/lv0
mke2fs 1.41.12 (17-May-2010) 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=67371008 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
Writing inode tables: done
Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 36885072 9376624 25634784 27% /
tmpfs 255524 264 255260 1% /dev/shm
/dev/sda1 297485 35202 246923 13% /boot
/dev/sr0 3027366 3027366 0 100% /media/RHEL_6.3 i386 Disc 1
[root@localhost ~]# mount /dev/vg0/lv0 /mnt/
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 36885072 9376624 25634784 27% /
tmpfs 255524 264 255260 1% /dev/shm
/dev/sda1 297485 35202 246923 13% /boot
/dev/sr0 3027366 3027366 0 100% /media/RHEL_6.3 i386 Disc 1
/dev/mapper/vg0-lv0 198337 5646 182451 4% /mnt
[root@localhost ~]#
[root@localhost ~]# e2fsck -f /dev/vg0/lv0
e2fsck 1.41.12 (17-May-2010) /dev/vg0/lv0 is mounted.
WARNING!!! The filesystem is mounted. If you continue you ***WILL*** cause ***SEVERE*** filesystem damage.
Do you really want to continue (y/n)? yes
/dev/vg0/lv0: recovering journal Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg0/lv0: 11/51200 files (0.0% non-contiguous), 12109/204800 blocks
[root@localhost ~]# lvextend -L +30M /dev/vg0/lv0
Rounding size to boundary between physical extents: 32.00 MiB
Extending logical volume lv0 to 232.00 MiB
Logical volume lv0 successfully resized
[root@localhost ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 38G 9.7G 27G 27% /
tmpfs 262M 271k 262M 1% /dev/shm
/dev/sda1 305M 37M 253M 13% /boot
/dev/sr0 3.2G 3.2G 0 100% /media/RHEL_6.3 i386 Disc 1
/dev/mapper/vg0-lv0 204M 5.8M 187M 4% /mnt
root@localhost ~]# resize2fs /dev/vg0/lv0
resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg0/lv0 is mounted on /mnt; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/vg0/lv0 to 237568 (1k) blocks. The filesystem on /dev/vg0/lv0 is now 237568 blocks long.
[root@localhost ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 38G 9.7G 27G 27% /
tmpfs 262M 271k 262M 1% /dev/shm
/dev/sda1 305M 37M 253M 13% /boot
/dev/sr0 3.2G 3.2G 0 100% /media/RHEL_6.3 i386 Disc 1
/dev/mapper/vg0-lv0 236M 6.4M 218M 3% /mnt
逻辑卷的压缩
[root@localhost ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 38G 9.7G 27G 27% /
tmpfs 262M 271k 262M 1% /dev/shm
/dev/sda1 305M 37M 253M 13% /boot
/dev/sr0 3.2G 3.2G 0 100% /media/RHEL_6.3 i386 Disc 1
/dev/mapper/vg0-lv1 102M 5.8M 91M 7% /mnt
[root@localhost ~]# umount /mnt/
[root@localhost ~]# e2fsck -f /dev/vg0/lv1
e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vg0/lv1: 11/25688 files (9.1% non-contiguous), 8896/102400 blocks [root@localhost ~]# resize2fs /dev/vg0/lv1 30M
resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vg0/lv1 to 30720 (1k) blocks. The filesystem on /dev/vg0/lv1 is now 30720 blocks long.
[root@localhost ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 38G 9.7G 27G 27% /
tmpfs 262M 271k 262M 1% /dev/shm
/dev/sda1 305M 37M 253M 13% /boot
/dev/sr0 3.2G 3.2G 0 100% /media/RHEL_6.3 i386 Disc 1
[root@localhost ~]# mount /dev/vg0/lv1 /mnt/
[root@localhost ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 38G 9.7G 27G 27% /
tmpfs 262M 271k 262M 1% /dev/shm
/dev/sda1 305M 37M 253M 13% /boot
/dev/sr0 3.2G 3.2G 0 100% /media/RHEL_6.3 i386 Disc 1
/dev/mapper/vg0-lv1 31M 5.0M 24M 18% /mnt
[root@localhost ~]# lvreduce -L 30M /dev/vg0/lv1
Rounding size to boundary between physical extents: 32.00 MiB WARNING: Reducing active and open logical volume to 32.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv1? [y/n]: y
Reducing logical volume lv1 to 32.00 MiB Logical volume lv1 successfully resized
[root@localhost ~]# df -H
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 38G 9.7G 27G 27% /
tmpfs 262M 271k 262M 1% /dev/shm
/dev/sda1 305M 37M 253M 13% /boot
/dev/sr0 3.2G 3.2G 0 100% /media/RHEL_6.3 i386 Disc 1
/dev/mapper/vg0-lv1 31M 5.0M 24M 18% /mnt
现在有2快pv,一块大的用的很少,一块小的有没用,而我们现在想用那块大的,资源紧张时,我们该怎么节省空间
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb5 vg0 lvm2 a-- 296.00m 264.00m
/dev/sdb6 vg0 lvm2 a-- 96.00m 96.00m
[root@localhost ~]# pvmove /dev/sdb5 /dev/sdb6
/dev/sdb5: Moved: 0.0%
/dev/sdb5: Moved: 100.0%
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb5 vg0 lvm2 a-- 296.00m 296.00m
/dev/sdb6 vg0 lvm2 a-- 96.00m 64.00m
最后我们来移除逻辑卷
[root@localhost ~]# umount /mnt/
[root@localhost ~]# lvremove /dev/vg0/lv1
Do you really want to remove active logical volume lv1? [y/n]: y
Logical volume "lv1" successfully removed
[root@localhost ~]# lvs
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg0 2 0 0 wz--n- 392.00m 392.00m
[root@localhost ~]# vgremove /dev/vg0
Volume group "vg0" successfully removed
[root@localhost ~]# vgs
No volume groups found
[root@localhost ~]# pvremove /dev/sdb5
Labels on physical volume "/dev/sdb5" successfully wiped
[root@localhost ~]# pvremove /dev/sdb6
Labels on physical volume "/dev/sdb6" successfully wiped
[root@localhost ~]# pvs
到此我们的逻辑卷就完了