• Linux LVM简明教程


      
    建2块  linux lvm 格式的 分区  
     
    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 0x06d8c027.
    
    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-524287999, default 2048): 
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-524287999, default 524287999): +140G
    Partition 1 of type Linux and of size 140 GiB is set
    
    Command (m for help): t
    Selected partition 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: 268.4 GB, 268435456000 bytes, 524288000 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: 0x06d8c027
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vdb1            2048   293603327   146800640   8e  Linux LVM
    
    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 (293603328-524287999, default 293603328): 
    Using default value 293603328
    
    Last sector, +sectors or +size{K,M,G} (293603328-524287999, default 524287999): +100G
    Partition 2 of type Linux and of size 100 GiB is set
    
    Command (m for help): t
    Partition number (1,2, default 2): 
    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: 268.4 GB, 268435456000 bytes, 524288000 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: 0x06d8c027
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vdb1            2048   293603327   146800640   8e  Linux LVM
    /dev/vdb2       293603328   503318527   104857600   8e  Linux LVM
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    

      

    准备物理卷
     
    yum install -y lvm2
    

      

    [root@weifeng ~]# ls /dev/vdb1
    /dev/vdb1
    [root@weifeng ~]# partprobe
    
    [root@weifeng~]# ls /dev/vdb1
    /dev/vdb1
    
    [root@weifeng ~]# ls /dev/vdb2
    /dev/vdb2
    

       

    创建物理卷
     
    [root@weifeng ~]# pvcreate /dev/vdb1
      Physical volume "/dev/vdb1" successfully created.
    
    [root@weifeng ~]# pvcreate /dev/vdb2
      Physical volume "/dev/vdb2" successfully created.
    

      

    查看物理卷
     
    [root@weifeng ~]# pvdisplay
    
      "/dev/vdb2" is a new physical volume of "100.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/vdb2
      VG Name               
      PV Size               100.00 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               R1t7xi-rdXN-YyFm-fe60-EEHl-5lzd-IEoscW
       
      "/dev/vdb1" is a new physical volume of "140.00 GiB"
      --- NEW Physical volume ---
      PV Name               /dev/vdb1
      VG Name               
      PV Size               140.00 GiB
      Allocatable           NO
      PE Size               0   
      Total PE              0
      Free PE               0
      Allocated PE          0
      PV UUID               wXq8wP-ccgu-JvOz-yUk9-9SvR-XnuQ-k05zEN
       
    

       

    查看物理卷
    [root@weifeng ~]# pvs
      PV         VG Fmt  Attr PSize   PFree  
      /dev/vdb1     lvm2 ---  140.00g 140.00g
      /dev/vdb2     lvm2 ---  100.00g 100.00g
    

      

    创建卷组
      
    [root@weifeng ~]# vgcreate vg1 /dev/vdb1 /dev/vdb2
      Volume group "vg1" successfully created
    

      

    查看卷组 

    [root@weifeng ~]# vgdisplay
      --- Volume group ---
      VG Name               vg1
      System ID             
      Format                lvm2
      Metadata Areas        2
      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                2
      Act PV                2
      VG Size               239.99 GiB
      PE Size               4.00 MiB
      Total PE              61438
      Alloc PE / Size       0 / 0   
      Free  PE / Size       61438 / 239.99 GiB
      VG UUID               A4eITy-lscO-9pAv-hCqF-qA7v-LCTw-gdmkhU
    
    [root@weifeng ~]# vgs
      VG  #PV #LV #SN Attr   VSize   VFree  
      vg1   2   0   0 wz--n- 239.99g 239.99g
    

       

    创建逻辑卷
     
    [root@weifeng ~]# lvcreate -L 140G -n lv1 vg1
      Logical volume "lv1" created.
    
    [root@weifeng ~]# mkfs.xfs /dev/vg1/lv1
    meta-data=/dev/vg1/lv1           isize=512    agcount=4, agsize=9175040 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=36700160, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=17920, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    
    [root@weifeng ~]# mkdir /var/lib/docker 
    [root@weifeng ~]# mount /dev/vg1/lv1 /var/lib/docker
    [root@weifeng ~]# df -h
    Filesystem           Size  Used Avail Use% Mounted on
    devtmpfs             7.5G     0  7.5G   0% /dev
    tmpfs                7.6G     0  7.6G   0% /dev/shm
    tmpfs                7.6G  460K  7.6G   1% /run
    tmpfs                7.6G     0  7.6G   0% /sys/fs/cgroup
    /dev/vda1             59G  2.1G   55G   4% /
    tmpfs                1.6G     0  1.6G   0% /run/user/0
    /dev/mapper/vg1-lv1  140G   33M  140G   1% /var/lib/docker
    
    
    [root@weifeng ~]# lvcreate -L 98G -n lv2 vg1
      Logical volume "lv2" created.
    [root@weifeng ~]# mkfs.xfs /dev/vg1/lv2
    meta-data=/dev/vg1/lv2           isize=512    agcount=4, agsize=6422528 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0, sparse=0
    data     =                       bsize=4096   blocks=25690112, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=12544, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    [root@weifeng ~]# mkdir /workspace 
    
    [root@weifeng ~]# mount /dev/vg1/lv2 /workspace 
    
    [root@weifeng ~]# df -h
    Filesystem           Size  Used Avail Use% Mounted on
    devtmpfs             7.5G     0  7.5G   0% /dev
    tmpfs                7.6G     0  7.6G   0% /dev/shm
    tmpfs                7.6G  464K  7.6G   1% /run
    tmpfs                7.6G     0  7.6G   0% /sys/fs/cgroup
    /dev/vda1             59G  2.1G   55G   4% /
    tmpfs                1.6G     0  1.6G   0% /run/user/0
    /dev/mapper/vg1-lv1  140G   33M  140G   1% /var/lib/docker
    /dev/mapper/vg1-lv2   98G   33M   98G   1% /workspace
    

      

    修改fstab文件

    [root@weifeng ~]# cat /etc/fstab 
    
    /dev/mapper/vg1-lv1  /var/lib/docker  xfs   defaults 0 0
    /dev/mapper/vg1-lv2  /workspace       xfs    defaults 0 0 
    

       

    删除分区
     
    fdisk /dev/vdb
    
    输入 d , wq
    

     
    删除 vg
     
    [root@rocketmq-1 ~]# vgremove vg1
    Do you really want to remove volume group "vg1" containing 2 logical volumes? [y/n]: y
    Do you really want to remove active logical volume vg1/lv1? [y/n]: y
      Logical volume "lv1" successfully removed
    Do you really want to remove active logical volume vg1/lv2? [y/n]: y
      Logical volume "lv2" successfully removed
      Volume group "vg1" successfully removed
    
    [root@rocketmq-1 ~]# vgdisplay
    
    [root@rocketmq-1 ~]# mkfs.xfs -f /dev/vdb
    
     
    进行扩容操作 
    [root@compute ~]# umount /mnt/
    [root@compute ~]# lvresize -L 200M /dev/vg1/lv1
      New size (50 extents) matches existing size (50 extents).
     
    检查磁盘
    [root@compute ~]# e2fsck -f /dev/vg1/lv1
    e2fsck 1.42.9 (28-Dec-2013)
    Pass 1: Checking inodes, blocks, and sizes
    Pass 2: Checking directory structure
    Pass 3: Checking directory connectivity
    Pass 4: Checking reference counts
    Pass 5: Checking group summary information
    /dev/vg1/lv1: 11/25688 files (9.1% non-contiguous), 8896/102400 blocks
     
     
    更新逻辑卷信息
    [root@compute ~]# resize2fs /dev/vg1/lv1
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/vg1/lv1 to 204800 (1k) blocks.
    The filesystem on /dev/vg1/lv1 is now 204800 blocks long.
     
     
    分区已经扩容
    [root@compute ~]# mount /dev/vg1/lv1 /mnt/
    [root@compute ~]# df -h
    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   18G  2.1G   16G  12% /
    devtmpfs                 907M     0  907M   0% /dev
    tmpfs                    917M     0  917M   0% /dev/shm
    tmpfs                    917M  8.6M  908M   1% /run
    tmpfs                    917M     0  917M   0% /sys/fs/cgroup
    /dev/sda1                497M  169M  328M  34% /boot
    tmpfs                    184M     0  184M   0% /run/user/0
    /dev/mapper/vg1-lv1      190M  1.6M  175M   1% /mnt
     
  • 相关阅读:
    以UIWebView的方式来播放网络多媒体档案
    Cocoa.Programming.for.Mac系统文章翻译
    iOS开发教程:Storyboard全解析第二部分
    boost日期、时间操作
    使用thrift大量编译警告消息方法
    一键自动往crontab添加条目脚本
    apache thrift的不足
    将Fedora 18 LXDE安装到U盘和进入图形界面的方法
    boost库thread.hpp编译警告(type attributes are honored only at type definition)已修复
    平板电视必知知识
  • 原文地址:https://www.cnblogs.com/weifeng1463/p/12189430.html
Copyright © 2020-2023  润新知