美文网首页
linux磁盘管理---LVM

linux磁盘管理---LVM

作者: Sigers | 来源:发表于2019-04-09 11:15 被阅读0次

    一、创建lvm
    大致步骤:
    1.fdisk /dev/vdb,创建一个分区如/dev/vdb1
    2.创建pv,pvcreate /deb/vdb1
    3.创建vg,vgcreate name /dev/vdb1
    4.创建lv,lvcreate -L 20G -n lvname vgname

    root@ubuntu:~# fdisk /dev/sdb
    
    Welcome to fdisk (util-linux 2.27.1).
    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.
    Created a new DOS disklabel with disk identifier 0x4f478fce.
    
    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1): 
    First sector (2048-41943039, default 2048): 
    Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 
    
    Created a new partition 1 of type 'Linux' and of size 20 GiB.
    
    Command (m for help): t
    Selected partition 1
    Partition type (type L to list all types): 8e
    Changed type of partition 'Linux' to 'Linux LVM'.
    
    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
    
    root@ubuntu:~# 
    root@ubuntu:~# fdisk -l
    Disk /dev/sda: 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: 0xca984eb8
    
    Device     Boot    Start      End  Sectors  Size Id Type
    /dev/sda1  *        2048 39942143 39940096   19G 83 Linux
    /dev/sda2       39944190 41940991  1996802  975M  5 Extended
    /dev/sda5       39944192 41940991  1996800  975M 82 Linux swap / Solaris
    
    
    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: 0x4f478fce
    
    Device     Boot Start      End  Sectors Size Id Type
    /dev/sdb1        2048 41943039 41940992  20G 8e Linux LVM
    
    
    Disk /dev/sdc: 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
    
    
    root@ubuntu:~#
    root@ubuntu:~# pvcreate /dev/sdb1
      /run/lvm/lvmetad.socket: connect failed: No such file or directory
      WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
      Physical volume "/dev/sdb1" successfully created
    root@ubuntu:~# vgcreate sdb1vg1 /dev/sdb1     #sdb1vg1是自己命名的vg名
      Volume group "sdb1vg1" successfully created
    root@ubuntu:~# lvcreate -L 19G -n lvsdb1 sdb1vg1    #lvsdb1是自己命名的lv名
      Logical volume "lvsdb1" created.
    root@ubuntu:~# lvdisplay 
      --- Logical volume ---
      LV Path                /dev/sdb1vg1/lvsdb1
      LV Name                lvsdb1
      VG Name                sdb1vg1
      LV UUID                M6TXKf-Jsql-SG0C-mVCK-zTPE-OWV3-EkwSGY
      LV Write Access        read/write
      LV Creation host, time ubuntu, 2018-09-16 23:31:31 -0700
      LV Status              available
      # open                 0
      LV Size                19.00 GiB
      Current LE             4864
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           252:0
    root@ubuntu:~# mkfs.ext3 /dev/sdb1vg1/lvsdb1 
    mke2fs 1.42.13 (17-May-2015)
    Creating filesystem with 4980736 4k blocks and 1245184 inodes
    Filesystem UUID: 27702051-2e69-429a-aa21-aea3ab1a6605
    Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done   
    
    root@ubuntu:~# mount /dev/sdb1vg1/lvsdb1 /wj/lvmtest1
    root@ubuntu:~# df -h
    Filesystem                  Size  Used Avail Use% Mounted on
    udev                        469M     0  469M   0% /dev
    tmpfs                        98M  4.5M   93M   5% /run
    /dev/sda1                    19G  1.6G   17G   9% /
    tmpfs                       488M     0  488M   0% /dev/shm
    tmpfs                       5.0M     0  5.0M   0% /run/lock
    tmpfs                       488M     0  488M   0% /sys/fs/cgroup
    tmpfs                        98M     0   98M   0% /run/user/0
    /dev/mapper/sdb1vg1-lvsdb1   19G   45M   18G   1% /wj/lvmtest1
    root@ubuntu:~#
    

    上述报错用下面命令解决

    root@ubuntu:~# systemctl enable lvm2-lvmetad.service 
    Synchronizing state of lvm2-lvmetad.service with SysV init with /lib/systemd/systemd-sysv-install...
    Executing /lib/systemd/systemd-sysv-install enable lvm2-lvmetad
    root@ubuntu:~# systemctl enable lvm2-lvmetad.socket
    root@ubuntu:~# systemctl start lvm2-lvmetad.service 
    root@ubuntu:~# systemctl start lvm2-lvmetad.socket
    

    二、lvm扩容

    大致步骤
    1.fdisk /dev/vdb,创建一个分区如/dev/vdb1
    2.创建pv,pvcreate /deb/vdb1
    3.vgextend vgname pvname(/dev/vdb1,用lvdisplay查看)
    4.lvextend -L +10G lvpath(lvdisplay查看)
    5.resize2fs lvpath

    先fdisk一块sdc2盘
    然后具体操作如下

    root@ubuntu:~# pvcreate /dev/sdc2
      Physical volume "/dev/sdc2" successfully created
    root@ubuntu:~# vgdisplay 
      --- Volume group ---
      VG Name               sdb1vg1
      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               20.00 GiB
      PE Size               4.00 MiB
      Total PE              5119
      Alloc PE / Size       4864 / 19.00 GiB
      Free  PE / Size       255 / 1020.00 MiB
      VG UUID               CE3SUU-zD0y-3Rrm-hehH-OXhK-PDVE-XPHClv
    root@ubuntu:~# vgextend sdb1vg1 /dev/sdc2
      Volume group "sdb1vg1" successfully extended
    root@ubuntu:~# df -h
    Filesystem                  Size  Used Avail Use% Mounted on
    udev                        469M     0  469M   0% /dev
    tmpfs                        98M  4.5M   93M   5% /run
    /dev/sda1                    19G  1.6G   17G   9% /
    tmpfs                       488M     0  488M   0% /dev/shm
    tmpfs                       5.0M     0  5.0M   0% /run/lock
    tmpfs                       488M     0  488M   0% /sys/fs/cgroup
    tmpfs                        98M     0   98M   0% /run/user/0
    /dev/mapper/sdb1vg1-lvsdb1   19G   45M   18G   1% /wj/lvmtest1
    root@ubuntu:~# lvdisplay 
      --- Logical volume ---
      LV Path                /dev/sdb1vg1/lvsdb1
      LV Name                lvsdb1
      VG Name                sdb1vg1
      LV UUID                M6TXKf-Jsql-SG0C-mVCK-zTPE-OWV3-EkwSGY
      LV Write Access        read/write
      LV Creation host, time ubuntu, 2018-09-16 23:31:31 -0700
      LV Status              available
      # open                 1
      LV Size                19.00 GiB
      Current LE             4864
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           252:0
       
    root@ubuntu:~# lvextend -L +5G /dev/sdb1vg1/lvsdb1 
      Size of logical volume sdb1vg1/lvsdb1 changed from 19.00 GiB (4864 extents) to 24.00 GiB (6144 extents).
      Logical volume lvsdb1 successfully resized.
    root@ubuntu:~# df -h
    Filesystem                  Size  Used Avail Use% Mounted on
    udev                        469M     0  469M   0% /dev
    tmpfs                        98M  4.5M   93M   5% /run
    /dev/sda1                    19G  1.6G   17G   9% /
    tmpfs                       488M     0  488M   0% /dev/shm
    tmpfs                       5.0M     0  5.0M   0% /run/lock
    tmpfs                       488M     0  488M   0% /sys/fs/cgroup
    tmpfs                        98M     0   98M   0% /run/user/0
    /dev/mapper/sdb1vg1-lvsdb1   19G   45M   18G   1% /wj/lvmtest1
    root@ubuntu:~# resize2fs /dev/sdb1vg1/lvsdb1 
    resize2fs 1.42.13 (17-May-2015)
    Filesystem at /dev/sdb1vg1/lvsdb1 is mounted on /wj/lvmtest1; on-line resizing required
    old_desc_blocks = 2, new_desc_blocks = 2
    The filesystem on /dev/sdb1vg1/lvsdb1 is now 6291456 (4k) blocks long.
    
    root@ubuntu:~# df -h
    Filesystem                  Size  Used Avail Use% Mounted on
    udev                        469M     0  469M   0% /dev
    tmpfs                        98M  4.5M   93M   5% /run
    /dev/sda1                    19G  1.6G   17G   9% /
    tmpfs                       488M     0  488M   0% /dev/shm
    tmpfs                       5.0M     0  5.0M   0% /run/lock
    tmpfs                       488M     0  488M   0% /sys/fs/cgroup
    tmpfs                        98M     0   98M   0% /run/user/0
    /dev/mapper/sdb1vg1-lvsdb1   24G   45M   23G   1% /wj/lvmtest1
    root@ubuntu:~#
    
    Re-reading the partition table failed.: Device or resource busy
    

    解决:

    partprobe
    

    相关文章

      网友评论

          本文标题:linux磁盘管理---LVM

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