Difference between revisions of "EBC Exercise 02 Setting Up Windows Subsystem for Linux"
(→Installing WSL) |
m (→Sharing the network) |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 13: | Line 13: | ||
== Installing WSL == | == Installing WSL == | ||
− | Simply got to | + | Simply got to https://docs.microsoft.com/en-us/windows/wsl/install and follow the directions. |
− | + | In order to use certain features when working with the BeagleBone, you will need wsl 2. To check which version you have run the command below. | |
− | + | host$ '''wsl.exe –l –v''' | |
− | * Ubuntu | + | NAME STATE VERSION |
+ | * Ubuntu Running 2 | ||
− | The NAME is your distribution name and VERSION is the version of wsl you are running. | + | The NAME is your distribution name and VERSION is the version of wsl you are running (1 or 2). If you have version 2 then you are good to go, otherwise, to switch to wsl 2 run: |
− | + | host$ '''wsl.exe --set-version <distribution name> 2''' | |
− | + | host$ '''wsl.exe --set-default-version 2''' | |
− | Run ' | + | Run 'host$ wsl -l -v' again and you should see that wsl is now version 2. |
− | |||
− | |||
− | |||
− | |||
== Sharing the network == | == Sharing the network == | ||
Line 46: | Line 43: | ||
* Press OK to go back to the Properties window and | * Press OK to go back to the Properties window and | ||
* press OK again. | * press OK again. | ||
+ | |||
+ | In WSL enter | ||
+ | |||
+ | host$ '''sudo iptables -t nat -A POSTROUTING -s 192.168.7.2 -o eth0 -j MASQUERADE''' | ||
+ | host$ '''sudo sysctl net.ipv4.ip_forward=1''' | ||
+ | |||
After that, ssh into the bone, and run the command | After that, ssh into the bone, and run the command | ||
+ | host$ '''ssh bone''' | ||
bone$ '''sudo route add default gw 192.168.7.1''' | bone$ '''sudo route add default gw 192.168.7.1''' | ||
(This command needs to be run every time you boot the Bone.) | (This command needs to be run every time you boot the Bone.) | ||
The Bone should now have access to the internet. If you disconnect the Bone from your host, you may have to stop sharing your internet and reshare it, then set the IP and DNS Addresses to be automatic again for it to work. | The Bone should now have access to the internet. If you disconnect the Bone from your host, you may have to stop sharing your internet and reshare it, then set the IP and DNS Addresses to be automatic again for it to work. | ||
+ | |||
+ | You should be on the Internet now. | ||
+ | |||
+ | bone$ '''ping -c2 google.com''' | ||
+ | PING google.com (142.250.191.142) 56(84) bytes of data. | ||
+ | 64 bytes from ord38s29-in-f14.1e100.net (142.250.191.142): icmp_seq=1 ttl=112 time=8.35 ms | ||
+ | 64 bytes from ord38s29-in-f14.1e100.net (142.250.191.142): icmp_seq=2 ttl=112 time=8.43 ms | ||
+ | |||
+ | --- google.com ping statistics --- | ||
+ | 2 packets transmitted, 2 received, 0% packet loss, time 1002ms | ||
+ | rtt min/avg/max/mdev = 8.354/8.393/8.433/0.039 ms | ||
+ | |||
+ | If pinging doesn't work, try editting '''/etc/resolv.conf''' on the bone and add the following line | ||
+ | to the end of the file. | ||
+ | |||
+ | nameserver 8.8.8.8 | ||
+ | nameserver 8.8.4.4 | ||
{{YoderHead}} | {{YoderHead}} |
Latest revision as of 11:09, 4 December 2023
Embedded Linux Class by Mark A. Yoder
The Beagle can run standalone with a monitor and keyboard and mouse, but we use it in an iot mode where it's accessed through the network. When used this way an Linux host is used that is either a native install on a laptop (or desktop) or a virtual machine running under Windows.
The purpose of this wiki is to introduce a third option, running in the Windows Subsystem of Linux (wsl).
The Windows Subsystem of Linux
wsl lets developers run a GNU/Linux environment directly on Windows, unmodified, without the overhead of a traditional virtual machine or dualboot setup. Details about wsl can be found here: https://docs.microsoft.com/en-us/windows/wsl/about, or just googling for it. Here I'll highlight how to install and use is for the class.
Installing WSL
Simply got to https://docs.microsoft.com/en-us/windows/wsl/install and follow the directions. In order to use certain features when working with the BeagleBone, you will need wsl 2. To check which version you have run the command below.
host$ wsl.exe –l –v NAME STATE VERSION * Ubuntu Running 2
The NAME is your distribution name and VERSION is the version of wsl you are running (1 or 2). If you have version 2 then you are good to go, otherwise, to switch to wsl 2 run:
host$ wsl.exe --set-version <distribution name> 2 host$ wsl.exe --set-default-version 2
Run 'host$ wsl -l -v' again and you should see that wsl is now version 2.
Sharing the network
We used ip masquerading to have the host computer share the network with the Beagle. Here you need to set up Windows to do the sharing.
Once the Beagle is connected to your host computer running Windows 10, there should be an "ethernet connection" created over usb.
To share your internet from Windows:
- Right click the wifi or ethernet icon in your taskbar, and select the Open Network & Internet Settings option.
- Once the window is opened, scroll to the bottom and press Change adapter options under Advanced network settings.
- To share your internet, right click on the adapter that your host is using to access the internet, and select Properties.
- Go to the sharing tab at the top, and check the Allow other network users to connect through this computer's Internet connection option. If you have multiple internet adapters, you might need to select the Bone using the drop down menu. It should be the adapter with the description Remote NDIS Compatible Device in the Network Connection window.
- Press OK at the bottom, then
- right click the adapter for the Bone (the one labled Remote NDIS Compatible Device), and press Properties.
- Double click on the Internet Protocol Version 4 option on the main tab, and
- set both the IP address and DNS server addresses to be set automatically.
- Press OK to go back to the Properties window and
- press OK again.
In WSL enter
host$ sudo iptables -t nat -A POSTROUTING -s 192.168.7.2 -o eth0 -j MASQUERADE host$ sudo sysctl net.ipv4.ip_forward=1
After that, ssh into the bone, and run the command
host$ ssh bone bone$ sudo route add default gw 192.168.7.1
(This command needs to be run every time you boot the Bone.) The Bone should now have access to the internet. If you disconnect the Bone from your host, you may have to stop sharing your internet and reshare it, then set the IP and DNS Addresses to be automatic again for it to work.
You should be on the Internet now.
bone$ ping -c2 google.com PING google.com (142.250.191.142) 56(84) bytes of data. 64 bytes from ord38s29-in-f14.1e100.net (142.250.191.142): icmp_seq=1 ttl=112 time=8.35 ms 64 bytes from ord38s29-in-f14.1e100.net (142.250.191.142): icmp_seq=2 ttl=112 time=8.43 ms --- google.com ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1002ms rtt min/avg/max/mdev = 8.354/8.393/8.433/0.039 ms
If pinging doesn't work, try editting /etc/resolv.conf on the bone and add the following line to the end of the file.
nameserver 8.8.8.8 nameserver 8.8.4.4
Embedded Linux Class by Mark A. Yoder