跳转至

台式机改造计划

记录了对将台式机从 windows 换位 linux 后折腾的各种内容

linux 挂载 ntfs 分区

  • 不考虑和 windows 兼容的话(在 linux 下创建的文件,在 windows 中会显示为其它用户导致无法访问)

    • 将 own 设置为指定用户和组
    • umask 表示文件和目录权限哪些位为 0,0022 即 755
    sudo mount -t ntfs-3g -o umask=0022,gid=1000,uid=1000 /dev/sda2 /home/yfy/D
    
  • 其它

    • umount 占用失败

      umount -l ... #lazy umount
      
    • 添加到 fstab 自动挂载

      UUID=7E3AF70F3AF6C367  /home/yfy/D  ntfs  usermapping=/home/yfy/app/ntfs-3g/UserMapping,umask=0022 0 0
      

      说明:

      • fstab 格式

        [Device] [Mount Point] [File System Type] [Options] [Dump] [Pass]
        
      • device 域

        • Label : LABEL=label
        • Network ID
          • Samba : //server/share
          • NFS : server:/share
          • SSHFS : sshfs#user@server:/share
        • Device : /dev/sdxy (not recommended)
      • 获得 UUID

        sudo blkid
        

linux 分享 Samba

https://ubuntu.com/tutorials/install-and-configure-samba#3-setting-up-samba

Easily Install and Configure Samba File Server on Ubuntu 22.04 - kifarunix.com

安装

sudo apt update
sudo apt install samba

设置共享目录

sudo vim /etc/samba/smb.conf

[sambashare]
    comment = Samba on Ubuntu
    path = /home/username/sambashare
    read only = no
    browsable = yes

运行

sudo service smbd restart
#sudo ufw allow samba

#添加用户并设置密码
sudo smbpasswd -a username

命令行分区

docker,portainer

安装 docker

#添加源
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
   "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

#安装
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

#sudo groupadd docker
sudo usermod -aG docker $USER

#启动
sudo systemctl enable docker
sudo systemctl start docker

#测试
docker info
docker run --rm hello-world

安装 portainer

docker volume create portainer_data

docker run -d -p 9001:8000 -p 9000:9000 --name portainer \
    --restart=always \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v portainer_data:/data \
    portainer/portainer-ce

KVM, cockpit

KVM install

KVM: How to Install Kvm on Ubuntu 20.04 | Linuxize

sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager
  • qemu-kvm - software that provides hardware emulation for the KVM hypervisor.
  • libvirt-daemon-system - configuration files to run the libvirt daemon as a system service.
  • libvirt-clients - software for managing virtualization platforms.
  • bridge-utils - a set of command-line tools for configuring ethernet bridges.
  • virtinst - a set of command-line tools for creating virtual machines.
  • virt-manager - an easy-to-use GUI interface and supporting command-line utilities for managing virtual machines through libvirt.

brctl

The “virbr0” bridge does not have any physical interfaces added. “virbr0-nic” is a virtual device with no traffic routed through it. The sole purpose of this device is to avoid changing the MAC address of the “virbr0” bridge.

KVM install win10

How To Install Windows 10 on Ubuntu KVM? – GetLabsDone

CLI

参考:

基本
#列出虚拟机(domain)
virsh list  #active
virsh list --all

#查看虚拟机信息
virsh dominfo vm_name
virsh edit vm_name  #XML格式

#开启、关闭
virsh start vm_name
virsh shutdown vm_name 
virsh reboot vm_name
virsh destroy test  #强制关闭
virsh autostart vm_name #设置自动启动
virsh autostart --disable vm_name #关闭设置自动启动

#挂起
sudo virsh suspend test
sudo virsh resume test
开启 VNC
virsh shutdown <domain-name>
virsh edit <domain-name>

#Add below XML contents within <devices> block
<graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
  <listen type='address' address='0.0.0.0'/>
</graphics>

Cockpit

Cockpit: How to Install Cockpit Web Console on Ubuntu 20.04 Server (linuxtechi.com)

