zoukankan      html  css  js  c++  java
  • lvm逻辑卷的拉伸与缩小

    拉伸一个逻辑卷(逻辑卷的拉伸操作可以在线执行,不需要卸载逻辑卷)

    [root@zq ~]# lvextend -L 1G /dev/zq/mylv         #扩展1g的大小给mylv逻辑卷 这个没有+  是不可以的
      New size given (256 extents) not larger than existing size (512 extents)
      Run `lvextend --help' for more information.
    [root@zq ~]# lvextend -L +1G /dev/zq/mylv     #这才是对的
      Size of logical volume zq/mylv changed from 2.00 GiB (512 extents) to 3.00 GiB (768 extents).
      Logical volume mylv successfully resized.
    [root@zq ~]# lvs
      LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      mylv zq   -wi-ao---- 3.00g                                                    
    [root@zq ~]# df -h         #这里发现大小并没有变,刚刚拉伸的是底层并没有更新文件系统,操作系统并不能识别文件系统,我们需要更新一下
    文件系统             容量  已用  可用 已用% 挂载点
    /dev/sda3             20G  3.2G   17G   16% /
    devtmpfs             475M     0  475M    0% /dev
    tmpfs                489M  156K  489M    1% /dev/shm
    tmpfs                489M  7.1M  482M    2% /run
    tmpfs                489M     0  489M    0% /sys/fs/cgroup
    /dev/mapper/zq-mylv  2.0G  6.0M  1.8G    1% /mnt
    /dev/sda1            497M  138M  359M   28% /boot
    tmpfs                 98M  4.0K   98M    1% /run/user/42
    tmpfs                 98M   20K   98M    1% /run/user/1000
    [root@zq ~]# resize2fs /dev/zq/mylv   #更新文件系统,操作系统重新扫描,这个时候才可以使用额外的1g空间
    resize2fs 1.42.9 (28-Dec-2013)
    Filesystem at /dev/zq/mylv is mounted on /mnt; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 1
    The filesystem on /dev/zq/mylv is now 786432 blocks long.
    
    [root@zq ~]# df -h
    文件系统             容量  已用  可用 已用% 挂载点
    /dev/sda3             20G  3.2G   17G   16% /
    devtmpfs             475M     0  475M    0% /dev
    tmpfs                489M  156K  489M    1% /dev/shm
    tmpfs                489M  7.1M  482M    2% /run
    tmpfs                489M     0  489M    0% /sys/fs/cgroup
    /dev/mapper/zq-mylv  2.9G  6.0M  2.8G    1% /mnt
    /dev/sda1            497M  138M  359M   28% /boot
    tmpfs                 98M  4.0K   98M    1% /run/user/42
    tmpfs                 98M   20K   98M    1% /run/user/1000
    [root@zq ~]# lvs
      LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      mylv zq   -wi-a----- 3.00g                                                    
    [root@zq ~]# vgs
      VG   #PV #LV #SN Attr   VSize  VFree 
      zq     2   1   0 wz--n- 19.99g 16.99g
    [root@zq ~]# lvextend -L +17G /dev/zq/mylv 
      Insufficient free space: 4352 extents needed, but only 4350 available
    [root@zq ~]# lvextend -L +16G /dev/zq/mylv 
      Size of logical volume zq/mylv changed from 3.00 GiB (768 extents) to 19.00 GiB (4864 extents).
      Logical volume mylv successfully resized.
    [root@zq ~]# resize2fs /dev/zq/mylv 
    resize2fs 1.42.9 (28-Dec-2013)
    请先运行 'e2fsck -f /dev/zq/mylv'.
    
    [root@zq ~]# e2fsck -f /dev/zq/mylv 
    e2fsck 1.42.9 (28-Dec-2013)
    /dev/zq/mylv: 正在修复日志
    第一步: 检查inode,块,和大小
    第二步: 检查目录结构
    第3步: 检查目录连接性
    Pass 4: Checking reference counts
    第5步: 检查簇概要信息
    Free inodes count wrong (196597, counted=196596).
    处理<y>?/dev/zq/mylv: ***** 文件系统已修改 *****
    /dev/zq/mylv: 12/196608 files (0.0% non-contiguous), 30268/786432 blocks
    [root@zq ~]# df -h
    文件系统        容量  已用  可用 已用% 挂载点
    /dev/sda3        20G  3.2G   17G   16% /
    devtmpfs        475M     0  475M    0% /dev
    tmpfs           489M  156K  489M    1% /dev/shm
    tmpfs           489M  7.1M  482M    2% /run
    tmpfs           489M     0  489M    0% /sys/fs/cgroup
    /dev/sr0        3.8G  3.8G     0  100% /mnt
    /dev/sda1       497M  138M  359M   28% /boot
    tmpfs            98M  4.0K   98M    1% /run/user/42
    tmpfs            98M   12K   98M    1% /run/user/1000
    [root@zq ~]# resize2fs /dev/zq/mylv 
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/zq/mylv to 4980736 (4k) blocks.
    The filesystem on /dev/zq/mylv is now 4980736 blocks long.
    
    [root@zq ~]# df -h
    文件系统        容量  已用  可用 已用% 挂载点
    /dev/sda3        20G  3.2G   17G   16% /
    devtmpfs        475M     0  475M    0% /dev
    tmpfs           489M  156K  489M    1% /dev/shm
    tmpfs           489M  7.1M  482M    2% /run
    tmpfs           489M     0  489M    0% /sys/fs/cgroup
    /dev/sr0        3.8G  3.8G     0  100% /mnt
    /dev/sda1       497M  138M  359M   28% /boot
    tmpfs            98M  4.0K   98M    1% /run/user/42
    tmpfs            98M   12K   98M    1% /run/user/1000
    [root@zq ~]# ^C
    [root@zq ~]# vgs
      VG   #PV #LV #SN Attr   VSize  VFree   
      zq     2   1   0 wz--n- 19.99g 1016.00m
    [root@zq ~]# lvs
      LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      mylv zq   -wi-a----- 19.00g                                                    
    [root@zq ~]# mount
    sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    devtmpfs on /dev type devtmpfs (rw,nosuid,size=486124k,nr_inodes=121531,mode=755)
    securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
    tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
    tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
    tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
    cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
    pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
    cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
    cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
    cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
    cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
    cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
    cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
    cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
    cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
    cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
    configfs on /sys/kernel/config type configfs (rw,relatime)
    /dev/sda3 on / type xfs (rw,relatime,attr2,inode64,noquota)
    systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=25,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
    hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
    mqueue on /dev/mqueue type mqueue (rw,relatime)
    debugfs on /sys/kernel/debug type debugfs (rw,relatime)
    sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
    nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
    /dev/sr0 on /mnt type iso9660 (ro,relatime)
    /dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
    tmpfs on /run/user/42 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700,uid=42,gid=42)
    fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
    tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700,uid=1000,gid=1000)
    gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
    [root@zq ~]# mount /dev/zq/mylv /mnt/
    [root@zq ~]# mount
    sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    devtmpfs on /dev type devtmpfs (rw,nosuid,size=486124k,nr_inodes=121531,mode=755)
    securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
    tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
    tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
    tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
    cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
    pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
    cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
    cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
    cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
    cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
    cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
    cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
    cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
    cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
    cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
    configfs on /sys/kernel/config type configfs (rw,relatime)
    /dev/sda3 on / type xfs (rw,relatime,attr2,inode64,noquota)
    systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=25,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
    hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
    mqueue on /dev/mqueue type mqueue (rw,relatime)
    debugfs on /sys/kernel/debug type debugfs (rw,relatime)
    sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
    nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
    /dev/sr0 on /mnt type iso9660 (ro,relatime)
    /dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
    tmpfs on /run/user/42 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700,uid=42,gid=42)
    fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
    tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700,uid=1000,gid=1000)
    gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
    /dev/mapper/zq-mylv on /mnt type ext4 (rw,relatime,data=ordered)
    [root@zq ~]# df -h
    文件系统             容量  已用  可用 已用% 挂载点
    /dev/sda3             20G  3.2G   17G   16% /
    devtmpfs             475M     0  475M    0% /dev
    tmpfs                489M  156K  489M    1% /dev/shm
    tmpfs                489M  7.1M  482M    2% /run
    tmpfs                489M     0  489M    0% /sys/fs/cgroup
    /dev/mapper/zq-mylv   19G   11M   18G    1% /mnt
    /dev/sda1            497M  138M  359M   28% /boot
    tmpfs                 98M  4.0K   98M    1% /run/user/42
    tmpfs                 98M   12K   98M    1% /run/user/1000

    拉伸,更新,挂载,查看都得注意,不过拉伸的时候注意先后顺序pv,vg,lv

    加入我们现在想再扩充空间

    [root@zq ~]# vgdisplay 
      --- Volume group ---
      VG Name               zq
      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               19.99 GiB
      PE Size               4.00 MiB
      Total PE              5118
      Alloc PE / Size       4864 / 19.00 GiB
      Free  PE / Size       254 / 1016.00 MiB  #剩余的空间不到1g  怎么办
      VG UUID               0wgWs7-WGXn-QwvV-4ccu-Jmut-fQPI-dspeby
    [root@zq ~]# pvs              #显示只有两块物理磁盘
      PV         VG   Fmt  Attr PSize  PFree   
      /dev/sdb   zq   lvm2 a--  10.00g       0 
      /dev/sdc   zq   lvm2 a--  10.00g 1016.00m

    现在我们首先添加物理磁盘然后卷组扩展进来把新添加的pv,后面的顺序依次扩展就可以了

    缩小一个逻辑卷(逻辑卷的缩小操作必须离线执行,要卸载逻辑卷)

    1、卸载已经挂载的逻辑卷 umount /dev/zq/mylv

    2、缩小文件系统(会提示需要运行fsck检查文件系统)resize2fs /dev/zq/mylv 1G   切记先缩小文件系统跟扩展的时候恰恰相反,缩小为1g

    3、缩小LV  lvreduce -L -1G /dev/zq/mylv

    4、查看缩小后的LV  lvdispaly

    5、挂载  mount /dev/zq/mylv /mnt

    [root@zq ~]# e2fsck -f /dev/zq/mylv   #检查磁盘损坏 -f 遇到一切错误跳过不提示
    e2fsck 1.42.9 (28-Dec-2013)
    第一步: 检查inode,块,和大小
    第二步: 检查目录结构
    第3步: 检查目录连接性
    Pass 4: Checking reference counts
    第5步: 检查簇概要信息
    /dev/zq/mylv: 12/1245184 files (0.0% non-contiguous), 97345/4980736 blocks
    [root@zq ~]# mount
    sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    devtmpfs on /dev type devtmpfs (rw,nosuid,size=486124k,nr_inodes=121531,mode=755)
    securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
    tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
    tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
    tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
    cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
    pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
    cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
    cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
    cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
    cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
    cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
    cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
    cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
    cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
    cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
    configfs on /sys/kernel/config type configfs (rw,relatime)
    /dev/sda3 on / type xfs (rw,relatime,attr2,inode64,noquota)
    systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=25,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
    hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
    mqueue on /dev/mqueue type mqueue (rw,relatime)
    debugfs on /sys/kernel/debug type debugfs (rw,relatime)
    sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
    nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
    /dev/sr0 on /mnt type iso9660 (ro,relatime)
    /dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
    tmpfs on /run/user/42 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700,uid=42,gid=42)
    fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
    tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700,uid=1000,gid=1000)
    gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
    /dev/mapper/zq-mylv on /mnt type ext4 (rw,relatime,data=ordered)
    tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700)
    [root@zq ~]# umount /mnt/
    [root@zq ~]# mount
    sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    devtmpfs on /dev type devtmpfs (rw,nosuid,size=486124k,nr_inodes=121531,mode=755)
    securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
    tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
    tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
    tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
    cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
    pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
    cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
    cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
    cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
    cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
    cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
    cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
    cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
    cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
    cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
    configfs on /sys/kernel/config type configfs (rw,relatime)
    /dev/sda3 on / type xfs (rw,relatime,attr2,inode64,noquota)
    systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=25,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
    hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
    mqueue on /dev/mqueue type mqueue (rw,relatime)
    debugfs on /sys/kernel/debug type debugfs (rw,relatime)
    sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
    nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
    /dev/sr0 on /mnt type iso9660 (ro,relatime)
    /dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
    tmpfs on /run/user/42 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700,uid=42,gid=42)
    fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
    tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700,uid=1000,gid=1000)
    gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
    tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700)
    [root@zq ~]# 
    [root@zq ~]# resize2fs /dev/zq/mylv 10G
    resize2fs 1.42.9 (28-Dec-2013)
    请先运行 'e2fsck -f /dev/zq/mylv'.
    
    [root@zq ~]# e2fsck -f /dev/zq/mylv 
    e2fsck 1.42.9 (28-Dec-2013)
    第一步: 检查inode,块,和大小
    第二步: 检查目录结构
    第3步: 检查目录连接性
    Pass 4: Checking reference counts
    第5步: 检查簇概要信息
    /dev/zq/mylv: 12/1245184 files (0.0% non-contiguous), 97345/4980736 blocks
    [root@zq ~]# resize2fs /dev/zq/mylv 10G
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/zq/mylv to 2621440 (4k) blocks.
    The filesystem on /dev/zq/mylv is now 2621440 blocks long.
    
    [root@zq ~]# lvs
      LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      mylv zq   -wi-a----- 19.00g                                                    
    [root@zq ~]# lvreduce -L -9G /dev/zq/mylv 
      WARNING: Reducing active logical volume to 10.00 GiB
      THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce mylv? [y/n]: y
      Size of logical volume zq/mylv changed from 19.00 GiB (4864 extents) to 10.00 GiB (2560 extents).
      Logical volume mylv successfully resized.
    [root@zq ~]# lvs
      LV   VG   Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      mylv zq   -wi-a----- 10.00g                                                    
    [root@zq ~]# mount /dev/zq/mylv /mnt/
    [root@zq ~]# mount
    sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    devtmpfs on /dev type devtmpfs (rw,nosuid,size=486124k,nr_inodes=121531,mode=755)
    securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
    tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
    tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
    tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
    cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
    pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
    cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
    cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
    cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
    cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
    cgroup on /sys/fs/cgroup/net_cls type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls)
    cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
    cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
    cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
    cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
    configfs on /sys/kernel/config type configfs (rw,relatime)
    /dev/sda3 on / type xfs (rw,relatime,attr2,inode64,noquota)
    systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=25,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
    hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
    mqueue on /dev/mqueue type mqueue (rw,relatime)
    debugfs on /sys/kernel/debug type debugfs (rw,relatime)
    sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
    nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
    /dev/sr0 on /mnt type iso9660 (ro,relatime)
    /dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
    tmpfs on /run/user/42 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700,uid=42,gid=42)
    fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
    tmpfs on /run/user/1000 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700,uid=1000,gid=1000)
    gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,relatime,user_id=1000,group_id=1000)
    tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=100136k,mode=700)
    /dev/mapper/zq-mylv on /mnt type ext4 (rw,relatime,data=ordered)
    View Code

    缩小这块操作要小心,可能损坏大小,所以缩小的时候尽量做一个误差出来

  • 相关阅读:
    [NOI2019] 回家路线
    [NOIP2016] 天天爱跑步
    [CF1187D] Subarray Sorting
    [THUPC2018] 弗雷兹的玩具商店
    [AGC006C] Rabbit Exercise
    [AGC005F] Many Easy Problems
    [51Nod2558] 选址
    [BZOJ3771] Triple
    [APIO2019] 奇怪装置
    [CTSC2018] 假面
  • 原文地址:https://www.cnblogs.com/zq6041/p/6859268.html
Copyright © 2011-2022 走看看