株式会社ヴァンデミックシステム

Blog

<スポンサーリンク>

仮想マシンはCentOS7.4。だからファイルシステムはxfs。
16GBから32GBへ拡張したい。

#物理ボリューム一覧
[root@docker ~]# pvs
  PV         VG                 Fmt  Attr PSize   PFree
  /dev/sda2  centos_linuxserver lvm2 a--  <15.00g    0
 
#ボリュームグループ一覧 
[root@docker ~]# vgs
  VG                 #PV #LV #SN Attr   VSize   VFree
  centos_linuxserver   1   2   0 wz--n- <15.00g    0

#論理ボリューム一覧
[root@docker ~]# lvs
  LV   VG                 Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos_linuxserver -wi-ao---- 13.39g                                     
  swap centos_linuxserver -wi-ao----  1.60g                                     

#初期値を確認(16GBで作っているけど17.2GBなってるけど近しいからいいかな)
[root@docker ~]# fdisk -l

Disk /dev/sda: 17.2 GB, 17179869184 bytes, 33554432 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000ecbdd

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM

Disk /dev/mapper/centos_linuxserver-root: 14.4 GB, 14382268416 bytes, 28090368 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト


Disk /dev/mapper/centos_linuxserver-swap: 1719 MB, 1719664640 bytes, 3358720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト

#「/」を拡張したい
[root@docker ~]# df -h
ファイルシス                        サイズ  使用  残り 使用% マウント位置
/dev/mapper/centos_linuxserver-root    14G  3.0G   11G   23% /
devtmpfs                              910M     0  910M    0% /dev
tmpfs                                 920M     0  920M    0% /dev/shm
tmpfs                                 920M  8.6M  912M    1% /run
tmpfs                                 920M     0  920M    0% /sys/fs/cgroup
/dev/sda1                            1014M  143M  872M   15% /boot
tmpfs                                 184M     0  184M    0% /run/user/0

#一旦シャットダウン
[root@docker ~]# shutdown -h now

16GB→32GBへ変更

#sdaが増えていることを確認
[root@docker ~]# fdisk -l

Disk /dev/sda: 34.4 GB, 34359738368 bytes, 67108864 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000ecbdd

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM

Disk /dev/mapper/centos_linuxserver-root: 14.4 GB, 14382268416 bytes, 28090368 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト


Disk /dev/mapper/centos_linuxserver-swap: 1719 MB, 1719664640 bytes, 3358720 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト

#物理的に拡張
[root@docker ~]# fdisk /dev/sda
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.


コマンド (m でヘルプ): p

Disk /dev/sda: 34.4 GB, 34359738368 bytes, 67108864 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000ecbdd

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    33554431    15727616   8e  Linux LVM

コマンド (m でヘルプ): d ←一旦sda2を消す
パーティション番号 (1,2, default 2):
Partition 2 is deleted

コマンド (m でヘルプ): p

Disk /dev/sda: 34.4 GB, 34359738368 bytes, 67108864 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000ecbdd

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048     2099199     1048576   83  Linux

コマンド (m でヘルプ): n ←sda2を新規作成
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
パーティション番号 (2-4, default 2):
最初 sector (2099200-67108863, 初期値 2099200):
初期値 2099200 を使います
Last sector, +sectors or +size{K,M,G} (2099200-67108863, 初期値 67108863):
初期値 67108863 を使います
Partition 2 of type Linux and of size 31 GiB is set

コマンド (m でヘルプ): 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

コマンド (m でヘルプ): t ←「Linux LVM」を選択
パーティション番号 (1,2, default 2):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

コマンド (m でヘルプ): p ←最終チェック sda2の終点が増えていることを確認

Disk /dev/sda: 34.4 GB, 34359738368 bytes, 67108864 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000ecbdd

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    67108863    32504832   8e  Linux LVM

コマンド (m でヘルプ): w ←書き込む
パーティションテーブルは変更されました!

