西部开源学习笔记BOOK2-《unit 5》

#########################

####### unit5.lvm #######

#########################

lvm的逻辑关系:

物理分区--->pv物理卷---->vg物理卷组----->取出一部分的叫lvm

/\

||组成

pe(卷的最小单位)

注意:那vg可不可以无限扩大? 不可以

因为xfs文件系统最大支持18EB,超过的话就无法管理。

######1.创建物理分区########

[[email protected] ~]# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x0e7029a1.

Command (m for help): n

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p):

Using default response p

Partition number (1-4, default 1):

First sector (2048-20971519, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +500M

Partition 1 of type Linux and of size 500 MiB is set

Command (m for help): n

Partition type:

p primary (1 primary, 0 extended, 3 free)

e extended

Select (default p):

Using default response p

Partition number (2-4, default 2):

First sector (1026048-20971519, default 1026048):

Using default value 1026048

Last sector, +sectors or +size{K,M,G} (1026048-20971519, default 20971519): +500M

Partition 2 of type Linux and of size 500 MiB is set

Command (m for help): t

Partition number (1,2, default 2):

Hex code (type L to list all codes): 8e ##分区id号:8e Linux LVM

Changed type of partition ‘Linux‘ to ‘Linux LVM‘

Command (m for help): t

Partition number (1,2, default 2): 1

Hex code (type L to list all codes): 8e

Changed type of partition ‘Linux‘ to ‘Linux LVM‘

Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x0e7029a1

Device Boot Start End Blocks Id System

/dev/vdb1 2048 1026047 512000 8e Linux LVM

/dev/vdb2 1026048 2050047 512000 8e Linux LVM

Command (m for help): wq

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[[email protected] ~]# partprobe

#######2.创建lvm#######

[[email protected] ~]# pvcreate /dev/vdb1 ##创建pv

Physical volume "/dev/vdb1" successfully created

[[email protected] ~]# vgcreate tbr /dev/vdb1 ##创建vg,取名为tbr,包含/dev/vdb1

Volume group "tbr" successfully created

[[email protected] ~]# lvcreate -L 100M -n lv0 tbr ##

Logical volume "lv0" created

[[email protected] ~]# mkfs.xfs /dev/tbr/lv0

meta-data=/dev/tbr/lv0 isize=256 agcount=4, agsize=6400 blks

= sectsz=512 attr=2, projid32bit=1

= crc=0

data = bsize=4096 blocks=25600, 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/tbr/lv0 /mnt/

[[email protected] ~]# df

Filesystem 1K-blocks Used Available Use% Mounted on

/dev/vda1 10473900 3119952 7353948 30% /

devtmpfs 927072 0 927072 0% /dev

tmpfs 942660 80 942580 1% /dev/shm

tmpfs 942660 17040 925620 2% /run

tmpfs 942660 0 942660 0% /sys/fs/cgroup

/dev/mapper/tbr-lv0 98988 5280 93708 6% /mnt

[[email protected] ~]# ll /dev/tbr/lv0

lrwxrwxrwx. 1 root root 7 11月 6 01:29 /dev/tbr/lv0 -> ../dm-0

[[email protected] ~]# ll /dev/mapper/tbr-lv0

lrwxrwxrwx. 1 root root 7 11月 6 01:29 /dev/mapper/tbr-lv0 -> ../dm-0

[[email protected] ~]# watch -n 1 ‘echo "===pvinfo===";pvs;echo "===vginfo===";vgs;echo

"===lvinfo===";lvs;df -h /mnt‘

===pvinfo===

PV VG Fmt Attr PSize PFree

/dev/vdb1 tbr lvm2 a-- 496.00m 396.00m

===vginfo===

VG #PV #LV #SN Attr VSize VFree

tbr 1 1 0 wz--n- 496.00m 396.00m

===lvinfo===

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert

lv0 tbr -wi-ao---- 100.00m

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/tbr-lv0 97M 5.2M 92M 6% /mnt

############2.扩展lvm############

[[email protected] ~]# lvcreate -L 100M -n lv0 tbr

Logical volume "lv0" created

[[email protected] ~]# mkfs.xfs /dev/tbr/lv0

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/tbr-lv0 297M 5.5M 292M 2% /mnt

[[email protected] ~]# lvextend -L 200M /dev/tbr/lv0

Extending logical volume lv0 to 200.00 MiB

Logical volume lv0 successfully resized

[[email protected] ~]# lvextend -L 500M /dev/tbr/lv0

Extending logical volume lv0 to 500.00 MiB

Insufficient free space: 75 extents needed, but only 74 available

[[email protected] ~]# lvextend -L 300M /dev/tbr/lv0

Extending logical volume lv0 to 300.00 MiB

Logical volume lv0 successfully resized

[[email protected] ~]# xfs_growfs /dev/tbr/lv0

[[email protected] ~]# pvcreate /dev/vdb2

Physical volume "/dev/vdb2" successfully created

[[email protected] ~]# vgextend tbr /dev/vdb2

Volume group "tbr" successfully extended

[[email protected] ~]# lvextend -L 600M /dev/tbr/lv0

Extending logical volume lv0 to 600.00 MiB

Logical volume lv0 successfully resized

===pvinfo===

PV VG Fmt Attr PSize PFree

/dev/vdb1 tbr lvm2 a-- 496.00m 0

/dev/vdb2 tbr lvm2 a-- 496.00m 392.00m

===vginfo===

VG #PV #LV #SN Attr VSize VFree

tbr 2 1 0 wz--n- 992.00m 392.00m

===lvinfo===

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert

lv0 tbr -wi-ao---- 600.00m

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/tbr-lv0 297M 5.5M 292M 2% /mnt

[[email protected] ~]# xfs_growfs /dev/tbr/lv0

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/tbr-lv0 597M 5.8M 591M 1% /mnt

#############3.缩减lvm##############

[[email protected] ~]# umount /mnt

[[email protected] ~]# mkfs.ext4 /dev/tbr/lv0

[[email protected] ~]# e2fsck -f /dev/tbr/lv0

[[email protected] ~]# resize2fs /dev/tbr/lv0 400M

[[email protected] ~]# mount /dev/tbr/lv0 /mnt/

[[email protected] ~]# lvreduce -L 400M /dev/tbr/lv0

WARNING: Reducing active and open logical volume to 400.00 MiB

THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce lv0? [y/n]: y

Reducing logical volume lv0 to 400.00 MiB

Logical volume lv0 successfully resized

[[email protected] ~]# pvmove /dev/vdb1 /dev/vdb2

/dev/vdb1: Moved: 13.0%

/dev/vdb1: Moved: 100.0%

[[email protected] ~]# vgreduce tbr /dev/vdb1

===pvinfo===

PV VG Fmt Attr PSize PFree

/dev/vdb1 lvm2 a-- 500.00m 500.00m

/dev/vdb2 tbr lvm2 a-- 496.00m 96.00m

[[email protected] ~]# pvremove /dev/vdb1

===pvinfo===

PV VG Fmt Attr PSize PFree

/dev/vdb2 tbr lvm2 a-- 496.00m 96.00m

pvmove的时候耐心等待,不要ctrl+c(操作数据时要小心)

#####特殊情况#####

1.如果先缩减了物理卷组的大小,而没有缩减文件系统的大小。(卸载再挂载之后会有问题)

需要卸载2次的问题:##df查看时,只显示第一次挂载的设备

[[email protected] ~]# lvcreate -L 10M -n lv0-backup -s /dev/tbr/lv0

Rounding up size to full physical extent 12.00 MiB

Logical volume "lv0-backup" created

[[email protected] ~]# mount /dev/tbr/lv0-backup /mnt

[[email protected] ~]# df

Filesystem 1K-blocks Used Available Use% Mounted on

/dev/vda1 10473900 3123860 7350040 30% /

devtmpfs 927072 0 927072 0% /dev

tmpfs 942660 80 942580 1% /dev/shm

tmpfs 942660 17056 925604 2% /run

tmpfs 942660 0 942660 0% /sys/fs/cgroup

/dev/mapper/tbr-lv0 588352 912 551972 1% /mnt

[[email protected] ~]# umount /mnt/

[[email protected] ~]# df

Filesystem 1K-blocks Used Available Use% Mounted on

/dev/vda1 10473900 3123860 7350040 30% /

devtmpfs 927072 0 927072 0% /dev

tmpfs 942660 80 942580 1% /dev/shm

tmpfs 942660 17056 925604 2% /run

tmpfs 942660 0 942660 0% /sys/fs/cgroup

/dev/mapper/tbr-lv0 588352 912 551972 1% /mnt

[[email protected] ~]# umount /mnt/

[[email protected] ~]# df

Filesystem 1K-blocks Used Available Use% Mounted on

/dev/vda1 10473900 3123860 7350040 30% /

devtmpfs 927072 0 927072 0% /dev

tmpfs 942660 80 942580 1% /dev/shm

tmpfs 942660 17056 925604 2% /run

tmpfs 942660 0 942660 0% /sys/fs/cgroup

时间: 2024-10-22 21:01:16

西部开源学习笔记BOOK2-《unit 5》的相关文章

西部开源学习笔记BOOK2《vsftp服务》

###unit.9 vsftpd服务### 1.什么是ftp 2.安装ftp yum install vsftpd -y systemctl start vsftpd firewall-cmd --permanent --add-server=ftp firewall-cmd --reload firewall-cmd --list-all public (default, active) interfaces: eth0 sources: services: dhcpv6-client ftp

西部开源学习笔记BOOK2《自动安装系统》

############################# #####  unit1自动安装系统 ##### ############################# ################################### #### Network Install(HTTP,FTP,NFS) #### ################################### #######1.kickstart脚本###### kickstart脚本是自动应答系统在安装过程中一切

西部开源学习笔记BOOK2《ldap网络帐号》

############################## ##### unit8.ldap网络帐号 ###### ############################## ####1.ldap是什么#### ldap目录服务认证,和windows活动目录类似,就是记录数据的一种方式 ####2.ldap客户端所需软件#### [[email protected] ~]# yum install sssd krb5-workstation -y ####3.如何开启ldap用户认证####

西部开源学习笔记BOOK3《unit 4.SMTP》

################################ ########## unit4.SMTP ########## ################################ ###########1.实验环境搭建############ desktop:172.25.254.119 hostname:maillinux.linux.com dns-server:172.25.254.219 server:172.25.254.219 hostname:mailwestos

西部开源学习笔记BOOK3《DNS本地高速缓存服务器》

################################# ####### 配置高速缓存DNS ######## ################################# ################ ### DNS总揽 ### ################ ##权威名称服务器 -存储并提供某个区域整个DNS域或DNS域的一部分的实际数据.权威名称服务器的类型包括 *Master包含原始区域数据.有时称作"主要"名称服务器 *Slaver备份服务器通过区域传送

西部开源学习笔记BOOK3《unit 2.DNS服务器集群》

############################### ###### unit2.DNS服务器集群 ###### ############################### ##########实验环境########## 主DNS server:172.25.254.219(Master) [[email protected] ~]# vim /etc/resolv.conf 3 nameserver 172.25.254.219 备DNS server:172.25.254.11

西部开源学习笔记《unit 1》

#####################虚拟机控制##################### [[email protected] ~]$ rht-vmctl start desktop        ###打开desktop虚拟机 [[email protected] ~]$ rht-vmctl veiw desktop         ###显示desktop虚拟机 [[email protected] ~]$ rht-vmctl poweroff desktop     ###关闭des

西部开源学习笔记BOOK2-《unit 4》

############################## ##### unit4.管理系统存储 ##### ############################## #########1.分区划分########## [[email protected] ~]# fdisk /dev/vdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write

西部开源学习笔记BOOK2-《unit 6》

############################# #### unit6.shell脚本命令 #### ############################# ###########1.diff########### diff         file  file1            ##比较两个文件的不同 -c                          ##显示周围的行 -u                          ##按照统一格式输出生成补丁 -r