Dockerコンテナを作りまくっていたら、ディスク容量が足りなくなってきました。
そこでファイルシステムを拡張させたいと思います
残りの空き状況を確認(df -h)
/dev/mapper/centos-root がやばいですね。。
とりあえず100GBほど足します
追加ディスクの確認(fdisk -l)
今回追加したのは /dev/sdb の100GBディスクです
※ここでディスクが認識されていない場合、下記コマンドで認識させる
パーティション作成
/dev/sdb 100GB全て Linux LVMのパーティションとして作成します。
確認
/dev/sdb1 の新規パーティションができていることを確認
そこから論理ボリューム(LV)を切り出しています。
そのため、下記順序で実施します
ext4=>resize2fsコマンド
xfs=>xfs_growfsコマンド
ファイルシステムの拡張
拡張されました。
そこでファイルシステムを拡張させたいと思います
参考サイト
https://qiita.com/mtomoaki_96kg/items/baf772405a46846563e9空き状態の確認
残りの空き状況を確認(df -h)
# df -h ファイルシス サイズ 使用 残り 使用% マウント位置 /dev/mapper/centos-root 50G 49G 1.9G 97% / devtmpfs 4.8G 0 4.8G 0% /dev tmpfs 4.9G 0 4.9G 0% /dev/shm tmpfs 4.9G 468K 4.9G 1% /run tmpfs 4.9G 0 4.9G 0% /sys/fs/cgroup /dev/sda1 1014M 142M 873M 14% /boot /dev/mapper/centos-home 47G 34M 47G 1% /home tmpfs 984M 0 984M 0% /run/user/1000
とりあえず100GBほど足します
LVMの確認(lvdisplay)
/dev/centos/root を拡張させます
VolumeGroup(vgdisplay)
# lvdisplay --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID FQfcNL-eIES-tiyH-vdxi-Eu5J-XI3f-ArWPVc LV Write Access read/write LV Creation host, time pug, 2017-12-02 10:21:24 +0900 LV Status available # open 2 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/home LV Name home VG Name centos LV UUID rmc4yv-wle1-53VK-41tR-TuFz-RFaN-2sD2LL LV Write Access read/write LV Creation host, time pug, 2017-12-02 10:21:25 +0900 LV Status available # open 1 LV Size 46.99 GiB Current LE 12030 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID 8kuWOf-MSHK-LW42-l86m-3jfH-Ub7R-GjXEy5 LV Write Access read/write LV Creation host, time pug, 2017-12-02 10:21:26 +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 8192 Block device 253:0
VolumeGroup(vgdisplay)
# vgdisplay --- Volume group --- VG Name centos 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 <99.00 GiB PE Size 4.00 MiB Total PE 25343 Alloc PE / Size 25342 / 98.99 GiB Free PE / Size 1 / 4.00 MiB VG UUID gzrJQ4-fbyb-e83L-NTEN-oVJT-X0o7-vNWgqx
PhysicalVolume(pvdisplay)
# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size <99.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 25343 Free PE 1 Allocated PE 25342 PV UUID 1SkZ1h-1wS8-ThOZ-pLGj-PN3S-C5PP-g3223t
ディスクの追加とパーティションの作成
100GBのディスクを追加しましたので、確認です追加ディスクの確認(fdisk -l)
今回追加したのは /dev/sdb の100GBディスクです
# fdisk -l
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk label type: dos ディスク識別子: 0x000e73f1 デバイス ブート 始点 終点 ブロック Id システム /dev/sda1 * 2048 2099199 1048576 83 Linux /dev/sda2 2099200 209715199 103808000 8e Linux LVM Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk /dev/mapper/centos-home: 50.5 GB, 50457477120 bytes, 98549760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk /dev/loop0: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk /dev/loop1: 2147 MB, 2147483648 bytes, 4194304 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk /dev/mapper/docker-253:0-100736515-pool: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 65536 バイト / 65536 バイト
※ここでディスクが認識されていない場合、下記コマンドで認識させる
# lsscsi [1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0 [2:0:0:0] disk VMware Virtual disk 1.0 /dev/sda
# echo "- - -" > /sys/class/scsi_host/host2/scan
# lsscsi [1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0 [2:0:0:0] disk VMware Virtual disk 1.0 /dev/sda [2:0:1:0] disk VMware Virtual disk 1.0 /dev/sdb (←見えるようになった)
パーティション作成
/dev/sdb 100GB全て Linux LVMのパーティションとして作成します。
# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x04e5e77b. コマンド (m でヘルプ): コマンド (m でヘルプ): m コマンドの動作 a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) コマンド (m でヘルプ): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p パーティション番号 (1-4, default 1): 最初 sector (2048-209715199, 初期値 2048): 初期値 2048 を使います Last sector, +sectors or +size{K,M,G} (2048-209715199, 初期値 209715199): 初期値 209715199 を使います Partition 1 of type Linux and of size 100 GiB is set コマンド (m でヘルプ): t Selected partition 1 Hex code (type L to list all codes): L 0 空 24 NEC DOS 81 Minix / 古い Li bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux スワップ c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 隠し C: ド c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux 拡張領域 c7 Syrinx 5 拡張領域 41 PPC PReP Boot 86 NTFS ボリューム da 非 FS データ 6 FAT16 42 SFS 87 NTFS ボリューム db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux プレーン de Dell ユーティリ 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX ブート可能 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 ブートマネ 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad ハ eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 拡張領域 (L 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC 11 隠し FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq 診断 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 隠し FAT16 <32M 61 SpeedStor ab Darwin ブート f2 DOS セカンダリ 16 隠し FAT16 63 GNU HURD または af HFS / HFS+ fb VMware VMFS 17 隠し HPFS/NTFS 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI スワップ fd Linux raid 自動 1b 隠し W95 FAT32 70 DiskSecure Mult bb 隠し Boot Wizar fe LANstep 1c 隠し W95 FAT32 75 PC/IX be Solaris ブート ff BBT 1e 隠し W95 FAT16 80 古い Minix Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' コマンド (m でヘルプ): m コマンドの動作 a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) コマンド (m でヘルプ): w パーティションテーブルは変更されました! ioctl() を呼び出してパーティションテーブルを再読込みします。 ディスクを同期しています。
確認
/dev/sdb1 の新規パーティションができていることを確認
# fdisk -l /dev/sdb Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト Disk label type: dos ディスク識別子: 0x04e5e77b デバイス ブート 始点 終点 ブロック Id システム /dev/sdb1 2048 209715199 104856576 8e Linux LVM
LVMの拡張
LVMは物理ボリューム(PV)をいくつか束ねてボリュームグループ(VG)としていそこから論理ボリューム(LV)を切り出しています。
そのため、下記順序で実施します
- 物理ボリューム作成(pvcreate)
- ボリュームグループの拡張(vgextend)
- 論理ボリュームの拡張(lvextend)
1.物理ボリュームの作成(pvcreate)
2.ボリュームグループの拡張(vgextend)
vgdisplayでVG Nameを確認(今回は centos)し拡張する
拡張後 VG Sizeが追加されていることを確認する
# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created.
# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name centos PV Size <99.00 GiB / not usable 3.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 25343 Free PE 1 Allocated PE 25342 PV UUID 1SkZ1h-1wS8-ThOZ-pLGj-PN3S-C5PP-g3223t "/dev/sdb1" is a new physical volume of "<100.00 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size <100.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID 78RLid-n9Nx-aXt2-IBHX-U6S2-s4Qg-hSOQMX
2.ボリュームグループの拡張(vgextend)
vgdisplayでVG Nameを確認(今回は centos)し拡張する
拡張後 VG Sizeが追加されていることを確認する
# vgdisplay --- Volume group --- VG Name centos 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 <99.00 GiB PE Size 4.00 MiB Total PE 25343 Alloc PE / Size 25342 / 98.99 GiB Free PE / Size 1 / 4.00 MiB VG UUID gzrJQ4-fbyb-e83L-NTEN-oVJT-X0o7-vNWgqx
# vgextend centos /dev/sdb1 Volume group "centos" successfully extended
# vgdisplay --- Volume group --- VG Name centos System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 5 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 2 Act PV 2 VG Size 198.99 GiB PE Size 4.00 MiB Total PE 50942 Alloc PE / Size 25342 / 98.99 GiB Free PE / Size 25600 / 100.00 GiB VG UUID gzrJQ4-fbyb-e83L-NTEN-oVJT-X0o7-vNWgqx
3.論理ボリュームの拡張(lvextend)
拡張対象のLV Pathを確認(今回は/dev/centos/root)しlvを拡張する
このとき、空き容量を全て拡張する
拡張対象のLV Pathを確認(今回は/dev/centos/root)しlvを拡張する
このとき、空き容量を全て拡張する
# lvdisplay --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID FQfcNL-eIES-tiyH-vdxi-Eu5J-XI3f-ArWPVc LV Write Access read/write LV Creation host, time pug, 2017-12-02 10:21:24 +0900 LV Status available # open 2 LV Size 2.00 GiB Current LE 512 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:1 --- Logical volume --- LV Path /dev/centos/home LV Name home VG Name centos LV UUID rmc4yv-wle1-53VK-41tR-TuFz-RFaN-2sD2LL LV Write Access read/write LV Creation host, time pug, 2017-12-02 10:21:25 +0900 LV Status available # open 1 LV Size 46.99 GiB Current LE 12030 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID 8kuWOf-MSHK-LW42-l86m-3jfH-Ub7R-GjXEy5 LV Write Access read/write LV Creation host, time pug, 2017-12-02 10:21:26 +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 8192 Block device 253:0
# lvextend -l +100%FREE /dev/centos/root Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 150.00 GiB (38400 extents). Logical volume centos/root successfully resized.
# lvdisplay /dev/centos/root --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID 8kuWOf-MSHK-LW42-l86m-3jfH-Ub7R-GjXEy5 LV Write Access read/write LV Creation host, time pug, 2017-12-02 10:21:26 +0900 LV Status available # open 1 LV Size 150.00 GiB Current LE 38400 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:0
ファイルシステムの拡張
最後、OSのファイルシステム側を拡張します。CentOS7は、xfsなのでコマンドがちょっと違いますext4=>resize2fsコマンド
xfs=>xfs_growfsコマンド
ファイルシステムの拡張
# xfs_growfs /dev/centos/root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=3276800 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=13107200, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal bsize=4096 blocks=6400, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
# df -h ファイルシス サイズ 使用 残り 使用% マウント位置 /dev/mapper/centos-root 150G 49G 102G 33% / devtmpfs 4.8G 0 4.8G 0% /dev tmpfs 4.9G 0 4.9G 0% /dev/shm tmpfs 4.9G 472K 4.9G 1% /run tmpfs 4.9G 0 4.9G 0% /sys/fs/cgroup /dev/sda1 1014M 142M 873M 14% /boot /dev/mapper/centos-home 47G 34M 47G 1% /home tmpfs 984M 0 984M 0% /run/user/1000
拡張されました。
コメント
コメント一覧 (8)
現在CentOS7でディスク拡張を実施したものの、どうしていいものなのかわからず、ご教示頂ける方を探しており、ここに辿り着きました。
私の方は大阪なのですが、もし可能でしたらお会いしたいと思います。
kazuyak1027@yahoo.co.jp
ぜひお助けくださいませ
残念ながらお会いする事は難しいのですが、具体的に困っていることを記載頂ければ、お答えできるかもしれません
有難うございます!
良かったです!
DISKFULLだと言われ、困っておりましたところ、こちらのサイトに辿り着きました。
大変助かりました。ありがとうございます!
今度ボリューム拡張を予定しており、検索していたらたどりつきました。
拡張でわからないことがあり、大変お手数ですがご教示頂けますと幸いです。
rootボリュームの拡張を予定しているのですが、
上記作業ではレスキューモードなどは使用していますでしょうか?
サイトによっては使用したりしなかったりで、どちらが正しいのか気になります。。
以下、私の環境です。
centos6.10
LVM
ext4
オンプレミス
宜しくお願いいたします。、
このページにたどり着けて良かったです。助かりました。
(広告で評価の選択肢がかくれちゃう...5つ星です!)