package manager: apt

基本概念

Ubuntu 版本代号

都是动物, 都是两个词,并且两个词的首字母相同,从6.06开始,首字母从D开始递增。

中间版本也有代号 Ubuntu 14.10 (Utopic Unicorn) 以及 Ubuntu 14.04.5 LTS (Trusty Tahr) 官网可以查看

1
2
3
4
5
6
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.5 LTS
Release: 20.04
Codename: focal

各版本 代号

PPA(Personal Package Archive)

  • PPA 代表 个人包存档。
  • PPA 允许应用程序开发人员和 Linux 用户创建自己的存储库来分发软件。
  • 使用 PPA,您可以轻松获得更新的软件版本或无法通过官方 Ubuntu 存储库获得的软件。
  • 除了PPA之外,其他操作系统也有类似的概念,例如Debian的APT存储库、Fedora的DNF存储库等。

常见三板斧

1
2
3
sudo add-apt-repository ppa:dr-akulavich/lighttable
sudo apt-get update
sudo apt-get install lighttable-installer

DEB packages

DEB packages(Debian Binary Package)是Debian及其基于Debian的操作系统(如Ubuntu)中使用的软件包格式。它们是一种存档格式,包含软件的二进制文件、配置文件、依赖关系和其他必要的文件。DEB packages是一种用于软件分发和安装的标准格式。

  • 相比于PPA,大部分DEB的包没有source.list.不能自动更新。

repository

存储库是文件的集合,其中包含有关各种软件、其版本和其他一些详细信息(如校验和)的信息。每个 Ubuntu 版本都有自己的一套官方的四个存储库:

  • Main – Canonical-supported free and open-source software. 规范支持的免费和开源软件。
  • Universe – Community-maintained free and open-source software. 社区维护的自由和开源软件。
  • Restricted – Proprietary drivers for devices. 设备的专有驱动程序。
  • Multiverse – Software restricted by copyright or legal issues. 受版权或法律问题限制的软件。

Ubuntu 添加软件源

换源操作官方教程官方软件源

清华教程或者科大教程

1
2
3
sudo nano /etc/apt/sources.list
# add link
# ctrl+X y enter保存

清空缓存

1
2
sudo apt clean && sudo apt autoclean
sudo apt-get update /autoremove /upgrade

PPA vs repository

to read: https://itsfoss.com/ppa-guide/

实践

Ubuntu20.04 install old gcc4.8

寻找支持gcc-4.8的apt源,也就是xenial版本的一个源。

1
2
3
4
5
6
7
8
vim /etc/apt/sources.list

deb http://dk.archive.ubuntu.com/ubuntu/ xenial main
deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe

sudo apt update
//会显示 Get:54 http://dk.archive.ubuntu.com/ubuntu xenial/main i386 Packages [1,196 kB]
sudo apt install gcc-4.8

Ubuntu20.04 install new glibc-2.35

Ubuntu 22.04 有对应的 glibc

1
deb https://mirrors.ustc.edu.cn/ubuntu/ jammy main restricted universe multiverse

原本的思路是安装gcc-11, 结果发现glibc需要增量安装。需要在node5进行测试。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Unpacking libc6:i386 (2.35-0ubuntu3) over (2.31-0ubuntu9.9) ...
Preparing to unpack .../6-libselinux1_3.3-1build2_amd64.deb ...
De-configuring libselinux1:i386 (3.0-1build2) ...
Unpacking libselinux1:amd64 (3.3-1build2) over (3.0-1build2) ...
tar: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /lib/x86_64-linux-gnu/libselinux.so.1)
tar: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /lib/x86_64-linux-gnu/libselinux.so.1)
dpkg-deb: error: tar subprocess returned error exit status 1
dpkg: error processing archive /tmp/apt-dpkg-install-b0waQ0/7-libselinux1_3.3-1build2_i386.deb (--unpack):
dpkg-deb --control subprocess returned error exit status 2
tar: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /lib/x86_64-linux-gnu/libselinux.so.1)
tar: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /lib/x86_64-linux-gnu/libselinux.so.1)
dpkg-deb: error: tar subprocess returned error exit status 1
dpkg: error processing archive /tmp/apt-dpkg-install-b0waQ0/8-libc-bin_2.35-0ubuntu3_amd64.deb (--unpack):
dpkg-deb --control subprocess returned error exit status 2
Errors were encountered while processing:
/tmp/apt-dpkg-install-b0waQ0/4-libc6_2.35-0ubuntu3_amd64.deb
/tmp/apt-dpkg-install-b0waQ0/7-libselinux1_3.3-1build2_i386.deb
/tmp/apt-dpkg-install-b0waQ0/8-libc-bin_2.35-0ubuntu3_amd64.deb
/usr/bin/dpkg: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /lib/x86_64-linux-gnu/libselinux.so.1)
/usr/bin/dpkg: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /lib/x86_64-linux-gnu/libselinux.so.1)
/usr/bin/gdbus: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /lib/x86_64-linux-gnu/libselinux.so.1)
/usr/bin/gdbus: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by /lib/x86_64-linux-gnu/libselinux.so.1)
E: Sub-process /usr/bin/dpkg returned an error code (1)
E: Sub-process dpkg --set-selections returned an error code (1)
E: Couldn't revert dpkg selection for approved remove/purge after an error was encountered!

