Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request to repair the error of qemu nbd in the switch_root process #2637

Open
lz-lunzi opened this issue Mar 9, 2024 · 5 comments
Open

Request to repair the error of qemu nbd in the switch_root process #2637

lz-lunzi opened this issue Mar 9, 2024 · 5 comments
Labels
bug Our bugs

Comments

@lz-lunzi
Copy link

lz-lunzi commented Mar 9, 2024

Describe the bug
A clear and concise description of what the error is.

Distribution used
Which distribution was this behaviour seen in?

Dracut version
Version: 059-16.fc39

Init system
/sbin/init -> ../lib/systemd/systemd
To Reproduce
`QEMUNBD=$(getarg qemunbd=)

export QEMUNBD
echo "test:$QEMUNBD"

if [ -n "$QEMUNBD" ]; then
modprobe nbd
modprobe nvme
modprobe ntfs3
if ismounted "$NEWROOT"; then
umount "$NEWROOT"
else
echo "Directory $NEWROOT is not mounted."
fi

    ### reset the value of the root variable
    HOSTDEV="${root#block:}"
    echo "blkid: $(blkid)"
    # HOSTDEV="/dev/nvme0n1p1"
    [ -n "$KROOT" ]  ||  root="/dev/nbd0p2"
    # [ -n "$KROOT" ]  &&  root="$KROOT"
    realroot="$root"
    export root
    echo "root:$root"

                    
    ###  auto probe the fs-type of the partition in which vhd-file live and mount it  /host
    mkdir -p /host
    echo "check host:$(ls /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}
    # ln -s "$HOSTDEV" "/run/initramfs/host_device"
     ( exec -a @ntfs-3g ntfs-3g  $HOSTDEV /host ) | (while read l; do warn $l; done)
 
    ### mount the vhd-file on a loop-device
    if [ "${QEMUNBD#/}" != "${QEMUNBD}" ]; then
            
            [ -e /host$QEMUNBD ] || sleep 3
            mkdir -p /var/lock
            ( exec -a @ndb qemu-nbd -c  /dev/nbd0  /host$QEMUNBD   ) | (while read l; do warn $l; done)
            
            udevadm settle


            [ -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
    echo "KLOOPFSTYPE: $KLOOPFSTYPE"
    [ -e "$realroot" ] || sleep 3
    mount -t "ext4" -o rw $realroot $NEWROOT
    if [  "${HOSTHIDDEN}" != "y" ] ; then
            [ -d "${NEWROOT}"/host ] || mkdir -p ${NEWROOT}/host
            echo "NEWROOT: $(ls $NEWROOT)"
            mount -R /host   ${NEWROOT}/host
            
            #  mount -n -o move  /host   ${NEWROOT}/host
    fi
    echo "$(ls ${NEWROOT}/host)"
    echo "$(ls ${NEWROOT})"

fi`

sudo dracut -i ./kloop/10-vhdmount-kloop.sh /lib/dracut/hooks/pre-mount/10-vhdmount-kloop.sh --no-hostonly --install " vi /etc/virc ps grep cat rm blkid losetup kpartx partx mount.fuse mount.ntfs-3g ntfs-3g shutdown qemu-nbd " --add-drivers "fuse dm-mod nbd nvme " -o " plymouth btrfs crypt cifs fcoe fcoe-uefi iscsi nfs" ./kloop/initramfs.img
`menuentry 'niumao ' --class fedora {
insmod gzio
insmod part_msdos
insmod part_gpt
insmod ext2
insmod ntfs
insmod probe
insmod search
set vhdfile="/Blackup/kloop_dracut/kloop_dracut.vhd"
set root=(hd1,gpt2)
search --no-floppy -f --set=aabbcc $vhdfile
set root=${aabbcc}
probe -u --set=ddeeff ${aabbcc}
linux /Blackup/kloop_dracut/vmlinuz rw root=UUID=${ddeeff} qemunbd=$vhdfile selinux=0 rd.debug rd.shell rd.break=dracut-pre-mount rd.break=dracut-pre-trigger rd.break=dracut-initqueue rd.break=initqueue rd.break=pre-pivot rd.memlunit=2048M rd.ip=auto nbd.max_part=16

initrd	  /Blackup/kloop_dracut/initramfs.img 

}`
Expected behavior
A clear and concise description of what you expected to happen.

Additional context
logs:https://gist.github.com/lz-lunzi/0570a44040270fb676cac4dcbd5c0a96

@lz-lunzi lz-lunzi added the bug Our bugs label Mar 9, 2024
@LaszloGombos
Copy link
Collaborator

There is also a systemd issue - systemd/systemd#31690 that you did not linked to

@lz-lunzi
Copy link
Author

Who knows how to protect specific processes during switch switching
https://mirrors.edge.kernel.org/pub/linux/utils/boot/dracut/dracut.html#_cleanup_and_switch_root

@lz-lunzi
Copy link
Author

hCorrelation of similar problems
#1032

@lz-lunzi
Copy link
Author

