For security reasons, our server must be accessed via SSH. Below is an example of how to connect to our course VPN:
- Download wireguard.
- Open WireGuard and select "Import tunnel from file."
- Choose the
.conf
file provided in the TA's email. - Click "Activate" to connect.
Having a nice ssh setting makes connection to server much more easier. Originally, connecting to server requires the following steps
-
Run ssh command with username and ip address specified
-
Enter password
But with ssh config and authorized_keys, you can connect to the server with just a short command, for example
ssh nachos
Besides, you can also use Visual Studio Code to connect to the server with just a click after configuring ssh config.
- Client: The machine you are using to connect to the server, for example your laptop.
- Server: The machine you are connecting to, for example the server provided by the course.
- To run a command on the client means to run the command on your PC terminal.
- To run a command on the server means to ssh to the server and run the command on the server terminal.
-
Open terminal (Client)
-
Run the following command to create a new ssh config file and open it (Client)
# For MacOS touch ~/.ssh/config open ~/.ssh/config # For Windows cmd notepad %userprofile%\.ssh\config # For Windows powershell notepad $env:userprofile\.ssh\config
-
Add the following content to the file. (Replace
os24team99
with your username) (Client)Host nachos HostName 192.168.5.2 user os24team99
-
Save and close the file
-
Then you can connect to the server with the following command (Client)
ssh nachos
-
Open terminal (Client)
-
Run the following command to generate a new ssh key (Client)
ssh-keygen
-
Copy your public key (Client)
# For MacOS ssh-copy-id nachos # For Windows cmd type %userprofile%\.ssh\id_rsa.pub | ssh nachos "cat >> ~/.ssh/authorized_keys" # For Windows powershell Get-Content $env:userprofile\.ssh\id_rsa.pub | ssh nachos "cat >> ~/.ssh/authorized_keys"
-
Now you can connect to the server without entering password (Client)
ssh nachos
You can choose to use mobaxterm in Windows, but you can also use vscode, a much more convenient choice.
-
Install Remote - SSH extension in vscode link
-
Click on the icon at the left
-
Connect to host
Congratulations! Now you can connect to the server with just a click.
-
Connect to the server
-
Copy the nachos folder to your home directory (Server)
cp -r /home/os2024/share/NachOS-4.0_MP1 .
- Connect to the server with vscode
- Hit
cmd+o
for MacOS orctrl+k ctrl+o
for Windows, type/home/os2024/os24team99/NachOS-4.0_MP1/code
and click ok - Now you can edit the nachos code in vscode
We have already set up git in the NachOS-4.0_MP1 folder. It is recommended to use git to manage your code.
Some useful git commands:
-
Create a commit
git add . git commit -m "Your commit message"
-
Push your code to the remote repository if you have added your remote repository
git push
It is recommended to install the extension C/C++, and Makefile tools, and set up the file NachOS-4.0_MP1/code/.vscode/c_cpp_properties.json
(We have already set up this file for you)
{
"configurations": [
{
"name": "Linux",
"intelliSenseMode": "gcc-x64",
"includePath": [
"${workspaceRoot}",
"${workspaceRoot}/filesys",
"${workspaceRoot}/lib",
"${workspaceRoot}/machine",
"${workspaceRoot}/network",
"${workspaceRoot}/test",
"${workspaceRoot}/threads",
"${workspaceRoot}/userprog"
],
"compilerPath": "/usr/bin/gcc",
"defines": [
"FILESYS_STUB", // Comment in MP4
"RDATA",
"SIM_FIX",
"CHANGED",
"LINUX",
"x86"
],
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
This file is used to provide intellisense for vscode, so that you can have code completion and go to definition.
There are also convenient shortcuts to use in vscode.
Build nachos
# Build test programs
# in code/test directory
make clean
make add
# Example to run a test
../build.linux/nachos -e add
# Build test programs
# in code/test directory
make clean
make add
# Example to run a test
../build.linux/nachos -e add
Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker's methodologies for shipping, testing, and deploying code, you can significantly reduce the delay between writing code and running it in production. Docker
- You can run the same environment on your local machine as the server, without installing the dependencies on your local machine.
- To stop relying on network connection to the server, and prevent power cut (which happens a lot recently).
-
Install WSL2 link
wsl --install
-
Install a Linux distribution from Microsoft Store, for example Ubuntu and setup your username and password
wsl --install -d Ubuntu
-
(Optional) Use WSL2 as the default version for better performance
wsl --set-default-version 2 wsl --set-version Ubuntu 2
-
Install Docker Desktop link
-
Enable WSL2 integration for your linux distribution in Docker Desktop
-
Start wsl
wsl
-
Make sure docker is running in wsl
docker --version
-
(Important) Do not be under
/mnt/
directory when performing the following steps, , as it will cause issues. If you are not sure, run the following command to go to your home directorycd ~
-
Download
NachOS-4.0_MP1
from your github repository or copy from the server to your directory, and you can start building and running nachos in the docker container.
- Install Docker link
- Download
NachOS-4.0_MP1
from your github repository or copy from the server to your directory, and you can start building and running nachos in the docker container.
-
Install Docker link
-
Download
NachOS-4.0_MP1
from your github repository or copy from the server. -
Run the following command to build the docker image (Client)
cd NachOS-4.0_MP1 make build # to build the image yourself # or make pull # to pull the built image from docker hub
-
Run the following command to start and get into the docker container (Client)
make run
-
Now you are in the docker container under
code/test
-
Now you can build and run nachos in the docker container (Docker)
bash build_nachos.sh -j # or clean and build bash build_nachos.sh -cj # or clean and build without showing make outputs bash build_nachos.sh -cqj
-
To run a test program (Docker)
# Build test programs # in code/test directory make clean make add # Example to run a test ../build.linux/nachos -e add
-
To exit the docker container, run the following command (Docker)
exit