FreeSurfer on Windows

From CCN Wiki
Jump to navigation Jump to search

Windows Subsystem for Linux

Windows Subsystem for Linux (WSL) is an environment native to Windows 10 that allows users to have full access to a Linux based operating system via terminal without an external virtual machine. Because it is native to Windows 10, some benefits include; full access to the system's resources without user allocation, lower overhead than traditional virtual machines, and it doesn't crash (fingers crossed).

This is -not- recommended for anyone with any blue or green color blindness as any and all attempts at changing blue and green text has been met with abject failure.

"Easy Button" Install

I'm using air quotes here, because this probably isn't something for computer-phobes. But I found a batch script provided by the FreeSurfer folks for setting up FreeSurfer on an Ubuntu installation on WSL. Link is here. Click the Code button to get the git clone or else download a zip archive of the files and unpack.

You will need to run the unpacked runme.bat script from a PowerShell terminal as an administrator on Windows. To run it, go to the directory of the runme.bat file and run the following command: start-process .\runme.bat

Note that, prior to running the script, I had also gone through all the hoops of joining the Windows Dev channel and updating my Windows 10 build to the latest version that would support Linux GUI programs (WSLg). I had also previously installed Ubuntu 20.04 from the Windows store. This was all before I found this handy script. It turns out that using a preview build of Windows 10 was probably not required. I imagine that the script might also handle installing Ubuntu for you, if you didn't already have it installed. However, if you take care of installing Ubuntu ahead of time, then when you run the FreeSurfer installation script, it's going to download FreeSurfer and its dependencies. I just accepted all the default settings for file locations, etc. Before you try running any FreeSurfer utility, you are going to need to request a free license file that you will have to save to your freesurfer installation directory. For me, that was c:\freesurfer\freesurfer\license.txt

Note: If you did not install Ubuntu prior to running runme.bat, make sure to close Ubuntu once it's installed to move on to FreeSurfer installation.

Setting up Windows Subsystem for Linux 2

The source instructions are found on the Windows website and should be referenced if any problems should arise, featured here is a condensed version of those instructions.

  • Run powershell as an administrator and run the following commands:

dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

  • Restart your computer.
  • Run powershell again and run the following command:

systeminfo | find "System Type"

  • If the terminal says you have an "x64-based PC" download and run this Linux kernel
  • Otherwise, if the terminal says you have an "ARM64-based PC" download and run this Linux kernel
  • Run powershell one more time and run the following command:

wsl --set-default-version 2

  • Now download this Ubuntu package and run it.
  • Follow the onscreen prompts to setup the Ubuntu package


Changing the background color

At this point, the text is probably an unreadable shade of dark blue and neon green on a black background. I have yet to find a solution to the text color, and I'm worried about going further as the next step would be to change system files. I don't mind (and have) destroyed virtual machines, but potential irreparable changes to my operating system is where I draw the line.

To change the background color:

  1. Right click on the title bar and go to "Properties"
  2. Go to the section labeled "Terminal"
  3. Checkmark the box labeled "Use Separate Background"
  4. Play around with various numbers in the "Red", "Green", and "Blue" boxes, I find 75 in each box to be tolerable.

Setting up FreeSurfer with Windows Subsystem for Linux 2

Onto the main event!

  • Go to the FreeSurfer Download page and save the CentOS 7 x86.64 (64b) tar archive onto your C: or D: drive. (Be sure it is readily accessible.)
  • Open your Ubuntu distribution and navigate to the root directory cd ~/../../

In the root directory exists a folder named "mnt." This folder is a direct access to all files located on your various drives (C: D: E: etc.).

  • Navigate to where you saved the CentOS file and move it to /usr/local. In my case; mv freesurfer-linux-centos7_x86_64-7.1.1.tar.gz /usr/local
  • Go to /usr/local and type the following command

tar -zxvpf freesurfer-linux-centos7_x86_64-7.1.1.tar.gz

  • Change your .bashrc file according to the instructions listed on the New Research Staff page.
  • Restart your Ubuntu, if everything works you should see the following on the first line of the terminal

-------- freesurfer-linux-centos7_x86_64-7.1.1-(some numbers)-(some numbers and letters) --------

Setting up a GUI for Windows Subsystem for Linux 2

Windows has not come out with their own GUI for WSL 2 at the time of writing this. They have claimed it will be coming soon, so this step will not be of use if it is already out. To check, try running freeview in the terminal. If no GUI exists, the terminal will hang. To fix that, press Ctrl+C.

To run an external GUI:

  • Download and run this file
  • After installation, run XLaunch
  • Display settings are personal preference, feel free to play with these
  • Select "Start no client"
  • Check the "Disable Access Control" box and leave the rest of the settings as is.
  • If you're happy with the display settings, click "Save configuration." Save this file in a readily accessible place, as this is how you will start the GUI.

Potential Issues:

FreeSurfer: "Error while loading shared libraries: libgomp1"

I ran into this issue when attempting to run freeview. In short, some package does not exist on the linux distribution that FreeSurfer needs. Type the following commands:

sudo apt-get update

sudo apt-get install libgomp1