Motivation
There was a need to access files mounted to Windows 10 machine via Google Drive File Stream (GDFS, as G: drive) from WSL, to be able to work with them on the same machine with Linux tools like vim, bash, etc., not to be dependent on separate Linux machine, nor inefficiently installing those tools in Windows (some could work, some not without problems or at all), nor copy them after modifications from local to GDFS locations other way (manually).
Components
Solution consists of:
- Windows 10 OS
- drive G: mounted by Google Drive File Stream
- OpenSSH server for Windows (running as Windows 10 service)
- SFTP Net Drive
- Windows Subsystem for Linux (WSL)
Tools used during implementation:
- Windows PowerShell
- WSL Bash
Hacks honorable to be mentioned
- sharing files between Windows 10 and WSL (files outside WSL needs to be mounted from WSL, not the opposite way)
- symlinking (on Windows!) Google Drive G: File Stream to Windows user profile (e.g. C:\Users\%user\GDrive\...) - free version of SFTP Net Drive does not support changing SSH default directory in SSH session
- GUI way
- command-line way
- OpenSSH workaround for unsupported GDFS mount in WSL (works also with compression)
- changing default user in WSL (avoiding knowing root or any other user password)
- setting up OpenSSH for Windows using public key authentication (avoiding saving any user password)
Steps
- install Ubuntu 18.04 LTS based WSL in Windows
- install Google Drive File Stream and connect to the service (mount as e.g. G:)
- install OpenSSH Server for Windows - optional feature (Settings > Apps > Manage optional features > Add a feature > OpenSSH Server > Install
- via Services management enable, set to start automatically & start OpenSSH Authentication Client and then via administrative PowerShell:
- Start-Service ssh-agent
- Start-Service sshd
- Install-Module -Force OpenSSHUtils
- comment AuthorizedKeysFile in C:\ProgramData\ssh\sshd_config
- non-administrative PowerShell:
- ssh-keygen
- bash -c 'cat .ssh/id_rsa.pub >> .ssh/authorized_keys'
- (bash is used instead of PowerShell, because various versions of PowerShell inconsistently handle character encoding on redirection, what could result to this)
- (troubleshoot if needed) and restart OpenSSH Server
- download SFTP Net Drive and install it (+ register to start on OS startup), connect with authorized username to localhost (mount as e.g. N:), there are these alternatives:
- SFTP Net Drive Free - legacy version from EldoS, supporting directory symlinking on Windows to mounted Google Drive, but: it seems, running scripts via WSL with mounted Google Drive with this version of SFTP Net Drive causes BOSD below, when trying to run bash script stored on Google Drive inside WSL (but maybe you won't need this):
(cbfs6.sys is component used by SFTP Net Drive...) - SFTP Net Drive V2 (or Full) - current version from /n software, supporting directory junctioning, but seemingly not symlinking (so if you need symlinking instead of junctioning and don't need running scripts directly from Google Drive, you can also try legacy version, or contact /n software with support ticket or feature request - see also known issues and how to get support)
- set installed program to start automatically after log-on (click on program in start menu, open file location, Windows+R: shell:startup, create shortcut of the program there)
- make directory symlink (if using SFTP Net Drive Free) or directory junction (if using SFTP Net Drive V2 or Full) on Windows from mounted user profile to G: - now G: can be accessed also from WSL as /mnt/n, but after mount in WSL:
- from cmd.exe: ubuntu
- mount N: from WSL: sudo mkdir /mnt/n; sudo mount -t drvfs N: /mnt/n
Further hacks
There were problems with perpetually changing inodes of files trying to write modifications by vim, therefore this workaround is currently in place:
cat ~/.vimrc
set nobackup
set backupcopy=yes
set noswapfile
set noundofile
set nowritebackup
Automatic mount of N: in WSL with owner's privileges:
tail -n 10 ~/.profile
if [ ! -d "/mnt/n/" ]; then
sudo mkdir /mnt/n
fi
sudo mount -t drvfs -o uid=1001,gid=1001 N: /mnt/n
# mount some folder
if [ ! -d "SYMLINKED_FOLDER_NAME" ]; then
rm -f SYMLINKED_FOLDER_NAME
rm -f SYMLINKED_FOLDER_NAME
ln -s /mnt/n/GDrive/... SYMLINKED_FOLDER_NAME
fi
Requires user to be in admin or sudo group in /etc/group and this settings in /etc/sudoers (via visudo in WSL) - not very secure setup, but WSL is not "mission critical server" :) :
sudo cat /etc/sudoers
# Members of the admin group may gain root privileges
%admin ALL=(ALL) NOPASSWD: ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) NOPASSWD: ALL
Conclusion
The purpose of this article is me to be able re-run these steps on another computers or user profiles and can be continually improved in the future, to be more exact.
Žiadne komentáre:
Zverejnenie komentára