“Aside” for Mac Users only

Since VMs do sometimes break (for example when the host OS X gets an update) it is not a good idea to save your work
on the VM. Instead, is advisable to store your work either on the Mac's hard drive or on a cloud storage service (e.g. OneDrive, Google Drive or iCloud drive).

If your VirtualBox guest OS is Linux there are no “visibility” issues between the Mac and the Linux VM.
The two machines can share folders through the mechanism provided by Virtual Box.

If your VirtualBox guest OS is Windows, the first option (saving the data on the Mac's hard drive) poses some visibility challenge. Since the Linux account (WSL) has no relationship to the Windows account,
the WSL account does not see the Mac OS Shared Folders provided through the Virtula Box mechanism.

Diversely, MobaXterm does not have any issue to access the Mac OS Shared Folders (this is because MobaXterm is a Linux emulator not a full Linux System environment)

Accessing WSL files from Windows is also not an issue:

  • From the WSL command line interface run

cd ~
explorer.exe .
  • This will launch File Explorer showing the current linux directory

> Network > wsl$ > Ubuntu > home > unixusername


1. How to make a folder on the Mac's hard drive accessible to WSL

a. on the Mac OS

  • select System Preferences > Users & Groups

  • add the windows OS user’ (example: claudio)

b. on the Mac OS

  • select System Preferences > Sharing

  • turn on the File Sharing Service

  • add the folder you want to share to the list of Shared Folder

  • add the windows user to the list of Users that can access the Shared Folders

  • shared folders can be accessed through samba at smb://some_address

c. on the Windows OS

  • select Explorer > This PC > Computer > Map Network drive

  • set the drive field to one of the available letters (example U:)

  • set the folder field to \\some_address\foldername

  • select reconnect to sign in

d. start the WSL terminal

  • run the command

sudo mkdir -p /mnt/u
sudo mount -t drvfs U: /mnt/u
  • to make the mounting permanent edit the file /etc/fstab

sudo vi /etc/fstab
  • add the following line

U: /mnt/u drvfs defaults 0 0
  • reload the fstab using

sudo mount -a
  • the owner of the mounted drive is root

  • to find out the uid and gid of the various users you can use the Linux command

id
  • for the unix user (example: utalarico) uid=1000 and gid=1000

  • for the windows user (example: claudio) uid=1001 and gid=513

  • to change the ownership of the mounted drive use:

sudo mount -t drvfs U: /mnt/u -o metadata,uid=1000,gid=1000
  • to learn how to modify the /etc/fstab for making the mounting permanent

    • look at how the previous command has modified the /etc/mtab or the /proc/mounts file

    • copy the corresponding line in the /etc/fstab file

U: /mnt/u drvfs rw,relatime,uid=1000,gid=1000,case=off 0 0
  • reload the fstab using

sudo mount -a
  • for convenience create a link to your mac's shared folder

ln -s /mnt/u ~/machome

2. How to access data on a cloud storage service using WSL (example: iCloud)

  • from Windows open the Microsoft store and install iCloud

  • the files are mounted at:

/mnt/c/Users/<windowsusername>/iCloudDrive/
  • for convenience create a link to iCloudDrive

ln -s /mnt/c/Users/<windowsusername>/iCloudDrive ~/ihome