HDDのパーティションのサイズ変更

以前、仮想マシンのHDDの増設方法で作成したHDDのパーティションサイズを変更する。
新たに仮想HDDを追加しても良いが、今回はパーティションサイズを変更する方法をメモ。
※ゲストOSが ubunntu の場合

仮想HDDのサイズ変更

  1. 仮想マシン設定の編集(D)から「ハードウェア」タブから増設したHDDを選択。
  2. 右ペインの「展開」をクリック。
  3. 任意のHDDサイズに変更し、「展開」をクリック。
  4. 確認で「OK」ボタンをクリックして完了。

ubuntuでのパーティションサイズの変更

パーティションの確認

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           394M  6.3M  388M   2% /run
/dev/sda1        59G   50G  6.3G  89% /
tmpfs           2.0G  212K  2.0G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sdb1        20G   13G  6.1G  68% /mnt/tmp_hdd
vmhgfs-fuse     477G  408G   69G  86% /mnt/hgfs
tmpfs           394M   56K  394M   1% /run/user/1000
$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


コマンド (m でヘルプ): p
Disk /dev/sdb: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x49de55dd

デバイス   起動 Start 最後から セクタ Size Id タイプ
/dev/sdb1        2048 83886079 83884032  40G 83 Linux

パーティションの削除

コマンド (m でヘルプ): d
Selected partition 1
Partition 1 has been deleted.

コマンド (m でヘルプ): p
Disk /dev/sdb: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x49de55dd

パーティションの作成

コマンド (m でヘルプ): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
パーティション番号 (1-4, default 1):
First sector (2048-83886079, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-83886079, default 83886079):

Created a new partition 1 of type 'Linux' and of size 40 GiB.

コマンド (m でヘルプ): p
Disk /dev/sdb: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x49de55dd

デバイス   起動 Start 最後から セクタ Size Id タイプ
/dev/sdb1        2048 83886079 83884032  40G 83 Linux

更新(書き込み)

コマンド (m でヘルプ): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: デバイスもしくはリソースがビジー状態です

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).

再起動を要求されたので再起動を行い、パーティションの確認
この時点ではパーティションサイズは更新されていないので注意!

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           394M  6.3M  388M   2% /run
/dev/sda1        59G   50G  6.3G  89% /
tmpfs           2.0G  212K  2.0G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sdb1        20G   13G  6.1G  68% /mnt/tmp_hdd
vmhgfs-fuse     477G  408G   69G  86% /mnt/hgfs
tmpfs           394M   52K  394M   1% /run/user/1000
$ sudo fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


コマンド (m でヘルプ): p
Disk /dev/sdb: 40 GiB, 42949672960 bytes, 83886080 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x49de55dd

デバイス   起動 Start 最後から セクタ Size Id タイプ
/dev/sdb1        2048 83886079 83884032  40G 83 Linux

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

resize2fsでパーティションサイズの変更

$ sudo resize2fs /dev/sdb1
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/sdb1 is mounted on /mnt/tmp_hdd; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/sdb1 is now 10485504 (4k) blocks long.
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           394M  6.3M  388M   2% /run
/dev/sda1        59G   50G  6.3G  89% /
tmpfs           2.0G  212K  2.0G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sdb1        40G   13G   25G  34% /mnt/tmp_hdd
vmhgfs-fuse     477G  408G   69G  86% /mnt/hgfs
tmpfs           394M   52K  394M   1% /run/user/1000

無事にパーティションサイズの変更を完了。


トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2021-05-15 (土) 07:30:50