Tuesday, 18 September 2018

External access to Crostini VM e.g. for backups or data transfer

This post shows how to set up Samba access to part of the VM filesystem used by Crostini. In an earlier post on backups & restores I explained how to export a backup as a tarfile:

and this post shows how the exported tarfile can be easily moved to another machine for safekeeping.

First, with your default 'penguin' container started, add the '$LXD_CONF' directory as a disk in your container by entering the following command the VM or 'termina':

    chmod o+w $LXD_CONF
    lxc config device add penguin sambashare disk source=$LXD_CONF

(note that the 'chmod' command is only necessary if you wish to write to the VM directory)

This will make '$LXD_CONF' accessible under your Linux files:

Next install the Samba package in your container 'penguin':

    sudo apt install samba

and then configure the share drive:

    sudo smbpasswd -a linuxiumcomau
    sudo vi /etc/samba/smb.conf

by adding:

       comment = Samba Share
       path = /home/linuxiumcomau/sambashare
       valid users = linuxiumcomau
       browseable = yes
       read only = no

and then restart the Samba service:

    sudo service smbd restart

and make a note of the container's IP address using 'hostname -I'.

You can optionally test that Samba is working by connecting as a Network File share:

Finally you need to add a forwarding rule to be able to access the Samba file share from an external machine on the same LAN as you Chrome device:

On your external machine you can now connect using 'Files' where you include the redirected port number with the IP address of your Chrome device:

or you can mount as a CIFS drive:

after which you can treat as part of your file system. For example in this scenario I took two screen shots on the external machine and then saved them on the '$LXD_CONF' drive and accessed them from Crostini:

Additionally I copied the 'eskimo.tar.gz' tarball to a local directory thus creating a external backup of my Crostini container.

Once finished simply un-mount as appropriate any instances of the Samba drive and remove it from the container by entering the following commands in your VM or 'termina':

    lxc config device remove penguin sambashare
    chmod o-w $LXD_CONF

(with the 'chmod' command only being necessary if you initially changed the permissions).

Please donate if you find this guide useful using the following link http://goo.gl/nXWSGf.

No comments:

Post a Comment