lz-lunzi commented Mar 14, 2024

This is some of my handling, although not successful. However, some information can be provided to facilitate understanding
{
echo "[Unit]"
echo "Before=initrd-root-fs.target"
echo "[Mount]"
echo "Where=/sysroot"
echo "What=/dev/nbd0p2"
echo "Type=ext4"
echo "Options=rw"
} > /etc/systemd/system/sysroot.mount

            {            
            echo  "[Unit]"
            echo  "Description=Qemu NBD Server"
            echo  "After=network.target"
            echo  "[Service]"
            echo  "ExecStart=qemu-nbd -c  /dev/nbd0  /host$QEMUNBD"
            echo  "Restart=always"
            echo  "RootService=true"
            echo  "SurviveFinalKillSignal=yes"
            echo  "[Install]"
            echo  "WantedBy=multi-user.target"
            }    > /etc/systemd/system/qemu-nbd.service

Reference:
https://systemd.io/ROOT_STORAGE_DAEMONS/

@lz-lunzi
Copy link
Author

lz-lunzi commented Apr 2, 2024

logs:
[ 24.890490] fedora systemctl[976]: Bus n/a: changing state UNSET → OPENING
[ 24.890784] fedora systemctl[976]: sd-bus: starting bus by connecting to /run/systemd/private...
[ 24.891276] fedora systemctl[976]: Bus n/a: changing state OPENING → AUTHENTICATING
[ 24.891560] fedora systemctl[976]: Executing dbus call org.freedesktop.systemd1.Manager StartUnit(initrd-switch-root.target, isolate)
[ 24.893117] fedora systemctl[976]: Bus n/a: changing state AUTHENTICATING → RUNNING
[ 24.893464] fedora systemctl[976]: Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=StartUnit cookie=1 reply_cookie=0 signature=ss error-name=n/a error-message=n/a
[ 24.894369] fedora systemctl[976]: Got message type=method_return sender=org.freedesktop.systemd1 destination=n/a path=n/a interface=n/a member=n/a cookie=3 reply_cookie=1 signature=o error-name=n/a error-message=n/a
[ 24.894893] fedora systemctl[976]: Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=GetUnit cookie=2 reply_cookie=0 signature=s error-name=n/a error-message=n/a
[ 24.896499] fedora systemctl[976]: Got message type=method_return sender=org.freedesktop.systemd1 destination=n/a path=n/a interface=n/a member=n/a cookie=114 reply_cookie=2 signature=o error-name=n/a error-message=n/a
[ 24.898173] fedora systemctl[976]: Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1/unit/initrd_2dswitch_2droot_2etarget interface=org.freedesktop.DBus.Properties member=Get cookie=3 reply_cookie=0 signature=ss error-name=n/a error-message=n/a
[ 24.955170] fedora systemctl[976]: Got message type=method_return sender=org.freedesktop.systemd1 destination=n/a path=n/a interface=n/a member=n/a cookie=288 reply_cookie=3 signature=v error-name=n/a error-message=n/a
[ 24.955987] fedora systemctl[976]: Bus n/a: changing state RUNNING → CLOSED
[ 25.003636] fedora systemd-journald[393]: Successfully sent stream file descriptor to service manager.
[ 25.001777] fedora udevadm[979]: Found cgroup2 on /sys/fs/cgroup/, full unified hierarchy
[ 25.001777] fedora udevadm[979]: Found container virtualization none.
[ 25.009743] fedora udevadm[979]: SELinux enabled state cached to: disabled
[ 25.034886] fedora systemd-journald[393]: Successfully sent stream file descriptor to service manager.
[ 25.041328] fedora @ystemctl[981]: Bus n/a: changing state UNSET → OPENING
[ 25.042086] fedora @ystemctl[981]: sd-bus: starting bus by connecting to /run/systemd/private...
[ 25.042595] fedora @ystemctl[981]: Bus n/a: changing state OPENING → AUTHENTICATING
[ 25.042985] fedora @ystemctl[981]: Switching root - root: /sysroot; init: n/a
[ 25.044560] fedora @ystemctl[981]: Bus n/a: changing state AUTHENTICATING → RUNNING
[ 25.045388] fedora @ystemctl[981]: Sent message type=method_call sender=n/a destination=org.freedesktop.systemd1 path=/org/freedesktop/systemd1 interface=org.freedesktop.systemd1.Manager member=SwitchRoot cookie=1 reply_cookie=0 signature=ss error-name=n/a error-message=n/a
[ 25.055008] fedora @ystemctl[981]: Got message type=method_return sender=org.freedesktop.systemd1 destination=n/a path=n/a interface=n/a member=n/a cookie=1 reply_cookie=1 signature=n/a error-name=n/a error-message=n/a
[ 25.056204] fedora @ystemctl[981]: Bus n/a: changing state RUNNING → CLOSED
[ 25.182251] fedora kernel: block nbd0: shutting down sockets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Our bugs
Projects
None yet
Development

No branches or pull requests

2 participants