Notes for Virtual Machines
Tips, hints, and tricks when working with Virtual Machines
Last update: 2022-06-29
Table of Content
Automount VMWare shared folder#
Unlike Virtual Box, VMWare does not automatically mount shared folders. Here are steps to make it work at system startup:
Make sure the mounting target folder exists. If not:
sudo mkdir /mnt/hgfs
Edit /etc/fstab
and add:
vmhgfs-fuse /mnt/hgfs fuse defaults,allow_other 0 0
Then remount:
sudo mount -a
A faster way, but be carefull of the redirection syntax: must use >>
to append a new line:
sudo mkdir -p /mnt/hgfs && \
sudo bash -c 'echo \
"vmhgfs-fuse /mnt/hgfs fuse defaults,allow_other 0 0" \
>> /etc/fstab'
Mount shared network folder in Ubuntu#
This is for mounting Samba shared-folder in Linux.
Install necessary packages:
sudo apt install -y \
smbclient \
cifs-utils
Then use smbclient
to probe sharing points:
smbclient -L //<ip>
Create a mount point:
sudo mkdir -p /media/SharedFolder
Then mount:
sudo mount -t cifs \
-o user=<username>,pass=<password>,uid=<uid>,gid=<gid> \
//<ip>/<share_point> \
<mount_point>
Run
id
to see ID of user and groups of the current user.
Install VirtualBox Guest Additions CD Image from Terminal#
Install build kernel modules:
sudo apt install -y dkms build-essential linux-headers-generic linux-headers-$(uname -r)
Insert Guest Additions CD Images and mount it:
sudo mkdir - /media/cdrom
sudo mount /dev/cdrom /media/cdrom
Change to the sudo account and run the build script:
./VBoxLinuxAdditions.run
VirtualBox Guest Additions functions only works in GUI desktop!
Compact Virtual Disk#
-
Install
zerofree
in the virtual machine -
Boot into Recovery mode
Press
ESC
while boot up to see Grub menu.
Select Advanced options → (recovery mode) → root.
Press Enter afterwards when Press Enter for maintenance appears on your screen. You’ll be given a terminal prompt. -
Run
zerofree
on the target disk, such as/dev/sda2
:zerofree -v /dev/sda2
Error: filesystem is mounted rw
Remount system in ro mode, and run zerofree again:
echo "u" > /proc/sysrq-trigger zerofree -v /dev/sda2
-
Shutdown the machine
poweroff
-
Compress the disk file
VBoxManage modifyhd --compact /path/to/VDI/VM.vdi