{
  "date": "2017-04-16T16:54:33",
  "slug": "sqlcl-on-bash-on-ubuntu-on-windows",
  "link": "https://www.dbi-services.com/blog/sqlcl-on-bash-on-ubuntu-on-windows/",
  "title": {
    "rendered": "SQLcl on Bash on Ubuntu on Windows"
  },
  "content": {
    "rendered": "<h2>By Franck Pachot</h2>\n<p>.<br />\nI&#8217;m running my laptop on Windows, which may sound weird, but Linux is unfortunately not an option when you exchange Microsoft Word documents, manage your e-mails and calendar with Outlook and present with Powerpoint using dual screen (I want to share on the beamer only the slides or demo screen, not my whole desktop). However, I have 3 ways to enjoy GNU/Linux: Cygwin to operate on my laptop, VirtualBox to run Linux hosts, and Cloud services when free trials are available.</p>\n<p>Now that Windows 10 has a Linux subsystem, I&#8217;ll try it to see if I still need Cygwin.<br />\nIn a summary, I&#8217;ll still use Cygwin, but may prefer this Linux subsystem to run SQLcl, the SQL Developer command line, from my laptop.</p>\n<p><!--more--></p>\n<h3>Bash on Ubuntu on Windows</h3>\n<p>In this post I&#8217;ll detail what I had to setup to get the following:<br />\n<a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureWin10bash000.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureWin10bash000.png\" alt=\"CaptureWin10bash000\" width=\"1024\" height=\"585\" class=\"alignnone size-large wp-image-15915\" /></a><br />\nBash on Windows 10 is available for several months, but with no interaction with the Windows system except accessing to the filesystems. I didn&#8217;t try that. This month, Microsoft has released a new update, called &#8216;Creator Update&#8217; for whatever reason.</p>\n<h3>Creator Update</h3>\n<p>You will probably have no choice to update to &#8216;Creator Update&#8217; soon but for the moment you have to download Windows10Upgrade9252.exe from <a href=\"https://www.microsoft.com/en-us/software-download/windows10\" target=\"_blank\" rel=\"noopener noreferrer\">https://www.microsoft.com/en-us/software-download/windows10</a></p>\n<h3>Windows Subsystem for Linux</h3>\n<p>You enable the feature from Control Panel -&gt; Programs and Features -&gt; Turn Windows features on and off:<br />\n<a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureWin10bash002.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureWin10bash002.png\" alt=\"CaptureWin10bash002\" width=\"984\" height=\"614\" class=\"alignnone size-full wp-image-15916\" /></a></p>\n<p>This requires a reboot. Windows is not yet an OS where you can install or enable features without closing everything. But at least in Windows 10 the reboot is very fast.</p>\n<h3>Developer mode</h3>\n<p>This is a beta feature and requires to enable developer mode:<br />\n<a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureWin10bash003.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureWin10bash003.png\" alt=\"CaptureWin10bash003\" width=\"614\" height=\"206\" class=\"alignnone size-full wp-image-15918\" /></a></p>\n<p>You do that on the Setup -&gt; Update and Security -&gt; For developers:</p>\n<p><a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureWin10bash001.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureWin10bash001.png\" alt=\"CaptureWin10bash001\" width=\"1024\" height=\"665\" class=\"alignnone size-large wp-image-15919\" /></a></p>\n<h3>Bash</h3>\n<p>Now, when you run it (type Bash in the start menu) it installs a subset of Ubuntu (downloaded from the web):<br />\n<a href=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureWin10bash005.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https://www.dbi-services.com/blog/wp-content/uploads/sites/2/2022/04/CaptureWin10bash005.png\" alt=\"CaptureWin10bash005\" width=\"873\" height=\"403\" class=\"alignnone size-full wp-image-15921\" /></a><br />\nIt asks for a user and password. You will need the password to sudo to root.<br />\nYou are in Windows/System32 here, which is ugly, so better exit and run again &#8216;Bash on Ubuntu on Windows&#8217;.</p>\n<h3>HOME</h3>\n<p>All my customization (.bash_profile .bashrc .vimrc .tmux.conf .ssh/config &#8230; ) is in my cygwin environment and I want to share it for the time I&#8217;ll run both Cygwin and Bash on Ubuntu on Windows. For this, I sudo and change the entry in /etc/passwd to have my home where I have my cygwin.home:</p>\n<pre><code>fpa:x:1000:1000:\"\",,,:/mnt/d/Dropbox/cygwin-home/:/bin/bash</code></pre>\n<h3>Mount</h3>\n<p>Here are the mount points I have on Cygwin</p>\n<pre><code>$ mount\nC:/cygwin64/bin on /usr/bin type ntfs (binary,auto)\nC:/cygwin64/lib on /usr/lib type ntfs (binary,auto)\nC:/cygwin64 on / type ntfs (binary,auto)\nC: on /cygdrive/c type ntfs (binary,posix=0,user,noumount,auto)\nD: on /cygdrive/d type ntfs (binary,posix=0,user,noumount,auto)</code></pre>\n<p>My C: and D: windows drives are mounted in /cygdrive</p>\n<p>Here are the mounts I have on the Windows Subsystem for Linux:</p>\n<pre><code>root@dell-fpa:/mnt# mount\nrootfs on / type lxfs (rw,noatime)\ndata on /data type lxfs (rw,noatime)\ncache on /cache type lxfs (rw,noatime)\nmnt on /mnt type lxfs (rw,noatime)\nsysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)\nproc on /proc type proc (rw,nosuid,nodev,noexec,noatime)\nnone on /dev type tmpfs (rw,noatime,mode=755)\ndevpts on /dev/pts type devpts (rw,nosuid,noexec,noatime)\nnone on /run type tmpfs (rw,nosuid,noexec,noatime,mode=755)\nnone on /run/lock type tmpfs (rw,nosuid,nodev,noexec,noatime)\nnone on /run/shm type tmpfs (rw,nosuid,nodev,noatime)\nnone on /run/user type tmpfs (rw,nosuid,nodev,noexec,noatime,mode=755)\nC: on /mnt/c type drvfs (rw,noatime)\nD: on /mnt/d type drvfs (rw,noatime)\nroot on /root type lxfs (rw,noatime)\nhome on /home type lxfs (rw,noatime)\nbinfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noatime)</code></pre>\n<p>Because I have scripts and configuration files that mention /cygdrive, I&#8217;ve created symbolic links for them:</p>\n<pre><code>fpa@dell-fpa:/mnt$ sudo su\n[sudo] password for fpa:\nroot@dell-fpa:/mnt# mkdir /cygdrive\nroot@dell-fpa:/# ln -s /mnt/c  /cygdrive/c \nroot@dell-fpa:/# ln -s /mnt/d  /cygdrive/D </code></pre>\n<h3>chmod</h3>\n<p>The first thin I do from my bash shell is to ssh to other hosts:</p>\n<pre><code>\nfpa@dell-fpa:/mnt/c/Users/fpa$ ssh 192.168.78.104\nBad owner or permissions on /mnt/d/Dropbox/cygwin-home//.ssh/config\n</code></pre>\n<p>Ok, permissions of .ssh was set from cygwin, let&#8217;s try it from Bash On Ubuntu on Linux:</p>\n<pre><code>\nfpa@dell-fpa:/mnt/c/Users/fpa$ chmod 644 /mnt/d/Dropbox/cygwin-home//.ssh/config\nfpa@dell-fpa:/mnt/c/Users/fpa$ ls -ld /mnt/d/Dropbox/cygwin-home//.ssh/config\n-rw-rw-rw- 1 root root 5181 Mar  5 16:56 /mnt/d/Dropbox/cygwin-home//.ssh/config\n</code></pre>\n<p>This is not what I want. With 644 I expect -rw-r&#8211;r&#8211;</p>\n<p>Let&#8217;s try 444:</p>\n<pre><code>\nfpa@dell-fpa:/mnt/c/Users/fpa$ chmod 444 /mnt/d/Dropbox/cygwin-home//.ssh/config\nfpa@dell-fpa:/mnt/c/Users/fpa$ ls -ld /mnt/d/Dropbox/cygwin-home//.ssh/config\n-r--r--r-- 1 root root 5181 Mar  5 16:56 /mnt/d/Dropbox/cygwin-home//.ssh/config\nfpa@dell-fpa:/mnt/c/Users/fpa$ ssh 192.168.78.104\nLast login: Sun Apr 16 15:18:07 2017 from 192.168.78.1\n...\n</code></pre>\n<p>Ok, this works but there&#8217;s a problem. It seems that the Bash On Ubuntu on Linux doesn&#8217;t allow to set permissions differently for user, group and others.</p>\n<h3>SQLcl</h3>\n<p>The second thing I do from bash in my laptop is to connect to databases with SQLcl. For Cygwin I had an alias that run the sql.bat script because Cygwin can run .bat files. When I run SQLcl from Cygwin, I run the Windows JDK. This doesn&#8217;t work in Bash on Ubuntu on Windows because we are in a Linux subsystem. But we don&#8217;t need to because SQLcl can be run directly from the sql bash script, calling the Linux JDK from the Linux subsystem. There&#8217;s only one thing to do: download the Linux JDK and  set JAVA_HOME to the directory.</p>\n<p>In my .bashrc I have the following to set the &#8216;sql&#8217; alias depending on which environment I am</p>\n<pre><code>\nif [[ $(uname -a) =~ CYGWIN ]]\nthen\n alias sql='/cygdrive/D/Soft/sqlcl/bin/sql.bat'\nelse\n alias sql='JAVA_HOME=/mnt/d/Soft/jdk1.8.0-Linux /cygdrive/D/Soft/sqlcl/bin/sql'\nfi\n</code></pre>\n<p>What I observe here is that it is much faster (or less slower&#8230;) to start the JVM from the Linux subsystem.<br />\nHere 4 seconds to start SQLcl, connect and exit:</p>\n<pre><code>\nfpa@dell-fpa:/tmp$ time sql sys/oracle@//192.168.78.104/pdb1 as sysdba &lt;&lt;\n&nbsp;\nreal    0m4.684s\nuser    0m3.750s\nsys     0m2.484s\n&nbsp;\nfpa@dell-fpa:/tmp$ uname -a\nLinux dell-fpa 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux\n</code></pre>\n<p>Here the same from Windows (Cygwin to time &#8211; but it&#8217;s running on Windows):</p>\n<pre><code>\n$ time sql sys/oracle@//192.168.78.104/pdb1 as sysdba &lt;&lt;\nDisconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production\n&nbsp;\nreal    0m16.261s\nuser    0m0.000s\nsys     0m0.015s\n&nbsp;\nfpa@dell-fpa ~\n$ uname -a\nCYGWIN_NT-10.0 dell-fpa 2.7.0(0.306/5/3) 2017-02-12 13:18 x86_64 Cygwin\n</code></pre>\n<h3>So what?</h3>\n<p>The Linux subsystem on Windows is not yet ready. The only thing I proved here is that it is faster to start a Java application from Linux, but for this I always have a VirtualBox VM started on my laptop, and this is where it is faster to run it, and have a real Linux system.</p>\n",
    "protected": false
  }
}
