1. 下载一个指定版本的ubuntu base文件
Index of /ubuntu-base/releases
tar -xvf ubuntu-base-20.04.1-base-amd64.tar.xz -C .
cd ubuntu-base-20.04.1-base-amd64
2. 添加域名解析的IP
edit etc/resolv.conf
add `nameserver 8.8.8.8`
3. 绑定/dev 到 base文件里的dev
sudo mount --bind /dev dev
4. 修改sysroot路径为sysroot路径
sudo chroot $PWD
5. 安装开发库
apt update
apt-get install libc6-dev
6. 将sysroot里的库软链接地址从绝对路径改成相对路径
apt install symlinks
symlinks -cr /
7. 退出当前用户
exit
8. unmount dev
sudo umount dev
9. 注意:如果报错如下:
Reading package lists... Done
W: GPG error: http://security.ubuntu.com/ubuntu focal-security InRelease: Couldn't create temporary file /tmp/apt.conf.Q3Rffp for passing config to apt-key
E: The repository 'http://security.ubuntu.com/ubuntu focal-security InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
解决办法是:
chmod 1777 /tmp
# 给/tmp赋予正确权限
apt clean
清理apt缓存