PA0 is a guide to GNU/Linux development environment configuration. You are guided to install a GNU/Linux development environment. All PAs and Labs are done in this environment. If you are new to GNU/Linux, and you encounter some troubles during the configuration, which are not mentioned in this lecture note (such as "No such file or directory"), that is your fault. Go back to read this lecture note carefully. Remember, the machine is always right!
信息框说明
讲义中会出现一些信息框, 根据其颜色和左上角的图标可以得知信息的类别. 例如本信息框就是一些提示相关的内容. 其它类别主要还有
实验进度相关的提示
扩展阅读
选做思考题
实验必做内容
实验进度相关的必读信息
重要性超越实验的原则与方法
对, 你没有看错, 除了一些重要的信息之外, PA0的实验讲义都是英文!
随着科学技术的发展, 在国际学术交流中使用英语已经成为常态: 顶尖的论文无一不使用英文来书写, 在国际上公认的计算机领域经典书籍也是使用英文编著. 顶尖的论文没有中文翻译版; 如果需要获取信息, 也应该主动去阅读英文材料, 而不是等翻译版出版. "我是中国人, 我只看中文"这类观点已经不符合时代发展的潮流, 要站在时代的最前沿, 阅读英文材料的能力是不可或缺的.
阅读英文材料, 无非就是"不会的单词查字典, 不懂的句子反复读". 如今网上有各种词霸可解燃眉之急, 但英文阅读能力的提高贵在坚持. "刚开始觉得阅读英文效率低", 是所有中国人都无法避免的经历. 如果你发现身边的大神可以很轻松地阅读英文材料, 那是因为他们早就克服了这些困难. 引用陈道蓄老师的话: 坚持一年, 你就会发现有不同; 坚持两年, 你就会发现大有不同.
撇开这些高大上的话题不说, 阅读英文材料和你有什么关系呢?
有! 因为在PA中陪伴你的, 就是没有中文版的i386手册,
当然还有man
: 如果你不愿意阅读英文材料, 你是注定无法独立完成PA的.
作为过渡, 我们为大家准备了全英文的PA0. PA0的目的是配置实验环境, 同时熟悉GNU/Linux下的工作方式. 其中涉及的都是一些操作性的步骤, 你不必为了完成PA0而思考深奥的问题.
你需要独立完成PA0, 请你认真阅读讲义中的每一个字符, 并按照讲义中的内容进行操作:
当讲义提到要在互联网上搜索某个内容时, 你就去互联网上搜索这个内容.
如果遇到了错误, 请认真反复阅读讲义内容, 机器永远是对的.
如果你是第一次使用GNU/Linux, 你还需要查阅大量资料或教程来学习一些新工具的使用方法,
这需要花费大量的时间(例如你可能需要花费一个下午的时间, 仅仅是为了使用vim
在文件中键入两行内容).
这就像阅读英文材料一样, 一开始你会觉得效率很低, 但随着时间的推移, 你对这些工具的使用会越来越熟练.
相反, 如果你通过"投机取巧"的方式来完成PA0, 你将会马上在PA1中遇到麻烦.
正如etone所说, 你在专业上的技不如人, 迟早有一天会找上来.
另外, PA0的讲义只负责给出操作过程, 并不负责解释这些操作相关的细节和原理. 如果你希望了解它们, 请在互联网上搜索相关内容.
Installing Docker
Docker is an implementation of the lightweight virtualization technology. Virtual machines built by this technology is called "container". By using Docker, it is very easy to deploy GNU/Linux applications.
If you already have one copy of GNU/Linux distribution different from which we recommend, and you want to use your copy as the development environment, we still encourage you to install docker on your GNU/Linux distribution to use the same GNU/Linux distribution we recommend over docker to avoid issues brought by platform disparity. Refer to Docker online Document for more information about installing Docker for GNU/Linux. It is OK if you still insist on your GNU/Linux distribution. But if you encounter some troubles because of platform disparity, please search the Internet for trouble-shooting.
It is also OK to use traditional virtual machines, such as VMWare or VirtualBox, instead of Docker. If you decide to do this and you do not have a copy of GNU/Linux, please install Debian 9 distribution in the virtual machine. Also, please search the Internet for trouble-shooting if you have any problems about virtual machines.
必须使用64位的GNU/Linux
如果你打算使用已有的GNU/Linux平台, 请确保它是64位版本. 今年PA的新增特性会依赖于64位平台.
Download Docker from this website according to your host operating system,
then install Docker with default settings.
Reboot the system if necessary.
If your operating system can not meet the requirement of installing Docker,
please upgrade your operating system.
Do not install Docker Toolbox
instead.
It seems not very stable in Windows since it is based on VirtualBox.
Preparing Dockerfile
Dockerfile
is the configuration file used to build a Docker image.
Now we are going to prepare a Dockerfile with proper content by using the
terminal working environment.
- If your host is GNU/Linux or Mac, you can use the default terminal in the system.
- If your host is Windows, open
PowerShell
.
Type the following commands after the prompt, one command per line.
Every command is issued by pressing the Enter
key.
The contents after a #
is the comment about the command,
and you do not need to type the comment.
mkdir mydocker # create a directory with name "mydocker"
cd mydocker # enter this directory
Now use the text editor in the host to new a file called Dockerfile
.
- Windows: Type command
notepad Dockerfile
to open Notepad. - MacOS: Type command
open -e Dockerfile
to open TextEdit. - GNU/Linux: Use your favourite editor to open Dockerfile.
Now copy the following contents into Dockerfile:
# setting base image
FROM debian
RUN apt-get update
# Set the locale
RUN apt-get install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
RUN dpkg-reconfigure --frontend=noninteractive locales
RUN update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
# new a directory for sshd to run
RUN mkdir -p /var/run/sshd
# installing ssh server
RUN apt-get install -y openssh-server
# installing sudo
RUN apt-get install -y sudo
# make ssh services use IPv4 to let X11 forwarding work correctly
RUN echo AddressFamily inet >> /etc/ssh/sshd_config
# defining user account imformation
ARG username=ics
ARG userpasswd=ics
# adding user
RUN useradd -ms /bin/bash $username && (echo $username:$userpasswd | chpasswd)
# adding user to sudo group
RUN adduser $username sudo
# setting running application
CMD /usr/sbin/sshd -D
We choose the Debian distribution as the base image,
since it can be quite small.
Change username
and userpasswd
above to your favourite account settings.
Save the file and exit the editor.
For Windows user, notepad
will append suffix .txt
to the saved file.
This is unexpected.
Use the following command to rename the file.
mv Dockerfile.txt Dockerfile # rename the file to remove the suffix in Windows
Building Docker image
Keep the Internet conntected. Type the following command to build our image:
docker build -t ics-image .
This command will build an image with a tag ics-image
,
using the Dockerfile in the current directory (mydocker).
In particular, if your host is GNU/Linux,
all Docker commands should be executed with root privilege,
or alternatively you can add your account to the group docker
before executing any docker commands.
If it is the first time you run this command,
Docker will pull the base image debian
from Docker Hub.
This will cost several minutes to finish.
After the command above finished, type the following command to show Docker images:
docker images
This command will show information about all Docker images.
REPOSITORY TAG IMAGE ID CREATED SIZE
ics-image latest 7d9495d03763 4 minutes ago 210 MB
debian latest fb434121fc77 4 hours ago 100 MB
If you see a repository with name ics-image
, you are done with building image.
Now we can remove the directory mentioned above.
cd .. # go back to the parent directory
rm -r mydocker # remove the `mydocker` directory
Creating Debian container
After building the image, now we can create a container. Type the following command:
docker create --name=ics-vm -p 20022:22 --tmpfs /dev/shm:exec --privileged=true ics-image
This command will create a container with the following property:
- the name of the container is
ics-vm
- the Docker image is
ics-image
, which we just built - the default SSH port (
22
) in the container is bound to port20022
in the docker host - the container will get extended privileges (for GDB to run)
- mount
/dev/shm
with an executable flag
If the above command fails because a container with the same name already exists, type the following command to remove the existing container:
docker rm ics-vm
Then create the container again.
To see whether the container is created successfully, type the following command to show containers:
docker ps -a
This command will show information about all Docker containers.
If you see a container with name ics-vm
, you are done with creating container.