Windows安装虚拟机和ubuntu系统

一、社区账号及DCO协议签署

1.1、申请注册社区账号

登录码云并使用常用邮箱进行注册,该邮箱需要用于签署DCO,以及用于配置SSH公钥。
点我进入

1.2、签署DCO

点击此处打开DCO签署页面
签署OpenHarmony DCO(Developer Certificate of Origin,开发者原创声明)是加入OpenHarmony社区的第一步。在填写必要信息后,即可完成DCO签署。
在这里插入图片描述

二、下载VMware及Ubuntu

VMware下载地址
推荐版本号-16.1.2-17966106

Ubuntu下载地址
推荐版本号-20.04.2

三、创建VMare并安装Ubuntu系统

  1. 选择创建虚拟机
    在这里插入图片描述

  2. 选择对应Ubuntu的iso镜像文件
    在这里插入图片描述

  3. 后续添加用户名后点击下一步默认安装即可。
    在这里插入图片描述

  4. 需要注意的是,在选择磁盘容量的时候,尽可能填写一个大的虚拟内存,建议填800G以上。
    在这里插入图片描述

  5. 置用户名后,选择语言,之后每个过程选择“Done”即可,请牢记设置的用户名和密码,后面登录需要经常使用。
    在这里插入图片描述

  6. 安装完成标志(全程耗时约1h):
    在这里插入图片描述

四、 Linux环境基础配置

4.1 解锁root用户

root用户是Linux系统的最高权限用户,新安装的环境需要解锁,否则很多基础功能无法使用。

#创建没有密码的root用户
sudo passwd -u root
# 修改root用户密码
sudo passwd root

解锁方式详情参考

4.2 安装网络工具并查看本机IP用于ssh远程登录

未安装网络工具,则无法使用ifconfig等网络工具命令,安装命令如下:

#安装net-tools
sudo apt-get install net-tools
# 查看本机IP,获取IP用于SSH链接
ifconfig

4.3 开启ssh服务并用putty连接虚拟机

使用putty等ssh客户端连接虚拟机可以带来更舒适的Linux虚拟机的使用体验,最常用内容为文字拷贝(从windows拷贝,到VMware的Ubuntu里粘贴)。(拓展阅读: vim编辑器常用命令

sudo apt-get install ssh
#修改配置文件(缺少vim可用vi,也可以apt-get install vim)
sudo vim /etc/ssh/sshd_config
# 去除Authentication
后面五行注释,PermiRootLogin 后面字段改为yes
sudo /etc/init.d/ssh restart

配置修改参考
在这里插入图片描述
下载putty远程防问工具
putty下载链接

更多详情请参考:开启ssh服务及支持远程root登录

4.4 开启samba服务并用windows文件服务访问对应目录

为什么要开启samba服务?
开启samba服务后,就可以像访问window文件一样访问虚拟机中的文件

开启方式:

  1. 下载samba并配置:
#下载samba
sudo apt-get install samba
sudo apt-get install smbclient#修改配置文件(缺少vim可用vi,也可以apt-get install vim)
sudo vim /etc/samba/smb.conf
  1. 将下面【root】配置增加到文件末尾,配置文件各字段意义:可选参考
    直接可用配置(开启/root目录访问):
[root]
    comment = All users
    force user = root
    path = /root
    browseable = yes
    available = yes
    public = yes
    writeable = yes
  1. 重启samba:
#重启samba
sudo /etc/init.d/smbd restart
  1. 配置验证,重启smbd后,“WIN+R”后输入“\ifconfig查出的IP\smb.cof中配置的路径”即可访问对应文件目录:
    在这里插入图片描述在这里插入图片描述

4.5 ssh保持长时间链接配置(可选)

因VMware直接操作虚拟机不便于操作,采用ssh链接虚拟机会断连接导致影响体验,或无法确定部分操作是否因为断连而操作失败。建议配置shh长时间不断连接。
参考配置,编辑配置文件、复制粘贴所有配置项后、重启ssh服务即可。

五、配置Linux开发环境及下载代码

以下步骤,建议在root用户下执行,切换root用户:

su root

5.1 配置Git及公钥

5.1.1 配置Git

在Ubuntu窗口,输入如下命令并按回车确认,配置Git的用户名和邮箱。

注:将“yourname”修改为你的码云账号名;将”your-email-address”修改为码云注册的邮箱地址。

git config --global user.name "yourname"
git config --global user.email "your-email-address"
git config --global credential.helper store
5.1.2 配置公钥
  1. 生成公钥
    在Ubuntu系统命令行界面,输入如下命令并按4次回车确认,生成SSH公私钥对。

注:将”your-email-address”修改为码云注册的邮箱地址。

ssh-keygen -t ed25519 -C "your-email-address"

显示如下内容后,则表示SSH公私钥对生成成功。

Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/hdf/.ssh/id_ed25519):
Created directory '/home/hdf/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/hdf/.ssh/id_ed25519
Your public key has been saved in /home/hdf/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:QWfFUgDMZ1dEJ+ZJkZ1a/CNpxGak89mqXxxxXxxXXXxx xxxx@xxxxxx.com
The key's randomart image is:
+--[ED25519 256]--+
|       xx.+===X+o|
|       .oo+ +O.B.|
|        .o =+E* .|
|         .  o=X..|
|        S   .=.o.|
|              o  |
|             .o. |
|           xxxxx |
|          .o=o ..|
+----[SHA256]-----+
  1. 查看生成的公钥
    在Ubuntu系统命令行界面,输入如下命令并按回车,查看生成的公钥内容。
