mdbook

Install via:

sudo pacman -S mdbook
$ yay mdbook-toc

For using cargo tuna mirror site, do following modifications:

$ vim  ~/.cargo/config 
[source.crates-io]
replace-with = 'tuna'

[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

Install pdf generation and pdf outline:

$ cargo install mdbook-pdf
$ pip install --break-system-packages mdbook-pdf-outline
$ vim ~/.zshrc
...
export PATH=/home/dash/.cargo/bin:/home/dash/.local/bin:$PATH

Now add following definition to your book:

[preprocessor.toc]
command = "mdbook-toc"
renderer = ["html"]

[output.html]

[output.pdf]
## Set for auto-retrying if failed to generate PDF.
# trying-times = 1
## This backend only support latest Chromium based browsers, not Safari and Firefox currently.
## If needed, please specify the full path.
## If you specify the wrong binary, chances are that there will be a timeout error.
# browser-binary-path = ""
## Assign the static hosting site url so that relative links outside the book can be fixed.
#static_site_url = "https://aye10032.gitbook.io/computernetwork/"
## Check Chrome Devtools Protocol Docs for the explanation of the following params:
## https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF
landscape = false
display-header-footer = true
print-background = true
theme = ""
scale = 0.8
paper-width = 8
paper-height = 10
margin-top = 0.5
margin-bottom = 0.5
margin-left = 0.5
margin-right = 0.5
page-ranges = ""
ignore-invalid-page-ranges = false
header-template = "<h3 style='font-size:8px; margin-left: 48%' class='title'></h3>"
footer-template = "<p style='font-size:10px; margin-left: 48%'><span class='pageNumber'></span> / <span class='totalPages'></span></p>"
prefer-css-page-size = true

[output.pdf-outline]
like-wkhtmltopdf = true

Generate book pdf:

$ mdbook pdf
$ ls -l -h book/pdf-outline/*.pdf
-rw-r--r-- 1 dash root 8.8M May 17 10:00 book/pdf-outline/output.pdf

ChangingEDIDInQemu

edid retrieve

Install edid related packages:

$ sudo apt install -y edid-decode read-edid

Find the edid in /sys:

$ sudo find /sys | grep edid
/sys/kernel/debug/dri/0/Virtual-1/edid_override
/sys/devices/pci0000:00/0000:00:01.0/drm/card0/card0-Virtual-1/edid
/sys/module/drm_kms_helper/parameters/edid_firmware
/sys/module/drm/parameters/edid_firmware
/sys/module/drm/parameters/edid_fixup

The /sys/devices/pci0000:00/0000:00:01.0/drm/card0/card0-Virtual-1/edid file is your edid file, transfer it to windows machine.

edid modification

Using AW EDID Editor for editing the edid file:

/images/2024_05_13_10_26_13_772x524.jpg

Remove the items you won’t preserve:

/images/2024_05_13_10_26_41_834x651.jpg

Modified items:

/images/2024_05_13_10_27_10_554x397.jpg

Using the new edid file

Edit the grub options:

$ sudo vim /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet drm.edid_firmware=Virtual-1:edid/edidno1080.bin"

Add initram-tools hooks(Added scripts in kmod - the hacking way):

$ cat /usr/share/initramfs-tools/hooks/kmod 

......
......
......
# hacking for edid
mkdir -p ${DESTDIR}/lib/firmware/edid
mkdir -p ${DESTDIR}/usr/lib/firmware/edid

cp /lib/firmware/edid/edidno4k.bin ${DESTDIR}/lib/firmware/edid/
cp /lib/firmware/edid/edidno1080.bin ${DESTDIR}/lib/firmware/edid/
cp /usr/lib/firmware/edid/edidno4k.bin ${DESTDIR}/usr/lib/firmware/edid/
cp /usr/lib/firmware/edid/edidno1080.bin ${DESTDIR}/usr/lib/firmware/edid/

Update the kernel and initramfs:

$ sudo update-grub2
$ sudo update-initramfs -u -k all

Effects

edid-decode result:

root@idvrescue:/home/hhh# edid-decode < /sys/devices/pci0000:00/0000:00:01.0/drm/card0/card0-Virtual-1/edid
......
hecksum: 0x47

----------------

Block 1, CTA-861 Extension Block:
  Revision: 3
  Native detailed modes: 0
  Video Data Block:
    VIC  31:  1920x1080   50.000000 Hz  16:9     56.250 kHz    148.500000 MHz
Checksum: 0x95

Dmesg output:

$ sudo dmesg | grep edid
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-6.1.0-18-amd64 root=UUID=f1fa5be7-1a17-46e3-ac0d-ab936027037e ro quiet drm.edid_firmware=Virtual-1:edid/edidno1080.bin
[    0.014022] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-6.1.0-18-amd64 root=UUID=f1fa5be7-1a17-46e3-ac0d-ab936027037e ro quiet drm.edid_firmware=Virtual-1:edid/edidno1080.bin
[    0.635432] [drm] features: -virgl +edid -resource_blob -host_visible
[    0.635877] platform Virtual-1: firmware: direct-loading firmware edid/edidno1080.bin
[    0.635885] [drm] Got external EDID base block and 1 extension from "edid/edidno1080.bin" for connector "Virtual-1"

/images/2024_05_13_10_31_17_647x580.jpg

WorkingTipsOnIncusBasedFogServer

1. dhcpd服务器考虑

1.1 dhcpd在容器内出现的问题

因为incus内部使用的是私有网络,因此一旦将isc-dhcp-server启动在容器内,则只能监听容器内部的地址,而一旦更改子网定义为主机网络侧,则会出现dhcpd.conf检查错误:

5月 08 08:58:44 fogincuschinese dhcpd[2532]: No subnet declaration for eth0 (10.147.148.100).
5月 08 08:58:44 fogincuschinese dhcpd[2532]: ** Ignoring requests on eth0.  If this is not what
5月 08 08:58:44 fogincuschinese dhcpd[2532]:    you want, please write a subnet declaration
5月 08 08:58:44 fogincuschinese dhcpd[2532]:    in your dhcpd.conf file for the network segment
5月 08 08:58:44 fogincuschinese dhcpd[2532]:    to which interface eth0 is attached. **
5月 08 08:58:44 fogincuschinese dhcpd[2532]: 
5月 08 08:58:44 fogincuschinese dhcpd[2532]: 
5月 08 08:58:44 fogincuschinese dhcpd[2532]: Not configured to listen on any interfaces!

出现上述问题的原因在于:容器内eth0为10.147.148.100, 而主机侧为192.168.1.0.24, 无法写如下的配置文件(diff文件更改了默认dhcpd.conf中的监听网段) :

root@fogincuschinese:~# diff /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.back 
24c24
< subnet 192.168.1.0 netmask 255.255.255.0{
---
> subnet 10.147.148.0 netmask 255.255.255.0{
26c26
<     range dynamic-bootp 192.168.1.50 192.168.1.90;
---
>     range dynamic-bootp 10.147.148.10 10.147.148.254;
29c29
<     option routers 192.168.1.33;
---
>     option routers 10.147.148.1;
31c31
<     next-server 192.168.1.40;
---
>     next-server 10.147.148.100;

1.2 dhcpd在主机上的实现

安装:

# apt install -y isc-dhcp-server

配置,使能:

$ sudo vim /etc/dhcp/dhcpd.conf 
subnet 192.168.1.0 netmask 255.255.255.0{
    option subnet-mask 255.255.255.0;
    range dynamic-bootp 192.168.1.50 192.168.1.90;
    default-lease-time 21600;
    max-lease-time 43200;
    option routers 192.168.1.33;
    option domain-name-servers 223.5.5.5;
    next-server 192.168.1.40;
}
$ sudo systemctl daemon-reload
$ sudo systemctl start isc-dhcp-server
$ sudo systemctl enable isc-dhcp-server

需要对齐fogserver中的配置.

2. tftpd服务

如果直接使用inpus中的容器,则因为tftp的通信协商机制中,会因为使用1024~65535的随机端口和客户端通信,而容器本身比较难搞定proxy, 而导致通信失败。
因此我们需要将tftpd也从里面搞出来, 在主机上实现。

但,如果做了这么多以后,还是容器吗?

所以上面的方式,未必适合

3. macvlan网

直接用macvlan直接覆盖。

注意替换IP:

Change FOG Server IP Address
Procedural Steps
Follow appropriate steps for your Linux distribution to change the OS’s IP address.

Update the ipaddress= field (and other fields if necessary) inside the /opt/fog/.fogsettings file. The .fogsettings file.

Rerun the installer, you’ll need to use –recreate-CA and –recreate-keys keys as the installer provides a certificate with a Common Name based on the ip which will be shipped in the iPxe kernel and failed to load any https resources as the certificate isn’t valid anymore.

Update the IP address inside /tftpboot/default.ipxe (look for the chain line i.e chain https://x.x.x.x/fog/service/ipxe/boot.php##params)

Update the IP address for the storage node on the FOG system where you changed the IP address Web Interface -> Storage Management

Update the IP address on a any master storage node that may reference this FOG server Web Interface -> Storage Management

(For master server) Update the FOG_WEB_HOST value Web Interface -> FOG Configuration -> FOG Settings -> Web Server -> FOG_WEB_HOST

(For master server) Update the FOG_TFTP_HOST value Web Interface -> FOG Configuration -> FOG Settings -> TFTP Server -> FOG_TFTP_HOST

Optionaly if you have configured a dhcpd:

Update IP addresses (fog and gateway) inside the /etc/dhcp/dhcpd.conf.

Don’t forgot to check your /etc/export for nfs server as well as your apache2 configuration as the installer override it.

incus 快速启动流程

  1. 用户需要安装好incus.
  2. 导入镜像,配置网路。
  3. 快速开出实例,作为Pxe和部署服务器使用。

Steps:

dash@server:~$ tar xzvf incusdebs.tar.gz
$ sudo chmod 777 -R incuddebs
$ sudo apt install -y incus
sudo adduser dash incus-admin

init yaml:

config:
  images.auto_update_interval: "0"
networks: []
storage_pools:
- config: {}
  description: ""
  name: default
  driver: dir
profiles:
- config: {}
  description: ""
  devices:
    root:
      path: /
      pool: default
      type: disk
  name: default
projects: []
cluster: null

quickly init:

# cat init.sh 
cat <<EOF | incus admin init --preseed
config:
  images.auto_update_interval: "0"
networks: []
storage_pools:
- config: {}
  description: ""
  name: default
  driver: dir
profiles:
- config: {}
  description: ""
  devices:
    root:
      path: /
      pool: default
      type: disk
  name: default
projects: []
cluster: null
EOF

Create incusbr0(macvlan):

 incus network create incusbr0 --type=macvlan parent=enp7s0

Edit profile default:

cat default.yaml | incus profile edit default

Add new profile:

incus profile create nfs-server
    cat nfs-server-profile.yaml | incus profile edit nfs-server

另外的机器上导出镜像:

# incus publish fogincuschinese --alias fogAuto
Instance published with fingerprint: 0a4a4299661f19d880a203031b4e7df88996a99be110979975633baf9504b1dc
# incus image export fogAuto .
Image exported successfully!           

开始导入镜像:

# ls -l -h 0a4a4299661f19d880a203031b4e7df88996a99be110979975633baf9504b1dc.tar.gz 
-rw-rw-r-- 1 dash dash 857M May  8 09:06 0a4a4299661f19d880a203031b4e7df88996a99be110979975633baf9504b1dc.tar.gz
root@server:/home/dash# incus image import 0a4a4299661f19d880a203031b4e7df88996a99be110979975633baf9504b1dc.tar.gz --alias fogAuto
Image imported with fingerprint: 0a4a4299661f19d880a203031b4e7df88996a99be110979975633baf9504b1dc
root@server:/home/dash# incus image list
+---------+--------------+--------+----------------------------------------+--------------+-----------+-----------+----------------------+
|  ALIAS  | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |   SIZE    |     UPLOAD DATE      |
+---------+--------------+--------+----------------------------------------+--------------+-----------+-----------+----------------------+
| fogAuto | 0a4a4299661f | no     | Debian bookworm amd64 (20240506_05:24) | x86_64       | CONTAINER | 856.42MiB | 2024/05/08 09:08 UTC |
+---------+--------------+--------+----------------------------------------+--------------+-----------+-----------+----------------------+

开始开出第一个实例:

# LANG=zh_CN.UTF-8 incus launch fogAuto fogInstance  -p nfs-server -p default -c security.privileged=true -c raw.apparmor="mount fstype=rpc_pipefs, mount fstype=nfsd,"
Launching fogInstance
root@server:/home/dash# incus  list        
+-------------+---------+---------------------+------+-----------+-----------+
|    NAME     |  STATE  |        IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+-------------+---------+---------------------+------+-----------+-----------+
| fogInstance | RUNNING | 192.168.1.44 (eth0) |      | CONTAINER | 0         |
+-------------+---------+---------------------+------+-----------+-----------+
root@server:/home/dash# incus exec fogInstance bash
root@fogInstance:~# 

进入到实例里开始重新部署为192.168.1.46:

root@fogInstance:~# cd regen/
root@fogInstance:~/regen# ls
1_regen.sh  2_reinstall.sh  cn-fogproject-master  inventoy.ini	mysql.sh  regen.yml  templates
root@fogInstance:~/regen# vim inventoy.ini 
root@fogInstance:~/regen# ./1_regen.sh 

PLAY [Write fogsettings] *********************************************************************************************************************************************************************

...
这里需要重启一次容器实例,非常快:   

root@server:/home/dash# incus exec fogInstance bash
root@fogInstance:~# cd regen/
root@fogInstance:~/regen# ./2_reinstall.sh 

push 镜像到相应位置:

incus file push -pr idvnext/ fogInstance/images/idvnext/

接下来就可以愉快的玩耍了。

综合

传递文件:

$ scp -r hostincus/ dash@192.168.1.38:~

incusAdjustNetworking

The default networking bridge incusbr0 enabled the dhcp by default, that’s not good for using dhcpd service in containers, so I have to remove the default behavior of the incusbr0, and add a new behavior for it.

Directly delete the bridge will get an error:

$ incus network delete incusbr0
Error: The network is currently in use

Show this network’s usage:

$ incus network show incusbr0
config:
  ipv4.address: 10.147.148.1/24
  ipv4.nat: "true"
  ipv6.address: none
description: ""
name: incusbr0
type: bridge
used_by:
- /1.0/instances/fogincuschinese
- /1.0/instances/foginlxc
- /1.0/profiles/default
managed: true
status: Created
locations:
- none

Edit its profile:

$ incus profile edit default
config: {}
description: Default Incus profile
devices:
-  eth0:
-    name: eth0
-    network: incusbr0
-    type: nic
  root:
    path: /
    pool: default
    type: disk
name: default
used_by:
- /1.0/instances/foginlxc
- /1.0/instances/fogincuschinese

Now you could delete this networking via:

$ incus network delete incusbr0
Network incusbr0 deleted

RE-create the networking via following command(dhcpv4/v6 disabled):

$ incus network create incusbr0 ipv4.dhcp=false ipv6.dhcp=false ipv4.address=10.147.148.1/24
Network incusbr0 created

Check this networking:

$ ip a show incusbr0
10: incusbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 00:16:3e:c9:c4:e6 brd ff:ff:ff:ff:ff:ff
    inet 10.147.148.1/24 scope global incusbr0
       valid_lft forever preferred_lft forever
    inet6 fd42:1515:fb8e:9dab::1/64 scope global 
       valid_lft forever preferred_lft forever

RE-Add the networking profile into default:

$ incus profile edit default
...
description: Default Incus profile
devices:
+  eth0:
+    name: eth0
+    network: incusbr0
+    type: nic
  root:
...

Re-lauch the previously stopped container instance:

$ incus start fogincuschinese
$ incus list
+-----------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
|      NAME       |  STATE  |         IPV4          |                     IPV6                      |   TYPE    | SNAPSHOTS |
+-----------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| fogincuschinese | RUNNING | 10.147.148.100 (eth0) | fd42:1515:fb8e:9dab:216:3eff:fef3:8307 (eth0) | CONTAINER | 0         |
+-----------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+

Until now you could enable the dhcpd in container and then use forwarding rules for redirect to host.

Final command:

incus network create incusbr0 ipv4.dhcp=false ipv4.address=10.147.148.1/24 ipv4.nat=true ipv6.address=none

InstallFogServerInIncus

Bridge ways:

Create incus instance:

$ incus launch images:debian/12 fogserver
$ incus list                   
+-----------+---------+----------------------+-----------------------------------------------+-----------+-----------+
|   NAME    |  STATE  |         IPV4         |                     IPV6                      |   TYPE    | SNAPSHOTS |
+-----------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| fogserver | RUNNING | 10.238.20.219 (eth0) | fd42:9396:9aca:8842:216:3eff:fe04:5da6 (eth0) | CONTAINER | 0         |
+-----------+---------+----------------------+-----------------------------------------------+-----------+-----------+

Configure the incus instance:

dash@hope:~$ incus exec fogserver bash
root@fogserver:~# vi /etc/apt/sources.list
root@fogserver:~# cat /etc/apt/sources.list
# Generated by distrobuilder
deb http://mirrors.ustc.edu.cn/debian bookworm main
deb http://mirrors.ustc.edu.cn/debian bookworm-updates main
deb http://mirrors.ustc.edu.cn/debian-security/ bookworm-security main
root@fogserver:~# apt update -y && apt install -y git

Fetch the source code:

root@fogserver:~# git clone https://github.com/fogproject/fogproject.git fogproject-master

Cloning into 'fogproject-master'...
remote: Enumerating objects: 158214, done.
remote: Counting objects: 100% (4216/4216), done.
remote: Compressing objects: 100% (1073/1073), done.
remote: Total 158214 (delta 3135), reused 4011 (delta 3023), pack-reused 153998
Receiving objects: 100% (158214/158214), 848.89 MiB | 14.41 MiB/s, done.
Resolving deltas: 100% (112946/112946), done.
root@fogserver:~# du -hs fogproject-master/
890M	fogproject-master/

Using fogserver in container is not a good idea.