Install newest gcc

https://gist.github.com/application2000/73fd6f4bf1be6600a2cf9f56315a2d91

update-alternatives 设置软件版本

1
2
3
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 1 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-6.0
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-10 1 --slave /usr/bin/clang++ clang++ /usr/bin/clang++-10
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20

将某个版本加入gcc候选中,最后的数字是优先级.

运行下面命令切换

1
sudo update-alternatives --config gcc

代理 apt-get

apt不能使用export http_proxy的代理,需要额外设置

临时设置

如果只是暂时设置代理,一次性使用:

1
2
3
4
5
sudo -E http_proxy="http://proxy.example.com:port" apt-get update

# or -o 'xxx'
sudo apt -o Acquire::https::proxy="http://<proxy-url>:<port>/" update
sudo apt-get -o Acquire::http::proxy="http://<proxy-url>:<port>/" update

永久设置

Or add lines in /etc/apt/apt.conf

1
2
3
4
5
6
7
Acquire::http::proxy "http://<proxy>:<port>/";
Acquire::ftp::proxy "ftp://<proxy>:<port>/";
Acquire::https::proxy "https://<proxy>:<port>/";

Acquire::http::proxy "http://127.0.0.1:7233/";
Acquire::ftp::proxy "ftp://127.0.0.1:7233/";
Acquire::https::proxy "https://127.0.0.1:7233/";

This was the reason why you could reach proxy but couldn’t get past it, since there is no username password information. So just put that info into it.

1
2
3
Acquire::http::proxy "http://<username>:<password>@<proxy>:<port>/";
Acquire::ftp::proxy "ftp://<username>:<password>@<proxy>:<port>/";
Acquire::https::proxy "https://<username>:<password>@<proxy>:<port>/";

save the file and you are done…

TIP: More better add these lines in another file, /etc/apt/apt.conf.d/80proxy. This will ensure that after a version upgrade changes won’t be lost.

Could not handshake

1
2
Err:3 https://swupdate.openvpn.net/community/openvpn3/repos focal Release
Could not handshake: The TLS connection was non-properly terminated. [IP: 127.0.0.1 7233]
  • 直接将Acquire::https::proxy "https://<proxy>:<port>/";
  • 改成Acquire::https::proxy "http://<proxy>:<port>/";

有时候代理也解决不了,就只能手动安装deb

可以参考jellyfin的教程

问题

E

1
2
3
4
5
6
7
shaojiemike@snode6 ~/github/llvm-3.5/llvm-project  [01:59:12]
> apt update
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)

sudo 解决, or sudo rm /var/lib/apt/lists/lock

