unit5~~使用逻辑卷管理器管理灵活存储
来源:互联网 发布:淘宝上小提琴教学视频 编辑:程序博客网 时间:2024/06/08 00:34
1.LVM逻辑卷的创建
为什么使用逻辑卷
• 逻辑卷和逻辑卷管理有助于更加轻松地管理
磁盘空间。如果文件系统需要更多的空间 ,
可以将其卷组的可用空间分配给逻辑卷 , 并
且可以调整文件系统的大小。如果磁盘开始
出现错误 , 可以通过卷组将替换磁盘注册为
物理卷 , 并且逻辑卷的范围可迁移到新磁盘
。
使用命令行工具实施 LVM 存储
• 准备物理卷
– disk 用于创建与 LVM 结合使用的新分区。在要与 LVM 结合使用的分区上 , 始终将
“ 类型 ” 设置为 “ 0x8e Linux LVM”
– pvcreate /dev/vdaN 用于初始化分区 ( 或其他物理设备 ), 使其作为物理卷与 LVM 结
合使用。直接在物理卷中创建用于存储 LVM 配置数据的表头
• 创建卷组
– vgcreate vgname /dev/vdaN 将创建名为 vgname 且由物理卷 /dev/vdaN 组成的卷
组。您可以在创建时指定其他物理卷 ( 以空格隔开 ), 也可以随后使用 vgextend 添加
新物理卷
• 创建和使用新逻辑卷
– lvcreate -n lvname -L 2G vgname 从 vgname 上可用物理区块创建名为 lvname 、
容量为 2GB 的新逻辑卷
– mkfs -t ext4 /dev/vgname/lvname 将在新逻辑卷上创建 ext4 文件系统
– mkdir /data 建立所需目录作为挂载点
– 向 /etc/fstab 文件中添加一下条目:
/dev/mapper/vgname-lvname /data ext4 defaults 1 2
– 运行 mount -a 可在 /etc/fstab 中挂载所有文件系统 , 包括您刚刚添加的条目
Command (m for help): t ##选择分区类型Partition number (1,2, default 2): 1Hex code (type L to list all codes): 8e ##选择LVM类型的分区Changed type of partition 'Linux' to 'Linux LVM'Command (m for help): p ##显示创建好的分区Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x92763b95 Device Boot Start End Blocks Id System/dev/vdb1 2048 2099199 1048576 8e Linux LVM/dev/vdb2 2099200 4196351 1048576 8e Linux LVMCommand (m for help): wqThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[root@localhost ~]# partprobe [root@localhost ~]# pvcreate /dev/vdb1 Physical volume /dev/vdb1 not found Can't open /dev/vdb1 exclusively. Mounted filesystem?[root@localhost ~]# mount /dev/vdb1 /mntmount: unknown filesystem type 'linux_raid_member'[root@localhost ~]# pvcreate /dev/vdb1 Physical volume /dev/vdb1 not found Can't open /dev/vdb1 exclusively. Mounted filesystem?[root@localhost ~]# vgcreate vg0 /dev/vdb1 Physical volume /dev/vdb1 not found Physical volume /dev/vdb1 not found Can't open /dev/vdb1 exclusively. Mounted filesystem? Unable to add physical volume '/dev/vdb1' to volume group 'vg0'.[root@localhost ~]# dfFilesystem 1K-blocks Used Available Use% Mounted on/dev/vda1 10473900 3298000 7175900 32% /devtmpfs 927072 0 927072 0% /devtmpfs 942660 140 942520 1% /dev/shmtmpfs 942660 664 941996 1% /runtmpfs 942660 0 942660 0% /sys/fs/cgroup[root@localhost ~]# mdadm -D /dev/md0mdadm: md device /dev/md0 does not appear to be active.[root@localhost ~]# mdadm -S /dev/md0mdadm: stopped /dev/md0[root@localhost ~]# pvcreate /dev/vdb1 Physical volume /dev/vdb1 not foundWARNING: linux_raid_member signature detected on /dev/vdb1 at offset 4096. Wipe it? [y/n] y Wiping linux_raid_member signature on /dev/vdb1.WARNING: xfs signature detected on /dev/vdb1 at offset 0. Wipe it? [y/n] y Wiping xfs signature on /dev/vdb1. Physical volume "/dev/vdb1" successfully created[root@localhost ~]# vgcreate vg0 /dev/vdb1 Volume group "vg0" successfully created[root@localhost ~]# lvcreate -L 300M -n lv0 vg0 Logical volume "lv0" created[root@localhost ~]# mkfs.xfs /dev/vg0/lv0meta-data=/dev/vg0/lv0 isize=256 agcount=4, agsize=19200 blks = sectsz=512 attr=2, projid32bit=1 = crc=0data = bsize=4096 blocks=76800, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=0log =internal log bsize=4096 blocks=853, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0[root@localhost ~]# mount /dev/vg0/lv0 /mnt[root@localhost ~]#
2.查看 LVM 状态信息
• pvdisplay /dev/vdaN 将显示有关特定物理
卷的信息
• vgdisplay vgname 将显示有关特定卷组的
信息
• lvdisplay /dev/vgname/lvname 将显示有
关特定逻辑卷的信息
3.逻辑卷的扩展
[root@localhost ~]# lvextend -L 900M /dev/vg0/lv0 ##lv的扩展大小后为900M Extending logical volume lv0 to 900.00 MiB Logical volume lv0 successfully resized[root@localhost ~]# xfs_growfs /dev/vg0/lv0 ##文件系统的扩展meta-data=/dev/mapper/vg0-lv0 isize=256 agcount=4, agsize=19200 blks = sectsz=512 attr=2, projid32bit=1 = crc=0data = bsize=4096 blocks=76800, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=0log =internal bsize=4096 blocks=853, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 76800 to 230400[root@localhost ~]# lvextend -L 1500M /dev/vg0/lv0 ##lv扩展为1500M,提示大小不够 Extending logical volume lv0 to 1.46 GiB Insufficient free space: 150 extents needed, but only 30 available[root@localhost ~]# pvcreate /dev/vdb2 ##生成新的pv Physical volume /dev/vdb2 not foundWARNING: linux_raid_member signature detected on /dev/vdb2 at offset 4096. Wipe it? [y/n] y Wiping linux_raid_member signature on /dev/vdb2. Physical volume "/dev/vdb2" successfully created[root@localhost ~]# vgextend vg0 /dev/vdb2 ##将新的pv扩展到vg0中 Volume group "vg0" successfully extended[root@localhost ~]# lvextend -L 1500M /dev/vg0/lv0 ##重新进行lv扩展,并成功 Extending logical volume lv0 to 1.46 GiB Logical volume lv0 successfully resized[root@localhost ~]# xfs_growfs /dev/vg0/lv0 ##扩展文件系统meta-data=/dev/mapper/vg0-lv0 isize=256 agcount=12, agsize=19200 blks = sectsz=512 attr=2, projid32bit=1 = crc=0data = bsize=4096 blocks=230400, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=0log =internal bsize=4096 blocks=853, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data blocks changed from 230400 to 384000[root@localhost ~]#
4.逻辑卷的缩减
更改文件系统类型
[root@localhost ~]# umount /mnt/ ##先进行卸载
[root@localhost ~]# mkfs.ext4 /dev/vg0/lv0 ##更改文件系统类型
缩减前的准备工作
[root@localhost ~]# e2fsck -f /dev/vg0/lv0
e2fsck 1.42.9 (28-Dec-2013)
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/96000 files (9.1% non-contiguous), 15356/384000 blocks
[root@localhost ~]# mount /dev/vg0/lv0 /mnt
先缩减文件系统为300M
在进行卸载,然后缩减lv,依次进行缩减
5.创建和使用快照进行备份
• 创建 /dev/vgname/lvname 的名为 snaplvname 、大小
为 20M 的新快照卷
– lvcreate -s -n snaplv -L 20M /dev/vgname/lvname
• 如果备份软件要求 , 请挂载该快照 , 并使备份程序指向新
挂载点
– mkdir /snapmount
– mount -o ro /dev/vgname/snaplv /snapmount
• 验证快照逻辑卷的状态
– lvs /dev/vgname/snaplv
• 不再使用快照时 , 请解除挂载并删除它
– umount /snapmount
– lvremove /dev/vgname/snaplv
- unit5~~使用逻辑卷管理器管理灵活存储
- RHEL-RH134-UNIT5-使用逻辑卷管理器管理灵活存储
- 使用逻辑卷管理器管理灵活存储
- 使用逻辑卷管理器管理灵活存储
- 使用逻辑卷管理器管理灵活存储
- Linux下使用逻辑卷管理器管理灵活存储
- 5.使用逻辑卷管理器管理灵活存储 lvm
- unit2.5 使用逻辑卷管理器管理灵活存储
- 逻辑卷管理器(LVM)管理灵活存储
- 第五 使用逻辑卷管理器灵活存储
- 使用逻辑卷管理灵活存储
- linux杂谈(六):使用逻辑卷管理器管理灵活存储
- Linux运维笔记----使用逻辑卷管理器管理灵活存储
- linux基础2-5使用逻辑卷管理器管理灵活存储
- Linux学习第五单元-使用逻辑卷管理器管理灵活存储
- liunx初级学习之使用逻辑卷管理器灵活管理2-5
- Unix逻辑卷管理器---AIX存储管理的基础
- LVM逻辑卷管理器配置使用详解
- 2017 第十四届浙江acm省赛总结(退役???)
- java-jar包关联源文件
- web-xml
- linux Makefile(二)
- Angular第一天学习
- unit5~~使用逻辑卷管理器管理灵活存储
- opencv笔记(4):边缘检测
- Activity生命周期
- 表达式求值(栈(操作数栈+操作符栈))
- 斗地主AI算法——第六章の牌型判断
- lightOj 1341Aladdin and the Flying Carpet 算数基本定理
- OSTU 最佳全局阈值处理-最大类间方差法
- docker时间校正
- Spring学习笔记之Spring Security