Fedora COSMIC Atomic 后需要安装必要的软件

安装第三方源

docker配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
curl -fsSL https://download.docker.com/linux/fedora/docker-ce.repo -o docker-ce.repo

sudo install -o root -g root -m 644 docker-ce.repo /etc/yum.repos.d/docker-ce.repo

sudo rm -f /etc/yum.repos.d/docker-ce.repo

sudo tee /etc/yum.repos.d/docker-ce.repo > /dev/null <<'EOF'
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/fedora/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/fedora/gpg
EOF

安装nofree源

1
2
3
rpm-ostree install \
https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm \
https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

安装高频软件

1
2
3
rpm-ostree install fcitx5 fcitx5-rime fcitx5-configtool fcitx5-gtk3 fcitx5-gtk4 fcitx5-qt5 fcitx5-qt6 librime-lua \
vim net-tools host-spawn \
docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
1
systemctl reboot
阅读更多

Fedora Atomic安装docker

安装软件包

下载 docker 官方 repo 文件到系统 etc

ostree 只读,不能 dnf config‑manager

1
2
curl -fsSL https://download.docker.com/linux/fedora/docker-ce.repo -o docker-ce.repo
sudo install -o root -g root -m 644 docker-ce.repo /etc/yum.repos.d/docker-ce.repo

替换 docker‑ce.repo 为阿里云源

1
2
3
4
5
6
7
8
9
10
sudo rm -f /etc/yum.repos.d/docker-ce.repo

sudo tee /etc/yum.repos.d/docker-ce.repo > /dev/null <<'EOF'
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/fedora/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/fedora/gpg
EOF

安装软件

1
2
3
sudo rpm-ostree install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

systemctl reboot

配置docker服务

1
2
3
sudo systemctl enable --now docker
sudo usermod -aG docker $USER # 没有报错,但实际会执行失败
sudo gpasswd -a s$USER docker # 用此命令替换,仍然执行失败

失败原因
docker 组由 docker‑ce rpm 在 **/usr/lib/group**注册,没有写入可写的 /etc/group。
gpasswd / usermod 只会读写 /etc/group

把 docker 组条目复制到可写的 /etc/group

1
2
getent group docker | sudo tee -a /etc/group
grep docker /etc/group

输出应当看到 docker:x:964:。

此时再次执行sudo usermod -aG docker $USER 。把用户加入 docker 组。通过id命令查询到groups 列表里面出现 docker。

测试

1
docker run --rm hello-world

Fedora Atomic安装node.js和npm

原因

Atomic /usr 是只读OSTree镜像;系统nodejs的npm默认全局目录指向 /usr/lib/node_modules,root也无法写入,会直接报错 EACCES。

sudo npm‑g 不仅会权限报错,npm脚本以root执行还有安全风险。

通过NVM安装

node、npm、全部全局包都放在家目录,完全不碰系统layered包。

1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

写入shell配置,重启终端:

1
source ~/.bashrc

安装LTS版本:

1
2
3
4
5
nvm install --lts
nvm use --lts

# 查看默认的全局包位置,通常在用户的home目录下
npm config get prefix

安装成功之后就可以不需要sudo安装全局包:

1
npm install -g typescript

