1,准备工作虚拟机vmware 和redhat6 server,模拟给redhat6添加两块SCSI硬盘大小为5G和7G 也可以自定大小,添加完成->开机,(如果开机状态添加的)# :reboot
2,查看磁盘的磁盘名 fdisk -l (确定/dev/sdb和/dev/sdc 两块磁盘)
[[email protected] ~]# ll /dev/sd*
brw-rw----. 1 root disk 8, 0 Mar 24 06:55 /dev/sda
brw-rw----. 1 root disk 8, 1 Mar 24 06:55 /dev/sda1
brw-rw----. 1 root disk 8, 2 Mar 24 06:55 /dev/sda2
brw-rw----. 1 root disk 8, 16 Mar 24 06:55 /dev/sdb
brw-rw----. 1 root disk 8, 32 Mar 24 06:55 /dev/sdc
3对/dev/sdb 和/dev/sdc 分区
[[email protected] ~]# fdisk /dev/sdb
Command (m for help): n --->命令n 创建新分区
Command action
e extended ---->e为扩展分区
p primary partition (1-4)----->p为主分区
p ----->我们这里选择主分区
Partition number (1-4): 1 ----->主分区编号,选择默认
First cylinder (1-652, default 1): ----->起始柱面号码,选择默认
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-652, default 652): ----->结束柱面编号,根据自己的磁盘划分,可以用+#G来确定
Using default value 652
Command (m for help): t----->命令t 改变分区类型
Selected partition 1
Hex code (type L to list codes): 8e----->类型为8e LVM 如果有不知道类型的可以L查看
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): w----->命令w 保存退出
以同样方法创建/dev/sdc
4执行命令:partprobe ----->重新读取分区表
cat /proc/partitons ----->查看分区表是否加载创的新分区
5pv 物理卷
1:pv 创建
[[email protected] ~]# pvcreate /dev/sdb1 /dev/sdc1-----> pvcreate 跟要加入pv的设备
Physical volume "/dev/sdb1" successfully created
Physical volume "/dev/sdc1" successfully created
2:pv :查看pv信息
[[email protected] ~]# pvs -----> 查看pv信息
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup lvm2 a-- 19.51g 0
/dev/sdb1 lvm2 a-- 4.99g 4.99g
/dev/sdc1 lvm2 a-- 6.99g 6.99g
---------------------------------------------------------------
[[email protected] ~]# pvdisplay -----> 查看pv的详细信息
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID NtZgu3-kqfB-HYtw-YMzu-oM6r-Fy9c-0kmeqf
"/dev/sdb1" is a new physical volume of "4.99 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size 4.99 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID CCEdHk-dQJi-YfZi-SGnO-cnoc-mLgV-AqwokJ
"/dev/sdc1" is a new physical volume of "6.99 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc1
VG Name
PV Size 6.99 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID tbAPyW-Mxzp-spvY-6qtA-k08s-pj40-7gWZHo
----------------------------------------------------------------------------
3:pv 的移除
[[email protected] ~]# pvremove /dev/sdb1------>跟要移除的分区
Labels on physical volume "/dev/sdb1" successfully wiped
[[email protected] ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 VolGroup lvm2 a-- 19.51g 0
/dev/sdc1 lvm2 a-- 6.99g 6.99g
-----------------------------------------------------
4:pv 元数据的移动
pvmove :加入vg以后,及生成PE ;使用pvremove 之前,要pvmove 转移原数据
----------------------------------------------------
5;pvscan 扫描系统上pv
[[email protected] ~]# pvscan
PV /dev/sda2 VG VolGroup lvm2 [19.51 GiB / 0 free]
PV /dev/sdb1 lvm2 [4.99 GiB]
PV /dev/sdc1 lvm2 [6.99 GiB]
Total: 3 [31.50 GiB] / in use: 1 [19.51 GiB] / in no VG: 2 [11.99 GiB
=============================================
6 vg 卷组
1;创建vg vgcreate
[[email protected] ~]# vgcreate myvg /dev/sdb1 /dev/sdc1---->vgcreate vg_name /part/to/sd :vgcreate 卷组名 跟要创建vg的设备
Volume group "myvg" successfully created
2;显示vg vgs/vgdisplay
[[email protected] ~]# vgs
VG #PV #LV #SN Attr VSize VFree
VolGroup 1 2 0 wz--n- 19.51g 0
myvg 2 0 0 wz--n- 11.98g 11.98g
-----------------------------------------------
[[email protected] ~]# vgdisplay
--- Volume group ---
VG Name myvg
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 11.98 GiB
PE Size 4.00 MiB
Total PE 3068
Alloc PE / Size 0 / 0
Free PE / Size 3068 / 11.98 GiB
VG UUID 7qz29d-SrAL-wgpf-0sQZ-XgjJ-mtVf-1eQpEG
--- Volume group ---
VG Name VolGroup
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 19.51 GiB
---------------------------------------------
3 删除vg vgremove
[[email protected] ~]# vgremove myvg ---->vgremove 卷组名
Volume group "myvg" successfully removed
4缩减vg(从vg中缩减pv) vgreduce
[[email protected] ~]# vgreduce myvg /dev/sdc1----->vgreduce 卷组名 卷组中的设备
Removed "/dev/sdc1" from volume group "myvg"
5扩展vg ;vgextend
[[email protected] ~]# vgextend myvg /dev/sdc1--->vgextend 要添加卷组名 要添加设备
Volume group "myvg" successfully extended
6扫描vg vgscan
[[email protected] ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "myvg" using metadata type lvm2
Found volume group "VolGroup" using metadata type lvm2
----------------------------------------------------------
7 lv 逻辑卷
1逻辑卷创建:lvcreate -L #G -n lv_name vg_name
-L :指定创建lv大小
-n :lv的名字
[[email protected] ~]# lvcreate -L 6G -n testlv myvg--->
Logical volume "testlv" created
2 lv 的查看 :lvs :查看信息 / lvdisplay:查看详细信息
[[email protected] ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 17.51g
lv_swap VolGroup -wi-ao---- 2.00g
testlv myvg -wi-a----- 6.00g
3 扫描lv :lvscan
[[email protected] ~]# lvscan
ACTIVE ‘/dev/myvg/testlv‘ [6.00 GiB] inherit
ACTIVE ‘/dev/VolGroup/lv_root‘ [17.51 GiB] inherit
ACTIVE ‘/dev/VolGroup/lv_swap‘ [2.00 GiB] inherit
4 格式化 mkfs /mke2fs
mke2fs -j /dev/myvg/testlv
[[email protected] ~]# mkfs /dev/myvg/testlv
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
393216 inodes, 1572864 blocks
78643 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1610612736
48 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
5挂载lv mount
mkdir -p /mnt/lv 在mnt目录下创建lv目录,留挂载用
mount /dev/myvg/testlv /mnt/lv
[[email protected] lv]# ll /mnt/lv ----->查看挂载点,看到lost+found 说明成功挂载
total 16
drwx------. 2 root root 16384 Mar 24 19:07 lost+found
6 查看挂载后的lv大小 df -lh
[[email protected] lv]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 1.9G 15G 12% /
tmpfs 931M 0 931M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/myvg-testlv 6.0G 12M 5.6G 1% /mnt/lv
8:lv的扩展
*1 扩展lv物理边界 ,先查看一下vg中是否有足够的可用空间
lvextend -L [+]#G /part/to/lv_name
注: 带+扩展#G 不带+表达扩展到#G
[[email protected] ~]# lvextend -L 10G /dev/myvg/testlv
Extending logical volume testlv to 10.00 GiB
Logical volume testlv successfully resized
(2)查看lv大小 lvs
Logical volume testlv successfully resized
[[email protected] lv]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root VolGroup -wi-ao---- 17.51g
lv_swap VolGroup -wi-ao---- 2.00g
testlv myvg -wi-ao---- 10.0 这是lv已经扩展到10G了。我们现在来看一下df -lh文件(3)系统中的lv大小
[[email protected] lv]# df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 1.9G 15G 12% /
tmpfs 931M 0 931M 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/myvg-testlv 6.0G 12M 5.6G 1% /mnt/lv 这是文件系统中的lv还是6G没有变化,所有我们还要扩展lv的文件系统边界
*2 扩展lv的文件系统边界 (在redhat5上支持在线扩展,redhat6不支持。需要卸载挂载)
lvsize2fs /part/to/lv_name #G
-p 扩展到和物理边界一样大
先卸载挂载umount /dev/myvg/testlv
[[email protected] lv]# umount /dev/myvg/testlv
umount: /mnt/lv: device is busy.---->磁盘繁忙,不让我们卸载。
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[[email protected] lv]# fuser -mk /dev/myvg/testlv---->把挂载点上的进程结束,可能会logout 重登
//dev/myvg/testlv: 2164c
再强行磁盘检查 e2fsck -f /dev/myvg/testlv
[[email protected] ~]# e2fsck -f /dev/myvg/testlv
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
最后扩展lv的文件系统边界 resize2fs /dev/myvg/testlv 10G
[[email protected] ~]# resize2fs /dev/myvg/testlv 10G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/myvg/testlv to 2621440 (4k) blocks.
The filesystem on /dev/myvg/testlv is now 2621440 blocks long.
重新挂载启动,mount /dve/myvg/testlv /mnt/lv
设置开机自动挂载 vi /etc/fstab 在里面添加一行
/dev/myvg/testlv /mnt/lv ext3 defaults 0 0
~
9 :lv的缩减
1,要先检查文件系统,确定缩减后的数据能够放的下
2,不能在线缩减,必须先卸载
3,缩减之前,必须先磁盘检查e2fsck ,再缩减lv文件系统大小resize2fs /part/to/lv_name
最后在缩减lv物理边界的大lvreduce -L #G /part/to/lv_name。
4,重新挂载启用
10 快照卷
lvcreate -s -L #G -n lv_name vg