Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions kvmapp/system/init.d/S03usbdev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 13 additions & 12 deletions server/service/storage/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 = ""
}

Expand Down