文書更新:2018年05月30日(水) 午後8時11分38秒

Home > 備忘録 > LVM に関すること > LVMの縮小( 76 )

LVMの縮小

LVM(default install LVM)のサイズとHDDのパーティションサイズを縮小します。オンラインでは縮小できないので、Live CDで起動する。
  1. LVMをアクティブにする。
  2. [root@server]# lvm vgchange -a y
      2 logical volume(s) in volume group "vg_leom" now active
  3. Filesystemのチェック
  4. [root@server]# fsck -fc /dev/vg_leom/lv_root
    fsck from util-linux-ng 2.17.2
    e2fsck 1.41.10 (10-Feb-2009)
    Checking for bad blocks (read-only test): done                                
    /dev/mapper/vg_leom-lv_root: Updating bad block inode.
    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/mapper/vg_leom-lv_root: ***** FILE SYSTEM WAS MODIFIED *****
    /dev/mapper/vg_leom-lv_root: 229264/7208960 files (0.9% non-contiguous), 9017188/28835840 blocks
  5. Filesystemのリサイズ
  6. [root@server]# resize2fs -p /dev/vg_leom/lv_root 100G
    resize2fs 1.41.10 (10-Feb-2009)
    Resizing the filesystem on /dev/vg_leom/lv_root to 26214400 (4k) blocks.
    Begin pass 2 (max = 543469)
    Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Begin pass 3 (max = 880)
    Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    Begin pass 4 (max = 28093)
    Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    The filesystem on /dev/vg_leom/lv_root is now 26214400 blocks long.
  7. Logical volumeのリサイズ
  8. [root@server]# lvm lvresize /dev/vg_leom/lv_root --size 100G
      WARNING: Reducing active logical volume to 100.00 GiB
      THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce lv_root? [y/n]: y
      Reducing logical volume lv_root to 100.00 GiB
      Logical volume lv_root successfully resized
  9. Physical volumeのリサイズ
  10. [root@server]# lvm pvresize /dev/sda2 --setphysicalvolumesize 100G
      /dev/sda2: cannot resize to 25599 extents as 26104 are allocated.
      0 physical volume(s) resized / 1 physical volume(s) not resized
    リサイズできていない
    [root@server]# lvm pvresize /dev/sda2 --setphysicalvolumesize 101G
      /dev/sda2: cannot resize to 25855 extents as 26104 are allocated.
      0 physical volume(s) resized / 1 physical volume(s) not resized
    リサイズできていない
    [root@server]# lvm pvresize /dev/sda2 --setphysicalvolumesize 102G
      Physical volume "/dev/sda2" changed
      1 physical volume(s) resized / 0 physical volume(s) not resized
    リサイズ成功
  11. fdiskコマンドでパーティションサイズを変更する
  12. [root@server]# fdisk /dev/sda
    
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
             switch off the mode (command 'c') and change display units to
             sectors (command 'u').
    
    Command (m for help): d
    Partition number (1-4): 2
    
    Command (m for help): n
    Command action
       e   extended
       p   primary partition (1-4)
    p
    Partition number (1-4): 2
    First cylinder (26-60801, default 26): 
    Using default value 26
    Last cylinder, +cylinders or +size{K,M,G} (26-60801, default 60801): +102G
    
    Command (m for help): t
    Partition number (1-4): 2
    Hex code (type L to list codes): 8e
    Changed system type of partition 2 to 8e (Linux LVM)
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.
  13. Physical volumeの確認とリサイズ
  14. [root@server]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               vg_leom
      PV Size               120.00 GiB / not usable 3.81 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              30719
      Free PE               4615
      Allocated PE          26104
      PV UUID               eXmCVb-Om8g-06LC-WABT-bk5l-ADce-krBIUA
    「PV Size」が120Gのままで、リサイズできていない
    [root@server]# pvresize /dev/sda2 100G
      Physical volume "/dev/sda2" changed
      Failed to read physical volume "100G"
      1 physical volume(s) resized / 0 physical volume(s) not resized

    [root@server]# pvdisplay
      --- Physical volume ---
      PV Name               /dev/sda2
      VG Name               vg_leom
      PV Size               102.00 GiB / not usable 1.76 MiB
      Allocatable           yes 
      PE Size               4.00 MiB
      Total PE              26112
      Free PE               8
      Allocated PE          26104
      PV UUID               eXmCVb-Om8g-06LC-WABT-bk5l-ADce-krBIUA
    リサイズ成功
  15. 最後にFilesystemのチェック
  16. [root@server]# fsck -fc /dev/vg_leom/lv_root
    fsck from util-linux-ng 2.17.2
    e2fsck 1.41.10 (10-Feb-2009)
    Checking for bad blocks (read-only test): done                                
    /dev/mapper/vg_leom-lv_root: Updating bad block inode.
    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/mapper/vg_leom-lv_root: ***** FILE SYSTEM WAS MODIFIED *****
    /dev/mapper/vg_leom-lv_root: 229286/6553600 files (0.9% non-contiguous), 8976966/26214400 blocks
    Logical volumeのサイズを120Gから100Gに変更するするつもりが、結果的に102Gに変更することにした。