使用schroot在Ubuntu 22.04中安装“Ubuntu 16.04子系统
新的高通SDK需要较新的Ubuntu版本,但老的高通SDK却不兼容,因为Ubuntu 22.04的rootfs环境与16.04差异巨大,导致SDK中部分项目在编译时由于依赖不兼容导致编译出错。同时又因为服务器硬件升级导致安装旧版本的Ubuntu系统时,部分硬件由于驱动问题得不到支持,不得不将系统升级到新版本的Ubuntu上来。那又该如何去兼容老的高通SDK编译环境?使用Dockers和LXC容器,会带来文件权限问题,操作非常麻烦;使用PVE或Hyper-V等虚拟机方案也不错,但是硬件资源利用率又是一个问题。schroot就是可以兼容当前用户权限的虚拟化方案。
下面介绍如何安装schroot并部署Ubuntu 16.04 LTS(xenial)根文件系统。
1、安装ubuntu 16.04LTS Rootfs
====================================
sudo apt install debootstrap schroot
mkdir -p ~/chroot
cd ~/chroot
sudo debootstrap --arch=amd64 xenial ./ https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
2、配置chroot环境
====================================
新建配置文件:xenial.conf,放到/etc/schroot/chroot.d/
(注)该配置使用/etc/schroot/default配置修改而来
[xenial]
description=Ubuntu 16.04 LTS (build env)
type=directory
directory=/home/pi/chroot/
users=pi
groups=pi
root-groups=root
aliases=default
修改挂载目录/etc/schroot/default/fstab
(注)workspace和Qualcomm等挂载点需要提前创建好空文件夹,否则自动生成的文件夹可能会有权限问题
# <file system> <mount point> <type> <options> <dump> <pass>
/proc /proc none rw,bind 0 0
/sys /sys none rw,bind 0 0
/dev /dev none rw,bind 0 0
/dev/pts /dev/pts none rw,bind 0 0
/dev/shm /dev/shm none rw,bind 0 0
/home/pi/workspace /home/pi/workspace none rw,bind 0 0
/home/pi/Qualcomm /home/pi/Qualcomm none rw,bind 0 0
/tmp /tmp none rw,bind 0 0
/pkg /pkg none rw,bind 0 0
/prj /prj none rw,bind 0 0
建挂载点的空文件夹
cd ~/chroot
mkdir -p /home/pi/workspace
mkdir -p /home/pi/Qualcomm
3、修复apt证书校验错误问题
====================================
先在host系统中修改chroot系统的/ect/apt/sources.list,将https改为http,然后进入环境,重装证书
sudo schroot
apt --reinstall install ssl-cert ca-certificates
改回/ect/apt/sources.list
然后再apt update更新
(可选)从ubuntu 16.04LTS机器上拷贝/etc/ssl文件夹到chroot对应目录
4、更新系统
====================================
补全apt list
# deb cdrom:[Ubuntu 16.04.7 LTS _Xenial Xerus_ - Release amd64 (20200806)]/ xenial main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.huaweicloud.com/repository/ubuntu/ xenial main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://mirrors.huaweicloud.com/repository/ubuntu/ xenial-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://mirrors.huaweicloud.com/repository/ubuntu/ xenial universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial universe
deb http://mirrors.huaweicloud.com/repository/ubuntu/ xenial-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://mirrors.huaweicloud.com/repository/ubuntu/ xenial multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://mirrors.huaweicloud.com/repository/ubuntu/ xenial-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://mirrors.huaweicloud.com/repository/ubuntu/ xenial-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu xenial partner
# deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.huaweicloud.com/repository/ubuntu/ xenial-security main restricted
# deb-src http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://mirrors.huaweicloud.com/repository/ubuntu/ xenial-security universe
# deb-src http://security.ubuntu.com/ubuntu xenial-security universe
deb http://mirrors.huaweicloud.com/repository/ubuntu/ xenial-security multiverse
# deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse
更新系统
apt update
apt upgrade
5、安装编译环境
====================================
安装库工具
sudo schroot
apt install bash-completion bc gcc git-core gnupg flex bison build-essential zip unzip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev libgl1-mesa-dev libxml2-utils xsltproc openjdk-8-jdk libssl-dev libxml-simple-perl device-tree-compiler
安装python 2.7.18
(注)使用apt install python安装的版本是2.7.10,该版本对部分项目存在兼容性问题,因此需要手动编译安装
安装python编译环境
sudo schroot
apt install pkg-config libreadline-dev libc6-dev libncursesw5-dev build-essential gdb pkg-config libbz2-dev libffi-dev libgdbm-dev liblzma-dev libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev lzma lzma-dev tk-dev uuid-dev zlib1g-dev libmpdec-dev
手动编译
schroot
wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz
tar xf Python-2.7.18.tgz
cd Python-2.7.18
./configure --enable-optimizations
make -j32
make install
安装pip,不要使用root
schroot
wget https://bootstrap.pypa.io/pip/get-pip.py
chmod +x get-pip.py
python2 get-pip.py
python3 get-pip.py
# 换源
pip2 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 部分SDK需要的Python环境
pip2 install pycrypto
pip3 install pycryptodome
安装bear
schroot
pip3 install bear
设置python复用
sudo schroot
update-alternatives --install /usr/bin/python python /usr/local/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
update-alternatives --config python
5、安装ccache
wget https://github.com/ccache/ccache/releases/download/v4.10.2/ccache-4.10.2-linux-x86_64.tar.xz
tar xf ccache-4.10.2-linux-x86_64.tar.xz
cd ccache-4.10.2-linux-x86_64
sudo schroot
make install
6、问题解决方案:
====================================
1、无法显示中文
安装字符
sudo schroot
apt install language-pack-zh-hans locales
# dpkg-reconfigure locales
修改/etc/locale.gen
# This file lists locales that you wish to have built. You can find a list
# of valid supported locales at /usr/share/i18n/SUPPORTED, and you can add
# user defined locales to /usr/local/share/i18n/SUPPORTED. If you change
# this file, you need to rerun locale-gen.
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
修改/etc/default/locale
# File generated by update-locale
LANG="zh_CN.UTF-8"
LANGUAGE="zh_CN:zh:en_US:en"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
生成字符集
locale-gen
设置时区
vim /etc/timezone
Asia/Shanghai
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
3、修改脚本解释器
dpkg-reconfigure dash
选【否】
4、配置user环境,将以下文件从源主机上拷贝
.bash_history
.bash_logout
.bashrc
.profile
.gitcommit
.gitconfig
.viminfo
.cache/
.config/
.local/
.ssh/
将以下环境变量添加到.bashrc
# set PATH so it includes user's private bin directories
export PATH=~/.local/bin:$PATH
export USE_CCACHE=1
export CCACHE_DIR=/var/tmp/ccache
export CCACHE_EXEC=/usr/local/bin/ccache
export CCACHE_COMPRESS=1
# export CCACHE_COMPRESSLEVEL=3
export SOONG_GEN_COMPDB=1
export SOONG_GEN_COMPDB_DEBUG=1
export ARMLMD_LICENSE_FILE=/pkg/qct/software/arm/RVDS/5.01bld94/license.dat
export HEXAGON_ROOT=$HOME/Qualcomm/HEXAGON_Tools
export LANG="zh_CN.UTF-8"
export LANGUAGE="zh_CN:zh:en_US:en"
export LC_NUMERIC="zh_CN.UTF-8"
export LC_TIME="zh_CN.UTF-8"
export LC_MONETARY="zh_CN.UTF-8"
export LC_PAPER="zh_CN.UTF-8"
export LC_IDENTIFICATION="zh_CN.UTF-8"
export LC_NAME="zh_CN.UTF-8"
export LC_ADDRESS="zh_CN.UTF-8"
export LC_TELEPHONE="zh_CN.UTF-8"
export LC_MEASUREMENT="zh_CN.UTF-8"