|
本帖最后由 2011niumao 于 2023-6-16 10:30 编辑
看看我这个方案。好像我也没有成功,但是Ubuntu系统qemu-nbd是成功了的,只是明显感觉到系统迟钝。
注意,引导参数是 qemu-nbd. 它的值是vhd文件的含路径的名称。
注意,需要安装ntfs-3g, 最好是我修订过的ntfs-3g
- ########################################################################
- ### KLOOP by niumao ###
- ########################################################################
- QEMUNBD=$(getarg qemunbd=)
- export QEMUNBD
-
- if [ -n "$QEMUNBD" ]; then
- ### reset the value of the root variable
- HOSTDEV="${root#block:}"
- [ -n "$KROOT" ] || root="/dev/loop0"
- [ -n "$KROOT" ] && root="$KROOT"
- realroot="$root"
- export root
- if ismounted "$NEWROOT"; then
- umount "$NEWROOT"
- fi
-
- ### auto probe the fs-type of the partition in which vhd-file live and mount it /host
- mkdir -p /host
- if [ -z "${HOSTFSTYPE}" ]; then
- HOSTFSTYPE="$(blkid -s TYPE -o value "$HOSTDEV")"
- [ -z "${HOSTFSTYPE}" -o "${HOSTFSTYPE}" = "ntfs" ] && HOSTFSTYPE="ntfs-3g"
- fi
- [ "${HOSTFSTYPE}" = "ntfs-3g" ] || modprobe ${HOSTFSTYPE}
- mount -t "${HOSTFSTYPE}" -o rw $HOSTDEV /host
-
- ### mount the vhd-file on a loop-device
- if [ "${QEMUNBD#/}" != "${QEMUNBD}" ]; then
- modprobe nbd
- [ -e /host$QEMUNBD ] || sleep 3
- qemu-nbd -c /dev/nbd0 /host$QEMUNBD
- kpartx -av /dev/nbd0
- [ -e "$realroot" ] || sleep 3
- fi
- ### mount the realroot / in vhd-file on $NEWROOT
- if [ -z "${KLOOPFSTYPE}" ]; then
- KLOOPFSTYPE="$(blkid -s TYPE -o value "$realroot")"
- [ -z "${KLOOPFSTYPE}" ] && KLOOPFSTYPE="ext4"
- fi
- [ -e "$realroot" ] || sleep 3
- mount -t "${KLOOPFSTYPE}" -o rw $realroot $NEWROOT
-
- ### mount /host in initrd to /host of the realrootfs
- if [ "${HOSTHIDDEN}" != "y" ] ; then
- [ -d "${NEWROOT}"/host ] || mkdir -p ${NEWROOT}/host
- mount -R /host ${NEWROOT}/host
- fi
- fi
- ########################################################################
- ### END, KLOOP by niumao ###
- ########################################################################
复制代码 |
|