diff --git a/kvmapp/system/init.d/S03usbdev b/kvmapp/system/init.d/S03usbdev index df5e2486..cebda146 100755 --- a/kvmapp/system/init.d/S03usbdev +++ b/kvmapp/system/init.d/S03usbdev @@ -106,17 +106,15 @@ start_usb_dev(){ fi echo "NanoKVM USB Mass Storage0520" > functions/mass_storage.disk0/lun.0/inquiry_string disk=$(cat /boot/usb.disk0) - if [ -z "${disk}" ] + if [ -n "${disk}" ] then - # if [ ! -e /mnt/usbdisk.img ] - # then - # fallocate -l 8G /mnt/usbdisk.img - # mkfs.vfat /mnt/usbdisk.img - # fi - echo /dev/mmcblk0p3 > functions/mass_storage.disk0/lun.0/file - else cat /boot/usb.disk0 > functions/mass_storage.disk0/lun.0/file fi + # When usb.disk0 is empty, no backing file is set. The device + # reports "no media" (removable=1). Previously this defaulted to + # /dev/mmcblk0p3, exposing the NanoKVM's raw eMMC partition as a + # USB disk — causing Legacy BIOS systems to hang during boot. + # See: https://github.com/sipeed/NanoKVM/issues/633 fi ls /sys/class/udc/ | cat > UDC diff --git a/server/service/storage/image.go b/server/service/storage/image.go index 4e0be465..ef513d42 100644 --- a/server/service/storage/image.go +++ b/server/service/storage/image.go @@ -18,7 +18,6 @@ import ( const ( imageDirectory = "/data" - imageNone = "/dev/mmcblk0p3" cdromFlag = "/sys/kernel/config/usb_gadget/g0/functions/mass_storage.disk0/lun.0/cdrom" mountDevice = "/sys/kernel/config/usb_gadget/g0/functions/mass_storage.disk0/lun.0/file" inquiryString = "/sys/kernel/config/usb_gadget/g0/functions/mass_storage.disk0/lun.0/inquiry_string" @@ -109,16 +108,17 @@ func (s *Service) MountImage(c *gin.Context) { } // mount - image := req.File - if image == "" { - image = imageNone - } - - if err := os.WriteFile(mountDevice, []byte(image), 0o666); err != nil { - log.Errorf("mount file %s failed: %s", image, err) - rsp.ErrRsp(c, -2, "mount image failed") - return + if req.File != "" { + if err := os.WriteFile(mountDevice, []byte(req.File), 0o666); err != nil { + log.Errorf("mount file %s failed: %s", req.File, err) + rsp.ErrRsp(c, -2, "mount image failed") + return + } } + // When req.File is empty the device stays unmounted (no media). + // Previously this wrote /dev/mmcblk0p3, exposing the NanoKVM's raw + // eMMC partition as a USB disk — causing Legacy BIOS boot hangs. + // See: https://github.com/sipeed/NanoKVM/issues/633 h := hid.GetHid() h.Lock() @@ -156,8 +156,9 @@ func (s *Service) GetMountedImage(c *gin.Context) { return } - image := strings.ReplaceAll(string(content), "\n", "") - if image == imageNone { + image := strings.TrimSpace(string(content)) + if image == "/dev/mmcblk0p3" { + // Backward compat: treat eMMC partition as "no image mounted" image = "" }