Linux 2 unit5
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 2 unit5相关的知识,希望对你有一定的参考价值。
unit5 使用逻辑卷管理灵活存储
###LVM创建###
[[email protected] ~]# mkdir /weixindata ##建立目录
[[email protected] ~]# pvcreate /dev/vdb1 ##建立pv
Physical volume /dev/vdb1 notfound
Can‘t open /dev/vdb1 exclusively. Mounted filesystem?
[[email protected] ~]# vgcreate vg0 /dev/vdb1 ##建立vg
Physical volume /dev/vdb1 notfound
Physical volume /dev/vdb1 notfound
Can‘t open /dev/vdb1 exclusively. Mounted filesystem?
Unable to add physical volume‘/dev/vdb1‘ to volume group ‘vg0‘.
[[email protected] ~]# mkfs.xfs /dev/vg0
/dev/vg0: No such file or directory
Usage: mkfs.xfs
/* blocksize */ [-blog=n|size=num]
/* metadata */ [-m crc=[0|1]
/* data subvol */ [-dagcount=n,agsize=n,file,name=xxx,size=num,
(sunit=value,swidth=value|su=num,sw=num|noalign),
sectlog=n|sectsize=num
/* force overwrite */ [-f]
/* inode size */ [-ilog=n|perblock=n|size=num,maxpct=n,attr=0|1|2,
projid32bit=0|1]
/* no discard */ [-K]
/* log subvol */ [-lagnum=n,internal,size=num,logdev=xxx,version=n
sunit=value|su=num,sectlog=n|sectsize=num,
lazy-count=0|1]
/* label */ [-L label (maximum 12characters)]
/* naming */ [-nlog=n|size=num,version=2|ci,ftype=0|1]
/* no-op info only */ [-N]
/* prototype file */ [-p fname]
/* quiet */ [-q]
/* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx]
/* sectorsize */ [-slog=n|size=num]
/* version */ [-V]
devicename
is required unless -d name=xxx is given.
is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxxKiB),
xxxm (xxx MiB), xxxg (xxx GiB), xxxt(xxx TiB) or xxxp (xxx PiB).
is xxx (512 byte blocks).
[[email protected] ~]# mdadm -D /dev/md0 ##查看设备信息
mdadm: md device /dev/md0 does not appear to be active.
[[email protected] ~]# mdadm -S /dev/md0 ##停止此设备
mdadm: stopped /dev/md0
[[email protected] ~]# mdadm -a /dev/md0 /dev/vdb2 ##添加一个新设备
[[email protected] ~]# vgcreate vg0 /dev/vdb1
Volume group "vg0"successfully created
[[email protected] ~]# lvcreate -L 300M -n lv0 vg0 ##创建300M的lv0在vg0下
Logical volume "lv0"created
[[email protected] ~]# mkfs.xfs /dev/vg0/lv0 ##格式化
meta-data=/dev/vg0/lv0 isize=256 agcount=4,agsize=19200 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=76800, 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
[[email protected] ~]# mount /dev/vg0/lv0 /weixindata/ ##挂载
[[email protected] ~]# ll /dev/mapper/vg0-lv0
lrwxrwxrwx. 1 root root 7 Apr 22 03:52 /dev/mapper/vg0-lv0 -> ../dm-0 ##下面测试结果出现/mapper实则和/vg0相同
[[email protected] ~]# ll /dev/vg0/lv0
lrwxrwxrwx. 1 root root 7 Apr 22 03:52 /dev/vg0/lv0 -> ../dm-0
测试结果
口令:watch -n 1 ‘echo ===pvmessage==;pvs;echo===vgmessage===;vgs;echo===lvm message===;lvs;echo ===;df/weixindata‘
===pvmessage==
PV VG Fmt Attr PSize PFree
/dev/vdb1 vg0 lvm2 a-- 1020.00m 720.00m
VG #PV #LV #SN Attr VSize VFree
vg0 1 1 0 wz--n- 1020.00m 720.00m
LV VG Attr LSize Pool Origin Data
% Move Log Cpy%Sync Convert
lv0 vg0 -wi-ao---- 300.00m
===
Filesystem 1K-blocks Used Available U
se% Mounted on
/dev/mapper/vg0-lv0 303788 15520 288268
6% /weixindata
####设备拉伸####
[[email protected] ~]# lvextend -L 900M /dev/vg0/lv0 ##将原设备拉伸为900M
Extending logical volume lv0 to 900.00MiB
Logical volume lv0 successfullyresized
[[email protected]ation ~]# 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=0
data = bsize=4096 blocks=76800, 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 76800 to 230400
[[email protected] ~]# lvextend -L 1200M /dev/vg0/lv0 ##继续拉伸为1200
Extending logical volume lv0 to 1.17GiB
Insufficient free space: 75 extentsneeded, but only 30 available ///提醒剩余空间不足
[[email protected] ~]# pvcreate /dev/vdb2 ##创建另一个pv
Physical volume "/dev/vdb2"successfully created
[[email protected] ~]# vgextend vg0 /dev/vdb2 ##将另一个pv加入vg中
Volume group "vg0"successfully extended
[[email protected] ~]# lvextend -L 1200M /dev/vg0/lv0 ##继续拉伸
Extending logical volume lv0 to 1.17GiB
Logical volume lv0 successfully resized//拉伸成功
[[email protected] ~]# 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=0
data = bsize=4096 blocks=230400, 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 230400 to 307200
###系统的缩减###
1)缩减之前所做准备
[[email protected] ~]# umount /weixindata/ ##卸载
[[email protected] ~]# mkfs.ext4 /dev/vg0/lv0 ##更改文件系统
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
76800 inodes, 307200 blocks
15360 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=314572800
10 block groups
32768 blocks per group, 32768 fragments per group
7680 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376,294912
Allocating group tables: done
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
[[email protected] ~]# mount /dev/vg0/lv0 /weixindata/ ##挂载
[[email protected] ~]# df ##查看挂载是否成功
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 104739003241020 7232880 31% /
devtmpfs 927072 0 927072 0% /dev
tmpfs 942660 472 942188 1% /dev/shm
tmpfs 942660 17080 925580 2% /run
tmpfs 942660 0 942660 0% /sys/fs/cgroup
/dev/mapper/vg0-lv0 1176704 3600 1095280 1% /weixindata
2)开始缩减
[[email protected] ~]# umount /weixindata/ ##卸载
[[email protected] ~]# 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/76800 files (0.0% non-contiguous), 13924/307200 blocks
[[email protected] ~]# resize2fs /dev/vg0/lv0 300M ##缩减文件系统为300M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg0/lv0 to 76800 (4k) blocks.
The filesystem on /dev/vg0/lv0 is now 76800 blocks long.
[[email protected] ~]# mount /dev/vg0/lv0 /weixindata/ ##挂载
[[email protected] ~]# lvreduce -L 300 /dev/vg0/lv0 ##缩减设备
WARNING: Reducing active and openlogical volume to 300.00 MiB
THIS MAY DESTROY YOUR DATA (filesystemetc.)
Do you really want to reduce lv0? [y/n]: y
Reducing logical volume lv0 to 300.00MiB
Logical volume lv0 successfullyresized
[[email protected] ~]# pvmove /dev/vdb1 /dev/vdb2 ##把设备1信息传给设备2
[[email protected] ~]# vgreduce vg0 /dev/vdb1 ##把vdb1从vg0移除
Removed "/dev/vdb1" fromvolume group "vg0"
/dev/vdb1: Moved: 1.3%
/dev/vdb1: Moved: 100.0%
[[email protected] ~]# pvremove /dev/vdb1 把vdb1从pv移除
Labels on physical volume"/dev/vdb1" successfully wiped
####快照####
[[email protected] ~]# touch /weixindata/file{1..10}
[[email protected] ~]# ls /weixindata/
file1 file2 file4 file6 file8 lost+found
file10 file3 file5 file7 file9
[[email protected] ~]# umount /weixindata/
[[email protected] ~]# cd /weixindata/
[[email protected] weixindata]# ls
[[email protected] weixindata]# cd
[[email protected] ~]# lvcreate -L 50M -nlv0backup -s /dev/vg0/lv0 ###创建快照
Rounding up size to full physicalextent 52.00 MiB
Logical volume "lv0backup"created
[[email protected] ~]# mount /dev/vg0/lv0backup /weixindata/
[[email protected] ~]# cd /weixindata/
[[email protected] weixindata]# ls
file1 file2 file4 file6 file8 lost+found
file10 file3 file5 file7 file9
[[email protected] weixindata]# rm -fr *
[[email protected] weixindata]# ls
[[email protected] weixindata]# cd
[[email protected] ~]# umount /weixindata/
[[email protected] ~]# lvremove /dev/vg0/lvobackup ##删除坏了的快照
One or more specified logical volume(s)not found.
[[email protected] ~]# lvcreate -L 50M -nlv0backup -s /dev/vg0/lv0 ##重新快照
Rounding up size to full physicalextent 52.00 MiB
Logical volume "lv0backup"already exists in volume group "vg0"
[[email protected] ~]# mount /dev/vg0/lv0backup /weixindata/
[[email protected] ~]# ls /weixindata/
file1 file2 file4 file6 file8 lost+found
file10 file3 file5 file7 file9
监护口令:
watch -n 1 ‘echo ===pvmessage==; pvs;echo===vgmessage===;vgs;echo===lvmmessage===;lvs;echo ===;df /weixindata‘
快照成功时监护界面:
===pvmessage==
PV VG Fmt Attr PSize PFree
/dev/vdb2 vg0 lvm2 a-- 1020.00m 668.00m
VG #PV #LV #SN Attr VSize VFree
vg0 1 2 1 wz--n- 1020.00m 668.00m
LV VG Attr LSize Pool Origin
Data% Move Log Cpy%Sync Convert
lv0 vg0 owi-a-s--- 300.00m
lv0backup vg0 swi-a-s--- 52.00m lv0
0.00
===
Filesystem 1K-blocks Used Available Use%
Mounted on
/dev/vda1 10473900 3240980 7232920 31%
/
####LVM的删除####
[[email protected] ~]# umount /weixindata/ ##卸载
[[email protected] ~]# lvremove /dev/vg0/lv0backup ##删除快照
Do you really want to remove active logical volume lv0backup? [y/n]: y
Logical volume "lv0backup"successfully removed
[[email protected] ~]# lvremove /dev/vg0/lv0 ##删除lv0本身
Do you really want to remove active logical volume lv0? [y/n]: y
Logical volume "lv0"successfully removed
[[email protected]ation ~]# vgremove vg0 删除vg
Volume group "vg0"successfully removed
[[email protected] ~]# pvremove /dev/vdb2 删除pv
Labels on physical volume"/dev/vdb2" successfully wiped
本文出自 “AELY木” 博客,转载请与作者联系!
以上是关于Linux 2 unit5的主要内容,如果未能解决你的问题,请参考以下文章