I’ve been doing a lot of back end investigation the past few months – trying to build something to support future projects. Most of it’s just random poking about with new technologies and different ways of doing “stuff” but then sometimes while doing this you find something that is really cool and resonates with the way your brain works. For me this month it was Rust and RHEL WSL.
I got here by a round about route of looking at golang programming and docker integration for back end processing of a game. A way to offload non-game-critical systems to other processors. Like a high score system that keeps player profiles and scores online which can be called from within the game when needed. I know there are heaps of good services out there that do this – but I like poking into stuff and having that level of control.
The other thing is – sometimes stuff just makes sense. I’ve been a long time linux user and champion but have always been locked into a Wintel desktop in the studio due to the support needs of my audio kit. (I have a Line 6 KB37 which integrates the midi keyboard and guitar effects pedals into one unit – it’s freaking awesome and I’m terrified that one day it will break and be out of support). I’d run linux as a virtual machine and used cygwin and my favourite mobaXterm as a solution to this but while poking around within the docker community I came across WSL. The Windows Subsystem for Linux.
WSL
The Windows Subsystem for Linux is a compatibility layer which runs Linux binary executables natively on Windows. WSL v2 has a real Linux kernel (though there are some storage issues if you need more info read the docs). The default linux kernel is Ubuntu which I’m OK with – one of my favourite linux distributions is the Ubuntu Studio but I’ve been a Red Hat admin for a long time so am more comfortable there but there was no RHEL or CentOS supported platform. But then I found the RHWSL project by a Japanese Developer called Yosuke Sano and I was intrigued and immediately hooked.
Basically this is how I set up WSL on my Windows 10 Workstation.
C:\Users\zulu>wsl –list –online
The following is a list of valid distributions that can be installed.
Install using ‘wsl –install -d ‘.
C:\Users\zulu>WSL –list –all
Windows Subsystem for Linux Distributions:
Ubuntu (Default)
NAME FRIENDLY NAME
Ubuntu Ubuntu
Debian Debian GNU/Linux
kali-linux Kali Linux Rolling
openSUSE-42 openSUSE Leap 42
SLES-12 SUSE Linux Enterprise Server v12
Ubuntu-16.04 Ubuntu 16.04 LTS
Ubuntu-18.04 Ubuntu 18.04 LTS
Ubuntu-20.04 Ubuntu 20.04 LTS
C:\Users\zulu>wsl –set-default-version 2
For information on key differences with WSL 2 please visit https://aka.ms/wsl2
The operation completed successfully.
C:\Users\zulu>WSL –HELP
Invalid command line option: –HELP
Copyright (c) Microsoft Corporation. All rights reserved.
Usage: wsl.exe [Argument] [Options…] [CommandLine]
I downloaded the RHWSL package from git, extracted it and run the executable to register the package with WSL and install the root file system and that was it.
This is how I set the RHWSL distribution as my default:
d:\RedHat\RHWSL>wsl -d RHWSL
Here are a bunch of useful links if you want to explore more:
https://docs.docker.com/desktop/windows/wsl/
https://docs.microsoft.com/en-us/windows/wsl/install
https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers
https://dev.to/bowmanjd/using-podman-on-windows-subsystem-for-linux-wsl-58ji
https://github.com/yosukes-dev/RHWSL
https://github.com/yosukes-dev/RHWSL/releases
If you want more info on WSL yosukes-dev has an “Awesome” resource list.
Rust
I started looking at Rust as part of a wider investigation into “modern” programming languages. I spent a few weeks looking at go (golang) and as much as it was a great multi-purpose language and super easy to start using I was a little gobsmacked at how large the binaries were (they are statically compiled) and being someone who is always on tiny machines I kept getting a niggling feeling that a whole system of go programs would be a big chunk of disk on a small device doing work that that might be easier done slower with a simple shell script (I exaggerate!). Anyway in a lot of the stuff I read golang and rust were comparable. I will come back to go as the community and contributions seemed most excellent.
Plus Rust made sense to me in places where Go didn’t. I really don’t have a logical excuse here or a well reasoned argument. Sometimes you just like a language cause it “feels” right. I had the same thing with Ruby. Anyway this is how I got started with Rust on the RHWSL…
https://www.rust-lang.org/learn/get-started
If you’re a Windows Subsystem for Linux user run the following in your terminal, then follow the on-screen instructions to install Rust.
curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs | sh
I started following the hello world tutorial to set up the system and it wasn’t all plain sailing. For one I probably should have done the install as a normal user but after mucking around with environment variables and permissions into the root user directories it was just easier to do the work as root. (I know rolling over in my grave). So it wasn’t all plain sailing – and once I got to the compile stage there were a few basic compiling tools that the RHWSL needed. This is how it went:
https://doc.rust-lang.org/cargo/getting-started/first-steps.html
[root@Venom RHWSL]# mkdir rustProgramming
[root@Venom RHWSL]# cd rustProgramming/
[root@Venom rustProgramming]# cargo new hello_world
Created binary (application) hello_world
package
[root@Venom rustProgramming]#
[root@Venom rustProgramming]# ls -ltr
total 0
drwxrwxrwx 1 root root 4096 Feb 8 18:27 hello_world
[root@Venom rustProgramming]#
[root@Venom rustProgramming]# cd hello_world/
[root@Venom hello_world]# ls -ltr
total 0
-rwxrwxrwx 1 root root 180 Feb 8 18:27 Cargo.toml
drwxrwxrwx 1 root root 4096 Feb 8 18:27 src
[root@Venom hello_world]# cat Cargo.toml
[package]
name = “hello_world”
version = “0.1.0”
edition = “2021”
See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[root@Venom hello_world]# cat src/main.rs
fn main() {
println!(“Hello, world!”);
}
[root@Venom hello_world]# cargo build
Compiling hello_world v0.1.0 (/mnt/d/RedHat/RHWSL/rustProgramming/hello_world)
error: linker cc
not found
|
= note: No such file or directory (os error 2)
error: could not compile hello_world
due to previous error
Bingo – first problem – no compiler. I installed make and gcc – not really sure if I needed make but figured it would be a nice to have anyway.
[root@Venom hello_world]# which make
/usr/bin/which: no make in (/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/Program Files (x86)/ ……….lots more here
[root@Venom hello_world]# which cc
/usr/bin/which: no cc in (/root/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/Program Files (x86)/ ……….lots more here
[root@Venom hello_world]# yum install make
…Dependencies resolved.
Package Architecture Version Repository Size
Installing:
make x86_64 1:4.2.1-10.el8 ubi-8-baseos 498 k
…. more in here you don’t need to see …
Installed:
make-1:4.2.1-10.el8.x86_64
Complete!
[root@Venom hello_world]# which make
/usr/bin/make
[root@Venom hello_world]# yum install gcc
…Dependencies resolved
…. more in here you don’t need to see …
Installing dependencies:
binutils x86_64 2.30-108.el8_5.1 ubi-8-baseos 5.8 M
cpp x86_64 8.5.0-4.el8_5 ubi-8-appstream 10 M
glibc-devel x86_64 2.28-164.el8 ubi-8-baseos 1.0 M
glibc-headers x86_64 2.28-164.el8 ubi-8-baseos 480 k
…Transaction Summary
Install 14 Packages
Total download size: 51 M
Installed size: 123 M
Installed:
Complete!
[root@Venom hello_world]# which cc
/usr/bin/cc
[root@Venom hello_world]# cargo build
Compiling hello_world v0.1.0 (/mnt/d/RedHat/RHWSL/rustProgramming/hello_world)
Finished dev [unoptimized + debuginfo] target(s) in 2.09s
[root@Venom hello_world]# ls -ltr
total 0
-rwxrwxrwx 1 root root 180 Feb 8 18:27 Cargo.toml
drwxrwxrwx 1 root root 4096 Feb 8 18:27 src
-rwxrwxrwx 1 root root 155 Feb 8 18:28 Cargo.lock
drwxrwxrwx 1 root root 4096 Feb 8 18:28 target
You can run the executable like this:
[root@Venom hello_world]# ./target/debug/hello_world
Hello, world!
Or just run from command:
[root@Venom hello_world]# cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
Running target/debug/hello_world
Hello, world!
Yay !