Skip to content

Instantly share code, notes, and snippets.

@ijin82
Last active May 4, 2021 14:48
Show Gist options
  • Save ijin82/a0f3aaa34d7b57a4004cdf25248d4ff7 to your computer and use it in GitHub Desktop.
Save ijin82/a0f3aaa34d7b57a4004cdf25248d4ff7 to your computer and use it in GitHub Desktop.
VirtualBox, additional disk for MySQL

VirtualBox, additional disk for MySQL

  • Open VirtualBox
  • File - Virtual Media Manager
  • Create - VDI - Dynamically Allocated - set path & size (60Gb good enough for us) - close
  • Stop your target VM
  • Go to VM settings (right click on VM)
  • Storage - Controller SATA - press plus icon "Add new storage attachment" - Hard disk
  • Choose your pre-created VDI disk - that have to appear as attached after addition
  • Start your target VM - Login to your VM (vagrant up - vagrant ssh)
  • lsblk
  • Find your attached drive, mine looks like this
sdb                         8:16   0   62G  0 disk
  • Format new drive
sudo mkfs.ext4 /dev/sdb
  • Create folder for mount point
sudo mkdir /mysql-drive
  • Now fix fstab
sudo vim /etc/fstab

Add this line (according your dev name from lsblk)

/dev/sdb /mysql-drive ext4 defaults 0 0

REM Must be added before #VAGRANT-BEGIN section

  • Mount your drive & check that
sudo mount -a
ls -lah /mysql-drive
  • Stop MySQL and copy that data to new path
sudo service mysql stop
sudo cp -R /var/lib/mysql /mysql-drive/mysql
sudo chown -R mysql:mysql /mysql-drive
sudo mv /var/lib/mysql /var/lib/mysql_original
  • Fix MySQL config to set up new data path
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

Find directive datadir and set that up to your new path

datadir = /mysql-drive/mysql
  • Fix AppArmor config to allow new MySQL data path
sudo vim /etc/apparmor.d/tunables/alias

Add your alias path there

alias /var/lib/mysql/ -> /mysql-drive/mysql/,

Restart AppArmor

sudo service apparmor restart
  • Start MySQL service
sudo service mysql start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment