1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ubuntu の VMのディスク容量拡大

Last updated at Posted at 2018-05-15

確かに前にも同じことをやってましたが、特に忘れたのでまたひどい目にあってしまった。今度こそメモしておかないと。。。

 発端

  仕事でVirtualBoxのUbuntuのVMをつかって、いろいろ調べているが、ある日突然ツールをインストールされてくれなくなった。あらら、ディスクの容量が足りないとのメッセージがあるので、早速容量拡大に着手。

 考えた方法

  最初はVirtualBoxのVboxmangaeでリサイズすればいいじゃと思っていましたが、なんという甘さ。

  VBoxManage modifyhd C:\Users\DM02\VirtualBoxVMs\ubuntu16.04\ubuntu16.04.vdi --resize 23960

  
それがあくまでも物理ディスクの増設(VMで無い場合)にすぎないんですよ。一応ITをやっている私が失念しているのはちょっと恥ずかしいですが。

 次の手順

  それからは時間の無駄使いの旅です。
  まずfdisk を使ってやろうかと思って、unmountから始りました。

qiita.sh
    sudo unmount /dev/sda1

  となると、 mount: /dev/sda1 is already mounted or / busy と失敗。
  今度はむりやりでもやっていきます。

qiita.sh
    sudo unmount -l /dev/sda1

無事終了したものの、/ をunmountした時点で何でもだめとなりました。

qiita.sh

sudo fdisk /dev/sda
sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?

  馬鹿なことをしたなぁ.不本意ながらも、GpartedのBootISOをダウンロードして、そこからBootするようにしました。
今度こそうまくいくんじゃないかと思ったが、なんと未使用、未partitionのディスクスペースがありながらも、dev/sda1の拡大を許してくれないようです。しょうがなく、その未使用スペースを/dev/sda4として新たにpartition を作成して、再起動しました。
  partitionが追加されたものの、Mountしない限り使えないですよ。他のディレクトリーにMountしてもいいのですが、やはり/ にMountしたいよね。複数devをmountしてもいいってどこかで見たことあるので、やってみました。エラーメッセージが無いものの、容量は変わらないまま。 今度は /etc/fstabもいじってみて、/dev/sda4 のUUIDを調べて/にMountするように一行追加して再起動したら、何にも改善されていないです。
  別に自分がLinuxのAdminになるつもりもないし、何でそんなこといちいちしないといけないんだよとイラついてもしょうがないので、他の手を捜します。
  ついに、これを発見,手順通りやっていきます。
  ---以下 C/P
As always, make sure you have a backup of your data - since we're going to modify the partition table there's a chance to lose all your data if you make a typo, for example.

Run sudo fdisk /dev/sda

use p to list the partitions. Make note of the start cylinder of /dev/sda1
use d to delete first the swap partition (2) and then the /dev/sda1 partition. This is very scary but is actually harmless as the data is not written to the disk until you write the changes to the disk.
use n to create a new primary partition. Make sure its start cylinder is exactly the same as the old /dev/sda1 used to have. For the end cylinder agree with the default choice, which is to make the partition to span the whole disk.
use a to toggle the bootable flag on the new /dev/sda1
review your changes, make a deep breath and use w to write the new partition table to disk. You'll get a message telling that the kernel couldn't re-read the partition table because the device is busy, but that's ok.
Reboot with sudo reboot. When the system boots, you'll have a smaller filesystem living inside a larger partition.

The next magic command is resize2fs. Run sudo resize2fs /dev/sda1 - this form will default to making the filesystem to take all available space on the partition.

  ---ここまで  

さすがですね、ばっちり。
あれれ、これじゃSwap partitionがなくなったんじゃないか。

仕方なく、またGpartedをつかって、Swap Partitionを追加します。
うん、一応大丈夫そうに見えますが、なぜか/etc/fstabがまだ昔のまま、ぜんぜん反映されていないようです。

未解決課題

1. なぜ複数のPartitionを同じ/にMountしても、反映されないか
2. なぜ全部正常のように見えていて、fdiskでも見えるようになったが、/etc/fstabに変更がないか
 linux のディスク管理にはまったくの素人なので、今度時間が見つけたら調べてみよう。

追記

その後に気づいたんですが、ここの方法を使えば、別にSwap領域をOverlapしなくても済みますが。(taking care not to overlap with other partitions)、まぁ、全ての場合それが出来るとは限らないですが。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?