zoukankan      html  css  js  c++  java
  • Linux——磁盘以及逻辑卷的使用


    磁盘以及逻辑卷的介绍

    一:磁盘的介绍

    1:磁盘的分区:

    磁盘分区的类型:
    主分区
    扩展分区
    逻辑分区
    其中主分区加扩展分区最多有4个,扩展分区不能存数据,扩展分区只能有一个对一个磁盘来说;但是有一个
    缺陷:只能存数据,不能安装系统,即便是安装了,也不能启动。
    
    特殊:把一个磁盘可以直接做成一个扩展分区,在扩展分区上,创建逻辑分区,
    

    2:格式化:

    分区完成之后,格式化(创建文件系统)
    Linux上的文件系统(单机文件系统)
    ext3,ext4,xfs(centos7上有)
    
    

    3:挂载(凡是块设备,想要使用必须挂载),挂载到一个目录上,这个目录叫做挂载点;

    实例:
    首先添加一块硬盘
    在这里插入图片描述
    查看是否存在这块硬盘:

    [root@node03 ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0  500M  0 part /boot
    └─sda2            8:2    0 19.5G  0 part 
      ├─centos-root 253:0    0 17.5G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sdb               8:16   0    8G  0 disk 
    sr0              11:0    1    4G  0 rom  
    [root@node03 ~]# 
    
    

    开始分区:

    磁盘存放在/dev/下
    
    [root@node03 ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0  500M  0 part /boot
    └─sda2            8:2    0 19.5G  0 part 
      ├─centos-root 253:0    0 17.5G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sdb               8:16   0    8G  0 disk 
    sr0              11:0    1    4G  0 rom  
    [root@node03 ~]# fdisk /dev/sdb
    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 0x9e93954e.
    
    Command (m for help): 
    Command (m for help): m
    Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       g   create a new empty GPT partition table
       G   create an IRIX (SGI) partition table
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)
    
    
    其中常用的指令:
    n:add添加一个分区
    d:delete删除
    w:保存退出
    q:退出不保存
    t:修改分区的id
    p:显示分区的结果
    
    
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)    代表主分区
       e   extended													代表扩展分区
    
    创建500M的分区:+500M
    
    
    

    创建文件系统:

    mkfs -t 文件系统  磁盘分区名称
    或者
    
    mkfs.文件系统  磁盘分区名称
    [root@node03 ~]# mkfs.
    mkfs.btrfs   mkfs.cramfs  mkfs.ext2    mkfs.ext3    mkfs.ext4    mkfs.minix   mkfs.xfs 
    
    

    实例2:
    主分区1 ,为500M,挂载到 /bj
    主分区2,为500M,挂载到/sh
    逻辑分区5:为500M,挂载到/tj
    逻辑分区6:为500M,挂载到/wh
    创建ext4的文件系统;

    1.创建分区
    [root@node03 ~]# fdisk /dev/sdb 
    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 0x52e91368.
    
    Command (m for help): m
    Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       g   create a new empty GPT partition table
       G   create an IRIX (SGI) partition table
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)
    
    Command (m for help): 
    
    
    创建主分区1
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    Partition number (1-4, default 1): 
    First sector (2048-16777215, default 2048): 
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): +500M
    Partition 1 of type Linux and of size 500 MiB is set
    
    创建主分区2
    Command (m for help): n
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): p
    Partition number (2-4, default 2): 
    First sector (1026048-16777215, default 1026048): 
    Using default value 1026048
    Last sector, +sectors or +size{K,M,G} (1026048-16777215, default 16777215): +500M
    Partition 2 of type Linux and of size 500 MiB is set
    
    创建扩展分区,把剩余的空间都给,扩展分区
    Command (m for help): n
    Partition type:
       p   primary (2 primary, 0 extended, 2 free)
       e   extended
    Select (default p): e
    Partition number (3,4, default 3): 
    First sector (2050048-16777215, default 2050048): 
    Using default value 2050048
    Last sector, +sectors or +size{K,M,G} (2050048-16777215, default 16777215): 
    Using default value 16777215
    Partition 3 of type Extended and of size 7 GiB is set
    
    
    创建逻辑分区:5
    Command (m for help): n
    Partition type:
       p   primary (2 primary, 1 extended, 1 free)
       l   logical (numbered from 5)
    Select (default p): l
    Adding logical partition 5
    First sector (2052096-16777215, default 2052096): 
    Using default value 2052096
    Last sector, +sectors or +size{K,M,G} (2052096-16777215, default 16777215): +500M 
    Partition 5 of type Linux and of size 500 MiB is set
    
    创建逻辑分区6
    Command (m for help): n
    Partition type:
       p   primary (2 primary, 1 extended, 1 free)
       l   logical (numbered from 5)
    Select (default p): l
    Adding logical partition 6
    First sector (3078144-16777215, default 3078144): 
    Using default value 3078144
    Last sector, +sectors or +size{K,M,G} (3078144-16777215, default 16777215): +500M
    Partition 6 of type Linux and of size 500 MiB is set
    	
    t  (type)代表t:修改分区的id :8e
    最后输入:w代表保存退出;
    

    partprobe /dev/vdb 代表:内核能识别到分区的变化

    查看创建出来的分区:

    [root@node03 ~]# lsblk|grep sdb
    sdb               8:16   0    8G  0 disk 
    ├─sdb1            8:17   0  500M  0 part 
    ├─sdb2            8:18   0  500M  0 part 
    ├─sdb3            8:19   0    1K  0 part 
    ├─sdb5            8:21   0  500M  0 part 
    └─sdb6            8:22   0  500M  0 part 
    

    分区创建出来,想要这个分区能正常使用,确保内核能识别到;

    [root@node03 ~]# cat /proc/partitions 
    major minor  #blocks  name
    
       8       16    8388608 sdb
       8       17     512000 sdb1
       8       18     512000 sdb2
       8       19          1 sdb3
       8       21     512000 sdb5
       8       22     512000 sdb6
       8        0   20971520 sda
       8        1     512000 sda1
       8        2   20458496 sda2
      11        0    4228096 sr0
     253        0   18317312 dm-0
     253        1    2097152 dm-1
    

    为了避免不生效

    partprobe /dev/sdb    磁盘名称
    

    创建文件系统:

    mkfs -t ext4 /dev/sdb1 
    mkfs -t ext4 /dev/sdb2
    mkfs -t ext4 /dev/sdb5
    mkfs -t ext4 /dev/sdb6
    

    创建挂载点

    mkdir /{bj,sh,tj,wh}
    

    挂载:(实现开机自动挂载)

    [root@node03 ~]# cat /etc/fstab 
    
    #
    # /etc/fstab
    # Created by anaconda on Sat Nov 28 23:28:09 2020
    #
    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    #
    /dev/mapper/centos-root /                       xfs     defaults        0 0
    UUID=77d39fde-4252-4586-a797-0cf0566a3e5c /boot                   xfs     defaults        0 0
    /dev/mapper/centos-swap swap                    swap    defaults        0 0
    
    
    /dev/sdb1       /bj    ext4     defaults 0 0
    /dev/sdb2       /tj    ext4     defaults 0 0
    /dev/sdb5       /wh    ext4     defaults 0 0 
    /dev/sdb6       /sh    ext4     defaults 0 0
    

    让系统重新读取以下/etc/fstab mount -a

    
    [root@node03 ~]# mount -a
    

    查看:

    [root@node03 ~]# df -Th
    Filesystem              Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root xfs        18G  930M   17G   6% /
    devtmpfs                devtmpfs  479M     0  479M   0% /dev
    tmpfs                   tmpfs     489M     0  489M   0% /dev/shm
    tmpfs                   tmpfs     489M  6.7M  483M   2% /run
    tmpfs                   tmpfs     489M     0  489M   0% /sys/fs/cgroup
    /dev/sda1               xfs       497M  125M  373M  25% /boot
    tmpfs                   tmpfs      98M     0   98M   0% /run/user/0
    /dev/sdb1               ext4      477M  2.3M  445M   1% /bj
    /dev/sdb2               ext4      477M  2.3M  445M   1% /tj
    /dev/sdb5               ext4      477M  2.3M  445M   1% /wh
    /dev/sdb6               ext4      477M  2.3M  445M   1% /sh
    

    取消挂载:

    [root@node03 ~]# umount /dev/sdb6
    [root@node03 ~]# df -Th
    Filesystem              Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root xfs        18G  930M   17G   6% /
    devtmpfs                devtmpfs  479M     0  479M   0% /dev
    tmpfs                   tmpfs     489M     0  489M   0% /dev/shm
    tmpfs                   tmpfs     489M  6.7M  483M   2% /run
    tmpfs                   tmpfs     489M     0  489M   0% /sys/fs/cgroup
    /dev/sda1               xfs       497M  125M  373M  25% /boot
    tmpfs                   tmpfs      98M     0   98M   0% /run/user/0
    /dev/sdb1               ext4      477M  2.3M  445M   1% /bj
    /dev/sdb2               ext4      477M  2.3M  445M   1% /tj
    /dev/sdb5               ext4      477M  2.3M  445M   1% /wh
    

    查看某一个设备的id(查看uuid的目的是,在挂载时可以用uuid)

    
    [root@node03 ~]# blkid /dev/sdb6
    /dev/sdb6: UUID="a0e776f0-e638-4efd-b2dd-2d95f7cc2c72" TYPE="ext4" 
    

    二:逻辑卷的介绍

    优势:在常规使用磁盘时它有一个缺陷,比如我服务器上有500G的磁盘,我要对其经行分区,格式化挂载,在磁盘中存放数据,当我的数据量大于磁盘的容量时,怎么办?
    可以把这个磁盘扩容成一个较大容量,使用lvm方式管理磁盘;
    lvm管理磁盘的过程:
    它利用物理磁盘或分区虚拟出一个逻辑磁盘出来,将来存储数据在这个虚拟的磁盘上;

    1:首先把物理磁盘转换成lvm管理的最基本的单位,pv(物理卷),物理卷的名字和磁盘的名字相同
    2:拿一个或多个pv组成一个虚拟的磁盘池,这个磁盘池叫做VG(卷组),卷组叫什么名自己起;
    3:在卷组的基础上创建逻辑卷(LV)
    
    

    假设现在创建了一个lv,规划的时候没有规划好,随着数据越来越多,磁盘空间不够大,可以扩展;而在扩展的时候原有的数据不会发生改变;
    组成lv的底层设备必须是裸设备,裸设备代表:没有文件系统。

    工作流程:
    磁盘/分区——》PV——》VG——》LV——》格式化——》挂载使用
    创建PV:

    pvcreate 磁盘/分区
    

    查看PV:

    pvscan
    

    创建VG

    vgcreate  卷组名称 物理卷名称
    

    查看VG

    vgscan 或vgdispaly 【卷组名称】
    

    LV的创建:

    
    lvcreate -L 容量 -n 逻辑卷名称 卷组名称
    

    查看LV

    lvscan 
    当用lvscan查看时,有块设备文件来标识它结构如下:
    /dev/卷组名称/逻辑卷名称
    

    实例1:

    创建逻辑卷     /dev/data/webdata,大小为2G,为其创建ext4文件系统,并将其挂载到/web/htdocs目录
    

    分析:

    其中:data为卷组名,webdata为逻辑卷名
    

    1:首先创建pv

    pvcreate 硬盘名称
    
    [root@localhost ~]# lsblk
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0  500M  0 part /boot
    └─sda2            8:2    0 19.5G  0 part 
      ├─centos-root 253:0    0 17.5G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sdb               8:16   0   10G  0 disk 
    sr0              11:0    1    4G  0 rom  
    [root@localhost ~]# pvcreate /dev/sdb 
      Physical volume "/dev/sdb" successfully created
      
    查看pv
    [root@localhost ~]# pvscan
      PV /dev/sda2   VG centos   lvm2 [19.51 GiB / 40.00 MiB free]
      PV /dev/sdb                lvm2 [10.00 GiB]
      Total: 2 [29.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 1 [10.00 GiB]
    

    2:创建vg

    vgcreate 卷组名称 物理卷名称
    
    
    [root@localhost ~]# vgcreate data /dev/sdb 
      Volume group "data" successfully created
    
    
    查看:
    [root@localhost ~]# vgdisplay data
      --- Volume group ---
      VG Name               data
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  1
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                0
      Open LV               0
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               10.00 GiB
      PE Size               4.00 MiB
      Total PE              2559
      Alloc PE / Size       0 / 0   
      Free  PE / Size       2559 / 10.00 GiB
      VG UUID               BHCNFG-9j0i-gFSx-qVAi-DIPj-Nbfv-U0LAMH
    

    3:创建lv

    lvcreate -L 大小 -n 逻辑卷名称  卷组名称
    
    
    [root@localhost ~]# lvcreate -L 2G -n webdata data
      Logical volume "webdata" created.
    [root@localhost ~]# lvscan
      ACTIVE            '/dev/data/webdata' [2.00 GiB] inherit
      ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
      ACTIVE            '/dev/centos/root' [17.47 GiB] inherit
    

    4:格式化(创建文件系统)

    mkfs.ext4 逻辑卷所对应的软连接
    
    [root@localhost ~]# mkfs.ext4 /dev/data/webdata 
    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
    131072 inodes, 524288 blocks
    26214 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=536870912
    16 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
            32768, 98304, 163840, 229376, 294912
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done 
    

    5:挂载
    创建挂载点目录:

    mkdir -pv /web/htdocs
    
    [root@localhost ~]# mkdir -pv /web/htdocs
    mkdir: created directory ‘/web’
    mkdir: created directory ‘/web/htdocs’
    

    自动挂载:

    编辑/etc/fstab
    
    [root@localhost ~]# echo "/dev/data/webdata /web/htdocs ext4 defaults 0 0" >>/etc/fstab 
    [root@localhost ~]# cat /etc/fstab 
    
    #
    # /etc/fstab
    # Created by anaconda on Thu Dec 24 17:02:01 2020
    #
    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    #
    /dev/mapper/centos-root /                       xfs     defaults        0 0
    UUID=c8c10022-ef8a-4f97-b5d2-a4899084f396 /boot                   xfs     defaults        0 0
    /dev/mapper/centos-swap swap                    swap    defaults        0 0
    /dev/data/webdata /web/htdocs ext4 defaults 0 0
    
    
    mount -a (其目的是让系统重新读取以下/etc/fstab里面的文件)
    
    

    6:验证是否挂载成功:

    [root@localhost ~]# df -Th
    Filesystem               Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root  xfs        18G  856M   17G   5% /
    devtmpfs                 devtmpfs  479M     0  479M   0% /dev
    tmpfs                    tmpfs     489M     0  489M   0% /dev/shm
    tmpfs                    tmpfs     489M  6.7M  483M   2% /run
    tmpfs                    tmpfs     489M     0  489M   0% /sys/fs/cgroup
    /dev/sda1                xfs       497M  125M  373M  25% /boot
    tmpfs                    tmpfs      98M     0   98M   0% /run/user/0
    /dev/mapper/data-webdata ext4      2.0G  6.0M  1.8G   1% /web/htdocs
    [root@localhost ~]# lsblk 
    NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
    sda               8:0    0   20G  0 disk 
    ├─sda1            8:1    0  500M  0 part /boot
    └─sda2            8:2    0 19.5G  0 part 
      ├─centos-root 253:0    0 17.5G  0 lvm  /
      └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
    sdb               8:16   0   10G  0 disk 
    └─data-webdata  253:2    0    2G  0 lvm  /web/htdocs
    sr0              11:0    1    4G  0 rom 
    
    
    

    实例2:扩展逻辑卷

    扩展逻辑卷,首先扩展逻辑卷的物理边界,延长的这部分空间默认存不了数据,因为扩大的这部分没有文件系统。

    步骤:
    1:扩展物理空间边界
    2:扩展文件系统
    在这里插入图片描述需求:扩展逻辑卷/dev/data/webdata到4G
    其中LV是基于VG创建出来的,首先查看VG,确保VG的剩余空间够不够,
    1:首先查看卷组的剩余空间够不够;

    1:查看是那个卷组
    [root@localhost ~]# lvscan
      ACTIVE            '/dev/data/webdata' [2.00 GiB] inherit
      ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
      ACTIVE            '/dev/centos/root' [17.47 GiB] inherit
    2:查看卷组的容量是否够用
    [root@localhost ~]# vgdisplay data
      --- Volume group ---
      VG Name               data
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  2
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                1
      Open LV               1
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               10.00 GiB
      PE Size               4.00 MiB
      Total PE              2559
      Alloc PE / Size       512 / 2.00 GiB
      Free  PE / Size       2047 / 8.00 GiB
      VG UUID               BHCNFG-9j0i-gFSx-qVAi-DIPj-Nbfv-U0LAMH  
    其中VG总大小:VG Size     10.00 GiB
    剩余的大小为:Free  PE / Size   2047 / 8.00 GiB
    也就是说确保了卷组的剩余空间是足够的;
    如果不够先扩展卷组,然后再扩展逻辑卷
    

    2:扩展逻辑卷的物理空间

    用到的命令是:lvextend,现在是2G再加2G,就到4G了;
    
    [root@localhost ~]# lvextend -L +2G /dev/data/webdata 
      Size of logical volume data/webdata changed from 2.00 GiB (512 extents) to 4.00 GiB (1024 extents).
      Logical volume webdata successfully resized.
    
    查看大小:
    [root@localhost ~]# lvscan 
      ACTIVE            '/dev/data/webdata' [4.00 GiB] inherit
      ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
      ACTIVE            '/dev/centos/root' [17.47 GiB] inherit
    这个是它物理边界的大小,已经扩展到了4G
    
    [root@localhost ~]# df -Th
    Filesystem               Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root  xfs        18G  856M   17G   5% /
    devtmpfs                 devtmpfs  479M     0  479M   0% /dev
    tmpfs                    tmpfs     489M     0  489M   0% /dev/shm
    tmpfs                    tmpfs     489M  6.7M  483M   2% /run
    tmpfs                    tmpfs     489M     0  489M   0% /sys/fs/cgroup
    /dev/sda1                xfs       497M  125M  373M  25% /boot
    tmpfs                    tmpfs      98M     0   98M   0% /run/user/0
    /dev/mapper/data-webdata ext4      2.0G  6.0M  1.8G   1% /web/htdocs
      
    它的文件系统还是2G,因此需要扩展文件系统;
    

    3:扩展文件系统

    resize2fs  逻辑卷名称    
    注意:
    1:resize2fs只适用于ext3/ext4这样的文件系统
    2:如果是xfs文件系统,那么用:xfs_growfs
    
    /dev/mapper/data-webdata ext4      2.0G  6.0M  1.8G   1% /web/htdocs
    [root@localhost ~]# resize2fs /dev/data/webdata 
    resize2fs 1.42.9 (28-Dec-2013)
    Filesystem at /dev/data/webdata is mounted on /web/htdocs; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 1
    The filesystem on /dev/data/webdata is now 1048576 blocks long.
    
    查看大小
    
    [root@localhost ~]# df -Th
    Filesystem               Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root  xfs        18G  856M   17G   5% /
    devtmpfs                 devtmpfs  479M     0  479M   0% /dev
    tmpfs                    tmpfs     489M     0  489M   0% /dev/shm
    tmpfs                    tmpfs     489M  6.7M  483M   2% /run
    tmpfs                    tmpfs     489M     0  489M   0% /sys/fs/cgroup
    /dev/sda1                xfs       497M  125M  373M  25% /boot
    tmpfs                    tmpfs      98M     0   98M   0% /run/user/0
    /dev/mapper/data-webdata ext4      3.9G  8.0M  3.7G   1% /web/htdocs
    

    实例3:扩展逻辑卷到10G

    首先查看lv的大小:
    [root@localhost ~]# lvscan 
      ACTIVE            '/dev/data/webdata' [4.00 GiB] inherit
      ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
      ACTIVE            '/dev/centos/root' [17.47 GiB] inherit
    为4G,还需要16G
    
    查看vg
    
    [root@localhost ~]# vgdisplay data
      --- Volume group ---
      VG Name               data
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                1
      Open LV               1
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               10.00 GiB
      PE Size               4.00 MiB
      Total PE              2559
      Alloc PE / Size       1024 / 4.00 GiB
      Free  PE / Size       1535 / 6.00 GiB
      VG UUID               BHCNFG-9j0i-gFSx-qVAi-DIPj-Nbfv-U0LAMH
    现在卷组的剩余空间不够;所以需要扩展卷组
    

    现在卷组的剩余空间不够;所以需要扩展卷组
    即再加一块盘,转化成pv物理卷,然后把物理卷卷加到卷组里面来

    转换成物理卷

    [root@localhost ~]# pvcreate /dev/sdc
      Physical volume "/dev/sdc" successfully created
    [root@localhost ~]# pvscan 
      PV /dev/sda2   VG centos   lvm2 [19.51 GiB / 40.00 MiB free]
      PV /dev/sdb    VG data     lvm2 [10.00 GiB / 6.00 GiB free]
      PV /dev/sdc                lvm2 [15.00 GiB]
      Total: 3 [44.50 GiB] / in use: 2 [29.50 GiB] / in no VG: 1 [15.00 GiB]
    

    扩展卷组:

    vgextend   卷组名 物理卷名
    [root@localhost ~]# vgextend data /dev/sdc 
      Volume group "data" successfully extended
    
    查看vg的大小:
    [root@localhost ~]# vgdisplay data
      --- Volume group ---
      VG Name               data
      System ID             
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  4
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                1
      Open LV               1
      Max PV                0
      Cur PV                2
      Act PV                2
      VG Size               24.99 GiB
      PE Size               4.00 MiB
      Total PE              6398
      Alloc PE / Size       1024 / 4.00 GiB
      Free  PE / Size       5374 / 20.99 GiB
      VG UUID               BHCNFG-9j0i-gFSx-qVAi-DIPj-Nbfv-U0LAMH
    
    
    即卷组总大小:  VG Size      24.99 GiB
    剩余大小 : Free  PE / Size       5374 / 20.99 GiB
    

    扩展lv

    [root@localhost ~]# lvextend -L +16G -n /dev/data/webdata 
      Size of logical volume data/webdata changed from 4.00 GiB (1024 extents) to 20.00 GiB (5120 extents).
      Logical volume webdata successfully resized.
    
    查看lv的大小:
    [root@localhost ~]# lvscan 
      ACTIVE            '/dev/data/webdata' [20.00 GiB] inherit
      ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
      ACTIVE            '/dev/centos/root' [17.47 GiB] inherit
    

    扩展文件系统:

    [root@localhost ~]# resize2fs /dev/data/webdata 
    resize2fs 1.42.9 (28-Dec-2013)
    Filesystem at /dev/data/webdata is mounted on /web/htdocs; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 3
    The filesystem on /dev/data/webdata is now 5242880 blocks long.
    

    查看:

    [root@localhost ~]# lvscan 
      ACTIVE            '/dev/data/webdata' [20.00 GiB] inherit
      ACTIVE            '/dev/centos/swap' [2.00 GiB] inherit
      ACTIVE            '/dev/centos/root' [17.47 GiB] inherit
    
    
    
    [root@localhost ~]# df -Th
    Filesystem               Type      Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root  xfs        18G  856M   17G   5% /
    devtmpfs                 devtmpfs  479M     0  479M   0% /dev
    tmpfs                    tmpfs     489M     0  489M   0% /dev/shm
    tmpfs                    tmpfs     489M  6.7M  483M   2% /run
    tmpfs                    tmpfs     489M     0  489M   0% /sys/fs/cgroup
    /dev/sda1                xfs       497M  125M  373M  25% /boot
    /dev/mapper/data-webdata ext4       20G   11M   19G   1% /web/htdocs
    tmpfs                    tmpfs      98M     0   98M   0% /run/user/0
    

    总结:
    lvcreate -L 2G -n webdata data
    lvextend -L +2G /dev/data/webdata

    有志者,事竟成,破釜沉舟,百二秦关终属楚; 苦心人,天不负,卧薪尝胆,三千越甲可吞吴。 想到与得到中间还有两个字——做到。
  • 相关阅读:
    JavaScript异步编程1——Promise的初步使用
    Pailler
    ElGamal
    RSA
    密码基础
    博客园中:为文章添加版权保护
    DCT实现水印嵌入与提取(带攻击)
    量子:基于EPR块对的两步量子直接通信
    量子:拜占庭协议和测谎问题的量子协议的实验证明
    liunx:网络命令
  • 原文地址:https://www.cnblogs.com/huoxc/p/14184177.html
Copyright © 2011-2022 走看看