Commit 9d37427
committed
fix: don't expose eMMC as USB mass storage when no image is mounted
When /boot/usb.disk0 exists but is empty (the default state), the USB
gadget init script (S03usbdev) sets /dev/mmcblk0p3 as the mass storage
backing file. This exposes the NanoKVM's raw eMMC partition (~162MB,
ext4/exfat) as a USB disk to the host computer.
On Legacy BIOS systems, the BIOS attempts to boot from this device,
reads invalid data (no MBR), and enters a HLT loop — completely hanging
the system with no keyboard input accepted. The only recovery is a
physical power cycle.
Similarly, the Go server (image.go) re-mounts /dev/mmcblk0p3 whenever
an ISO image is unmounted, re-exposing the eMMC partition.
Changes:
S03usbdev: Flip the empty-file check so that when usb.disk0 is empty,
no backing file is set. The mass_storage device (with removable=1)
reports "no media inserted" — which BIOS handles safely by skipping
to the next boot device. When usb.disk0 contains a path, that path
is used as before.
image.go: Remove the imageNone constant (/dev/mmcblk0p3). When
unmounting an image (empty request), the device stays unmounted instead
of falling back to the eMMC partition. GetMountedImage retains backward
compatibility by treating mmcblk0p3 as "no image" for devices that
haven't rebooted yet.
No changes needed to virtual-device.go — with this fix, toggling
"Virtual Disk" ON creates the mass_storage gadget with no media
(correct behavior), and users mount ISOs through the existing UI.
Refs: #633, #385, #438, #1871 parent 4af32fc commit 9d37427
2 files changed
Lines changed: 19 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | 111 | | |
119 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
120 | 118 | | |
121 | 119 | | |
122 | 120 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
109 | 108 | | |
110 | 109 | | |
111 | 110 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
121 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| |||
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
159 | | - | |
160 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
161 | 162 | | |
162 | 163 | | |
163 | 164 | | |
| |||
0 commit comments