etcd start fail

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
See "systemctl status etcd.service" and "journalctl -xe" for details.
invoke-rc.d: initscript etcd, action "start" failed.
● etcd.service - etcd - highly-available key value store
Loaded: loaded (/lib/systemd/system/etcd.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2024-09-05 22:21:44 EDT; 10ms ago
Docs: https://github.com/coreos/etcd
man:etcd
Process: 71732 ExecStart=/usr/bin/etcd $DAEMON_ARGS (code=exited, status=1/FAILURE)
Main PID: 71732 (code=exited, status=1/FAILURE)

Sep 05 22:21:43 huawei systemd[1]: Starting etcd - highly-available key value store...
Sep 05 22:21:44 huawei etcd[71732]: etcd on unsupported platform without ETCD_UNSUPPORTED_ARCH=arm64 set.
Sep 05 22:21:44 huawei systemd[1]: etcd.service: Main process exited, code=exited, status=1/FAILURE
Sep 05 22:21:44 huawei systemd[1]: etcd.service: Failed with result 'exit-code'.
Sep 05 22:21:44 huawei systemd[1]: Failed to start etcd - highly-available key value store.
dpkg: error processing package etcd-server (--configure):
installed etcd-server package post-installation script subprocess returned error exit status 1
dpkg: dependency problems prevent configuration of etcd:
etcd depends on etcd-server; however:
Package etcd-server is not configured yet.

dpkg: error processing package etcd (--configure):
dependency problems - leaving unconfigured
Setting up zsh (5.4.2-3ubuntu3.2) ...
No apport report written because the error message indicates its a followup error from a previous failure.
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Errors were encountered while processing:
etcd-server
etcd
E: Sub-process /usr/bin/dpkg returned an error code (1)

这个错误的主要原因是 etcd 尝试在不受支持的架构上运行(即 arm64),并且你没有设置环境变量 ETCD_UNSUPPORTED_ARCH=arm64 来强制 etcd 运行。因此,etcd 服务启动失败。

要解决这个问题,你可以尝试以下步骤:

  1. 设置环境变量 ETCD_UNSUPPORTED_ARCH=arm64

编辑 etcd.service 的配置文件,使其在启动时包含该环境变量。

  1. 打开 /lib/systemd/system/etcd.service

    1
    sudo nano /lib/systemd/system/etcd.service
  2. [Service] 部分添加以下行:

    1
    Environment="ETCD_UNSUPPORTED_ARCH=arm64"
  3. 保存并关闭文件。

  4. 重新加载 systemd 配置并启动 etcd

完成修改后,执行以下命令来重新加载 systemd 配置并启动 etcd

1
2
sudo systemctl daemon-reload
sudo systemctl start etcd
  1. 检查服务状态

检查 etcd 服务是否正常启动:

1
sudo systemctl status etcd
  1. 查看日志

如果 etcd 服务仍未启动,可以查看 journalctl 以获取详细日志:

1
journalctl -xe

这些步骤应该能帮助你解决 etcd 服务在 arm64 架构上的启动问题。如果问题仍然存在,日志可能会提供进一步的线索。

参考文献

https://blog.csdn.net/feinifi/article/details/121793945

Ubuntu server reInstall

思路

  1. 写U盘(见网上教程,注意备份U盘文件)
  2. 插U盘,开机前根据机器型号使用命令(F2,F4, F12或者Del)进入boit manager,选择从U盘boot
    1. 改引导启动顺序,把U盘启动改到最前面
  3. 根据提示安装ubuntu(服务器不用分区,默认就行,如果自己电脑双系统则需要根据内存设置分区)
  4. 设置root密码并进入root sudo passwd root
  5. 配置实验室网络

下载安装包

官网下载

重装系统怎么保留原本的磁盘文件

只要在安装系统时分出一个/home分区。你可以把Ubuntu的“/”分区看为Windows的C盘,重装Ubuntu时只格式化“/”分区,不格式化“/home”,这样就可以保留“/home”中的数据了。使用的时候就挂载就行

但是假如一开始没分区:

  1. 可以插块新盘当作系统盘,系统安装好之后,把旧的文件系统挂载到新系统的某个目录下
  2. 从旧的文件系统里划出一块区域,安装新系统。
    1. 在你要安装的目标磁盘中,通过删除卷和删除分区操作腾出一块未分配的磁盘空间作为安装区

从已有分区中提取空间

xfs类型不可以直接缩减,只扩不减。如果是ext2,ext3,ext4可以在线缩减,如果xfs盘要缩小就要删除后重新添加

https://www.ywbj.cc/?p=712

非系统根分区LVM缩容

  1. 取消挂载
    系统根分区无法在线取消挂载,所以这时请勿对系统根分区执行任何缩容操作
    1
    umount /lv/ #取消挂载目录
  2. e2fsck检查修复磁盘完整性
    1
    e2fsck -f /dev/vg0/lv0
  3. 缩小系统文件空间,即df -h查看的空间
    不取消挂载,这步会报错,注:一定先减文件系统,再减逻辑卷
    1
    resize2fs /dev/vg0/lv0 10G
  4. 缩小磁盘空间,即lsblk查看的空间
    不执行上面的操作,直接执行这步,虽然成功,但是会操作数据丢失,系统无法启动。
    1
    lvreduce -L 10G /dev/vg0/lv0
  5. 重新挂载
    1
    mount -a
    最后查看lvs空间

系统根分区LVM缩容(救援模式)

正常启动系统进入救援模式 :启动按shift键,出现选择系统界面,按e。找到以单词 linux 开头的行,并在该行的末尾添加以下内容(要到达末尾,只需按下 CTRL+e 或使用 END 键或左右箭头键):

1
systemd.unit=rescue.target

添加完成后,只需按下 CTRL+xF10 即可继续启动救援模式。几秒钟后,你将以 root 用户身份进入救援模式(单用户模式)

需要进一步的研究学习

遇到的问题

暂无

开题缘由、总结、反思、吐槽~~

参考文献

https://blog.csdn.net/weixin_40018873/article/details/109537532

https://www.ywbj.cc/?p=712