美文网首页
Linux系统磁盘划分、物理卷、卷组、逻辑卷建立以及扩容挂载自启

Linux系统磁盘划分、物理卷、卷组、逻辑卷建立以及扩容挂载自启

作者: 陳陳陳ccc | 来源:发表于2020-11-21 19:45 被阅读0次

    相关概念

    1、物理卷(pvcreate):通常一个分区或者一个硬盘就可以建立一个物理卷,物理卷的最小单位是PE,一般默认是4MB。

    2、卷组(vgcreate):用于创建LVM卷组。卷组(Volume Group)将多个物理卷组织成一个整体,屏蔽了底层物理卷细节。在卷组上创建逻辑卷时不用考虑具体的物理卷信息。

    3、逻辑卷(lvcreate):用于创建LVM的逻辑卷。逻辑卷是创建在卷组之上的。逻辑卷对应的设备文件保存在卷组目录下,例如:在卷组"vg1000"上创建一个逻辑卷"lvol0",则此逻辑卷对应的设备文件为"/dev/vg1000/lvol0"。

    实验开始

    [root@server ~]# fdisk -l /dev/sdb
    Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 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
    Disklabel type: dos
    Disk identifier: 0x1a726657
    [root@server ~]# 
    #分了两个主分区各10G
    [root@server ~]# fdisk /dev/sdb
    Device     Boot    Start      End  Sectors Size Id Type
    /dev/sdb1           2048 20973567 20971520  10G 83 Linux
    /dev/sdb2       20973568 41943039 20969472  10G 83 Linux
    
    #创建物理卷
    [root@server ~]# pvcreate /dev/sdb1 /dev/sdb2
    WARNING: dos signature detected on /dev/sdb2 at offset 510. Wipe it? [y/n]: y
      Wiping dos signature on /dev/sdb2.
    WARNING: atari signature detected on /dev/sdb2 at offset 466. Wipe it? [y/n]: y
      Wiping atari signature on /dev/sdb2.
      Physical volume "/dev/sdb1" successfully created.
      Physical volume "/dev/sdb2" successfully created.
    [root@server ~]# 
    ##查看创建是否成功
    [root@server ~]# pvscan
      PV /dev/sda2   VG rhel_server     lvm2 [<19.00 GiB / 0    free]
      PV /dev/sdb1                      lvm2 [10.00 GiB]
      PV /dev/sdb2                      lvm2 [<10.00 GiB]
      Total: 3 [<39.00 GiB] / in use: 1 [<19.00 GiB] / in no VG: 2 [<20.00 GiB]
    
    ##将物理卷添加到卷组,这里暂时只添加了/dev/sdb1的一个分区
    [root@server ~]# vgcreate vg1 /dev/sdb1
      Volume group "vg1" successfully created
    
    ##pvs查看加入的情况
    [root@server ~]# pvs
      PV         VG          Fmt  Attr PSize   PFree  
      /dev/sda2  rhel_server lvm2 a--  <19.00g      0 
      /dev/sdb1  vg1         lvm2 a--  <10.00g <10.00g
      /dev/sdb2              lvm2 ---  <10.00g <10.00g
    
    #在卷组Vg1下创建data并分配8G空间给到逻辑data
    [root@server ~]# lvcreate -n data -L 8G vg1
    WARNING: ext4 signature detected on /dev/vg1/data at offset 1080. Wipe it? [y/n]: y
      Wiping ext4 signature on /dev/vg1/data.
      Logical volume "data" created.
    [root@server ~]# 
    #将磁盘格式化为ext4类型
    [root@server ~]# mkfs.ext4 /dev/vg1/data
    mke2fs 1.44.3 (10-July-2018)
    Creating filesystem with 2097152 4k blocks and 524288 inodes
    Filesystem UUID: 3e9d17d5-f6f8-459e-bcdc-b0a4805fffbf
    Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done 
    [root@server ~]# 
    
    ##然后挂载就可以使用了
    [root@server ~]# mount /dev/vg1/data /root/data
    [root@server ~]# df -Th | grep data
    /dev/mapper/vg1-data         ext4      7.9G   36M  7.4G   1% /root/data
    
    ##假如data空间不够用了,这时候就要开始扩容了,将/dev/sdb2加入卷组Vg1
    [root@server ~]# vgextend vg1 /dev/sdb2
      Volume group "vg1" successfully extended
    ##查看剩余空间
    [root@server ~]# vgs
      VG          #PV #LV #SN Attr   VSize   VFree 
      rhel_server   1   2   0 wz--n- <19.00g     0 
      vg1           2   1   0 wz--n-  19.99g 11.99g
    
    #在线扩容将data增加多5G的空间
    [root@server ~]# lvextend /dev/vg1/data -L +5G
      Size of logical volume vg1/data changed from 8.00 GiB (2048 extents) to 13.00 GiB (3328 extents).
      Logical volume vg1/data successfully resized.
    [root@server ~]# lvs
      LV   VG          Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root rhel_server -wi-ao---- <17.00g                                                    
      swap rhel_server -wi-ao----   2.00g                                                    
      data vg1         -wi-ao----  13.00g   
    
    #因为扩容后没有格式化所以在文件系统上查看不到
    [root@server ~]# df -Th | grep data
    /dev/mapper/vg1-data         ext4      7.9G   36M  7.4G   1% /root/data
    
    #将扩容的空间加入到data文件系统上, resize2fs :针对文件系统ext2 ext3 ext4  xfs_growfs:针对文件系统xfs 
    
    [root@server ~]# resize2fs /dev/vg1/data
    resize2fs 1.44.3 (10-July-2018)
    Filesystem at /dev/vg1/data is mounted on /root/data; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 2
    The filesystem on /dev/vg1/data is now 3407872 (4k) blocks long.
    
    [root@server ~]# df -Th | grep data
    /dev/mapper/vg1-data         ext4       13G   40M   13G   1% /root/data
    [root@server ~]# 
    
    

    相关文章

      网友评论

          本文标题:Linux系统磁盘划分、物理卷、卷组、逻辑卷建立以及扩容挂载自启

          本文链接:https://www.haomeiwen.com/subject/vzpeiktx.html