先禁止docker和kvm(libvirtd)开机自动
1
2
| systemctl disable docker
systemctl disable libvirtd
|
自定义一个开机服务rc-local
rc-local.servic
nano /usr/lib/systemd/system/rc-local.service
1
2
3
4
5
6
7
8
9
10
11
12
13
| [Unit]
Description="/etc/rc.local Compatibility"
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardInput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
|
rc.local
nano /etc/rc.local
查找/etc/rc.local.d/下的脚本并执行
1
2
3
4
5
6
7
8
| #!/bin/sh
# /etc/rc.local
if test -d /etc/rc.local.d; then
for rcscript in /etc/rc.local.d/*.sh; do
test -r "${rcscript}" && sh ${rcscript}
done
unset rcscript
fi
|
权限 目录 和开机自启
1
2
3
| chmod a+x /etc/rc.local
mkdir /etc/rc.local.d
systemctl enable rc-local
|
创建自动脚本
sudo nano /etc/rc.local.d/auto-mount-and-start-aio.sh
内容如下
1
2
3
4
5
6
7
8
|
# 自动挂载
#mkdir-p mnt/nvme mnt/efi mnt/exfat
mount /dev/nvme0n1p6 /home/yanhui/mnt/exfat
mount /dev/nvme0n1p5 /home/yanhui/mnt/nvme
mount /dev/nvme0n1p1 /home/yanhui/mnt/efi
|
docker 和kvm的迁移
1
2
3
4
| systemctl stop docker
rsync -avzP /var/lib/docker /home/yanhui/mnt/nvme
mv /var/lib/docker /var/lib/docker.bak && ln -s /home/yanhui/mnt/nvme/docker /var/lib/
# 完成后 rm -rf /var/lib/docker.bak
|
1
2
3
4
| systemctl stop libvirtd
rsync -avzP /var/lib/libvirt /home/yanhui/mnt/nvme
mv /var/lib/libvirt /var/lib/libvirt.bak && ln -s /home/yanhui/mnt/nvme/libvirt /var/lib/
# 完成后 rm -rf /var/lib/libvirt.bak
|
修改docker和libvirtd服务启动顺序
1
| cd /usr/lib/systemd/system/
|
分别编辑 sudo nano libvirtd.service
和 sudo nano docker.service
在[Unit]
段 增加一行
这行是为了让docker和libvirtd 在rc-local这个服务之后启动,方便我们在 rc-local 内先挂载好磁盘
最后这两个服务设置为自动启动
1
2
3
4
| sudo systemctl enable libvirtd
sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl start libvirtd
|
另一个文章
https://dev.leiyanhui.com/arch/auto–dock-kvm/