next up previous contents
Next: 產生邏輯捲冊 Up: 邏輯捲軸管理 Previous: 放大 LV 標準作法   Contents

單一指令放大縮小 LV

  1. 以 lvresize 指令一次完成放大或縮小。 特別注意﹗lv 放大縮小應先卸載,無法卸載的分割區,盡量不要使用此方法做。例如根目錄無法卸載,且 lvm 相關命令在 /sbin 目錄下,直接將掛載根目錄 / 的分割區,做放大縮小,風險非常高,可能造成資料的損壞。
  2. 先檢查 LV vo 在 VG vg_kvm7home 內,大小為 93M ( 100M )。
    [root@kvm7 ~]# df -h
    Filesystem                   Size  Used Avail Use% Mounted on
    /dev/mapper/vg_kvm7usb-root  3.1G  1.1G  1.8G  37% /
    devtmpfs                     487M     0  487M   0% /dev
    tmpfs                        497M     0  497M   0% /dev/shm
    tmpfs                        497M  6.6M  491M   2% /run
    tmpfs                        497M     0  497M   0% /sys/fs/cgroup
    /dev/vda1                    197M  107M   90M  55% /boot
    /dev/mapper/vg_mnt-pub        24M     0   24M   0% /mnt/pub
    /dev/mapper/vg_kvm7home-vo    93M  1.6M   87M   2% /home
    
  3. 以單一指令 lvresize 將 LV vo 大小改為 40M,不用理會是放大還是縮小,其中 -r 選項是一併執行 resize2fs 的命令,不知道 vo 所屬的群組,可以使用 df -h 查看,或下命令時使用 TAB 參數提示。
    [root@kvm7 ~]# lvresize -L 40M -r /dev/vg_kvm7home/vo 
    Do you want to unmount "/home"? [Y|n] y
    fsck from util-linux 2.23.2
    /dev/mapper/vg_kvm7home-vo: 11/26624 files (9.1% non-contiguous), 9015/102400 blocks
    resize2fs 1.42.9 (28-Dec-2013)
    Resizing the filesystem on /dev/mapper/vg_kvm7home-vo to 40960 (1k) blocks.
    The filesystem on /dev/mapper/vg_kvm7home-vo is now 40960 blocks long.
    
      Size of logical volume vg_kvm7home/vo changed from 100.00 MiB (50 extents) to 40.00 MiB (20 extents).
      Logical volume vo successfully resized
    
  4. 再檢查 LV vg_kvm7home-vo 大小為 35M ( 40M )。
    [root@kvm7 ~]# df -h
    Filesystem                   Size  Used Avail Use% Mounted on
    /dev/mapper/vg_kvm7usb-root  3.1G  1.1G  1.8G  37% /
    devtmpfs                     487M     0  487M   0% /dev
    tmpfs                        497M     0  497M   0% /dev/shm
    tmpfs                        497M  6.6M  491M   2% /run
    tmpfs                        497M     0  497M   0% /sys/fs/cgroup
    /dev/vda1                    197M  107M   90M  55% /boot
    /dev/mapper/vg_mnt-pub        24M     0   24M   0% /mnt/pub
    /dev/mapper/vg_kvm7home-vo    35M  784K   32M   3% /home
    
  5. 以單一指令 lvresize 將 LV vg_kvm7home-vo 大小改為 80M,不用理會是放大還是縮小,其中 -r 選項是一併執行 resize2fs 的命令。
    [root@kvm7 ~]# lvresize -L 80M -r /dev/vg_kvm7home/vo 
      Size of logical volume vg_kvm7home/vo changed from 40.00 MiB (20 extents) to 80.00 MiB (40 extents).
      Logical volume vo successfully resized
    resize2fs 1.42.9 (28-Dec-2013)
    Filesystem at /dev/mapper/vg_kvm7home-vo is mounted on /home; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 1
    The filesystem on /dev/mapper/vg_kvm7home-vo is now 81920 blocks long.
    
  6. 再檢查 LV vg_kvm7home-vo 大小為 74M ( 80M )。
    [root@kvm7 ~]# df -h
    Filesystem                   Size  Used Avail Use% Mounted on
    /dev/mapper/vg_kvm7usb-root  3.1G  1.1G  1.8G  37% /
    devtmpfs                     487M     0  487M   0% /dev
    tmpfs                        497M     0  497M   0% /dev/shm
    tmpfs                        497M  6.6M  491M   2% /run
    tmpfs                        497M     0  497M   0% /sys/fs/cgroup
    /dev/vda1                    197M  107M   90M  55% /boot
    /dev/mapper/vg_mnt-pub        24M     0   24M   0% /mnt/pub
    /dev/mapper/vg_kvm7home-vo    74M  1.6M   68M   3% /home
    



2018-06-04