CentOS6のパーティション拡張
CentOS6.4のディスクを拡張したときのメモ。
環境はMacBookProでVMware Fusion5を使用しています。
CentOSのパーティションはLVMで設定してます。
/だけに全部割り当てている感じです。
以下の手順は自己責任でお願いします。
まず始めに物理的なディスクを拡張します。
VMwareのメニューから仮想マシン->ハードディスク(IDE)->ハードディスク(IDE)設定を選択。
適当に増やしたい分だけ増やします。注意書きにある通りシャットダウンしておかないと無理です。
増設したら起動します。
rootでログインしたらfdiskコマンドでちゃんと増えているか確認。
[root@vmware ~]# fdisk -l /dev/sda Disk /dev/sda: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0003b5d8 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 3917 30944256 8e Linux LVM
容量だけ53.7GBに増えてます。
実際に使える領域は増えていません。
Linux LVMのIdは後で指定しますので要確認。
パーティションを切り直します。
僕がやった時はデータは消えませんでしたが環境によっては消えるかもしれませんのでバックアップは取りましょう。
[root@vmware ~]# fdisk /dev/sda Command (m for help):
入ったらまず既存のパーティションを一旦消します。
Command (m for help): d Partition number (1-4): 2 Command (m for help): p Disk /dev/sda: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0003b5d8 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary.
消えたので作り直します。
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (64-6527, default 64): Using default value 64 Last cylinder, +cylinders or +size{K,M,G} (64-6527, default 6527): Using default value 6527 Command (m for help): p Disk /dev/sda: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0003b5d8 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 6527 51915103+ 83 Linux
LVMなので変更します。
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): p Disk /dev/sda: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0003b5d8 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 6527 51915103+ 8e Linux LVM
これで広がりました。
確認して大丈夫だったら保存して抜けます。
そしてマシンを再起動します。
この時点ではまだ増えていません。
dfで見ても元のままです。
次にだらだらと以下の手順を行います。
[root@vmware ~]# pvresize /dev/sda2 Physical volume "/dev/sda2" changed 1 physical volume(s) resized / 0 physical volume(s) not resized [root@vmware ~]# lvextend -L +20G /dev/mapper/vg_vmcentos-lv_root Extending logical volume lv_root to 45.57 GiB Logical volume lv_root successfully resized [root@vmware ~]# resize2fs /dev/mapper/vg_vmcentos-lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/vg_vmcentos-lv_root is mounted on /; on-line resizing required old desc_blocks = 2, new_desc_blocks = 3 Performing an on-line resize of /dev/mapper/vg_vmcentos-lv_root to 11945984 (4k) blocks. The filesystem on /dev/mapper/vg_vmcentos-lv_root is now 11945984 blocks long.
作業完了後dfで確認すると26GBから45GBに増えました。
思ったより簡単でした。