仅需

sudo apt install cockpit
sudo systemctl start cockpit

端口为 9090

要管理虚拟机需要安装

sudo apt install cockpit-machines

LXD

Linux Containers - LXD - Getting started

LXDUI

AdaptiveScale/lxdui: LXDUI is a web UI for the native Linux container technology LXD/LXC (github.com)

  • 仓库提供了 Dockerfile,但是 readme 中没有说
  • 目前安装有库依赖的问题,需要 patch 一个 pull request
    • 将 pull request 地址添加一个.patch 后缀,便可以下载一个 patch 文件
    • git am pathfiel
  • 默认用户名密码:admin, admin

其它

中文输入法

使用了默认 ibus 的中文输入法,ctrl-空格切换延迟有 500ms 有点大。

barrier

  1. 问题 1

    直接安装 barrier 后,连接时日志显示没有 SSL 相关的.pem 文件

    需要手动生成

    aaa
    
  2. 问题 2

    barrier 目前只支持 xorg,因此需要关闭 ubuntu22.04 wayland

    sudo vim /etc/gdm3/custom.conf
    
    #设置
    WaylandEnable=true --> false
    
    sudo systemctl restart gdm3
    

aria2 下载服务器

  • service

    Aria2c systemd service (github.com)

    [Unit]
    Description=Aria2c download manager
    After=network.target
    
    [Service]
    Type=simple
    User=www-data
    ExecStart=/usr/bin/aria2c --console-log-level=warn --enable-rpc --rpc-listen-all --conf-path=/etc/aria2.daemon
    
    [Install]
    WantedBy=multi-user.target
    
  • web

    • AriaNg

      [Unit]
      Description=Aria2 webUI
      After=syslog.target network.target
      
      [Service]
      Type=simple
      WorkingDirectory=/home/yfy/app/aria2-1.36.0/AriaNg
      
      ExecStart=/usr/bin/python3 -m http.server 6801
      
      [Install]
      WantedBy=multi-user.target
      

GUI

install alternative Desktop Environments: How to Install and Use Another Desktop Environment on Linux (howtogeek.com)