cat ~/.ssh/id_ed25519.pub
  1. 添加公钥
    将上一步显示的公钥内容添加到个人公钥管理中,位置:码云主页 - 设置 - 安全设置 - SSH公钥 - 添加公钥。点击这里跳转到码云添加公钥页面
    在这里插入图片描述
    更多细节可参考码云官方 - SSH公钥设置

5.2 使用一键式安装命令进行编译环境配置

5.2.1 一键式配置命令

打开Ubuntu窗口,输入如下Linux环境一键式安装命令并点击回车:

git clone git@gitee.com:landwind/openharmony_oneclick_env_init;cd openharmony_oneclick_env_init;sudo apt-get install dos2unix;sudo apt-get install genext2fx;sudo apt-get install liblz4-tool;dos2unix *.sh;bash init.sh --skip-code;source /etc/profile;cd /usr/bin/; sudo ln -s /usr/bin/python2.7 python

注:命令详细说明 - 一键式环境安装配置命令详情

在命令执行的过程中,需要与用户进行一定的交互,下面进行详细说明。
这里需要输入yes,将gitee.com的服务器添加到已知服务器列表中。

Cloning into 'openharmony_oneclick_env_init'...
The authenticity of host 'gitee.com (180.97.125.228)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

这里需要输入您的用户对应的密码并点击回车。

注:输入密码时不会回显。

Warning: Permanently added 'gitee.com,180.97.125.228' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 19, done.
......Command 'dos2unix' not found, but can be installed with:

sudo apt install dos2unix

[sudo] password for hdf:

这里需要关闭当前Ubuntu窗口,并重新打开。

/home/hdf/openharmony_oneclick_env_init/check.sh: line 37: /etc/wsl.conf: Permission denied
您当前系统为WSL Ubuntu,为防止文件系统出现权限问题,已经自动配置,请您重启终端生效
请您重启终端生效
请您重启终端生效
请您重启终端生效
自动配置 配置文件:/etc/wsl.conf
如您需要回退配置,请重命名/删除 /etc/wsl.conf ,并重启终端生效

在新打开的Ubuntu窗口中,重新输入一键式配置命令,并按回车,会显示如下内容。
这里需要输入hdf的密码并点击回车。

注:输入密码时不会回显。

 fatal: destination path 'openharmony_oneclick_env_init' already exists and is not an empty directory.
E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

Command 'dos2unix' not found, but can be installed with:

sudo apt install dos2unix

[sudo] password for hdf:

这里需要输入yes并点击回车,来测试gitee的ssh联通性。

WSL 文件系统已设置
准备检查与gitee.com的ssh联通性,如提示'.......continue connecting(yes/no)?',请您输入 yes

这里需要输入Y,来重新安装Git。

Hi XXXXX! You've successfully authenticated, but GITEE.COM does not provide shell access.

=========================================================================
检测到git使用gnutls编译,如果使用http/https协议下载大仓库代码,大概率出现
error: RPC failed; curl 56 GnuTLS recv error (-110)错误,建议重新安装git
=========================================================================


请确认是否重新安装git (Y/N):Y

然后Ubuntu窗口中会显示大量信息,直到出现如下内容,此时直接点击回车即可。

