core: qemu-nbd 卸载镜像后需要等待一段时间
This commit is contained in:
parent
cfb7985deb
commit
133054e9d1
26
trans.sh
26
trans.sh
@ -270,11 +270,6 @@ extract_env_from_cmdline() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
qemu_nbd() {
|
|
||||||
command qemu-nbd "$@"
|
|
||||||
sleep 5
|
|
||||||
}
|
|
||||||
|
|
||||||
mod_motd() {
|
mod_motd() {
|
||||||
# 安装后 alpine 后要恢复默认
|
# 安装后 alpine 后要恢复默认
|
||||||
# 自动安装失败后,可能手动安装 alpine,因此无需判断 $distro
|
# 自动安装失败后,可能手动安装 alpine,因此无需判断 $distro
|
||||||
@ -306,7 +301,7 @@ umount_all() {
|
|||||||
|
|
||||||
# 可能脚本不是首次运行,先清理之前的残留
|
# 可能脚本不是首次运行,先清理之前的残留
|
||||||
clear_previous() {
|
clear_previous() {
|
||||||
qemu_nbd -d /dev/nbd0 2>/dev/null || true
|
qemu-nbd -d /dev/nbd0 2>/dev/null || true
|
||||||
swapoff -a
|
swapoff -a
|
||||||
umount_all
|
umount_all
|
||||||
|
|
||||||
@ -1536,7 +1531,7 @@ install_qcow_el() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
modprobe nbd nbds_max=1
|
modprobe nbd nbds_max=1
|
||||||
qemu_nbd -c /dev/nbd0 $qcow_file
|
qemu-nbd -c /dev/nbd0 $qcow_file
|
||||||
|
|
||||||
# TODO: 改成循环mount找出os+fstab查找剩余分区?
|
# TODO: 改成循环mount找出os+fstab查找剩余分区?
|
||||||
os_part=$(lsblk /dev/nbd0p*[0-9] --sort SIZE -no NAME,FSTYPE | grep xfs | tail -1 | cut -d' ' -f1)
|
os_part=$(lsblk /dev/nbd0p*[0-9] --sort SIZE -no NAME,FSTYPE | grep xfs | tail -1 | cut -d' ' -f1)
|
||||||
@ -1587,7 +1582,7 @@ install_qcow_el() {
|
|||||||
|
|
||||||
# 取消挂载 nbd
|
# 取消挂载 nbd
|
||||||
umount /nbd/ /nbd-boot/ /nbd-efi/ || true
|
umount /nbd/ /nbd-boot/ /nbd-efi/ || true
|
||||||
qemu_nbd -d /dev/nbd0
|
qemu-nbd -d /dev/nbd0
|
||||||
|
|
||||||
# 如果镜像有efi分区,复制其uuid
|
# 如果镜像有efi分区,复制其uuid
|
||||||
# 如果有相同uuid的fat分区,则无法挂载
|
# 如果有相同uuid的fat分区,则无法挂载
|
||||||
@ -1712,7 +1707,7 @@ EOF
|
|||||||
dd_qcow() {
|
dd_qcow() {
|
||||||
if true; then
|
if true; then
|
||||||
modprobe nbd nbds_max=1
|
modprobe nbd nbds_max=1
|
||||||
qemu_nbd -c /dev/nbd0 $qcow_file
|
qemu-nbd -c /dev/nbd0 $qcow_file
|
||||||
|
|
||||||
# 检查最后一个分区是否是 btrfs
|
# 检查最后一个分区是否是 btrfs
|
||||||
# 即使awk结果为空,返回值也是0,加上 grep . 检查是否结果为空
|
# 即使awk结果为空,返回值也是0,加上 grep . 检查是否结果为空
|
||||||
@ -1742,11 +1737,11 @@ dd_qcow() {
|
|||||||
printf "yes" | parted /dev/nbd0 resizepart $part_num ${part_end}B ---pretend-input-tty
|
printf "yes" | parted /dev/nbd0 resizepart $part_num ${part_end}B ---pretend-input-tty
|
||||||
|
|
||||||
# 缩小 qcow2
|
# 缩小 qcow2
|
||||||
qemu_nbd -d /dev/nbd0
|
qemu-nbd -d /dev/nbd0
|
||||||
qemu-img resize --shrink $qcow_file $part_end
|
qemu-img resize --shrink $qcow_file $part_end
|
||||||
|
|
||||||
# 重新连接
|
# 重新连接
|
||||||
qemu_nbd -c /dev/nbd0 $qcow_file
|
qemu-nbd -c /dev/nbd0 $qcow_file
|
||||||
else
|
else
|
||||||
umount /mnt/btrfs
|
umount /mnt/btrfs
|
||||||
fi
|
fi
|
||||||
@ -1778,13 +1773,20 @@ dd_qcow() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
qemu_nbd -d /dev/nbd0
|
qemu-nbd -d /dev/nbd0
|
||||||
else
|
else
|
||||||
# 将前1M dd到内存,将1M之后 dd到硬盘
|
# 将前1M dd到内存,将1M之后 dd到硬盘
|
||||||
qemu-img dd if=$qcow_file of=/first-1M bs=1M count=1
|
qemu-img dd if=$qcow_file of=/first-1M bs=1M count=1
|
||||||
qemu-img dd if=$qcow_file of=/dev/disk/by-label/os bs=1M skip=1
|
qemu-img dd if=$qcow_file of=/dev/disk/by-label/os bs=1M skip=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 需要等待一下,不然会出现
|
||||||
|
# umount: /installer/: target is busy.
|
||||||
|
while fuser -sm /installer/; do
|
||||||
|
echo "Waiting for /installer/ to be unmounted..."
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
||||||
# 将前1M从内存 dd 到硬盘
|
# 将前1M从内存 dd 到硬盘
|
||||||
umount /installer/
|
umount /installer/
|
||||||
dd if=/first-1M of=/dev/$xda
|
dd if=/first-1M of=/dev/$xda
|
||||||
|
Loading…
Reference in New Issue
Block a user