page counter next up previous contents
Next: xfs lv 縮小 Up: XFS 檔案系統 Previous: Linux 檔案系統   Contents

ext4 lv 放大縮小

  1. 放大縮小都可以使用 lvresize 指令,不過最好先卸載檔案系統,再進行放大縮小,否則可能會造成檔案損壞,尤其根目錄無法卸載的情況下,直接進行放大縮小,風險非常高,若真有必要對根目錄進行放大縮小,建議改以隨身碟開機來對電腦硬碟進行分割區的放大縮小。
  2. 查看 partition 的 filesystem type,v6 預設為 ext4。
    [root@kvm8 ~]# df -Th /home
    Filesystem    Type    Size  Used Avail Use% Mounted on
    /dev/mapper/vg_kvmhome-vo
                  ext4     97M  5.6M   87M   7% /home
    
  3. 先卸載家目錄 /home。
    [root@kvm8 ~]# umount /home/
    
  4. 從原先的 80M 縮小為 50M,選項 -r 表示同時進行檔案系統的 resize。
    [root@kvm8 ~]# lvresize -L 50M /dev/mapper/vg_kvmhome-vo -r
    fsck from util-linux-ng 2.17.2
    e2fsck 1.41.12 (17-May-2010)
    /dev/mapper/vg_kvmhome-vo: clean, 47/20480 files, 8288/81920 blocks
    resize2fs 1.41.12 (17-May-2010)
    Resizing the filesystem on /dev/dm-2 to 51200 (1k) blocks.
    The filesystem on /dev/dm-2 is now 51200 blocks long.
    
      Reducing logical volume vo to 50.00 MiB
      Logical volume vo successfully resized
    
  5. 重新掛載再查看分割區 /dev/mapper/vg_kvmusb-vo 已調成 50M。
    [root@kvm8 ~]# mount -a
    [root@kvm8 ~]# df -h /home
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/vg_kvmhome-vo
                           49M  5.1M   41M  12% /home
    
  6. 卸載後再將分割區 /dev/mapper/vg_kvmusb-vo 放大成 120M,出現錯誤訊息,要求先檢查檔案系統。
    [root@kvm8 ~]# umount /home/
    [root@kvm8 ~]# lvresize -L 120M /dev/mapper/vg_kvmhome-vo -r
    fsck from util-linux-ng 2.17.2
    e2fsck 1.41.12 (17-May-2010)
    /dev/mapper/vg_kvmhome-vo: clean, 47/14336 files, 6998/51200 blocks
      Extending logical volume vo to 120.00 MiB
      Logical volume vo successfully resized
    resize2fs 1.41.12 (17-May-2010)
    Please run 'e2fsck -f /dev/dm-2' first.
    
    fsadm: Resize ext4 failed
      fsadm failed: 1
    
  7. 先檢查分割區 /dev/mapper/vg_kvmusb-vo,也就是 /dev/dm-2
    [root@kvm8 ~]# e2fsck -f /dev/dm-2
    e2fsck 1.41.12 (17-May-2010)
    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/dm-2: 47/14336 files (4.3% non-contiguous), 6998/51200 blocks
    
  8. 再將分割區 /dev/mapper/vg_kvmusb-vo 放大成 120M,已沒有錯誤訊息,要求先檢查檔案系統。
    [root@kvm8 ~]# lvresize -L 120M /dev/mapper/vg_kvmhome-vo -r
    fsck from util-linux-ng 2.17.2
    e2fsck 1.41.12 (17-May-2010)
    /dev/mapper/vg_kvmhome-vo: clean, 47/14336 files, 6998/51200 blocks
      Extending logical volume vo to 120.00 MiB
      Logical volume vo successfully resized
    resize2fs 1.41.12 (17-May-2010)
    Resizing the filesystem on /dev/dm-2 to 122880 (1k) blocks.
    The filesystem on /dev/dm-2 is now 122880 blocks long.
    
  9. 重新掛載再查看分割區 /dev/mapper/vg_kvmusb-vo 已調成 120M。
    [root@kvm8 ~]# mount -a
    [root@kvm8 ~]# df -h /home
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/vg_kvmhome-vo
                          117M  5.6M  105M   6% /home
    



2015-12-04