Create rebuild_qcow2.sh

This commit is contained in:
spiritLHLS 2023-04-08 22:34:40 +08:00 committed by GitHub
parent 61ff91f953
commit c5aaf8798c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

21
rebuild_qcow2.sh Normal file
View file

@ -0,0 +1,21 @@
#!/bin/bash
apt-get update
apt-get install libguestfs-tools
sudo apt-get install rng-tools
qcow_file=/root/qcow/ubuntu22.qcow2
echo "启用SSH功能..."
virt-customize -a $qcow_file --run-command "systemctl enable ssh"
virt-customize -a $qcow_file --run-command "systemctl start ssh"
echo "启用root登录..."
virt-customize -a $qcow_file --run-command "sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config"
virt-customize -a $qcow_file --run-command "systemctl restart sshd"
echo "创建备份..."
cp $qcow_file ${qcow_file}.bak
echo "复制新文件..."
cp $qcow_file ${qcow_file}.tmp
echo "覆盖原文件..."
mv ${qcow_file}.tmp $qcow_file
rm -rf *.bak
echo "修改完成"