From f62c5ee1c670552fb33d6e0903dea5466abdf1d0 Mon Sep 17 00:00:00 2001 From: bin456789 Date: Tue, 1 Aug 2023 21:48:20 +0800 Subject: [PATCH] =?UTF-8?q?core:=20nbd=20=E8=BF=9E=E6=8E=A5=E5=92=8C?= =?UTF-8?q?=E6=96=AD=E5=BC=80=E5=90=8E=E8=A6=81=20sleep=20=E5=87=A0?= =?UTF-8?q?=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trans.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/trans.sh b/trans.sh index 6a87fca..d2614b4 100644 --- a/trans.sh +++ b/trans.sh @@ -172,11 +172,16 @@ EOF done } +qemu_nbd() { + command qemu-nbd "$@" + sleep 5 +} + # 可能脚本不是首次运行,先清理之前的残留 clear_previous() { { # TODO: fuser and kill - qemu-nbd -d /dev/nbd0 + qemu_nbd -d /dev/nbd0 swapoff -a # alpine 自带的umount没有-R,除非安装了util-linux umount -R /iso /wim /installer /os/installer /os /nbd /nbd-boot /nbd-efi @@ -501,8 +506,7 @@ install_cloud_image() { } modprobe nbd - qemu-nbd -c /dev/nbd0 $qcow_file - sleep 5 + qemu_nbd -c /dev/nbd0 $qcow_file os_part=$(lsblk /dev/nbd0p*[0-9] --sort SIZE -no NAME,FSTYPE | grep xfs | tail -1 | cut -d' ' -f1) efi_part=$(lsblk /dev/nbd0p*[0-9] --sort SIZE -no NAME,FSTYPE | grep fat | tail -1 | cut -d' ' -f1) @@ -559,8 +563,7 @@ install_cloud_image() { # 取消挂载 nbd umount /nbd/ /nbd-boot/ /nbd-efi/ || true - qemu-nbd -d /dev/nbd0 - sleep 5 + qemu_nbd -d /dev/nbd0 # 创建 swap rm -rf /installer/* @@ -666,7 +669,7 @@ EOF # debian ubuntu arch if true; then modprobe nbd - qemu-nbd -c /dev/nbd0 $qcow_file + qemu_nbd -c /dev/nbd0 $qcow_file # 将前1M dd到内存 dd if=/dev/nbd0 of=/first-1M bs=1M count=1 @@ -690,7 +693,7 @@ EOF ;; esac - qemu-nbd -d /dev/nbd0 + qemu_nbd -d /dev/nbd0 else # 将前1M dd到内存,将1M之后 dd到硬盘 qemu-img dd if=$qcow_file of=/first-1M bs=1M count=1