複数パーティションが存在するディスク上のext4やxfsパーティションを拡張するには

## 【１】パーティションの拡張

### １．cfdiskを実行する
```
# cfdisk /dev/sda
```

### ２．拡張したいパーティションを選択し、[Resize]を選択する
```
                                                    Disk: /dev/sda
                                 Size: 150 GiB, 161061273600 bytes, 314572800 sectors
                             Label: gpt, identifier: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

    Device                           Start                End           Sectors          Size Type
    /dev/sda1                         2048               4095              2048            1M BIOS boot
 >> /dev/sda2                         4096          209713151         209709056          100G Linux filesystem
    Free space                   209713152          314572766         104859615           50G
 lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
 xPartition UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX                                                             x
 xPartition type: BIOS boot (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)                                                  x
 xFilesystem UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX                                                             x
 mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj

                  [ Delete ]  [ Resize ]  [  Quit  ]  [  Type  ]  [  Help  ]  [  Write ]  [  Dump  ]
　　　　　　　　　　　　　　　　　　↑
　　　　　　　　　　　　　　　　　　└ これを選択
```

### ３．拡張後のサイズを指定する。拡張可能な最大サイズで良ければ、そのままEnterキーを押下する
```
 New size: 150G
```

### ４．指定されたパーティションの容量が拡張されたことを確認し、[Write]を選択する
```
                                                    Disk: /dev/sda
                                 Size: 150 GiB, 161061273600 bytes, 314572800 sectors
                             Label: gpt, identifier: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

    Device                        Start                End            Sectors           Size Type
    /dev/sda1                      2048               4095               2048             1M BIOS boot
>>  /dev/sda2                      4096          314572766          314568671           150G Linux filesystem
 lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk
 xPartition UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX                                                             x
 xPartition type: BIOS boot (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)                                                  x
 xFilesystem UUID: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX                                                             x
 mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
                  [ Delete ]  [ Resize ]  [  Quit  ]  [  Type  ]  [  Help  ]  [  Write ]  [  Dump  ]
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　↑
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　└ これを選択

```

### ５．パーティションテーブルをディスクに書いて良いか聞かれるので、「yes」と入力する

```
 Are you sure you want to write the partition table to disk? yes
```

### ６．[Quit]を選択する
```
                  [ Delete ]  [ Resize ]  [  Quit  ]  [  Type  ]  [  Help  ]  [  Write ]  [  Dump  ]
　　　　　　　　　　　　　　　　　　　　　　　　　↑
　　　　　　　　　　　　　　　　　　　　　　　　　└ これを選択
```

## 【２】ファイルシステムに対して、拡張後の容量を認識させる

### ext4パーティションを拡張する場合
`resize2fs <ブロックデバイス（パーティション）名>`  を実行する。

```
# resize2fs /dev/sda2
resize2fs 1.45.5 (07-Jan-2020)
Filesystem at /dev/sda2 is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 19
The filesystem on /dev/sda2 is now 39321083 (4k) blocks long.
```

### xfsパーティションを拡張する場合
`xfs_growfs <ブロックデバイス（パーティション）名>`  を実行する。