LoginSignup
0
0

More than 3 years have passed since last update.

virtual box+Linux(Ubuntu19.04)のディスクを拡張する

Last updated at Posted at 2020-02-13

Virual boxでubuntu立ててdocker使ってたらubuntu(というか仮想マシン)自体のディスクが足りなくなった。
拡張めんどい。あとでまたやるときのために記録残しとく
LVMではなく物理パーティション向け

仮想マシン > 設定 > ストレージ > コントローラー: SATAのHDDの+アイコンを押して、新規ディスクの作成
VDIを選択(元々他のファイルタイプ選んでればそれを選択) > 固定サイズ(可変サイズでもいい) > パスとサイズを入力して作成 > 処理終わったらVM起動!

fdisk -lで新ディスクのブロックボリューム名確認

ディスク /dev/sdb: 20 GiB, 21474836480 バイト, 41943040 セクタ
Disk model: VBOX HARDDISK
単位: セクタ (1 * 512 = 512 バイト)
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト

cat /etc/fstabで現在のファイルシステムを確認
※UUID=345dde19-65a3-4580-bbd6-3cbb16f964a3 / ext4の、ext4がほしい情報

root@user-VirtualBox:~# cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=345dde19-65a3-4580-bbd6-3cbb16f964a3 /               ext4    errors=remount-ro 0       1
/swapfile                                 none            swap    sw              0       0
root@user-VirtualBox:~# parted /dev/sdb
GNU Parted 3.2
/dev/sdb を使用
GNU Parted へようこそ! コマンド一覧を見るには 'help' と入力してください。
(parted) mklabel gpt
(parted) mkpart
パーティションの名前?  []? newdisk
ファイルシステムの種類?  [ext2]? ext4
開始? 0%
終了? 100%
(parted) p
モデル: ATA VBOX HARDDISK (scsi)
ディスク /dev/sdb: 21.5GB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: gpt
ディスクフラグ:

番号  開始    終了    サイズ  ファイルシステム  名前     フラグ
 1    1049kB  21.5GB  21.5GB  ext4              newdisk

(parted)
root@user-VirtualBox:~# mkfs.ext4 /dev/sdb1
mke2fs 1.44.6 (5-Mar-2019)
Creating filesystem with 5242368 4k blocks and 1310720 inodes
Filesystem UUID: 8985105d-d482-41f6-85f7-82afeba1172b
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

いっぱい容量食ってるdockerイメージの置き場は/var/lib/dockerのようなので、
もともとの/var/lib/dockerを一時的にリネームして、新規にdockerディレクトリをつくって、新規パーティションをそこにマウント。dfで確認。で、そっちに元々のデータもうつす。わすれずにfstab書く

root@user-VirtualBox:/var/lib# mv docker _docker
root@user-VirtualBox:/var/lib# mkdir docker
root@user-VirtualBox:/var/lib# mount /dev/sdb1  /var/lib/docker
root@user-VirtualBox:/var/lib# df -h
/dev/sdb1        20G   45M   19G   1% /var/lib/docker
root@user-VirtualBox:~# vi /etc/fstab
/dev/sdb1                                 /var/lib/docker ext4    defaults        0       0

OS再起動してマウントされてて、dockerも普通に起動すればOK!

0
0
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
0
0