LoginSignup
3
3

More than 5 years have passed since last update.

LVM

Last updated at Posted at 2015-05-12

LVMで一つの論理ボリュームを100G減らして、他の論理ボリュームを追加する。

1.ディスクシステムの事前確認

$ df -h                                                                                                                                         
Filesystem                          Size  Used Avail Use% Mounted on
/dev/mapper/vg_kvmsimu02-lv_root   50G   38G  9.5G  80% /
tmpfs                               1.9G     0  1.9G   0% /dev/shm
/dev/vda1                           485M   33M  427M   8% /boot
/dev/mapper/vg_kvmsimu02-lv_home  439G   19G  398G   5% /home  ←こいつを100G減らしたい

2.マウント状況確認

# mount                                                                                                                                           
/dev/mapper/vg_kvmsimu02-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/vda1 on /boot type ext4 (rw)
/dev/mapper/vg_kvmsimu02-lv_home on /home type ext4 (rw)  ←これを一時的にアンマウントする
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)

3.パーティションの設定を確認

・今回の対象ではないかもですが、ディスクの対象を確認

# fdisk -l /dev/vda
ディスク /dev/vda: 536.9 GB, 536870912000 バイト
ヘッド 16, セクタ 63, シリンダ 1040253
Units = シリンダ数 of 1008 * 512 = 516096 バイト
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O size (minimum/optimal): 512 bytes / 512 bytes
ディスク識別子: 0x0004b73a

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/vda1   *           3        1018      512000   83  Linux
パーティション 1 は、シリンダ境界で終わっていません。
/dev/vda2            1018     1040254   523774976   8e  Linux LVM ←今回の対象はこれ
パーティション 2 は、シリンダ境界で終わっていません。

4.物理ボリューム確認

# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda2
  VG Name               vg_kvmsimu02
  PV Size               499.51 GiB / not usable 3.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              127874
  Free PE               0
  Allocated PE          127874
  PV UUID               UdE3ri-k6Va-cZse-kBZA-QPLM-qVXA-F5NdKK

5.ボリュームグループの確認

・今回は物理ボリュームとボリュームグループが1:1の関係

[root@-kvm-simu02 ~]# vgdisplay 
  --- Volume group ---
  VG Name               vg_kvmsimu02
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               499.51 GiB
  PE Size               4.00 MiB
  Total PE              127874
  Alloc PE / Size       127874 / 499.51 GiB
  Free  PE / Size       0 / 0   
  VG UUID               AwbSjG-KMLf-IeC0-koRO-W6q7-0hD3-eW4Zdv

6.論理ボリュームの確認

[root@-kvm-simu02 ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/vg_kvmsimu02/lv_root
  LV Name                lv_root
  VG Name                vg_kvmsimu02
  LV UUID                13fvFk-ZUQ3-qGR2-dzmN-sHqK-hdIB-tNaqED
  LV Write Access        read/write
  LV Creation host, time -kvm-simu02, 2014-09-22 21:10:43 +0900
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/vg_kvmsimu02/lv_home   ←こいつを100G減らしたい
  LV Name                lv_home
  VG Name                vg_kvmsimu02
  LV UUID                dyK2j2-UCB2-wann-NIlh-O5iW-K0e5-G1GzIU
  LV Write Access        read/write
  LV Creation host, time -kvm-simu02, 2014-09-22 21:10:45 +0900
  LV Status              available
  # open                 1
  LV Size                445.63 GiB
  Current LE             114082
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Logical volume ---
  LV Path                /dev/vg_kvmsimu02/lv_swap
  LV Name                lv_swap
  VG Name                vg_kvmsimu02
  LV UUID                mxeG5l-qQE2-pLYe-aO1h-LJU3-ecWx-4zW4cB
  LV Write Access        read/write
  LV Creation host, time -kvm-simu02, 2014-09-22 21:11:03 +0900
  LV Status              available
  # open                 1
  LV Size                3.88 GiB
  Current LE             992
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

7.umountが出来ることを確認

[root@-kvm-simu02 ~]# umount -l /home
[root@-kvm-simu02 ~]# df
Filesystem                         1K-blocks     Used Available Use% Mounted on
/dev/mapper/vg_kvmsimu02-lv_root  51606140 39098788   9885912  80% /
tmpfs                                1961452        0   1961452   0% /dev/shm
/dev/vda1                             495844    33483    436761   8% /boot
  /dev/vg_kvmsimu02/lv_homeが無くなっている
[root@-kvm-simu02 ~]# cd /home/
[root@-kvm-simu02 home]# ll
合計 0

#8.mountが出来ることを確認
・いったん元に戻す
[root@-kvm-simu02 home]# mount -t ext4 /dev/mapper/vg_kvmsimu02-lv_home /home
[root@-kvm-simu02 home]# df
Filesystem                         1K-blocks     Used Available Use% Mounted on
/dev/mapper/vg_kvmsimu02-lv_root  51606140 39098884   9885816  80% /
tmpfs                                1961452        0   1961452   0% /dev/shm
/dev/vda1                             495844    33483    436761   8% /boot
/dev/mapper/vg_kvmsimu02-lv_home 459946088 19904548 416677548   5% /home

ココから本番

9.対象のディレクトリをumount

[root@-kvm-simu02 home]# umount -l /home                                                                                                                          

[root@-kvm-simu02 home]# ll
合計 0

# df
Filesystem                         1K-blocks     Used Available Use% Mounted on
/dev/mapper/vg_kvmsimu02-lv_root  51606140 39099176   9885524  80% /
tmpfs                                1961452        0   1961452   0% /dev/shm
/dev/vda1                             495844    33483    436761   8% /boot

10.ディスク領域を削減し、マウントしなおす

# lvreduce -L -100G /dev/mapper/vg_kvmsimu02-lv_home
  WARNING: Reducing active and open logical volume to 345.63 GiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_home? [y/n]: y
  Reducing logical volume lv_home to 345.63 GiB
  Logical volume lv_home successfully resized
# mount -t ext4 /dev/mapper/vg_kvmsimu02-lv_home /home                                                                                       

11.100G減ったことを確認

# df -h
Filesystem                          Size  Used Avail Use% Mounted on
/dev/mapper/vg_kvmsimu02-lv_root   50G   38G  9.5G  80% /
tmpfs                               1.9G     0  1.9G   0% /dev/shm
/dev/vda1                           485M   33M  427M   8% /boot
/dev/mapper/vg_kvmsimu02-lv_home  339G   19G  298G   5% /home

12.論理ボリューム「lv_usr01」を作成し、ext4でフォーマット

# lvcreate -L 100G -n lv_usr01 vg_kvmsimu02                                                                                                     
  Logical volume "lv_usr01" created
# mkfs.ext4 /dev/mapper/vg_kvmsimu02-lv_usr01
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

13.mountし追加されたことを確認できました

# mount /dev/mapper/vg_kvmsimu02-lv_usr01 /usr01
# df -h
Filesystem                           Size  Used Avail Use% Mounted on
/dev/mapper/vg_kvmsimu02-lv_root    50G   38G  9.5G  80% /
tmpfs                                1.9G     0  1.9G   0% /dev/shm
/dev/vda1                            485M   33M  427M   8% /boot
/dev/mapper/vg_kvmsimu02-lv_home   339G   19G  298G   5% /home
/dev/mapper/vg_kvmsimu02-lv_usr01   99G  188M   94G   1% /usr01  ←★
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3