The example on this page covers adding a new 50GB /mysql filesystem to an existing Oracle Linux 8 VirtualBox VM (called OracleLinux8)
vboxmanage createhd --filename /media/${USER}/HDD1/VirtualBox/OracleLinux/mysql.vdi --size 51200
Confirm VM name...
vboxmanage list vms
Confirm SATA Controller Name...
vboxmanage showvminfo OracleLinux8 | grep "Storage Controller Name"
This name is generally SATA unless you have created your VM in a heavily customized mannerConfirm which Ports/Devices are already used...
vboxmanage showvminfo OracleLinux8 | grep "^SATA"
Attach the HD to the SATA Controller...
vboxmanage storageattach OracleLinux8 --storagectl "SATA" --port 1 --device 0 --type hdd \
--medium /media/${USER}/HDD1/VirtualBox/OracleLinux/mysql.vdi
vboxmanage startvm OracleLinux8
Identify device...
lsblk
Our device is shown as...sdb 8:16 0 50G 0 disk .. therefore the device will be /dev/sdbCreate the Physical Volume...
pvcreate /dev/sdb
Create Volume Group...
(called myvg using just the /dev/sdb device.. note, you can span multiple devices)vgcreate myvg /dev/sdb
Create Logical Volume...
(called mylv, size 49GB in the myvg Volume Group)lvcreate -n mylv -L 49G myvg
If you try to create a 50GB Logical Volume, you will get this error...Volume group "myvg" has insufficient free space (12799 extents): 12800 required.Create Filesystem...
(in this case an ext4 filesystem. Use the LV Path from the lvdisplay command. The filesystem will be the same size as the underlying Logical Volume)mkfs.ext4 /dev/myvg/mylv
Create a mount point...
mkdir /mysql
Mount the filesystem...
mount /dev/myvg/mylv /mysql
Give the device a Label...
e2label /dev/myvg/mylv mysql
For other filesystem types use appropriate alternative commands like xfs_admin or fatlabelAdd a line to /etc/fstab if you want it to mount automatically at boot time...
LABEL=mysql /mysql ext4 defaults 0 2
You can use a device node (/dev/myvg/mylv) but using a Label is now the recommended method.Alternatively...
fdisk -l
Check with...
pvs
pvdisplay
vgs
vgdisplay myvg
lvs
lvdisplay myvg
(note we're passing the VG not the LV)lvdisplay /dev/myvg/mylv
mount | grep "^/dev" | column -t
df -h
unmount /mysql
lvremove mylv
vgremove myvg
pvremove /dev/sdb
If the device already has a partition table, you will get this error from pvcreate...
Device /dev/sdb excluded by a filter.
wipefs --no-act /dev/sdb
Do a dry run...
(as root)wipefs --all --no-act /dev/sdb
Create backup and remove partition table signatures...
(as root)wipefs --all --backup /dev/sdb
List stored signatures...
(as root)find ~/ -maxdepth 1 -name 'wipefs-sdb-*.bak'
You cannot backout wipefs once you have overwritten any data on the device.
(i.e. there is a limited window for backout to be successful. Be careful.)This command (1) generates a list of commands to run to put the partition table back (run as root)...
find ~/ -maxdepth 1 -name "wipefs-sdb-*.bak"| while read file
do
addr=$(echo ${file} | sed "s/.*wipefs-.*-\(.*\).bak/\1/")
echo sudo dd if=${file} of=/dev/sdb seek=$((${addr})) bs=1 conv=notrunc
done'
Use this method to add a disk without using the Linux Logical Volume Manager (LVM)...
Identify device...
lsblk
Our device is shown as...sdb 8:16 0 50G 0 disk .. therefore the device will be /dev/sdbPartition the device (GUID Partition Table)...
parted
select /dev/sdb
mklabel gpt
mkpart
*** TO BE COMPLETED ***