Linux 2 Unit5

Source: Internet
Author: User

UNIT5 Flexible storage with logical volume management

# # #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 (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 03:52/dev/mapper/vg0-lv0. /dm-0 # #下面测试结果出现/mapper is the same as/vg0
[email protected] ~]# ll/dev/vg0/lv0
lrwxrwxrwx. 1 root root 7 Apr 03:52/dev/vg0/lv0. /dm-0

Test results

Password:watch-n 1 ' echo ===pvmessage==;p vs;echo===vgmessage===;vgs;echo===lvm Message===;lvs;echo = = =;d F/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]tion ~]# 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, if only available///warn of insufficient space left
[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//tensile success
[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) Prepare before shrinking
[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
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) Start shrinking
[email protected] ~]# umount/weixindata/# #卸载
[[email protected] ~]# e2fsck-f/dev/vg0/lv0 # #扫描 (How large the system detects the file system itself)

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.)
Does 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 remove VDB1 from 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) is 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


Guardianship Password:
watch-n 1 ' echo ===pvmessage==; pvs;echo===vgmessage===;vgs;echo===lvmmessage===;lvs;echo = = =;d F/weixindata '

Monitor screen when snapshot is successful:
===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]tion ~]# vgremove vg0 Delete VG
Volume Group "vg0" successfully removed
[[email protected] ~]# pvremove/dev/vdb2 remove PV
Labels on physical volume "/DEV/VDB2" successfully wiped


This article from "Aely Wood" blog, reproduced please contact the author!

Linux 2 Unit5

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.