Extend virtual box + Linux (Ubuntu 19.04) disk

When I set up ubuntu in Virual box and used docker, ubuntu (or virtual machine) itself ran out of disk. Expansion is troublesome. Keep a record for when you do it again later For physical partitions instead of LVM

Virtual Machine> Settings> Storage> Controller: Press + icon on SATA HDD to create new disk Select VDI (If you originally selected another file type, select it)> Fixed size (variable size is also acceptable)> Create by entering the path and size> Start VM after processing!

Check the block volume name of the new disk with fdisk -l

disk/dev/sdb: 20 GiB,21474836480 bytes,41943040 sector
Disk model: VBOX HARDDISK
unit:sector(1 * 512 =512 bytes)
Sector size(logic/Physics):512 bytes/512 bytes
I/O size(minimum/Recommendation):512 bytes/512 bytes

Check the current file system with cat / etc / fstab

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/Use sdb
Welcome to GNU Parted! To see the command list'help'Please enter.
(parted) mklabel gpt
(parted) mkpart
Partition name?  []? newdisk
File system type?  [ext2]? ext4
start? 0%
End? 100%
(parted) p
model: ATA VBOX HARDDISK (scsi)
disk/dev/sdb: 21.5GB
Sector size(logic/Physics): 512B/512B
Partition table: gpt
Disk flag:

Number Start End Size File System Name Flag
 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

The place for docker images that are eating a lot of space is like / var / lib / docker, so Temporarily rename the original / var / lib / docker, create a new docker directory, and mount the new partition there. Confirm with df. So, I will transfer the original data there. Write fstab without forgetting

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

If you restart the OS, it is mounted, and docker starts normally, it's OK!

Recommended Posts

Extend virtual box + Linux (Ubuntu 19.04) disk
Ubuntu Linux 20.04
[LVM] Extend virtual disk without adding partition
linux (ubuntu) memo
Monitor disk usage on Linux
Ubuntu / Linux laptop WiFi issues