逻辑卷LVM
创建 扫描 显示详细 扩展 删除 更改
pvcreate pvscan pvdisplay pvs
vgcreate vgscan vgdisplay vgs vgextend vgremove vgchange
lvcreate lvscan lvdisplay lvs lvextend lvremove lvchange
====创建逻辑卷
1. 创建物理卷PV,跟创建普通分区的方式一样 (整个硬盘,不需要分区)
#fdisk -l
/dev/sda9 124736840 126689965 976563 8e Linux LVM
/dev/sda10 126690029 128643154 976563 8e Linux LVM
# partx -a /dev/sda 让内核刷新分区表
# pvcreate /dev/sda9 //创建PV
#pvs //查看
#pvdisplay //查看,详细信息
#pvscan //扫描pv卷
2. 创建卷组VG,VG是PV的集合。VG可以设置1到多个
# vgcreate vg01 /dev/sda9 //创建一个卷组,将创建的一个pv指定到该卷组
#vgs //查看
#vgdisplay /dev/vg01
[root@station3 ~]# echo $[65534*4/1024] //PE为4M时,vg最大为255G .( 每个vg里最多只能有65534个PE )
255
3. 创建逻辑卷LV
# lvcreate -L 500M -n lv01 vg01 //L指定大小 n 指定名字
#lvs
#lvdisplay /dev/vg01/lv01
4. 创建文件系统并挂载
# mkfs.ext3 /dev/vg01/lv01 //只能格式化LV,不能对PV和VG格式化
# mkdir /mnt/lv01
# vim /etc/fstab //永久的改
/dev/vg01/lv01 /mnt/lv01 auto defaults 0 0
# mount -a //读一下/etc/fstab文件,将里面写入的能够挂载的都挂载
==== 扩展逻辑卷
第一种情况:lv所在的卷组还有足够用于扩展的空间 vgdisplay
# lvextend -L 900M /dev/vg01/lv01 扩逻辑卷,扩大到900M
# lvcreate -L +500M vg01 //扩大500M
# resize2fs /dev/vg01/lv01 扩大文件系统(火车空间同步的例子)
# df
第二种情况:lv所在的卷组没有足够的空间
# pvcreate /dev/sda11
# vgextend datastorage /dev/sda11 //指定了扩展VG组datastorage
# lvextend -L 3G /dev/datastorage/newlv //指定了从datastorage里拿空间,扩大到3G
注意: 逻辑卷lv只能从他自己的卷组里拿空间,lvdisplay可以看到自己所属的卷组
#pvremove /dev/sda
============================================================
# vgremove datastorage 删除VG
# vgcreate -s 64M datastorage /dev/sda10 //-s指定PE(物理扩展)大小
# lvcreate -L 65M -n database datastorage
Rounding up size to full physical extent 128.00 MB
# lvremove /dev/datastorage/database //删除lv
# lvcreate -l 2 -n newlv datastorage //l指定PE数量
# resize2fs /dev/datastorage/newlv
============================================================
认识文件系统
===============================================
元数据(文件权限,时间戳,指向block的指针等信息)是记录在inode里的
实际数据在block中的
由此引出,删除文件的原理:目录中的block中存放下属文件的inode和文件名信息等, 删除文件就是将目录block中相应的信息移除 ,所以删除文件要求其上司要有w权限。
但是文件中的block并没有被删除,但是空间大小为0了。
===============================================
# tune2fs -l /dev/datastorage/newlv 查看文件系统
Inode count: 32768
Block count: 131072
Reserved block count: 6553
Free blocks: 121267
Free inodes: 32757
First block: 1
Block size: 1024
# ll -i file 查看文件的inode
# tune2fs -l /dev/datastorage/newl 查看文件系统信息 superblock
# dumpe2fs /dev/datastorage/newlv 查看文件系统信息 详细
文件链接:
1. 符号链接 symbolic link 和windows的快捷方式一样
软链接 ,它只是将源文件的名字和inode等信息做了记录,并不指向真实数据的inode和block等
[root@station230 ~]# echo "file55555" >> file5
[root@station230 ~]# echo "file66666" >> file6 //创建原文件
原文件 链接文件
[root@station230 ~]# ln -s /root/file5 /file5 //创建好的软链接把源文件删除后,链接也就出错了,因为没有了原文件的名字和inode
[root@station230 ~]# ln -s file6 /file6 错误
注: 原文件建议使用绝对路径
[root@station230 ~]# ll /file*
lrwxrwxrwx 1 root root 11 11-02 11:26 /file5 -> /root/file5
lrwxrwxrwx 1 root root 5 11-02 11:26 /file6 -> file6 红底白字
示例二
[root@station230 ~]# echo "file55555" >> file5
[root@station230 ~]# echo "file66666" >> file6
[root@station230 ~]#
[root@station230 ~]# ln -s /root/file5 / //不起名就和原来的一样
[root@station230 ~]# ln -s /root/file6 /aaa
[root@station230 ~]#
[root@station230 ~]# ll /file5 /aaa
lrwxrwxrwx 1 root root 11 11-02 11:33 /aaa -> /root/file6
lrwxrwxrwx 1 root root 11 11-02 11:33 /file5 -> /root/file5
链接文件的权限没有意义
[root@station230 ~]# ll -i /root/file5 /file5 查看文件的inode
293764 lrwxrwxrwx 1 root root 11 11-02 11:33 /file5 -> /root/file5
70779 -rw-r--r-- 1 root root 10 11-02 11:33 /root/file5
2. 硬链接(指向同一个inode,硬链接可以将原文件删除,只是连接数少了一个 )
[root@station230 ~]# echo "file55555" >> file5
[root@station230 ~]# echo "file66666" >> file6
[root@station230 ~]#
[root@station230 ~]# ln /root/file5 /file5
[root@station230 ~]# ln /root/file6 /
[root@station230 ~]# ll -i /root/file5 /file5
70779 -rw-r--r-- 2 root root 20 11-02 11:36 /file5
70779 -rw-r--r-- 2 root root 20 11-02 11:36 /root/file5
root@station5 home]# ln 111 /home/it1/222
[root@station5 home]# cd ./it1/
[root@station5 it1]# ls
222 aaa aaaa grub.conf it rwx.jpg yum.repos.d
[root@station5 it1]# cat 222
2012年 10月 29日 星期一 14:38:27 CST
[root@station5 it1]# cd ..
[root@station5 home]# cat 111
2012年 10月 29日 星期一 14:38:27 CST
=============================================================
注: 硬链接
1. 不能跨分区(不能从/var和/boot之间做硬链接)
2. 不支持目录做硬链接
[root@station5 home]# ln /home/ /mnt
ln: “/home/”: 不允许将硬链接指向目录
=============================================================
======== 逻辑卷快照 snapshot ======
# lvcreate -L 50M -s -n lv01-snap /dev/vg01/lv01 //创建逻辑卷快照
# lvscan
ACTIVE '/dev/datastorage/newlv' [3.00 GB] inherit
ACTIVE Original '/dev/vg01/lv01' [900.00 MB] inherit
ACTIVE Snapshot '/dev/vg01/lv01-snap' [52.00 MB] inherit
[root@station230 ~]# mkdir /mnt/lv01-snap
[root@station230 ~]# mount /dev/vg01/lv01-snap /mnt/lv01-snap/ 挂载快照卷
[root@station230 ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/mapper/vg01-lv01
892621 496041 350735 59% /mnt/lv01
/dev/mapper/vg01-lv01--snap //这是原文件,/dev/vg01/lv01-snap是它的软链接
892621 496041 350735 59% /mnt/lv01-snap
[root@station230 ~]# ls /mnt/lv01
file1 hosts lost+found passwd
[root@station230 ~]# ls /mnt/lv01-snap/
file1 hosts lost+found passwd
==============================================================================================================
做快照卷的一瞬间,快照卷只是存储了原卷里文件的元数据,对原卷上的老文件(快照照下来的文件)操作(修改或者删除),在被修改或删除之前
就先被备份到快照卷里,再次强调这一切只针对作快照一瞬间的老文件数据,原卷新添加的文件不好使。访问作快照那一时刻的数据时,修改或者删除的在快照卷里访问,
没发生改变的老文件还是在原卷里访问。下面有例子
=============================================================================================================
[root@station230 ~]# echo ddddd >> /mnt/lv01/hosts
[root@station230 ~]# cat /mnt/lv01/hosts //查看原卷上的文件
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 station230.uplooking.com station230 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.2.129 sss
192.168.2.136 ssssss
ddddd //多了一行ddddd
[root@station230 ~]# cat /mnt/lv01-snap/hosts //查看快照卷
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 station230.uplooking.com station230 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.2.129 sss
192.168.2.136 ssssss
[root@station230 ~]# lvdisplay
# vgchange -a y vg01 激活卷组
# lvchange -a y lv01 激活逻辑卷
快照卷的应用
使用快照卷备份 示例:
1。 创建快照卷
# lvcreate -L 50M -s -n lv01-snap /dev/vg01/lv01
2。只读的方式挂载
mount -o ro /dev/vg01/lv01-snap /mnt/lv01-snap
3. 使用快照卷备份数据,涉及到快照那一刻数据的访问
4。备份完成后卸载并删除快照卷
==== 利用快照功能来克隆多个系统
1。 在逻辑卷上安装系统(原卷)
2。 对原卷做多个快照,产生多个系统
创建 扫描 显示详细 扩展 删除 更改
pvcreate pvscan pvdisplay pvs
vgcreate vgscan vgdisplay vgs vgextend vgremove vgchange
lvcreate lvscan lvdisplay lvs lvextend lvremove lvchange
====创建逻辑卷
1. 创建物理卷PV,跟创建普通分区的方式一样 (整个硬盘,不需要分区)
#fdisk -l
/dev/sda9 124736840 126689965 976563 8e Linux LVM
/dev/sda10 126690029 128643154 976563 8e Linux LVM
# partx -a /dev/sda 让内核刷新分区表
# pvcreate /dev/sda9 //创建PV
#pvs //查看
#pvdisplay //查看,详细信息
#pvscan //扫描pv卷
2. 创建卷组VG,VG是PV的集合。VG可以设置1到多个
# vgcreate vg01 /dev/sda9 //创建一个卷组,将创建的一个pv指定到该卷组
#vgs //查看
#vgdisplay /dev/vg01
[root@station3 ~]# echo $[65534*4/1024] //PE为4M时,vg最大为255G .( 每个vg里最多只能有65534个PE )
255
3. 创建逻辑卷LV
# lvcreate -L 500M -n lv01 vg01 //L指定大小 n 指定名字
#lvs
#lvdisplay /dev/vg01/lv01
4. 创建文件系统并挂载
# mkfs.ext3 /dev/vg01/lv01 //只能格式化LV,不能对PV和VG格式化
# mkdir /mnt/lv01
# vim /etc/fstab //永久的改
/dev/vg01/lv01 /mnt/lv01 auto defaults 0 0
# mount -a //读一下/etc/fstab文件,将里面写入的能够挂载的都挂载
==== 扩展逻辑卷
第一种情况:lv所在的卷组还有足够用于扩展的空间 vgdisplay
# lvextend -L 900M /dev/vg01/lv01 扩逻辑卷,扩大到900M
# lvcreate -L +500M vg01 //扩大500M
# resize2fs /dev/vg01/lv01 扩大文件系统(火车空间同步的例子)
# df
第二种情况:lv所在的卷组没有足够的空间
# pvcreate /dev/sda11
# vgextend datastorage /dev/sda11 //指定了扩展VG组datastorage
# lvextend -L 3G /dev/datastorage/newlv //指定了从datastorage里拿空间,扩大到3G
注意: 逻辑卷lv只能从他自己的卷组里拿空间,lvdisplay可以看到自己所属的卷组
#pvremove /dev/sda
============================================================
# vgremove datastorage 删除VG
# vgcreate -s 64M datastorage /dev/sda10 //-s指定PE(物理扩展)大小
# lvcreate -L 65M -n database datastorage
Rounding up size to full physical extent 128.00 MB
# lvremove /dev/datastorage/database //删除lv
# lvcreate -l 2 -n newlv datastorage //l指定PE数量
# resize2fs /dev/datastorage/newlv
============================================================
认识文件系统
===============================================
元数据(文件权限,时间戳,指向block的指针等信息)是记录在inode里的
实际数据在block中的
由此引出,删除文件的原理:目录中的block中存放下属文件的inode和文件名信息等, 删除文件就是将目录block中相应的信息移除 ,所以删除文件要求其上司要有w权限。
但是文件中的block并没有被删除,但是空间大小为0了。
===============================================
# tune2fs -l /dev/datastorage/newlv 查看文件系统
Inode count: 32768
Block count: 131072
Reserved block count: 6553
Free blocks: 121267
Free inodes: 32757
First block: 1
Block size: 1024
# ll -i file 查看文件的inode
# tune2fs -l /dev/datastorage/newl 查看文件系统信息 superblock
# dumpe2fs /dev/datastorage/newlv 查看文件系统信息 详细
文件链接:
1. 符号链接 symbolic link 和windows的快捷方式一样
软链接 ,它只是将源文件的名字和inode等信息做了记录,并不指向真实数据的inode和block等
[root@station230 ~]# echo "file55555" >> file5
[root@station230 ~]# echo "file66666" >> file6 //创建原文件
原文件 链接文件
[root@station230 ~]# ln -s /root/file5 /file5 //创建好的软链接把源文件删除后,链接也就出错了,因为没有了原文件的名字和inode
[root@station230 ~]# ln -s file6 /file6 错误
注: 原文件建议使用绝对路径
[root@station230 ~]# ll /file*
lrwxrwxrwx 1 root root 11 11-02 11:26 /file5 -> /root/file5
lrwxrwxrwx 1 root root 5 11-02 11:26 /file6 -> file6 红底白字
示例二
[root@station230 ~]# echo "file55555" >> file5
[root@station230 ~]# echo "file66666" >> file6
[root@station230 ~]#
[root@station230 ~]# ln -s /root/file5 / //不起名就和原来的一样
[root@station230 ~]# ln -s /root/file6 /aaa
[root@station230 ~]#
[root@station230 ~]# ll /file5 /aaa
lrwxrwxrwx 1 root root 11 11-02 11:33 /aaa -> /root/file6
lrwxrwxrwx 1 root root 11 11-02 11:33 /file5 -> /root/file5
链接文件的权限没有意义
[root@station230 ~]# ll -i /root/file5 /file5 查看文件的inode
293764 lrwxrwxrwx 1 root root 11 11-02 11:33 /file5 -> /root/file5
70779 -rw-r--r-- 1 root root 10 11-02 11:33 /root/file5
2. 硬链接(指向同一个inode,硬链接可以将原文件删除,只是连接数少了一个 )
[root@station230 ~]# echo "file55555" >> file5
[root@station230 ~]# echo "file66666" >> file6
[root@station230 ~]#
[root@station230 ~]# ln /root/file5 /file5
[root@station230 ~]# ln /root/file6 /
[root@station230 ~]# ll -i /root/file5 /file5
70779 -rw-r--r-- 2 root root 20 11-02 11:36 /file5
70779 -rw-r--r-- 2 root root 20 11-02 11:36 /root/file5
root@station5 home]# ln 111 /home/it1/222
[root@station5 home]# cd ./it1/
[root@station5 it1]# ls
222 aaa aaaa grub.conf it rwx.jpg yum.repos.d
[root@station5 it1]# cat 222
2012年 10月 29日 星期一 14:38:27 CST
[root@station5 it1]# cd ..
[root@station5 home]# cat 111
2012年 10月 29日 星期一 14:38:27 CST
=============================================================
注: 硬链接
1. 不能跨分区(不能从/var和/boot之间做硬链接)
2. 不支持目录做硬链接
[root@station5 home]# ln /home/ /mnt
ln: “/home/”: 不允许将硬链接指向目录
=============================================================
======== 逻辑卷快照 snapshot ======
# lvcreate -L 50M -s -n lv01-snap /dev/vg01/lv01 //创建逻辑卷快照
# lvscan
ACTIVE '/dev/datastorage/newlv' [3.00 GB] inherit
ACTIVE Original '/dev/vg01/lv01' [900.00 MB] inherit
ACTIVE Snapshot '/dev/vg01/lv01-snap' [52.00 MB] inherit
[root@station230 ~]# mkdir /mnt/lv01-snap
[root@station230 ~]# mount /dev/vg01/lv01-snap /mnt/lv01-snap/ 挂载快照卷
[root@station230 ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/mapper/vg01-lv01
892621 496041 350735 59% /mnt/lv01
/dev/mapper/vg01-lv01--snap //这是原文件,/dev/vg01/lv01-snap是它的软链接
892621 496041 350735 59% /mnt/lv01-snap
[root@station230 ~]# ls /mnt/lv01
file1 hosts lost+found passwd
[root@station230 ~]# ls /mnt/lv01-snap/
file1 hosts lost+found passwd
==============================================================================================================
做快照卷的一瞬间,快照卷只是存储了原卷里文件的元数据,对原卷上的老文件(快照照下来的文件)操作(修改或者删除),在被修改或删除之前
就先被备份到快照卷里,再次强调这一切只针对作快照一瞬间的老文件数据,原卷新添加的文件不好使。访问作快照那一时刻的数据时,修改或者删除的在快照卷里访问,
没发生改变的老文件还是在原卷里访问。下面有例子
=============================================================================================================
[root@station230 ~]# echo ddddd >> /mnt/lv01/hosts
[root@station230 ~]# cat /mnt/lv01/hosts //查看原卷上的文件
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 station230.uplooking.com station230 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.2.129 sss
192.168.2.136 ssssss
ddddd //多了一行ddddd
[root@station230 ~]# cat /mnt/lv01-snap/hosts //查看快照卷
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 station230.uplooking.com station230 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.2.129 sss
192.168.2.136 ssssss
[root@station230 ~]# lvdisplay
# vgchange -a y vg01 激活卷组
# lvchange -a y lv01 激活逻辑卷
快照卷的应用
使用快照卷备份 示例:
1。 创建快照卷
# lvcreate -L 50M -s -n lv01-snap /dev/vg01/lv01
2。只读的方式挂载
mount -o ro /dev/vg01/lv01-snap /mnt/lv01-snap
3. 使用快照卷备份数据,涉及到快照那一刻数据的访问
4。备份完成后卸载并删除快照卷
==== 利用快照功能来克隆多个系统
1。 在逻辑卷上安装系统(原卷)
2。 对原卷做多个快照,产生多个系统