逻辑卷的建立

逻辑卷的建立

逻辑卷是什么:

逻辑卷:卷组是一块逻辑硬盘,硬盘必须分区之后才能使用,我们把这个分区称作逻辑卷。逻辑卷可以被格式化和写入数据。我们可以把逻辑卷想象为分区。

为什么要建立逻辑卷

解决正常分区的缺点:没有备份功能 ,性能取决于硬盘本身

如何 建立逻辑卷

#创建物理卷
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdd1
#为卷组分配物理卷
[root@localhost ~]# vgcreate kk123 /dev/sdb1 /dev/sdd1
#从卷组创建逻辑卷
[root@localhost dev]# lvcreate -L +21G -n cxk11 kk123
#格式化 
[root@localhost mapper]# mkfs.xfs /dev/kk123/cxk11
#挂载
[root@localhost mapper]# mount  /dev/kk123/cxk11 mnt

增加逻辑卷的大小

#原本逻辑卷的大小
[root@localhost /]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/kk123/cxk11
  LV Name                cxk11
  VG Name                kk123
  LV UUID                1buBqE-qq2E-Bm0W-RM5u-ZmD2-jrff-59FElI
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2024-04-10 15:16:40 +0800
  LV Status              available
  # open                 1
  LV Size                21.00 GiB		#原本是21G
  Current LE             5376
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
  #对逻辑卷进行增加
  [root@localhost /]# lvextend -L +3G /dev/kk123/cxk11
  Size of logical volume kk123/cxk11 changed from 21.00 GiB (5376 extents) to 24.00 GiB (6144 extents).
  Logical volume kk123/cxk11 successfully resized.
#增加后的逻辑卷大小
  [root@localhost /]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/kk123/cxk11
  LV Name                cxk11
  VG Name                kk123
  LV UUID                1buBqE-qq2E-Bm0W-RM5u-ZmD2-jrff-59FElI
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2024-04-10 15:16:40 +0800
  LV Status              available
  # open                 1
  LV Size                24.00 GiB			#增加后变成了24G
  Current LE             6144
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:3
#但真正体现出来还 要格式化
[root@localhost /]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   39G  3.8G   35G   10% /
devtmpfs                 897M     0  897M    0% /dev
tmpfs                    912M     0  912M    0% /dev/shm
tmpfs                    912M  9.1M  903M    1% /run
tmpfs                    912M     0  912M    0% /sys/fs/cgroup
/dev/sda1               1014M  179M  836M   18% /boot
/dev/mapper/centos-home   19G   33M   19G    1% /home
tmpfs                    183M   12K  183M    1% /run/user/42
tmpfs                    183M     0  183M    0% /run/user/0
/dev/mapper/kk123-cxk11   21G   33M   21G    1% /mnt	#没有格式化前  
[root@localhost /]# xfs_growfs /mnt
meta-data=/dev/mapper/kk123-cxk11 isize=512    agcount=4, agsize=1376256 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=5505024, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2688, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 5505024 to 6291456
[root@localhost /]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   39G  3.8G   35G   10% /
devtmpfs                 897M     0  897M    0% /dev
tmpfs                    912M     0  912M    0% /dev/shm
tmpfs                    912M  9.1M  903M    1% /run
tmpfs                    912M     0  912M    0% /sys/fs/cgroup
/dev/sda1               1014M  179M  836M   18% /boot
/dev/mapper/centos-home   19G   33M   19G    1% /home
tmpfs                    183M   12K  183M    1% /run/user/42
tmpfs                    183M     0  183M    0% /run/user/0
/dev/mapper/kk123-cxk11   24G   33M   24G    1% /mnt		#格式化后
 #可以直接 —r ,不用再次格式化刷新 
 [root@localhost /]# lvextend -L +3G /dev/kk123/cxk11 -r
缩减逻辑卷大小

ext4可以xfs无法缩减,缩减会影响业务。

1.解挂载

2.检查文件系统完整性

3.缩减文件系统

4.缩减逻辑卷上下一致

5.再挂载回去

[root@localhost /]# df -h
文件系统                 容量  已用  可用 已用% 挂载点
/dev/mapper/centos-root   39G  4.1G   35G   11% /
devtmpfs                 897M     0  897M    0% /dev
tmpfs                    912M     0  912M    0% /dev/shm
tmpfs                    912M  9.0M  903M    1% /run
tmpfs                    912M     0  912M    0% /sys/fs/cgroup
/dev/sda1               1014M  179M  836M   18% /boot
/dev/mapper/centos-home   19G   33M   19G    1% /home
tmpfs                    183M   12K  183M    1% /run/user/42
tmpfs                    183M     0  183M    0% /run/user/0
/dev/mapper/aa11-abc123   30G   45M   28G    1% /mnt
[root@localhost /]# umount  mnt							#解挂载
[root@localhost /]# e2fsck -f /dev/vg01/mysql			#检查文件完整性
e2fsck 1.42.9 (28-Dec-2013)
e2fsck: 没有那个文件或目录 当尝试打开 /dev/vg01/mysql 时
Possibly non-existent device?
[root@localhost /]# e2fsck -f /dev/aa11/abc123
e2fsck 1.42.9 (28-Dec-2013)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/aa11/abc123: 11/1966080 files (0.0% non-contiguous), 167453/7864320 blocks
[root@localhost /]# resize2fs /dev/aa11/abc123 2G		#缩减文件系统
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/aa11/abc123 to 524288 (4k) blocks.
The filesystem on /dev/aa11/abc123 is now 524288 blocks long.

[root@localhost /]# lvreduce -L 2G /dev/aa11/abc123 	#缩减逻辑卷,缩减大小上下一致
  WARNING: Reducing active logical volume to 2.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce aa11/abc123? [y/n]: y
  Size of logical volume aa11/abc123 changed from 30.00 GiB (7680 extents) to 2.00 GiB (512 extents).
  Logical volume aa11/abc123 successfully resized.
[root@localhost /]# mount /dev/aa11/abc123 mnt			#重新挂载 
[root@localhost /]# mount  -a		#若你的挂载命令在 /etc/fstab中

posted @ 2024-04-10 16:49  红荼  阅读(71)  评论(0)    收藏  举报