台式机改造计划
记录了对将台式机从 windows 换位 linux 后折腾的各种内容
linux 挂载 ntfs 分区¶
-
不考虑和 windows 兼容的话(在 linux 下创建的文件,在 windows 中会显示为其它用户导致无法访问)
- 将 own 设置为指定用户和组
- umask 表示文件和目录权限哪些位为 0,0022 即 755
-
考虑和 windows 兼容(双系统),需要手动设置 windows 和 linux 用户映射。参考:permissions - How do I use 'chmod' on an NTFS (or FAT32) partition? - Ask Ubuntu
-
其它
-
umount 占用失败
-
添加到 fstab 自动挂载
说明:
-
fstab 格式
-
device 域
- Label : LABEL=label
- Network ID
- Samba : //server/share
- NFS : server:/share
- SSHFS : sshfs#user@server:/share
- Device : /dev/sdxy (not recommended)
-
获得 UUID
-
-
-
参考:
官方文档:Ubuntu Manpage: ntfs-3g - Third Generation Read/Write NTFS Driver
类似问题:https://askubuntu.com/a/514870
- 回答:https://askubuntu.com/posts/514870/edit
- 回答中提到的网页(因为原网页不在了,使用了 webarchive):Ownership and Permissions (archive.org)
- 回答:https://askubuntu.com/posts/514870/edit
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 vim /etc/samba/smb.conf
[sambashare]
comment = Samba on Ubuntu
path = /home/username/sambashare
read only = no
browsable = yes
运行
命令行分区¶
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
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¶
参考:
- Virsh commands cheatsheet to manage KVM guest virtual machines | ComputingForGeeks
- Commands for KVM hypervisor management | Kalle's playground (wordpress.com)
基本¶
#列出虚拟机(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)
仅需
端口为 9090
要管理虚拟机需要安装
LXD¶
Linux Containers - LXD - Getting started
LXDUI¶
- 仓库提供了 Dockerfile,但是 readme 中没有说
- 目前安装有库依赖的问题,需要 patch 一个 pull request
- 将 pull request 地址添加一个.patch 后缀,便可以下载一个 patch 文件
- git am pathfiel
- 默认用户名密码:admin, admin
其它¶
中文输入法¶
使用了默认 ibus 的中文输入法,ctrl-空格切换延迟有 500ms 有点大。
barrier¶
-
问题 1
直接安装 barrier 后,连接时日志显示没有 SSL 相关的.pem 文件
需要手动生成
-
问题 2
barrier 目前只支持 xorg,因此需要关闭 ubuntu22.04 wayland
aria2 下载服务器¶
-
下载 aria2:aria2/aria2(github.com)
windows 官方 github 有编译版,linux 没有,可以从q3aql/aria2-static-builds: aria2 static builds for GNU/Linux & Windows (with OpenSSL). (github.com)下载
-
web
-
AriaNg
-
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.
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.
切换桌面环境¶
- xfce: [xfce:getting-started Xfce Docs]
- How to Install and Use Another Desktop Environment on Linux (howtogeek.com)
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
常用 hexo 命令
hexo init
hexo new "aaa"
hexo clean #删除public目录(html)
hexo g #生成html
hexo s -p PORT #本地server
hexo d #部署
docker 安装¶
- 基于 node 基本镜像,创建一个包含 hexo 环境的 docker 镜像,入口点为 bash
- 运行该镜像,将 blog 目录映射到 docker 容器中,然后进行 hexo 操作
- [可选]部署时为了避免输入 github 密码,可以将.ssh 和.gitconfig 映射到容器中
dockerfile¶
参考
- 别人的 dockerfile:使用 docker 搭建 Hexo - wanf3ng's blog
说明:
- 默认了用户 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,则需要
之后正常使用 hexo 即可
docker 技巧:连接到已有容器。
attach
命令将终端的标准输入,标准输出,标准错误连接到正在运行的容器。如果容器正在运行的命令是 bash,则 exit 后,容器退出
exec
命令在容器内启动新的进程。常见如 bash
Docker¶
network¶
https://docs.docker.com/network/
host¶
- 容器不会获得自己的 ip
- 如果容器绑定在 80 端口,则访问主机 ip 的 80 端口即可
- 有利于优化性能
- 只在 linux 上支持
设置方法
-
docker run
-
compose
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 defaultbridge
network by default. Containers connected to the defaultbridge
network can communicate, but only by IP address, unless they are linked using the legacy--link
flag.
-
自己创建 network
-
设置默认 bridge
自启动¶
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-v6
为2001: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。
- 其中 TRANSMISSION_WEB_HOME 指定网页皮肤,使用ronggang/transmission-web-control: 一个 Transmission 浏览器管理界面。Transmission Web Control is a custom web UI. (github.com)
- 使用它的脚本安装有点问题,主要是网络下载不下来。
- 将 git 仓库中的 src 目录覆盖到容器中原本的 web 目录即可
- 然后最好修改一下 TRANSMISSION_WEB_HOME 位置
---
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