zoukankan      html  css  js  c++  java
  • LVM使用

    LVM框架

    LVM实验环境准备

    创建一个128MB的文件模拟磁盘

    [centos@centos lvm]$ dd if=/dev/zero of=./disk.img count=128 bs=1MB
    记录了128+0 的读入
    记录了128+0 的写出
    128000000字节(128 MB)已复制,2.29908 秒,55.7 MB/秒
    [centos@centos lvm]$ ls -la --block-size=1MB
    总用量 129
    drwxrwxr-x.  2 centos centos   1 4月   4 21:41 .
    drwx------. 17 centos centos   1 4月   4 21:29 ..
    -rw-rw-r--.  1 centos centos 128 4月   4 21:41 disk.img
    

    查看所有的loop设备

    [root@centos lvm]# losetup -a
    /dev/loop0: [64768]:203857781 (/var/lib/docker/devicemapper/devicemapper/data)
    /dev/loop1: [64768]:203857782 (/var/lib/docker/devicemapper/devicemapper/metadata)
    

    查看下一个未使用的loop设备

    [root@centos lvm]# losetup -f
    /dev/loop2
    

    关联loop设备

    [root@centos lvm]# losetup /dev/loop2 disk.img 
    

    使用新磁盘创建新逻辑卷LV

    创建LVM分区

    [root@centos lvm]# fdisk /dev/loop2
    欢迎使用 fdisk (util-linux 2.23.2)。
    
    更改将停留在内存中,直到您决定将更改写入磁盘。
    使用写入命令前请三思。
    
    Device does not contain a recognized partition table
    使用磁盘标识符 0x823c9167 创建新的 DOS 磁盘标签。
    
    命令(输入 m 获取帮助):n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    分区号 (1-4,默认 1):1
    起始 扇区 (2048-249999,默认为 2048):
    将使用默认值 2048
    Last 扇区, +扇区 or +size{K,M,G} (2048-249999,默认为 249999):
    将使用默认值 249999
    分区 1 已设置为 Linux 类型,大小设为 121.1 MiB
    
    命令(输入 m 获取帮助):t
    已选择分区 1
    Hex 代码(输入 L 列出所有代码):8e
    已将分区“Linux”的类型更改为“Linux LVM”
    
    命令(输入 m 获取帮助):p
    
    磁盘 /dev/loop2:128 MB, 128000000 字节,250000 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0x823c9167
    
          设备 Boot      Start         End      Blocks   Id  System
    /dev/loop2p1            2048      249999      123976   8e  Linux LVM
    
    命令(输入 m 获取帮助):w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 22: 无效的参数.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    正在同步磁盘。
    

    重启系统重新关联loop设备

    [root@centos centos]# losetup -a
    /dev/loop0: [64768]:203857781 (/var/lib/docker/devicemapper/devicemapper/data)
    /dev/loop1: [64768]:203857782 (/var/lib/docker/devicemapper/devicemapper/metadata)
    [root@centos centos]# losetup -f
    /dev/loop2
    [root@centos centos]# cd lvm/
    [root@centos lvm]# losetup /dev/loop2 disk.img 
    [root@centos lvm]# fdisk /dev/loop2
    欢迎使用 fdisk (util-linux 2.23.2)。
    
    更改将停留在内存中,直到您决定将更改写入磁盘。
    使用写入命令前请三思。
    
    
    命令(输入 m 获取帮助):p
    
    磁盘 /dev/loop2:128 MB, 128000000 字节,250000 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0x823c9167
    
          设备 Boot      Start         End      Blocks   Id  System
    /dev/loop2p1            2048      249999      123976   8e  Linux LVM
    
    命令(输入 m 获取帮助):
    

    创建物理卷PV

    [root@centos lvm]# pvcreate /dev/loop2
    WARNING: dos signature detected on /dev/loop2 at offset 510. Wipe it? [y/n]: y
      Wiping dos signature on /dev/loop2.
      Physical volume "/dev/loop2" successfully created
    [root@centos lvm]# pvdisplay 
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               49.51 GiB / not usable 3.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              12674
      Free PE               11
      Allocated PE          12663
      PV UUID               edqmZj-578L-tMix-DJOE-FFnh-C4n2-aeLIuA
       
      "/dev/loop2" is a new physical volume of "122.07 MiB"
      --- NEW Physical volume ---
      PV Name               /dev/loop2
      VG Name               
      PV Size               122.07 MiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               FyS8OO-sHy3-U297-8FWE-FtS3-TyFh-nzLFZu
    

    创建卷组VG

    [root@centos lvm]# vgdisplay 
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               49.51 GiB
      PE Size               4.00 MiB
      Total PE              12674
      Alloc PE / Size       12663 / 49.46 GiB
      Free  PE / Size       11 / 44.00 MiB
      VG UUID               EQ5hYJ-51Mx-QOd6-yVgZ-BD6A-EhxJ-0QHAqm
       
    [root@centos lvm]# vgcreate vgtest /dev/loop2
      Volume group "vgtest" successfully created
    [root@centos lvm]# vgdisplay 
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               49.51 GiB
      PE Size               4.00 MiB
      Total PE              12674
      Alloc PE / Size       12663 / 49.46 GiB
      Free  PE / Size       11 / 44.00 MiB
      VG UUID               EQ5hYJ-51Mx-QOd6-yVgZ-BD6A-EhxJ-0QHAqm
       
      --- Volume group ---
      VG Name               vgtest
      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               120.00 MiB
      PE Size               4.00 MiB
      Total PE              30
      Alloc PE / Size       0 / 0   
      Free  PE / Size       30 / 120.00 MiB
      VG UUID               g0JNXo-zxhI-4QQ3-eGsi-3xnm-aNXe-Vscq4A
    
    [root@centos lvm]# lvcreate -L 120M -n vps /dev/vgtest
      Logical volume "vps" created.
    [root@centos lvm]# lvdisplay
      --- Logical volume ---
      LV Path                /dev/centos/swap
      LV Name                swap
      VG Name                centos
      LV UUID                EwWI53-xxB2-dXlQ-xuIb-8xRa-BDpE-THn1bE
      LV Write Access        read/write
      LV Creation host, time centos, 2016-03-30 17:44:27 +0800
      LV Status              available
      # open                 2
      LV Size                2.00 GiB
      Current LE             512
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:1
       
      --- Logical volume ---
      LV Path                /dev/centos/root
      LV Name                root
      VG Name                centos
      LV UUID                smMyzH-3MQ4-uTib-8b9I-FVd5-qBvv-6Y5I7N
      LV Write Access        read/write
      LV Creation host, time centos, 2016-03-30 17:44:27 +0800
      LV Status              available
      # open                 1
      LV Size                47.46 GiB
      Current LE             12151
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
       
      --- Logical volume ---
      LV Path                /dev/vgtest/vps
      LV Name                vps
      VG Name                vgtest
      LV UUID                EzFbN3-TKqF-bBuC-buCu-dlib-vPwi-6atqtr
      LV Write Access        read/write
      LV Creation host, time centos, 2016-04-04 22:19:50 +0800
      LV Status              available
      # open                 0
      LV Size                120.00 MiB
      Current LE             30
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:3
    

    格式化LV逻辑卷为ext4文件系统格式

    [root@centos lvm]# mkfs.ext4 /dev/vgtest/vps 
    mke2fs 1.42.9 (28-Dec-2013)
    Discarding device blocks: 完成                            
    文件系统标签=
    OS type: Linux
    块大小=1024 (log=0)
    分块大小=1024 (log=0)
    Stride=0 blocks, Stripe width=0 blocks
    30720 inodes, 122880 blocks
    6144 blocks (5.00%) reserved for the super user
    第一个数据块=1
    Maximum filesystem blocks=33685504
    15 block groups
    8192 blocks per group, 8192 fragments per group
    2048 inodes per group
    Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729
    
    Allocating group tables: 完成                            
    正在写入inode表: 完成                            
    Creating journal (4096 blocks): 完成
    Writing superblocks and filesystem accounting information: 完成 
    

    挂载LVM目录到文件系统

    [centos@centos ~]$ mkdir vps
    [centos@centos ~]$ sudo mount -t ext4 /dev/vgtest/vps vps/
    [centos@centos ~]$ df -h
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   48G  4.4G   44G   10% /
    devtmpfs                 978M     0  978M    0% /dev
    tmpfs                    993M  152K  993M    1% /dev/shm
    tmpfs                    993M  9.0M  984M    1% /run
    tmpfs                    993M     0  993M    0% /sys/fs/cgroup
    /dev/sda1                497M  140M  357M   29% /boot
    tmpfs                    199M  4.0K  199M    1% /run/user/42
    tmpfs                    199M   12K  199M    1% /run/user/1000
    /dev/mapper/vgtest-vps   113M  1.6M  103M    2% /home/centos/vps
    

    由于这边关联的/dev/loop2设备每次系统重启后就自动detach,原因未知,所以这边没配置开机自动挂载了

    删除逻辑卷LV

    umount逻辑卷

    [root@centos centos]# df -h
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   48G  4.4G   44G   10% /
    devtmpfs                 978M     0  978M    0% /dev
    tmpfs                    993M  156K  993M    1% /dev/shm
    tmpfs                    993M  9.0M  985M    1% /run
    tmpfs                    993M     0  993M    0% /sys/fs/cgroup
    /dev/sda1                497M  140M  357M   29% /boot
    tmpfs                    199M   16K  199M    1% /run/user/1000
    /dev/mapper/vgtest-vps   113M  1.6M  103M    2% /home/centos/vps
    [root@centos centos]# umount /home/centos/vps
    

    删除逻辑卷LV

    [root@centos centos]# lvremove /dev/vgtest/vps 
    Do you really want to remove active logical volume vps? [y/n]: y
      Logical volume "vps" successfully removed
    [root@centos centos]# lvdisplay 
      --- Logical volume ---
      LV Path                /dev/centos/swap
      LV Name                swap
      VG Name                centos
      LV UUID                EwWI53-xxB2-dXlQ-xuIb-8xRa-BDpE-THn1bE
      LV Write Access        read/write
      LV Creation host, time centos, 2016-03-30 17:44:27 +0800
      LV Status              available
      # open                 2
      LV Size                2.00 GiB
      Current LE             512
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:1
       
      --- Logical volume ---
      LV Path                /dev/centos/root
      LV Name                root
      VG Name                centos
      LV UUID                smMyzH-3MQ4-uTib-8b9I-FVd5-qBvv-6Y5I7N
      LV Write Access        read/write
      LV Creation host, time centos, 2016-03-30 17:44:27 +0800
      LV Status              available
      # open                 1
      LV Size                47.46 GiB
      Current LE             12151
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
    

    删除卷组VG

    [root@centos centos]# vgremove vgtest 
      Volume group "vgtest" successfully removed
    [root@centos centos]# vgdisplay 
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               49.51 GiB
      PE Size               4.00 MiB
      Total PE              12674
      Alloc PE / Size       12663 / 49.46 GiB
      Free  PE / Size       11 / 44.00 MiB
      VG UUID               EQ5hYJ-51Mx-QOd6-yVgZ-BD6A-EhxJ-0QHAqm
    

    删除物理卷PV

    [root@centos centos]# pvremove /dev/loop2
      Labels on physical volume "/dev/loop2" successfully wiped
    [root@centos centos]# pvdisplay 
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               49.51 GiB / not usable 3.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              12674
      Free PE               11
      Allocated PE          12663
      PV UUID               edqmZj-578L-tMix-DJOE-FFnh-C4n2-aeLIuA
    

    扩大逻辑卷LV大小

    恢复删除逻辑卷LV之前的状态,再创建一个新的磁盘文件作为扩展文件

    [root@centos lvm]# dd if=/dev/zero of=./disk_ext.img count=128 bs=1MB
    记录了128+0 的读入
    记录了128+0 的写出
    128000000字节(128 MB)已复制,0.39764 秒,322 MB/秒
    [root@centos lvm]# losetup -f
    /dev/loop3
    [root@centos lvm]# losetup /dev/loop3 disk_ext.img 
    [root@centos lvm]# fdisk /dev/loop3
    欢迎使用 fdisk (util-linux 2.23.2)。
    
    更改将停留在内存中,直到您决定将更改写入磁盘。
    使用写入命令前请三思。
    
    Device does not contain a recognized partition table
    使用磁盘标识符 0x0ca75082 创建新的 DOS 磁盘标签。
    
    命令(输入 m 获取帮助):n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    分区号 (1-4,默认 1):1
    起始 扇区 (2048-249999,默认为 2048):
    将使用默认值 2048
    Last 扇区, +扇区 or +size{K,M,G} (2048-249999,默认为 249999):
    将使用默认值 249999
    分区 1 已设置为 Linux 类型,大小设为 121.1 MiB
    
    命令(输入 m 获取帮助):t
    已选择分区 1
    Hex 代码(输入 L 列出所有代码):8e
    已将分区“Linux”的类型更改为“Linux LVM”
    
    命令(输入 m 获取帮助):p
    
    磁盘 /dev/loop3:128 MB, 128000000 字节,250000 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0x0ca75082
    
          设备 Boot      Start         End      Blocks   Id  System
    /dev/loop3p1            2048      249999      123976   8e  Linux LVM
    
    命令(输入 m 获取帮助):w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 22: 无效的参数.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    正在同步磁盘。
    [root@centos lvm]# partprobe
    

    创建新的物理卷PV

    [root@centos lvm]# pvcreate /dev/loop3
    WARNING: dos signature detected on /dev/loop3 at offset 510. Wipe it? [y/n]: y
      Wiping dos signature on /dev/loop3.
      Physical volume "/dev/loop3" successfully created
    [root@centos lvm]# pvdisplay 
      --- Physical volume ---
      PV Name               /dev/loop2
      VG Name               vgtest
      PV Size               122.07 MiB / not usable 2.07 MiB
      Allocatable           yes (but full)
      PE Size               4.00 MiB
      Total PE              30
      Free PE               0
      Allocated PE          30
      PV UUID               TuUTR0-FeaK-FL23-QIIh-qPeC-cXmf-FF32by
       
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               49.51 GiB / not usable 3.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              12674
      Free PE               11
      Allocated PE          12663
      PV UUID               edqmZj-578L-tMix-DJOE-FFnh-C4n2-aeLIuA
       
      "/dev/loop3" is a new physical volume of "122.07 MiB"
      --- NEW Physical volume ---
      PV Name               /dev/loop3
      VG Name               
      PV Size               122.07 MiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               LLFy8f-YNua-YSp1-QByK-RqMv-PTii-t9DY9U
    

    扩展卷组VG的大小

    [root@centos lvm]# vgdisplay vgtest 
      --- Volume group ---
      VG Name               vgtest
      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               120.00 MiB
      PE Size               4.00 MiB
      Total PE              30
      Alloc PE / Size       30 / 120.00 MiB
      Free  PE / Size       0 / 0   
      VG UUID               tfTiUi-mNAe-1JTs-cOfy-AnKj-FKM1-wSSfJs
    
    [root@centos lvm]# vgextend vgtest /dev/loop3
      Volume group "vgtest" successfully extended
    [root@centos lvm]# vgdisplay vgtest 
      --- Volume group ---
      VG Name               vgtest
      System ID             
      Format                lvm2
      Metadata Areas        2
      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                2
      Act PV                2
      VG Size               240.00 MiB
      PE Size               4.00 MiB
      Total PE              60
      Alloc PE / Size       30 / 120.00 MiB
      Free  PE / Size       30 / 120.00 MiB
      VG UUID               tfTiUi-mNAe-1JTs-cOfy-AnKj-FKM1-wSSfJs
    

    扩展逻辑卷LV大小

    [root@centos lvm]# lvextend -L +20M /dev/vgtest/vps 
      Size of logical volume vgtest/vps changed from 120.00 MiB (30 extents) to 140.00 MiB (35 extents).
      Logical volume vps successfully resized.
    [root@centos lvm]# lvdisplay /dev/vgtest/vps | grep "LV Size"
      LV Size                140.00 MiB
    [root@centos lvm]# vgdisplay vgtest | grep "Free  PE / Size"
      Free  PE / Size       25 / 100.00 MiB 
    

    扩展文件系统大小

    [root@centos lvm]# e2fsck -f /dev/vgtest/vps 
    e2fsck 1.42.9 (28-Dec-2013)
    第一步: 检查inode,块,和大小
    第二步: 检查目录结构
    第3步: 检查目录连接性
    Pass 4: Checking reference counts
    第5步: 检查簇概要信息
    /dev/vgtest/vps: 11/30720 files (9.1% non-contiguous), 9529/122880 blocks
    [root@centos lvm]# resize2fs /dev/vgtest/vps 
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/vgtest/vps to 143360 (1k) blocks.
    The filesystem on /dev/vgtest/vps is now 143360 blocks long.
    
    [root@centos lvm]# mount /dev/vgtest/vps ../vps/
    

    缩小逻辑卷LV大小

    umount逻辑卷

    [root@centos lvm]# df -h
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   48G  4.5G   43G   10% /
    devtmpfs                 978M     0  978M    0% /dev
    tmpfs                    993M  156K  993M    1% /dev/shm
    tmpfs                    993M  9.0M  985M    1% /run
    tmpfs                    993M     0  993M    0% /sys/fs/cgroup
    /dev/sda1                497M  140M  357M   29% /boot
    tmpfs                    199M   16K  199M    1% /run/user/1000
    /dev/mapper/vgtest-vps   132M  1.6M  121M    2% /home/centos/vps
    [root@centos lvm]# umount /home/centos/vps
    [root@centos lvm]# lvdisplay /dev/vgtest/vps | grep "LV Size"
      LV Size                140.00 MiB
    

    检查文件系统整合性,然后缩小文件系统大小

    [root@centos lvm]# e2fsck -f /dev/vgtest/vps
    e2fsck 1.42.9 (28-Dec-2013)
    第一步: 检查inode,块,和大小
    第二步: 检查目录结构
    第3步: 检查目录连接性
    Pass 4: Checking reference counts
    第5步: 检查簇概要信息
    /dev/vgtest/vps: 11/36864 files (9.1% non-contiguous), 10303/143360 blocks
    [root@centos lvm]# resize2fs /dev/vgtest/vps 100M
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/vgtest/vps to 102400 (1k) blocks.
    The filesystem on /dev/vgtest/vps is now 102400 blocks long.
    

    缩小逻辑卷LV大小,大小和文件系统保持一致

    [root@centos lvm]# lvreduce -L 100M /dev/vgtest/vps 
      WARNING: Reducing active logical volume to 100.00 MiB
      THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce vps? [y/n]: y
      Size of logical volume vgtest/vps changed from 140.00 MiB (35 extents) to 100.00 MiB (25 extents).
      Logical volume vps successfully resized.
    [root@centos lvm]# lvdisplay /dev/vgtest/vps | grep "LV Size"
      LV Size                100.00 MiB
    [root@centos lvm]# vgdisplay vgtest | grep "Free  PE / Size"
      Free  PE / Size       35 / 140.00 MiB
    

    扩展VMWare虚拟机的磁盘大小

    给VMWare虚拟机新增一块硬盘

    查询当前磁盘使用情况

    [root@centos centos]# fdisk -l

    磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0x000bc6c9
    
       设备 Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     1026047      512000   83  Linux
    /dev/sda2         1026048   104857599    51915776   8e  Linux LVM
    
    磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    
    
    磁盘 /dev/mapper/centos-root:51.0 GB, 50964987904 字节,99540992 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    
    
    磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    
    [root@centos centos]# 
    

    在新增的磁盘上创建LVM分区

    [root@centos centos]# fdisk /dev/sdb 
    欢迎使用 fdisk (util-linux 2.23.2)。
    
    更改将停留在内存中,直到您决定将更改写入磁盘。
    使用写入命令前请三思。
    
    Device does not contain a recognized partition table
    使用磁盘标识符 0x76206a7b 创建新的 DOS 磁盘标签。
    
    命令(输入 m 获取帮助):n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    分区号 (1-4,默认 1):1
    起始 扇区 (2048-41943039,默认为 2048):
    将使用默认值 2048
    Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):
    将使用默认值 41943039
    分区 1 已设置为 Linux 类型,大小设为 20 GiB
    
    命令(输入 m 获取帮助):t
    已选择分区 1
    Hex 代码(输入 L 列出所有代码):8e
    已将分区“Linux”的类型更改为“Linux LVM”
    
    命令(输入 m 获取帮助):p
    
    磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0x76206a7b
    
       设备 Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048    41943039    20970496   8e  Linux LVM
    
    命令(输入 m 获取帮助):w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    正在同步磁盘。
    [root@centos centos]# partprobe
    

    创建物理卷PV

    [root@centos centos]# fdisk -l /dev/sdb 
    
    磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
    Units = 扇区 of 1 * 512 = 512 bytes
    扇区大小(逻辑/物理):512 字节 / 512 字节
    I/O 大小(最小/最佳):512 字节 / 512 字节
    磁盘标签类型:dos
    磁盘标识符:0x76206a7b
    
       设备 Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048    41943039    20970496   8e  Linux LVM
    [root@centos centos]# pvcreate /dev/sdb1
      Physical volume "/dev/sdb1" successfully created
    

    扩展卷组大小

    [root@centos centos]# pvdisplay 
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               centos
      PV Size               49.51 GiB / not usable 3.00 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              12674
      Free PE               11
      Allocated PE          12663
      PV UUID               edqmZj-578L-tMix-DJOE-FFnh-C4n2-aeLIuA
       
      "/dev/sdb1" is a new physical volume of "20.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/sdb1
      VG Name               
      PV Size               20.00 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               OqMQ6E-KYgh-W4Kl-OvEW-dUIZ-i1BJ-hZz9cg
       
    [root@centos centos]# vgdisplay 
      --- Volume group ---
      VG Name               centos
      System ID             
      Format                lvm2
      Metadata Areas        1
      Metadata Sequence No  3
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                1
      Act PV                1
      VG Size               49.51 GiB
      PE Size               4.00 MiB
      Total PE              12674
      Alloc PE / Size       12663 / 49.46 GiB
      Free  PE / Size       11 / 44.00 MiB
      VG UUID               EQ5hYJ-51Mx-QOd6-yVgZ-BD6A-EhxJ-0QHAqm
       
    [root@centos centos]# vgextend centos /dev/sdb1
      Volume group "centos" successfully extended
    [root@centos centos]# vgdisplay centos |grep 'Free  PE / Size'
      Free  PE / Size       5130 / 20.04 GiB
    

    扩展逻辑卷LV大小

    [root@centos centos]# lvdisplay 
      --- Logical volume ---
      LV Path                /dev/centos/swap
      LV Name                swap
      VG Name                centos
      LV UUID                EwWI53-xxB2-dXlQ-xuIb-8xRa-BDpE-THn1bE
      LV Write Access        read/write
      LV Creation host, time centos, 2016-03-30 17:44:27 +0800
      LV Status              available
      # open                 2
      LV Size                2.00 GiB
      Current LE             512
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:1
       
      --- Logical volume ---
      LV Path                /dev/centos/root
      LV Name                root
      VG Name                centos
      LV UUID                smMyzH-3MQ4-uTib-8b9I-FVd5-qBvv-6Y5I7N
      LV Write Access        read/write
      LV Creation host, time centos, 2016-03-30 17:44:27 +0800
      LV Status              available
      # open                 1
      LV Size                47.46 GiB
      Current LE             12151
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     8192
      Block device           253:0
       
    [root@centos centos]# lvextend -L +20G /dev/centos/root
      Size of logical volume centos/root changed from 47.46 GiB (12151 extents) to 67.46 GiB (17271 extents).
      Logical volume root successfully resized.
    

    扩展文件系统大小

    [root@centos centos]# xfs_growfs /dev/centos/root 
    meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=3110656 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=0        finobt=0
    data     =                       bsize=4096   blocks=12442624, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
    log      =internal               bsize=4096   blocks=6075, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    data blocks changed from 12442624 to 17685504
    [root@centos centos]# df -h
    文件系统                 容量  已用  可用 已用% 挂载点
    /dev/mapper/centos-root   68G  3.4G   65G    5% /
    devtmpfs                 978M     0  978M    0% /dev
    tmpfs                    993M  156K  993M    1% /dev/shm
    tmpfs                    993M  9.0M  984M    1% /run
    tmpfs                    993M     0  993M    0% /sys/fs/cgroup
    /dev/sda1                497M  140M  357M   29% /boot
    tmpfs                    199M  4.0K  199M    1% /run/user/42
    tmpfs                    199M  8.0K  199M    1% /run/user/1000
    [root@centos centos]# 
    

    问题处理

    centos7下使用resize2fs报错,产生原因是因为centos7下有些分区使用的是xfs的文件系统,需要使用 xfs_growfs 命令替代

    [root@centos centos]# resize2fs -p /dev/centos/root
    resize2fs 1.42.9 (28-Dec-2013)
    resize2fs: Bad magic number in super-block 当尝试打开 /dev/centos/root 时
    找不到有效的文件系统超级块.
    [root@centos centos]# df -T
    文件系统                类型        1K-块    已用     可用 已用% 挂载点
    /dev/mapper/centos-root xfs      49746196 3526408 46219788    8% /
    devtmpfs                devtmpfs  1001232       0  1001232    0% /dev
    tmpfs                   tmpfs     1016776     156  1016620    1% /dev/shm
    tmpfs                   tmpfs     1016776    9160  1007616    1% /run
    tmpfs                   tmpfs     1016776       0  1016776    0% /sys/fs/cgroup
    /dev/sda1               xfs        508588  143176   365412   29% /boot
    tmpfs                   tmpfs      203356       4   203352    1% /run/user/42
    tmpfs                   tmpfs      203356       8   203348    1% /run/user/1000
    

    参考

    http://www.litvip.com/category/lvm%E4%BD%BF%E7%94%A8/

  • 相关阅读:
    qt预览的UI界面和实际运行出来的界面分辨率不一样
    QByteArray转QString 例如 0x45 转成 “45”
    QML访问C++成员函数报错:TypeError: Property 'showHome' of object [object Object] is not a function
    Qt生成二维码
    Android解析编译之后的所有文件(so,dex,xml,arsc)格式
    Android逆向之旅---解析编译之后的Dex文件格式
    Android逆向之旅---解析编译之后的Resource.arsc文件格式
    Android逆向之旅---解析编译之后的AndroidManifest文件格式
    Android签名机制之---签名验证过程详解
    Android签名机制之---签名过程详解
  • 原文地址:https://www.cnblogs.com/silvermagic/p/7665800.html
Copyright © 2011-2022 走看看