========================================
请注意:
1. 脚本无法直接使用
2. 默认修改pip和apt-get安装源,如不需要请注释对应行
3. 默认安装众多依赖包,如有冲突请百度解决
4. 使用干净系统验证,无法做到万无一失,如遇失败,请尽量百度搜索解决,如果发现问题,欢迎提交PR/issue
!!!请一定注意!!! 下载源码默认执行 git reset --hard 和 git clean -fd,这会导致本地修改全部丢失
!!!请一定注意!!! 下载源码默认执行 git reset --hard 和 git clean -fd,这会导致本地修改全部丢失
!!!请一定注意!!! 下载源码默认执行 git reset --hard 和 git clean -fd,这会导致本地修改全部丢失
如果不需要执行,请注释download_code.sh对应行
-----------------------------------------------
Please note:
1. Scripts cannot be used directly.
2. Modify the pip and apt-get installation sources by default. If the installation sources are not required, comment out the corresponding lines.
3. Many dependency packages are installed by default. If there are conflicts, contact Baidu.
4. Use a clean system for verification, which cannot be foolproof. If the verification fails, try to search for and solve the problem. If any problem is found, submit a PR.
Please pay attention! To download the source code, run 'git reset --hard' and 'git clean -fd' by default. As a result, all local modifications will be lost.
Please pay attention! To download the source code, run 'git reset --hard' and 'git clean -fd' by default. As a result, all local modifications will be lost.
Please pay attention! To download the source code, run 'git reset --hard' and 'git clean -fd' by default. As a result, all local modifications will be lost.
If you do not need to perform this operation, comment out the line corresponding to download_code.sh.

5 4 3 2 1
确认以上信息后,请按回车(Enter)后继续...
After confirming the above information, press Enter to continue...

之后开始安装OpenHarmony开发环境依赖的库,耗时5-10分钟,请耐心等待。直到显示如下内容:

Success,gcc_riscv32 install success.Revision:riscv32-unknown-elf-gcc (GCC) 7.3.0
5,切换bash为默认shell,请在弹出窗口选择NO! | Switching shell to bash. Please select NO!
4,切换bash为默认shell,请在弹出窗口选择NO! | Switching shell to bash. Please select NO!
3,切换bash为默认shell,请在弹出窗口选择NO! | Switching shell to bash. Please select NO!
2,切换bash为默认shell,请在弹出窗口选择NO! | Switching shell to bash. Please select NO!
1,切换bash为默认shell,请在弹出窗口选择NO! | Switching shell to bash. Please select NO!

Switching shell to bash. Please select NO;

Please press Enter to continue

此时点击回车,并在接下来弹出的窗口中,通过方向键选择”No”并点击回车 。然后,在Ubuntu窗口中会显示如下内容:

5s 后开始下载最新代码

--------------------------------------------

请注意,脚本默认强制清理工作目录,执行 git reset --hard;git clean -fd, 这会导致本地工作目录所有修改丢失,请提前保存数据
请注意,脚本默认强制清理工作目录,执行 git reset --hard;git clean -fd, 这会导致本地工作目录所有修改丢失,请提前保存数据
请注意,脚本默认强制清理工作目录,执行 git reset --hard;git clean -fd, 这会导致本地工作目录所有修改丢失,请提前保存数据
确认以上信息后请按Enter确认:

此时,点击回车,完成一键式配置脚本的执行,并显示如下内容:

您使用了--skip-code跳过了代码下载,以下环境未配置,请您注意:
1. hb未安装,如果需要手工安装请cd到代码根目录执行:
    a) 安装:python3.8 -m pip install --user ohos-build
    b) 配置环境变量:编辑~/.bashrc文件,在最后一行增加 export PATH=~/.local/bin:$PATH
2. prebuilts下载脚本未执行,如果需要手工下载请cd到代码根目录执行:sudo bash build/prebuilts_download.sh


恭喜您, OpenHarmony环境搭建完成, 您可以退出当前终端, 重新进入加载新的环境变量
或者您可以在当前终端执行 source ~/.bashrc 立即生效
感谢您的使用

最后,我们输入source ~/.bashrc并点击回车,使环境变量生效。

5.2.2 下载安装repo

在Ubuntu窗口中,按照如下步骤执行,完成repo的安装。

  1. 输入mkdir ~/bin并点击回车,创建目录
  2. 输入curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > ~/bin/repo 并点击回车,下载repo
  3. 输入chmod a+x ~/bin/repo 并点击回车,修改repo权限
  4. 输入pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests并点击回车,安装requests
  5. 输入source ~/.profile并点击回车,使环境变量生效
  6. 输入repo help,如果显示如下内容,则说明repo安装成功
usage: repo COMMAND [ARGS]

repo is not yet installed.  Use "repo init" to install it here.

The most commonly used repo commands are:

  init      Install repo in the current working directory
  help      Display detailed help on a command

For access to the full online help, install repo ("repo init").

致谢

感谢原文提供者:https://thoughts.teambition.com/share/614c499bc9174900411c637b#title=OpenHarmony

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值