# Installing Tools

In GNU/Linux, you can download and install a software by one command (which may be difficult to do in Windows). This is achieved by the package manager. Different GNU/Linux distribution has different package manager. In Debian, the package manager is called `apt`.

You will download and install some tools needed for the OS lab from the network mirrors. Before using the network mirrors, you should check whether the container can access the Internet.

## Checking network state

By the default network setting of the container will share the same network state with your host. That is, if your host is able to access the Internet, so does the container. To test whether the container is able to access the Internet, you can try to ping a host outside the university LAN:

```
ping www.baidu.com -c 4
```

You should receive reply packets successfully:

```
PING www.a.shifen.com (39.156.66.14) 56(84) bytes of data.
64 bytes from 39.156.66.14: icmp_seq=1 ttl=37 time=23.4 ms
64 bytes from 39.156.66.14: icmp_seq=2 ttl=37 time=17.9 ms
64 bytes from 39.156.66.14: icmp_seq=3 ttl=37 time=45.3 ms
64 bytes from 39.156.66.14: icmp_seq=4 ttl=37 time=17.4 ms

--- www.a.shifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 51ms
rtt min/avg/max/mdev = 17.449/26.021/45.277/11.365 ms
```

If you get an "unreachable" message, please check whether you can access [www.baidu.com](http://www.baidu.com) in the host system.

## Updating APT package information

Now you can tell `apt` to retrieve software information from the sources:

```
apt-get update
```

However, you will receive an error message:

```
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
```

This is because `apt-get` requires superuser privilege to run.

{% hint style="info" %}
Why do some operations require superuser privilege?

In a real GNU/Linux, shutting down the system also requires superuser privilege. Can you provide a scene where bad thing will happen if the shutdown operation does not require superuser privilege?
{% endhint %}

To run `apt-get` with superuser privilege, use `sudo`. If you find an operation requires superuser permission, append `sudo` before that operation. For example,

```
sudo apt-get update
```

Enter your password you set previously in the `Dockerfile`. Now `apt-get` should run successfully. Since it requires Internet accessing, it may cost some time to finish.

## Installing tools for OS lab

The following tools are necessary for OS lab:

```
apt-get install build-essential    # build-essential packages, include binary utilities, gcc, make, and so on
apt-get install gdb                # GNU debugger
apt-get install git                # reversion control system
apt-get install qemu-system-x86    # QEMU
apt-get install bochs-x            # Bochs with X11 plugin
apt-get install mingw-w64          # GNU development environment for Windows applications
apt-get install nasm               # NASM
```

The usage of these tools is explained later.

## Using pre-configured image

In order to reduce your burden, and save your campus network traffic charges, we have prepared a pre-configured image for you. All operations before this section have been pre-executed in the image, including installing GNU/Linux and all tools. You can download the image from [this link](ftp://202.204.62.219/OSLab/oslab-image-pre-configured.tar).

{% hint style="warning" %}
注意: 你需要接入北科大校园网才能下载此 Docker 镜像.
{% endhint %}

After the download is complete, open host terminal and change directory to the download folder, type the following command:

```
docker load -i oslab-image-pre-configured.tar
```

This command will load the file `oslab-image-pre-configured.tar`, which we just downloaded, as a Docker image. This operation may take some time, and then we can type:

```
docker images
```

You will see output similar to the following:

```
REPOSITORY           TAG          IMAGE ID          CREATED             SIZE
oslab-image          configured   512f0596556f      38 seconds ago      1.85GB
```

That means the image has been loaded successfully. Now we can create a new container:

```
docker create --name=oslab-vm -p 20022:22 --tmpfs /dev/shm:exec --privileged=true oslab-image:configured
```

After that, you need to read the contents of [the second section](https://app.gitbook.com/s/-LnM_MK1Ma3MtweMDTEl/conf-linux/1st-exp-with-linux) carefully, and then you can continue to learn the follow-up part of the tutorial.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ustb-os-lab.gitbook.io/2019/conf-linux/inst-tools.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
