LVM下のswapからExt4 / にディスク容量を都合する
東京の仲間内の共有マシン,私が一昨年にマザボからストレージまでそっくり入れ替えたのだが,ルート・パーティションの空きが足りなくなってきたと指摘された.前は普通に数百GBのHDDだったのだが,静音と省電力を狙って64 GB (MLC) SSDにしたので...
$ df -Th ファイルシス タイプ サイズ 使用 残り 使用% マウント位置 rootfs rootfs 14G 13G 540M 97% / udev devtmpfs 10M 0 10M 0% /dev tmpfs tmpfs 357M 440K 357M 1% /run /dev/mapper/VgApricot-LvApricotRoot ext4 14G 13G 540M 97% / tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs tmpfs 714M 84K 714M 1% /run/shm /dev/sda2 ext3 194M 45M 147M 24% /boot /dev/mapper/VgApricot-LvApricotHome ext4 41G 36G 5.1G 88% /home tmpfs tmpfs 4.0G 52K 4.0G 1% /tmp
きつい(感想)
しかしパーティションの名前からお分かりのようにSSDはLVM管理下にある.LVMに対しては,今までメンドクセー以上の感想を持ったことが無かったが,こういうときにこそ役立つ.延命策として,ほとんど使われていないswap領域からディスク容量を / に都合すればよい.以下,作業前の内訳:
- VG "VgApricot": 59.4 GiB
- LV "LvApricotRoot": 13.7 GiB
- LV "LvApricotHome": 41.4 GiB
- LV "LvApricotSwap": 4.4 GiB
# vgdisplay --- Volume group --- VG Name VgApricot System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 18 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 59.43 GiB PE Size 4.00 MiB Total PE 15213 Alloc PE / Size 15213 / 59.43 GiB Free PE / Size 0 / 0 VG UUID XDRmpz-44Ni-wzk9-VnfC-Oo53-R1d6-Z971sZ # lvdisplay --- Logical volume --- LV Path /dev/VgApricot/LvApricotRoot LV Name LvApricotRoot VG Name VgApricot LV UUID fH37Uu-fvug-eo0M-a3i0-RF7j-31n1-WjYgln LV Write Access read/write LV Creation host, time , LV Status available # open 1 LV Size 13.67 GiB Current LE 3500 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:0 --- Logical volume --- LV Path /dev/VgApricot/LvApricotHome LV Name LvApricotHome VG Name VgApricot LV UUID 7L93sq-r3gj-JWDC-qo2A-MlJe-o901-DoxBiK LV Write Access read/write LV Creation host, time , LV Status available # open 1 LV Size 41.36 GiB Current LE 10588 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:1 --- Logical volume --- LV Path /dev/VgApricot/LvApricotSwap LV Name LvApricotSwap VG Name VgApricot LV UUID FEyH6h-1YkM-UNZi-yQ04-C13B-NaJW-aokPlo LV Write Access read/write LV Creation host, time , LV Status available # open 2 LV Size 4.39 GiB Current LE 1125 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:2
まずスワップ領域を取り外す.
$ free -m total used free shared buffers cached Mem: 3568 3422 146 0 350 1947 -/+ buffers/cache: 1124 2444 Swap: 4499 23 4476 # swapoff /dev/mapper/VgApricot-LvApricotSwap $ free -m total used free shared buffers cached Mem: 3568 3391 177 0 346 1905 -/+ buffers/cache: 1140 2428 Swap: 0 0 0
スワップ領域のLVを縮小.ここでオペミスするとシステム全体が死んでしまう恐れが...
# lvresize -L -3G /dev/mapper/VgApricot-LvApricotSwap WARNING: Reducing active logical volume to 1.39 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce LvApricotSwap? [y/n]: y Reducing logical volume LvApricotSwap to 1.39 GiB Logical volume LvApricotSwap successfully resized # vgdisplay --- Volume group --- VG Name VgApricot System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 19 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 59.43 GiB PE Size 4.00 MiB Total PE 15213 Alloc PE / Size 14445 / 56.43 GiB Free PE / Size 768 / 3.00 GiB VG UUID XDRmpz-44Ni-wzk9-VnfC-Oo53-R1d6-Z971sZ
確かに空きができた.この空きを全部使って LV LvApricotRoot
と,その中の / を拡張したい.しかし lvextend(8)
が便利オプション +100%FREE
を認識してくれなかった.仕方ないのでさっきと同じ 3 GB を指定する.
# lvextend -L +3G /dev/mapper/VgApricot-LvApricotRoot Extending logical volume LvApricotRoot to 16.67 GiB Logical volume LvApricotRoot successfully resized # vgdisplay --- Volume group --- VG Name VgApricot System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 20 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 59.43 GiB PE Size 4.00 MiB Total PE 15213 Alloc PE / Size 15213 / 59.43 GiB Free PE / Size 0 / 0 VG UUID XDRmpz-44Ni-wzk9-VnfC-Oo53-R1d6-Z971sZ # lvdisplay --- Logical volume --- LV Path /dev/VgApricot/LvApricotRoot LV Name LvApricotRoot VG Name VgApricot LV UUID fH37Uu-fvug-eo0M-a3i0-RF7j-31n1-WjYgln LV Write Access read/write LV Creation host, time , LV Status available # open 1 LV Size 16.67 GiB Current LE 4268 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:0 --- Logical volume --- LV Path /dev/VgApricot/LvApricotHome LV Name LvApricotHome VG Name VgApricot LV UUID 7L93sq-r3gj-JWDC-qo2A-MlJe-o901-DoxBiK LV Write Access read/write LV Creation host, time , LV Status available # open 1 LV Size 41.36 GiB Current LE 10588 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:1 --- Logical volume --- LV Path /dev/VgApricot/LvApricotSwap LV Name LvApricotSwap VG Name VgApricot LV UUID FEyH6h-1YkM-UNZi-yQ04-C13B-NaJW-aokPlo LV Write Access read/write LV Creation host, time , LV Status available # open 2 LV Size 1.39 GiB Current LE 357 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 254:2
さっき -3G で生じた空きを,今度は +3G することで全部ぴったり LvApricotRoot
に割り振ることができた.現状はこう:
- VG "VgApricot": 59.4 GiB
- LV "LvApricotRoot": 16.7 GiB
- LV "LvApricotHome": 41.4 GiB
- LV "LvApricotSwap": 1.4 GiB
ここで恐怖のファイルシステム拡張を執り行う.引数で拡張サイズを陽に指定しないことで,空き領域全てを使う意味になる:
# resize2fs /dev/mapper/VgApricot-LvApricotRoot resize2fs 1.42.5 (29-Jul-2012) Filesystem at /dev/mapper/VgApricot-LvApricotRoot is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 Performing an on-line resize of /dev/mapper/VgApricot-LvApricotRoot to 4370432 (4k) blocks. The filesystem on /dev/mapper/VgApricot-LvApricotRoot is now 4370432 blocks long. $ df -Th ファイルシス タイプ サイズ 使用 残り 使用% マウント位置 rootfs rootfs 17G 13G 3.5G 79% / udev devtmpfs 10M 0 10M 0% /dev tmpfs tmpfs 357M 440K 357M 1% /run /dev/mapper/VgApricot-LvApricotRoot ext4 17G 13G 3.5G 79% / tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs tmpfs 714M 84K 714M 1% /run/shm /dev/sda2 ext3 194M 45M 147M 24% /boot /dev/mapper/VgApricot-LvApricotHome ext4 41G 36G 5.1G 88% /home tmpfs tmpfs 4.0G 52K 4.0G 1% /tmp
うまく行ったようだ.スワップ領域を戻しておく.
# mkswap /dev/mapper/VgApricot-LvApricotSwap # swapon -a $ free -m total used free shared buffers cached Mem: 3568 3401 167 0 350 1906 -/+ buffers/cache: 1144 2424 Swap: 1427 0 1427
おしまい.