Debian 11启用rc.local方法

rc.local是一个令大家耳熟详的文件,它在Redhat系列操作系统中可以让用户添加自定义开机脚本并运行。但是在Debian 11操作系统中,这个功能不被默认开启。这篇文章将介绍如何开启rc.local。话不多说,开始~

先通过以下命令对systemd注入rc-local服务:

cat>>/etc/systemd/system/rc-local.service<<EOF
[Unit]
Description=/etc/rc.local
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target
EOF
  1. 执行daemon reload和启动服务开机启动

    systemctl daemon-reload && systemctl enable rc-local

  2. 创建一个空白的rc.local文件,并写入头尾,如下方

vi /etc/rc.local

#!/bin/sh -e

<your command>

exit 0
  1. 对rc.local赋予权限以执行

    chmod a+x /etc/rc.local

到这里,就全部完成了,在下一次重启中,该文件将会被自动调用并执行。

alpine ipv6 dhcp

alpine默认用udhcpc,运行 udhcpc6无法发现公网ipv6

apk add dhclient

vi /etc/network/interfaces

iface eth0 inet6 manual
  post-up dhclient -6 eth0

ubutnu 22 安装 kvm WebVirtMgr

1.kvm安装 参见https://sharadchhetri.com/install-kvm-on-ubuntu-20-04-lts-desktop/

sudo apt -y update
sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils

sudo adduser `id -un` libvirt
sudo adduser `id -un` kvm

sudo grep `id -un` /etc/group
virsh list --all


sudo apt install virt-manager

2.WebVirtMgr 参见 https://blog.csdn.net/qq_34146694/article/details/84871240

docker run -itd --name virtmgr -p6080:6080 -p8080:8080 --restart=always jieshao/web_kvm:onlyweb

修改网络为桥接
sudo vi /etc/netplan/00-installer-config.yaml

network:
  ethernets:
    eno5:
      dhcp4: no
      dhcp6: no
    eno6:
      dhcp4: no
      dhcp6: no
    eno7:
      dhcp4: no
      dhcp6: no
    eno8:
      dhcp4: no
      dhcp6: no
  version: 2
  bridges:
    br0:
      interfaces:
        - eno5
        - eno6
        - eno7
        - eno8
      addresses:
        - 192.168.1.140/24
      optional: true
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 233.5.5.5
          - 114.114.114.114
      dhcp4: no
      dhcp6: yes

打开主机防火墙
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT

sudo vi /etc/libvirt/libvirtd.conf

listen_tls = 0
listen_tcp = 1
auth_tcp = "none"

sudo vi /etc/default/libvirtd

LIBVIRTD_ARGS="-l -d"
start_libvirtd=yes

重启 sudo service libvirtd restart ,可能会报错,不用管它。 netstat -an|grep 16509 端口起来就行。
sudo systemctl enable docker
sudo systemctl enable libvirtd

修改webVirMgr密码
sudo docker exec virtmgr bash
/webvirmgr/manage.py changepassword admin

登录后
add connection 172.17.0.1,用户名密码暂时没什么用,随便设
添加存储池
Create Custom Instance
修改xml
网络:

 <interface type='bridge'>
  <mac address='52:54:00:4b:73:d6'/>
  <source bridge='br0'/>
  <target dev='vnet0'/>
  <model type='virtio'/>
  <alias name='net0'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>

差异磁盘:

 <disk type='file' device='disk'>
  <driver name='qemu' type='qcow2'/>
  <source file='子盘路径.img' index='2'/>
  <backingStore type='file' index='3'>
    <format type='qcow2'/>
    <source file='父盘路径.img'/>
    <backingStore/>
  </backingStore>
  <target dev='vda' bus='virtio'/>
  <alias name='virtio-disk0'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</disk>

双光驱

   <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source/>
      <backingStore/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='1' target='0' unit='1'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <source/>
      <backingStore/>
      <target dev='hdb' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
    </disk>

建差分盘用命令
sudo qemu-img create -f qcow2 -F qcow2 -o backing_file=父盘路径.img,size=60G 子盘路径.img

kvm client disk 扩容

Step 1: Shut down the VM
sudo virsh list
sudo virsh shutdown 主机名
sudo virsh list

Step 2: Extend guest OS disk
sudo virsh domblklist 主机名
sudo virsh dumpxml 主机名 | egrep 'disk type' -A 5
sudo qemu-img info /var/lib/libvirt/images/磁盘名.qcow2

Step 3: Extend guest VM disk
sudo qemu-img resize /var/lib/libvirt/images/磁盘名.qcow2 +10G
sudo qemu-img info /var/lib/libvirt/images/磁盘名.qcow2
sudo virsh start 主机名
sudo virsh blockresize 主机名 /var/lib/libvirt/images/磁盘名.qcow2 40G

extend root filesystem using LVM on Linux
lsblk
On Ubuntu / Debian system, run
sudo apt -y install cloud-guest-utils
For CentOS server, run
sudo yum -y install cloud-utils-growpart

sudo growpart /dev/vda 3
sudo pvresize /dev/vda3
sudo pvs
sudo vgs
df -hT
sudo lvextend -l +100%FREE /dev/name-of-volume-group/root

For ext4 filesystem
sudo resize2fs /dev/name-of-volume-group/root
For xfs filesystem
sudo xfs_growfs /

ubuntu 安装 HP 打印机驱动

https://developers.hp.com/hp-linux-imaging-and-printing/gethplip
不要安装太新的,有依赖问题,ubuntu18装3.17.11就可以

1.安装包
sudo apt-get install hplip printer-driver-hpcups

  1. 从这里下载和当前hplip版本对应的插件 http://www.openprinting.org/download/printdriver/auxfiles/HP/plugins/
  2. 安装刚刚下载的插件
    sudo hp-plugin hplip-3.20.3-plugin.run
  3. 运行 hp-setup 然后按照提示下一步就行了

解决设置界面还不能运行(pyqt*)的问题
sudo apt-get install hplip-gui

解决 canberra-gtk-module 加载失败的问题
sudo apt-get install libcanberra-gtk*