Using WSL2 to run HEP linux programmes on an MWS windows computer
WSL2 is the
Windows subsystem for Linux version 2, which allows a full linux experience, while still running an MWS computer in windows.
What can it do?
- Install a Linux OS, with a full kernel and all of the normal software available
- Use CVMFS to access HEP software remotely
- Copy files from the windows to linux disks transparently
- Use VS code on windows to edit inside the linux system
- Run the full LHCb software stack as if it were a linux system
- Use a limited amount of disk space and compress the linux virtual disk
What can't it do?
- It can not access as much CPU, memory or disk resources as a full linux install replacing MWS
- It requires you to become your own system administrator as the system will not be centrally managed
- Act as a server (ssh/web/etc) as the network is a NAT interface
How to install WSL
Follow the instructions on the Microsoft WSL webpage (
https://learn.microsoft.com/en-us/windows/wsl/install) for the detail but in summary:
- Open
powershell
- Choose your Linux version to install, in HEP you want a Redhat compatible version, at time of writing the best one is "OracleLinux_9_1" which is an exact clone of Redhat with Oracle branding replacing Redhat branding.
- Run
wsl --list --online
to see the current choices for OS
- Enter
wsl --install -d OracleLinux _9_1
- Wait while it installs
- You will be asked for a username and password, the username can be the same as MWS but use a different password
- To start wsl run
wsl ~
in powershell (note I'd recommend installing Terminal
in windows as that allows direct access)
- You then have a bare bones text only linux setup
- Install packages you need
sudo dnf install make git texlive
will give you access to make, git and latex for example
- The password for
sudo
is the linux password you created above
What just happened?
Assuming the above steps worked, how is your computer now setup? The wsl creates a virtual disk image in
C:\Users\Username\AppData\Local\Packages\LongRandomNameWithOSNameEmbedded\LocalState\ext4.vhdx
which has a virtual disk formatted as ext4 in which your linux files are stored. You can access your windows files from WSL at
/mnt/c/
and your WSL files in explorer by the linux link in the left hand bar, then the OS (if you have installed more than one), the path for direct access to your linux home directory is
\\wsl.localhost\OracleLinux_9_1\home\username
from windows. Note the wsl subsystem must be running to see this, if it is missing start it with
wsl ~
in a powershell or command prompt window. Note
wsl
without specifying a path starts with the linux prompt at the same file location as powershell.
Running software from CVMFS
You can run the default LHCb/ATLAS/ALICE etc software provided in CVMFS (other experiments should work but ask an expert).
- Install, configure and test CVMFS, see https://cvmfs.readthedocs.io/en/2.9/cpt-quickstart.html (note install as if it was Redhat then follow the WSL instructions further down the page)
- Note you will have to choose CVMFS servers to connect to, for your experiment ask an expert which servers to connect to. For example the ATLAS experiment has documentation here https://twiki.cern.ch/twiki/bin/view/AtlasComputing/Cvmfs21 but every experiment has a different set of servers.
- Setup an enviroment from CVMFS, e.g.
source /cvmfs/sft.cern.ch/lcg/views/LCG_105/x86_64-el9-gcc13-opt/setup.sh
for a generic LCG 105 or source /cvmfs/lhcb.cern.ch/lib/LbEnv
for LHCb specifically. Note this assumes you added stf.cern.ch
and/or lhcb.cern.ch
in the step above.
- Run the software normally
root myFile.root
should now work.
- Please be aware CVMFS copies file from RAL usng http (as the closest stratum 2 provider in the UK) and is normally very slow the first time you use it. Wait at least 5 minutes, 10 on a slow network connection, before assuming it has failed when accessing a package for the first time. After the first access it is normally very fast.
Likely issues
Missing software expected in a normal linux machine, such as
gcc
, which are needed but the ultra minimal install so far did not provide. You can add many of these with
sudo dnf group install "Development Tools"
which adds most of the software tools to do compilations.
There are a lot of libraries used by X11 (or wayland) that will not be installed but the CERN software assumes would be available, so you have to install then manually. Typically you get a message like:
missing library libz.so.1
and you have to install ABC to fix this
sudo dnf install zlib-devel
will generally do that. Some are more complicated, use repoquery to find what package has your missing library and install it (ignore the version number and other extensions).
> dnf repoquery --file */libz.so.1
...
zlib-0:1.2.11-31.el9.i686
...
> sudo dnf install zlib
I needed to install to compile and run the LHCb software stack:
- libglvnd-glx
- pcre2-utf16
- libXrender
- libSM
- libXft
- libXpm
- gcc-11
- g++
- libjpeg-turbo
- openssl-devel
- pcre-devel
- zlib-devel
- libzstd-devel
Some X11 programmes have odd graphical issues where menus appear away from what you expect. No idea how to fix this one other than learn to live with it or recompile the software. So far everything has worked for me but your mileage may vary.
Specific issues with MWS computers
There is one specific issue I encountered: the
V:/Batch
path is set in windows, by default wsl inherits the windows path, but it does not mount the V: drive automatically so gives an error.
Solve this by :
- Turning off the automatic addition of the windows path, follow the instructions here: https://learn.microsoft.com/en-us/windows/wsl/wsl-config and set
appendWindowsPath
to false
.
- Make a copy of your local user path in the "Edit enviroment vairables for your account" section of windows settings (note not the system variables)
- Set two new variables to
USERPATH
to %PATH%
and WSLENV
to WSLENV:USERPATH/p
- This captures the current path to
USERPATH
, but skips the additional enrties added by MWS, then the WSLENV
variable tells WSL to copy and convert all of the named variables in the list from Windows to Linux variables.
- https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/ has the full details on how
WSLENV
works.
- The USERPATH/p means convert a list of windows directories in USERPATH to a WSL list and set the WSL variable USERPATH to that list. The initial WLSENV; means add to the existing WLSENV rather than replace it.
- In the file
.bashrc
in your WSL home directory add the following:
# Using WSLENV to pass the USERPATH (i.e. local path) to WSL
# system path includes v:\ which is not available
if [[ -n $USERPATH ]]; then
PATH=${PATH}:${USERPATH}
fi
export PATH
- That makes all of the windows programmes available to run in WSL (note add the .exe to the end to use them).
--
DavidHutchcroft - 22 Jul 2024