关键词:

  • X windows sytem
  • Desktop environments

    • window manager

      system software that controls the placement and appearance of windows within a windowing system in a graphical user interface (GUI). It can be part of a desktop environment (DE) or be used standalone.

      Window managers are X clients that control the appearance and behaviour of the frames ("windows") where the various graphical applications are drawn. They determine the border, title bar, size, and ability to resize windows

      • Stacking
      • Tiling
        • i3
    • applications
  • Display manager(login manager)

    is typically a graphical user interface that is displayed at the end of the boot process in place of the default shell.

    • LightDM — Cross-desktop display manager, can use various front-ends written in any toolkit.
    • **[LXD — LXDE display manager. Can be used independent of the LXDE desktop environment.
    • SDDM — QML-based display manager and successor to KDM; recommended for Plasma and LXQt.

    The X server is usually started from the X Display Manager program xdm(1) or a similar display manager program. This utility is run from the system boot files and takes care of keeping the server running, prompting for usernames and passwords, and starting up the user sessions.

Desktop environments include basically everything you see after you log into your user account on your Linux distribution’s sign-in screen. The desktop itself, desktop background, panels, menus, file manager, settings windows, and many other applications and utilities all come from a desktop environment. Even each window’s titlebar is provided by an application known as a window manager that comes with the desktop environment.

X Windows System

man X(7)

X server 有两种启动方式

  • login manager
  • Xinit:不是给用户使用的,而是用于启动 X server 的工具
 %  xrdb $HOME/.Xresources
 %  xmodmap -e "keysym BackSpace = Delete"
 %  mkfontdir /usr/local/lib/X11/otherfonts
 %  xset fp+ /usr/local/lib/X11/otherfonts
 %  xmodmap $HOME/.keymap.km
 %  xsetroot -solid 'rgbi:.8/.8/.8'
 %  xset b 100 400 c 50 s 1800 r on
 %  xset q
 %  twm
 %  xmag
 %  xclock -geometry 48x48-0+0 -bg blue -fg white
 %  xeyes -geometry 48x48-48+0
 %  xbiff -update 20
 %  xlsfonts '*helvetica*'
 %  xwininfo -root
 %  xdpyinfo -display joesworkstation:0
 %  xhost -joesworkstation
 %  xrefresh
 %  xwd | xwud
 %  bitmap companylogo.bm 32x32
 %  xcalc -bg blue -fg magenta
 %  xterm -geometry 80x66-0-0 -name myxterm $*

man Xserver(1)

The X server is usually started from the X Display Manager program xdm(1) or a similar display manager program. This utility is run from the system boot files and takes care of keeping the server running, prompting for usernames and passwords, and starting up the user sessions.

Installations that run more than one window system may need to use the xinit(1) utility instead of a dis‐ play manager. However, xinit is to be considered a tool for building startup scripts and is not intended for use by end users. Site administrators are strongly urged to use a display manager, or build other interfaces for novice users.

切换桌面环境
VNC

使用 VNC 并不需要使用到 login manager

During installation, you may be prompted to choose a default display manager for Xfce. A display manager is a program that allows you to select and log in to a desktop environment through a graphical interface. You’ll only be using Xfce when you connect with a VNC client, and in these Xfce sessions you’ll already be logged in as your non-root Ubuntu user. So for the purposes of this tutorial, your choice of display manager isn’t pertinent. Select either one and press ENTER.

Docker node/hexo

直接安装

教程:https://hexo.io/zh-cn/docs/index.html

首先需要安装 node.js 和 git,然后安装 hexo

npm install -g hexo-cli

常用 hexo 命令

hexo init
hexo new "aaa"

hexo clean #删除public目录(html)
hexo g  #生成html
hexo s -p PORT #本地server
hexo d  #部署

docker 安装

  1. 基于 node 基本镜像,创建一个包含 hexo 环境的 docker 镜像,入口点为 bash
  2. 运行该镜像,将 blog 目录映射到 docker 容器中,然后进行 hexo 操作
  3. [可选]部署时为了避免输入 github 密码,可以将.ssh 和.gitconfig 映射到容器中
dockerfile

参考

说明:

  • 默认了用户 uid=1000。因此可以直接指定 User node 来避免容器内生成的文件为 root 所有问题。
  • 使用 node12.0,否则 hexo 运行会失败
FROM node:12.6.0-alpine

# 切换中科大源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
# 安装bash git openssh
RUN apk add bash git openssh

# 设置容器时区为上海,不然发布文章的时间是国际时间,也就是比我们晚8个小时
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata

# 安装hexo
RUN \ 
npm config set registry https://registry.npm.taobao.org \
&&npm install \
&&npm install hexo-cli -g \
&& npm install hexo-server --save \
&& npm install hexo-asset-image --save \
&& npm install hexo-wordcount --save \
&& npm install hexo-generator-sitemap --save \
&& npm install hexo-generator-baidu-sitemap --save \
&& npm install hexo-deployer-git --save

ARG GIT_NAME
ARG GIT_EMAIL

User node

# 设置git push时的用户名和邮箱
RUN \
 git config --global user.email "$GIT_EMAIL" \
 && git config --global user.name "$GIT_NAME"

WORKDIR /home/node/blog

EXPOSE 4000

ENTRYPOINT ["/bin/bash"]
build 镜像
docker build -t yfy/hexo-blog\
 --build-arg GIT_NAME="Fuyan Yuan"\
 --build-arg GIT_EMAIL="33221728+TheRainstorm@users.noreply.github.com"\
 .
运行
docker run -it --name hexo-blog\
 -p 4000:4000 \
 -v /home/yfy/Documents/hexo-blog:/home/node/blog/ \
 -v /home/yfy/.ssh:/home/node/.ssh\
 yfy/hexo-blog

如果 blog 下没有 node_modules,则需要

npm install

之后正常使用 hexo 即可

docker 技巧:连接到已有容器。

docker attach CONTAINER
docker exec -it CONTAINER CMD

attach命令将终端的标准输入,标准输出,标准错误连接到正在运行的容器。如果容器正在运行的命令是 bash,则 exit 后,容器退出

exec命令在容器内启动新的进程。常见如 bash

Docker

network

https://docs.docker.com/network/

host
  • 容器不会获得自己的 ip
  • 如果容器绑定在 80 端口,则访问主机 ip 的 80 端口即可
  • 有利于优化性能
  • 只在 linux 上支持

设置方法

  • docker run

    --network host
    
  • compose

    network_mode: "host"
    
bridge
  • 默认 bridge 缺点

    If you do not specify a network using the --network flag, and you do specify a network driver, your container is connected to the default bridge network by default. Containers connected to the default bridge network can communicate, but only by IP address, unless they are linked using the legacy --link flag.

  • 自己创建 network

    docker network create my-net
    docker network rm my-net
    
    #创建容器时指定网络
    docker create --network
    
    #连接已有容器
    docker network connect my-net my-nginx
    docker network disconnect my-net my-nginx
    
  • 设置默认 bridge

    #daemon.json
    {
      "bip": "192.168.1.1/24",
      "fixed-cidr": "192.168.1.0/25",
      "fixed-cidr-v6": "2001:db8::/64",
      "mtu": 1500,
      "default-gateway": "192.168.1.254",
      "default-gateway-v6": "2001:db8:abcd::89",
      "dns": ["10.20.1.2","10.20.1.3"]
    }
    

自启动

docker update --restart=always

ipv6

参考:How Do I Enable IPv6 Support for Docker Containers? | Linode Questions

If you need IPv6 support for Docker containers, you need to enable the option on the Docker daemon and reload its configuration, before creating any IPv6 networks or assigning containers IPv6 addresses.

When you create your network, you can specify the --ipv6 flag to enable IPv6. You can’t selectively disable IPv6 support on the default bridge network.

开启 ipv6 后,默认 brdige 自动配置了 ipv6,无法关闭(自己创建的 bridge network 才可以不启用 ipv6)

If you configure Docker for IPv6 support (see Use IPv6), the default bridge network is also configured for IPv6 automatically. Unlike user-defined bridges, you can’t selectively disable IPv6 on the default bridge.

我的路由器得到的 ipv6 是2001:da8:d800:336:8e53:c3ff:fe86:123d/64,应该是有一个 block 的。但是当我设置了 daemon.json 内fixed-cidr-v62001:da8:d800:336::/64后。默认的 bridge docker0 显示 ip 是2001:da8:d800:336::1/64。容器内确实获得了 ipv6 地址,但是无法 ping 通 host 物理网卡上的 ipv6 地址。也无法 ping 通路由器。

  • 所以感觉路由器得到的/64 的块并不属于我,没办法这样配置。
  • 可能还是得配置 nat。但是使用 ipv6 的还是少数(PT 下载需要),因此还是使用 host 网络类型吧。

Docker 应用

transmission PT 下载

说明:transmission 是 linux 下的 BT 下载软件,可以通过网页控制,有 docker 版本。

挑战:由于 PT 一般是只能 ipv6 访问的,因此要求 docker 容器能够 ipv6 访问。发现最简单的方式就是网络类型选择 host。

以下 docker compose 是 transmission 官方提供的,主要修改了其中 network_mode。

---
version: "2.1"
services:
  transmission:
    image: lscr.io/linuxserver/transmission:latest
    container_name: transmission
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=ASIA/ShangHai
      - USER=yfy
      - PASS=abcd4567
      - PEERPORT=51413
      - TRANSMISSION_WEB_HOME=/downloads/transmission/web
    volumes:
      - /home/yfy/Disk/BT/config:/config
      - /home/yfy/Disk/BT/downloads:/downloads
      - /home/yfy/Disk/BT/watch:/watch
    network_mode: "host"
    restart: unless-stopped

jellyfin