全程不需要sudo,全局包自动放在 ~/.nvm/versions/node/* 下面。

优点:可以随意切换node版本;系统rpm‑ostree操作完全不影响node环境。


排查命令

1
2
3
4
5
6
7
8
# npm全局安装路径
npm config get prefix

# 看PATH是否包含npm‑global bin
echo $PATH

# 列出已经安装的全局包
npm list -g --depth=0

cosmic桌面系统中增加dns配置解决github无法访问的问题

GitHub访问慢可能的原因

GitHub访问慢大概率是是因为DNS污染,无法解写GitHub域名。

解决方案

通常可以通过本机的网络的DNS配置来解决。现代Linux系统DNS配置通常是由取自DHCP服务,由系统网络管理服务自动配置,因此我们可以通过修改本机网络服务,增加额外的DNS服务器即可解决此问题。在cosmic桌面环境中可以在 cosmic settings → network & wireless → 选择链接的网络上connected(三个点)→ settings → IPV4 settings → Additional DNS servers 增加DNS服务配置,如果增加多个可以用英文逗号隔开,如223.5.5.5,8.8.8.8。

在单系统中如何隐藏grub菜单

在单系统中隐藏grub菜单

在 Fedora 44 中,可以启用 GRUB 的自动隐藏功能让启动过程更流畅。启用后,每次启动都会直接进入系统,如果需要时,可以在启动时按 F8 或长按左 Shift 键唤出菜单。具体操作如下:

1
2
sudo grub2-editenv - set menu_auto_hide=1
sudo grub2-editenv - unset menu_show_once

执行后重启电脑,GRUB 菜单应该就不再显示了。

如果之后想恢复菜单,可以取消这个设置:

1
2
sudo grub2-editenv - unset menu_auto_hide

注意:将值设为 0 是无效的,必须使用 unset 命令来移除这个变量

参考资料

阅读更多

在Pop!OS 24.04安装常用软件

安装中文输入法

  1. iBus输入法在PopOS 24.04上不能正常使用,需要安装fcitx输入法。

  2. 安装fcitx输入法:

    1
    2
    3
    4
    5
    6
    7
    8
    sudo apt install fcitx5 \
    fcitx5-chinese-addons \
    fcitx5-rime \
    fcitx5-frontend-gtk3 \
    fcitx5-frontend-gtk4 \
    fcitx5-frontend-qt4 \
    fcitx5-frontend-qt5 \
    fcitx5-frontend-qt6
  3. 安装fcitx5以后在系统设置中将fcitx5设置随系统启动。在cosmic settings → applications → startup applications 中添加fcitx5启动项。

  4. 重启系统后,在系统设置中将fcitx5设置为默认输入法。在language support 中将 keyboard input method system修改成fcitx5。或者使用im-config -n fcitx5将默认输入法设置成fcitx5。

  5. 设置输入法适应的环境变量

    1
    2
    3
    4
    echo 'QT_IM_MODULE=fcitx5' >> ~/.pam_environment
    echo 'QT_IM_MODULE=ibus' >> ~/.pam_environment
    echo 'XMODIFIERS=@im=fcitx5' >> ~/.pam_environment
    source ~/.pam_environment

注意:cosmic使用Wayland,相关的配置参考 https://fcitx-im.org/wiki/Using_Fcitx_5_on_Wayland
有指导建议在~/.config/environment.d/im.conf 中做上述配置,实际测试过程中对部分应用(如Firefox、LibreOffice等)无法生效。

  1. 再次重启系统就可以用fcitx5愉快的输入了。

解决WPS缩放问题

方式一:设置系统缩放

在cosmic settings → applications → x11 applications compatibility 中将x11 application scaling设置为: Maximum compatibility mode。

方式二:设置应用缩放

在/usr/share/applications(或者 Faltpak应用安装)目录下找到WPS的.desktop文件,在Exec=...前增加Exec=env QT_FONT_DPI=144 ...。如果采用的flatpak安装则可以使用flatpak override --user --env=QT_FONT_DPI=144 com.wps.Office,com.wps.Office需要替换成实际安装的Application ID。

QT应用中默认的DPI是96,对应的缩放比例是1.0,以此类推DPI和缩放比例对应关系如下:

DPI(QT_FONT_DPI) 缩放比例(QT_SCREEN_SCALE_FACTORS)
96 1.0
120 1.25
144 1.5
192 2.0
288 3.0

这两种方式各有利弊,第一种方式会导致WPS显示发虚;第二种方式在输入时Fcitx5输入法无法自动缩放。

解决WPS中Fcitx5输入面板过小的问题

  1. fcitx5的配置文件在~/.config/fcitx5/conf/classicui.conf
  2. 有三个配置型控制输入面板的缩放
1
2
3
4
5
6
# Use Per Screen DPI on X11
PerScreenDPI=False
# Force font DPI on Wayland
ForceWaylandDPI=0
# Enable fractional scale under Wayland
EnableFractionalScale=True
  • 第一个控制fcitx5在x11应用中如何缩放;
  • 第二、三个控制Wayland应用中缩放;为了统一控制fcitx5大小,我们同时关闭x11和Wayland的缩放功能,只有字体大小来控制面板大小。完整配置如下:
1
2
3
4
5
6
7
8
# Font
Font="Sans Serif 20" # 默认10号字,20大约等于200%缩放
# Use Per Screen DPI on X11
PerScreenDPI=False # 关闭x11自动缩放
# Force font DPI on Wayland
ForceWaylandDPI=48 # 系统200%缩放会导致在Wayland过大,把100%系统下对应的96缩小一半则刚刚好
# Enable fractional scale under Wayland
EnableFractionalScale=False # 关闭Wayland自动缩放

修改~/.config/fcitx5/conf/classicui.conf文件以后要重启fcitx5服务,保证新的配置已经生效。

解决了fcitx5面板缩放问题,配合wps的flatpak override --user --env=QT_FONT_DPI=144 com.wps.Office 缩放配置,就完美解决未随系统缩放、模糊、fcitx5过小各种问题。

其他问题

WPS在Linux有个一个很恶心的bug,如果添加过新的字体需要reboot一下系统,否则WPS登录界面会卡死。在Linux系统中用LibreOffice替换WPS Office。

Linux 文件权限简记

数字权限使用格式

在这种使用方式中,首先我们需要了解数字如何表示权限。 首先,我们规定 数字 4 、2 和 1表示读、写、执行权限,即 r=4,w=2,x=1 。此时其他的权限组合也可以用其他的八进制数字表示出来,

如:

1
2
3
rwx = 4 + 2 + 1 = 7
rw = 4 + 2 = 6
rx = 4 +1 = 5

即:

  • 若要同时设置 rwx (可读写运行) 权限则将该权限位 设置 为 4 + 2 + 1 = 7
  • 若要同时设置 rw- (可读写不可运行)权限则将该权限位 设置 为 4 + 2 = 6
  • 若要同时设置 r-x (可读可运行不可写)权限则将该权限位 设置 为 4 +1 = 5

命令格式 chmod [可选项] <mode> <file…>

在WSL中安装NixOS

在WSL中安装NixOS

Install NixOS-WSL

First, download nixos.wsl from the latest release.1 https://github.com/nix-community/NixOS-WSL/releases/tag/2505.7.0

If you have WSL version 2.4.4 or later installed, you can open (double-click) the .wsl file to install it. It is also possible to perform the installation from a PowerShell:

1
wsl --install --from-file nixos.wsl

nixos.wsl must be the path to the file you just downloaded if you’re running the command in another directory.

You can use the --name and --location flags to change the name the distro is registered under (default: NixOS) and the location of the disk image (default: %localappdata%\wsl\{some random GUID}). For a full list of options, refer to wsl --help

To open a shell in your NixOS environment, run wsl -d NixOS, select NixOS from the profile dropdown in Windows Terminal or run it from your Start Menu. (Adjust the name accordingly if you changed it)

  • 参考资料

https://nix-community.github.io/NixOS-WSL/install.html

配置vscode远程访问

The VSCode Remote server can not be run as-is on NixOS, because it downloads a nodejs binary that requires /lib64/ld-linux-x86-64.so.2 to be present, which isn’t the case on NixOS.

There are two options to get the server to run. Option 1 is more robust but might impact other programs. Option 2 is a little bit more brittle and sometimes breaks on updates but doesn’t influence other programs. Both options require wget to be installed:

1
2
3
environment.systemPackages = [
pkgs.wget
];

Option 1: Set up nix-ld
nix-ld is a program that provides /lib64/ld-linux-x86-64.so.2, allowing foreign binaries to run on NixOS.

To set it up, add the following to your configuration:

programs.nix-ld.enable = true;

  • 参考资料

https://nix-community.github.io/NixOS-WSL/how-to/vscode.html

Linux下如何修改分区Label

如何修改Linux分区标签Label

安装系统时如果没有为分区打标签,正常启动启动后不同文件管理器会显示对分区显示不同的名称。有的文件管理器会隐藏系统分区,显示其他分区类型(同一类分区类型特别容易误操作)。因此可以根据自己分区用途来设定不同的分区标签。

  • 查询系统分区情况
    lsblk -o name,mountpoint,label,size,uuid

  • 修改ntfs分区标签

    需要先安装ntfs3g软件,再通过ntfslabel命令修改;

  • 修改btrfs分区标签
    sudo btrfs filesystem label / NixOS

  • 修改ext3/ext4分区标签
    e2label device newlabel

nix-rebuild命令

nix-rebuil命令

1
2
3
4
5
6
7
nixos-rebuild {switch | boot | test | build | dry-build | dry-activate | edit | build-vm | build-vm-with-bootloader}
[{ --upgrade | --upgrade-all }] [--install-bootloader] [--no-build-nix] [--fast] [--rollback] [--builders builder-spec]
[--flake flake-uri] [--override-input input-name flake-uri]
[{ --profile-name | -p } name]
[--build-host host] [--target-host host] [--use-remote-sudo]
[--show-trace] [-I path] [{--verbose | -v}] [{--impure}] [{--max-jobs | -j} number] [{--keep-failed | -K}] [{--keep-going | -k}]

几个常见的命令

1
2
3
4
5
nixos-rebuild list-generations
sudo nix-collect-garbage -d
sudo nixos-rebuild boot
sudo nixos-rebuild switch -p profile-name

其中最后一条命令详解如下:

1
2
3
4
5
6
7
8
9
10
--profile-name,  -p

Instead of using the Nix profile /nix/var/nix/profiles/system to keep track of the current and previous system configurations, use /nix/var/nix/profiles/system-profiles/name. When you use GRUB 2, for every system profile created with this flag, NixOS will create a submenu named “NixOS - Profile 'name'” in GRUB’s boot menu, containing the current and previous configurations of this profile.

For instance, if you want to test a configuration file named test.nix without affecting the default system profile, you would do:

$ nixos-rebuild switch -p test -I nixos-config=./test.nix

The new configuration will appear in the GRUB 2 submenu “NixOS - Profile 'test'”.

可以在/nix/var/nix/profiles/system-profiles/ 目录下找到标签相关的文件,删除掉标签目录,重新执行一次sudo nixos-rebuild boot 就可以删除标签相关grub启动项目。

阅读更多