下载时速度慢
使用cbsd创建ubuntu jail的时候
cbsd jconstruct-tui
提示:
no base dir in: /usr/jails/basejail/base_amd64_amd64_jammy
Select base sources:0 .. CANCELa .. build b .. extract c .. pkg d .. repo
选了pkg没找到
fetch: https://pkg.convectix.com/FreeBSD:jammy:amd64/latest/distribution_amd64_amd64_jammy.tgz: Not Found
选了repo太慢:
config-based sources: https://dl.bsdstore.ru/releases/Linux/amd64/jammy/base.txz
register_base: no such bases here: /usr/jails/basejail/base_amd64_amd64_jammy
Looking for official Linux mirror:
retrieve base.txz from dl.bsdstore.ru, size: 148m
/usr/jails/tmp/src.26470/base.txz 0% of 147 MB 10 kBps 04h03m^C
这是跑到俄罗斯去下载base.txz了,速度非常慢。有时候还会找到https://dl.bsdstore.ru/releases/amd64/amd64/jammy/base.txz去下载,导致完全连不上
config-based sources: https://dl.bsdstore.ru/releases/Linux/amd64/jammy/base.txz
register_base: no such bases here: /usr/jails/basejail/base_amd64_amd64_jammy
Looking for official Linux mirror:
retrieve base.txz from dl.bsdstore.ru, size: 148m
/usr/jails/tmp/src.39578/base.txz 0% of 147 MB 10 kBps^[[A
/usr/jails/tmp/src.39578/base.txz 0% of 147 MB 77 kBps
/usr/jails/tmp/src.39578/base.txz 0% of 147 MB 9 kBps 02h36m^C^CPlease set unregister_base: arch
retry: 2/2
Not found
REPO: https://bsdstore.ru
found new mirror for jammy: https://dl.bsdstore.ru
Looking for: https://dl.bsdstore.ru/releases/amd64/amd64/jammy/base.txz
fetch: https://dl.bsdstore.ru/releases/amd64/amd64/jammy/base.txz: Not Found
retry: 1/2
fetch: https://dl.bsdstore.ru/releases/amd64/amd64/jammy/base.txz: Not Found
retry: 2/2
base not found: https://dl.bsdstore.ru/releases/amd64/amd64/jammy/base.txz
Not found data
Please set unregister_base: arch
于是只好先下载到本地,然后
选择使用本地base.txz
菜单里选择“ b .. extract ” ,也就是指定本地文件。
当然一开始走了弯路,使用了Ubuntu官网的base文件
使用Ubuntu官网base文件
Ubuntu Base 22.04.4 LTS (Jammy Jellyfish)
wget https://cdimage.ubuntu.com/ubuntu-base/releases/jammy/release/ubuntu-base-22.04.4-base-amd64.tar.gz
比如放置在/home/root/download/目录,并改名为base.txz 。这个文件只有28.45M...跟官方的相比相差太多了。
但是安装完之后报错:
x var/tmp/
mkdir: /usr/jails/basejail/base_amd64_amd64_jammy/var/db: No such file or directory
cp: /usr/jails/basejail/base_amd64_amd64_jammy/etc/ssl/cert.pem: No such file or directory
timeout: failed to run command ‘pkg’: No such file or directory
Bases registered: /usr/jails/basejail/base_amd64_amd64_jammy
后来发现cbsd官网base.txz位置在:https://dl.bsdstore.ru/releases/Linux/amd64/jammy/base.txz
而且大小是148MB,所以从ubuntu官网下载的base文件是不行的。重新下载,cbsd官网从国内连接很慢,但是从美国连接很快,想办法下载到本地,然后放置到/home/root/download目录。
(再来尝试一下,一开始这个文档都没有留存命令,所以到底是啥命令已经不知道了....多亏后来又试出来)
cbsd创建jail的命令:
cbsd jconstruct-tui
使用CBSD官网base文件
菜单里选择“ b .. extract ” ,也就是指定本地文件
/home/root/download/base.txz
这样就创建好了。
但是由于一开始不太懂,还下错了base.txz文件,所以走了很多弯路,以至于后来创建成功ubuntu jail子系统后,还以为没有创建成功,误以为这cbsd起linux的jail这个功能有问题。
后来才明白了,所谓Ubuntu jail子系统,就是创建一个FreeBSD jail,然后在jail里面再安装linux虚拟....好吧,其实这种理解也不完全正确,因为Ubuntu jail里确实只有一个进程,没有经过FreeBSD的周转。
# ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 64600 0.0 0.0 7456 3876 pts/1 R+ Jun15 0:00 ps -aux
root 64570 0.0 0.0 2876 1764 pts/1 S Jun15 0:00 /bin/sh
去掉ps哪个进程,这个Ubuntu jail子系统里只有64570这一个进程,相当省资源。
按照cbsd的手册来创建linux jail
由于前面的弯路,终于静下心来按照cbsd官网手册来操作创建Ubuntu jail 。但是使用下来,需要再手动创建Ubuntu的虚拟子系统。
首先用cbsd创建一个jail子系统:
cbsd jcreate jname=ubu jprofile=ubuntu_focal allow_raw_sockets=1
cbsd jstart ubu
登录子系统
cbsd jlogin ubu
这时候我们发现这个jail子系统还是FreeBSD系统:
cbsd jlogin ubu
Last login: Mon Jun 17 13:57:47 on pts/3
FreeBSD 14.1-RELEASE (GENERIC) releng/14.1-n267679-10e31f0946d8
后面就简单了,我们在FreeBSD jail子系统里,再安装Ubuntu虚拟子系统
安装centos子系统
pkg install emulators/linux_base-c7
当然由于各种原因,现在大家用cenos的越来越少了。
安装ubuntu子系统
首先使用pkg安装debootstrap
pkg install debootstrap
然后按照提示安装Ubuntu,debootstrap可以自由选择ubuntu的版本,比如bionic18.04、focal20.04和jammy22.04
debootstrap bionic /compat/ubuntu
安装好后,执行
chroot /compat/ubuntu /bin/bash
groups: cannot find name for group ID 0
groups: cannot find name for group ID 5
I have no name!@ubu:/#
I have no name!@ubu:/#
I have no name!@ubu:/#
I have no name!@ubu:/# uname -a
Linux ubu.my.domain 5.15.0 FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC x86_64 x86_64 x86_64 GNU/Linux
可见已经是linux 了!
Ubuntu apt 加速
修改/etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
deb http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
现在的问题是没有apt .... 估计可以用dpkg解决,不过不去管它了,前面装的版本是bionic ,也就是18.04版本,还是改成22 jammy版本吧(当然最后我们知道没有apt是因为用了错误的base.txz文件导致的)
安装Ubuntu22.04子系统
debootstrap jammy /compat/ubuntuchroot /compat/ubuntu /bin/bash
正常情况下这样就装好了。
以下部分都是因为使用了错误base.txz文件才走了很多弯路。
踩坑记录,只是为了留档
以下部分,一直到官方例子focal成功,都是踩坑记录留档,正常情况下不会碰到,大家也不需要去看。
尝试Ubuntu子系统里装apt
进入Ubuntu子系统之后还是没有apt,不慌,下载apt.deb
因为本系统是在FreeBSD的jail里面,所以是切换到FreeBSD,直接wget下载即可:
wget http://www.ftp.ne.jp/Linux/packages/ubuntu/archive/pool/main/a/apt/apt_2.9.4_amd64.deb
http://www.ftp.ne.jp/Linux/packages/ubuntu/archive/pool/main/a/apt/apt_2.9.4_amd64.deb
切换到ubuntu安装deb报错:
dpkg -i apt_2.9.4_amd64.deb
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 5 package 'dpkg':missing 'Description' field
dpkg: warning: parsing file '/var/lib/dpkg/status' near line 5 package 'dpkg':missing 'Architecture' field
Selecting previously unselected package apt.
(Reading database ... 0 files and directories currently installed.)
Preparing to unpack apt_2.9.4_amd64.deb ...
Unpacking apt (2.9.4) ...
dpkg: dependency problems prevent configuration of apt:apt depends on base-passwd (>= 3.6.1) | adduser; however:Package base-passwd is not installed.Package adduser is not installed.apt depends on gpgv; however:Package gpgv is not installed.apt depends on libapt-pkg6.0t64 (>= 2.9.4); however:Package libapt-pkg6.0t64 is not installed.apt depends on ubuntu-keyring; however:Package ubuntu-keyring is not installed.apt depends on libc6 (>= 2.38); however:Package libc6 is not installed.apt depends on libgcc-s1 (>= 3.3.1); however:Package libgcc-s1 is not installed.apt depends on libgnutls30t64 (>= 3.8.1); however:Package libgnutls30t64 is not installed.apt depends on libseccomp2 (>= 2.4.2); however:Package libseccomp2 is not installed.apt depends on libstdc++6 (>= 13.1); however:Package libstdc++6 is not installed.apt depends on libsystemd0; however:Package libsystemd0 is not installed.dpkg: error processing package apt (--install):dependency problems - leaving unconfigured
Errors were encountered while processing:apt
又下载了两个文件
wget http://www.ftp.ne.jp/Linux/packages/ubuntu/archive/pool/main/a/apt/libapt-pkg6.0t64_2.9.4_amd64.deb
wget http://www.ftp.ne.jp/Linux/packages/ubuntu/archive/pool/main/a/apt/apt-utils_2.9.4_amd64.deb
还是不管用,缺的东西有点多啊。
查看debootstrap jammy /compat/ubuntu时候的log信息,发现有apt的deb安装包。
于是进入jammy ubuntu,发现apt的deb包放在这个目录:/var/cache/apt/archives
里面有apt包,于是安装,并根据提示安装需要的包:
dpkg -i apt_2.4.5_amd64.deb
dpkg -i libapt-pkg6.0_2.4.5_amd64.deb
dpkg -i libstdc++6_12-20220319-1ubuntu1_amd64.deb
dpkg -i libxxhash0_0.8.1-1_amd64.deb dpkg -i libapt-pkg6.0_2.4.5_amd64.deb
还是报错:
apt update
/usr/lib/apt/methods/http: error while loading shared libraries: libnettle.so.8: cannot open shared object file: No such file or directory
Reading package lists... Done
E: Method http has died unexpectedly!
E: Sub-process http returned an error code (127)
E: Method /usr/lib/apt/methods/http did not start correctly
W: No sandbox user '_apt' on the system, can not drop privileges
E: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease
E: Some index files failed to download. They have been ignored, or old ones used instead.
I have no name!@ubu:/var/cache/apt/archives#
安装了很多deb包之后,执行
/var/cache/apt/archives# apt full-upgrade
Reading package lists... Done
Building dependency tree... Done
You might want to run 'apt --fix-broken install' to correct these.
按照提示,fix一下:
apt --fix-broken install
Reading package lists... Done
Building dependency tree... Done
Correcting dependencies... failed.
The following packages have unmet dependencies:apt : Depends: adduser but it is not installableDepends: gpgv but it is not installable orgpgv2 but it is not installable orgpgv1 but it is not installableDepends: ubuntu-keyring but it is not installableDepends: libsystemd0 but it is not installableRecommends: ca-certificates but it is not installablelibapt-pkg6.0 : Depends: libsystemd0 (>= 221) but it is not installablelibgcrypt20 : Depends: libgpg-error0 (>= 1.27) but it is not installablelibgnutls30 : Depends: libgmp10 (>= 2:6.2.1+dfsg) but it is not installableDepends: libhogweed6 (>= 3.6) but it is not installableDepends: libnettle8 (>= 3.7~) but it is not installablelibp11-kit0 : Depends: libffi8 (>= 3.4) but it is not installable
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages.
E: Unable to correct dependencies
还是有很多
dpkg -i libbz2-1.0_1.0.8-5build1_amd64.deb libgcrypt20_1.9.4-3ubuntu3_amd64.deb liblz4-1_1.9.3-2build2_amd64.deb liblzma5_5.2.5-2ubuntu1_amd64.deb libsystemd0_249.11-0ubuntu3_amd64.deb libudev1_249.11-0ubuntu3_amd64.deb libzstd1_1.4.8+dfsg-3build1_amd64.deb zlib1g_1%3a1.2.11.dfsg-2ubuntu9_amd64.deb gcc-12-base_12-20220319-1ubuntu1_amd64.deb
还差,继续安装
dpkg -i adduser_3.118ubuntu5_all.deb gpgv_2.2.27-3ubuntu2_amd64.deb ubuntu-keyring_2021.03.26_all.deb libsystemd0_249.11-0ubuntu3_amd64.deb ca-certificates_20211016_all.deb libgpg-error0_1.43-3_amd64.deb libgmp10_2%3a6.2.1+dfsg-3ubuntu1_amd64.deb libhogweed6_3.7.3-1build2_amd64.deb libnettle8_3.7.3-1build2_amd64.deb libffi8_3.4.2-4_amd64.deb
继续安装
dpkg -i passwd_1%3a4.8.1-2ubuntu2_amd64.deb debconf_1.5.79ubuntu1_all.deb libsystemd0_249.11-0ubuntu3_amd64.deb
继续安装
dpkg -i libsystemd0_249.11-0ubuntu3_amd64.deb openssl_3.0.2-0ubuntu1_amd64.deb debconf-i18n_1.5.79ubuntu1_all.deb libsystemd0_249.11-0ubuntu3_amd64.deb
继续
dpkg -i libaudit1_1%3a3.0.7-1build1_amd64.deb libssl3_3.0.2-0ubuntu1_amd64.deb libpam0g_1.4.0-11ubuntu2_amd64.deb libselinux1_3.3-1build2_amd64.deb libsemanage2_3.3-1build2_amd64.deb sensible-utils_0.0.17_all.deb
放弃了,这种笨方法不行啊。理论上应该是安装ubuntu的时候,这些库就应该安装好了。(对啊对啊,普通安装确实apt是安装好的,咱这是手动下载错误的base.txz文件的下场)
安装目录下的所有deb包
dpkg -i *.deb
还是不行,现在pkg update 可以执行,但是感觉有些问题,
而执行fix则报缺很多东西
apt --fix-broken install
Reading package lists... Done
Building dependency tree... Done
Correcting dependencies... failed.
The following packages have unmet dependencies:adduser : Depends: debconf (>= 0.5) but it is not installable ordebconf-2.0 but it is not installableapt : Depends: libsystemd0 but it is not installableca-certificates : Depends: debconf (>= 0.5) but it is not installable ordebconf-2.0 but it is not installableconsole-setup-linux : Depends: keyboard-configuration (= 1.205ubuntu3) but it is not installabledbus : Depends: libsystemd0 but it is not installabledebconf-i18n : Depends: debconf (= 1.5.79ubuntu1) but it is not installableDepends: liblocale-gettext-perl but it is not installableinit-system-helpers : Depends: perl-base (>= 5.20.1-3) but it is not installableiproute2 : Depends: debconf (>= 0.5) but it is not installable or
明白了,我创建的是focal,但是虚拟机里安装的是jammy,难道是这里不兼容?
现在改成创建jammy
cbsd jcreate jname=ubu jprofile=ubuntu_focal allow_raw_sockets=1
To edit VM properties use: cbsd jconfig jname=ubjammy
To start VM use: cbsd jstart ubjammy
To stop VM use: cbsd jstop ubjammy
To remove VM use: cbsd jremove ubjammy
For attach VM console use: cbsd jlogin ubjammy
login竟然会退出:
cbsd jlogin ubjammy
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0 x86_64)* Documentation: https://help.ubuntu.com* Management: https://landscape.canonical.com* Support: https://ubuntu.com/proThis system has been minimized by removing packages and content that are
not required on a system that users do not log into.To restore this content, you can run the 'unminimize' command.
Last login: Sat Jun 15 09:54:07 UTC 2024 on pts/1
Cannot execute /bin/bash: No such file or directory
看来要完全用官方的例子才行(其实这里是可以用jexec ubjammy sh 进入的,而且进去就是linux环境)
官方例子focal版本安装成功
cbsd jcreate jname=focal jprofile=ubuntu_focal allow_raw_sockets=1
进入jail之后
debootstrap focal /compat/ubuntu
再执行
chroot /compat/ubuntu /bin/bash
即可进入linux
也可以在host主机执行:
jexec focal chroot /compat/ubuntu /bin/bash
groups: cannot find name for group ID 0
groups: cannot find name for group ID 5
I have no name!@focal:/# uname -a
Linux focal.my.domain 5.15.0 FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC x86_64 x86_64 x86_64 GNU/Linux
但是进入之后apt还是没有(当然最后我们知道没有apt是因为用了错误的base.txz文件导致的) 。
安装apt参考这个文档:FreeBSD jail虚拟容器里装ubuntu系统没有apt命令怎么办?-CSDN博客
我怀疑没有apt,是因为我使用了错误的base.txz导致的,如果用官方的,应该没问题。但是现在找不到从哪里选了?(终于开窍了)
后来是重新安装了新版本的cbsd,再创建的时候用了正确的base.txz文件,这样创建好,apt存在了。apt update之后就能使用了。
总结
因为对cbsd不熟悉,所以在使用了错误的base.txz文件后,一步错,步步错。没有这个错误的文档的话,任何一种安装方法都是可以成功的,不管是
cbsd jconstruct-tui
还是
cbsd jcreate jname=ubu jprofile=ubuntu_focal allow_raw_sockets=1
cbsd jstart ubu
本文档当初为了解决下载base.txz速度慢问题才记录的,但最终影响到apt文件包的情况,所以水了这么一大篇文档。
不过也有所得,就是那个错误的base.txz文件是Ubuntu官网的文件,要比cbsd官网提供的文件小很多,如果真要再精简Ubuntu系统,这也是一种解决方案。
更详细的安装文档可以参考这篇:FreeBSD通过CBSD管理低资源容器jail来安装Ubuntu子系统实践-CSDN博客
调试
创建之后cbsd jstart jammy的时候报错
Check environment script: 00.check_distribution.sh
populate jails data from: /usr/jails/basejail/base_amd64_amd64_jammy ...
Applying custom skel dir template from: /usr/jails/basejail/base_amd64_amd64_jammy
mkdir: /usr/jails/jails/jammy/lib/init/rw: Read-only file system
mountfstab warning: mountfstab: unable to create mountpoint for tmpfs tmpfs: /usr/jails/jails/jammy/lib/init/rw
mountfstab warning: mountfstab: read-only location? Skip mount for: /usr/jails/jails/jammy/lib/init/rw
mkdir: /usr/jails/jails/jammy/dev/fd: No such file or directory
mountfstab warning: mountfstab: unable to create mountpoint for fdescfs fdescfs: /usr/jails/jails/jammy/dev/fd
mountfstab warning: mountfstab: read-only location? Skip mount for: /usr/jails/jails/jammy/dev/fd
这是另一台机器测试的时候报错,不知道怎么回事,先搁置。