ioctl() を呼び出してパーティションテーブルを再読込みします。

WARNING: Re-reading the partition table failed with error 16: デバイスもしくはリソースがビジー状態です.
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)
ディスクを同期しています。

#一旦リブート
[root@docker ~]# shutdown -r now

#物理ボリュームを拡張前に確認
[root@docker ~]# pvs
  PV         VG                 Fmt  Attr PSize   PFree
  /dev/sda2  centos_linuxserver lvm2 a--  <15.00g    0

#空き領域に全割り当て
[root@docker ~]# pvresize /dev/sda2
  Physical volume "/dev/sda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

#PFreeが増えていることがわかる
[root@docker ~]# pvs
  PV         VG                 Fmt  Attr PSize   PFree
  /dev/sda2  centos_linuxserver lvm2 a--  <31.00g 16.00g
  
  
#ボリュームグループもVFreeが増えている
[root@docker ~]# vgs
  VG                 #PV #LV #SN Attr   VSize   VFree
  centos_linuxserver   1   2   0 wz--n- <31.00g 16.00g

#論理ボリュームを拡張前に確認
[root@docker ~]# lvs
  LV   VG                 Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos_linuxserver -wi-ao---- 13.39g
  swap centos_linuxserver -wi-ao----  1.60g


#「/」のマウントポイント「/dev/mapper/centos_linuxserver-root」を拡張したい
[root@docker ~]# df
ファイルシス                        1K-ブロック    使用   使用可 使用% マウント位置
/dev/mapper/centos_linuxserver-root    14034944 3128924 10906020   23% /
devtmpfs                                 930916       0   930916    0% /dev
tmpfs                                    941940       0   941940    0% /dev/shm
tmpfs                                    941940    8676   933264    1% /run
tmpfs                                    941940       0   941940    0% /sys/fs/cgroup
/dev/sda1                               1038336  145612   892724   15% /boot
tmpfs                                    188392       0   188392    0% /run/user/0

#Free領域をすべて「/dev/mapper/centos_linuxserver-root」に割り当てる
[root@docker ~]# lvextend -l +100%FREE /dev/mapper/centos_linuxserver-root
  Size of logical volume centos_linuxserver/root changed from 13.39 GiB (3429 extents) to 29.39 GiB (7525 extents).
  Logical volume centos_linuxserver/root successfully resized.
  
#VFreeが0になり、VSizeが拡張された
[root@docker ~]# vgs
  VG                 #PV #LV #SN Attr   VSize   VFree
  centos_linuxserver   1   2   0 wz--n- <31.00g    0

#論理ボリュームも同じく
[root@docker ~]# lvs
  LV   VG                 Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos_linuxserver -wi-ao---- 29.39g
  swap centos_linuxserver -wi-ao----  1.60g
[root@docker ~]#

#ファイルシステム「/」を拡張
[root@docker ~]# xfs_growfs /
meta-data=/dev/mapper/centos_linuxserver-root isize=512    agcount=4, agsize=877824 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=3511296, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 3511296 to 7705600

#ちゃんと「/dev/mapper/centos_linuxserver-root」が増えているのでOK
[root@docker ~]# df -h
ファイルシス                        サイズ  使用  残り 使用% マウント位置
/dev/mapper/centos_linuxserver-root    30G  3.0G   27G   11% /
devtmpfs                              910M     0  910M    0% /dev
tmpfs                                 920M     0  920M    0% /dev/shm
tmpfs                                 920M  8.5M  912M    1% /run
tmpfs                                 920M     0  920M    0% /sys/fs/cgroup
/dev/sda1                            1014M  143M  872M   15% /boot
tmpfs                                 184M     0  184M    0% /run/user/0

<スポンサーリンク>

コメントを残す

Allowed tags:  you may use these HTML tags and attributes: <a href="">, <strong>, <em>, <h1>, <h2>, <h3>
Please note:  all comments go through moderation.

*

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)