Skip to content

Commit eaa162c

Browse files
author
Ubuntu
committed
reproducible vm image
1 parent 580d34e commit eaa162c

File tree

8 files changed

+1294
-0
lines changed

8 files changed

+1294
-0
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ AGENT.md
77
# Build artifacts and caches
88
target/
99
build/
10+
!crates/contracts/build/
1011
monitoring/
1112

1213
# CI/CD files (except the Dockerfile being built)

tee/configs/cmdline.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console=ttyS0 loglevel=8 debug earlyprintk=serial,ttyS0,115200

tee/docs/DEBUG_MODE.md

Lines changed: 367 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,367 @@
1+
# Debug Mode Configuration
2+
3+
This document describes the debugging optimizations made to the Katana TEE VM image build pipeline.
4+
5+
## Overview
6+
7+
All scripts and configurations have been optimized for maximum debugging visibility during development. This makes it easier to:
8+
- Troubleshoot boot issues
9+
- Verify each step of the build process
10+
- See what's happening inside the VM
11+
- Track down problems quickly
12+
13+
## Kernel Command Line (Debug Mode)
14+
15+
**File:** `tee/configs/cmdline.txt`
16+
17+
```
18+
console=ttyS0 loglevel=8 debug earlyprintk=serial,ttyS0,115200
19+
```
20+
21+
### Parameters Explained
22+
23+
| Parameter | Value | Purpose |
24+
|-----------|-------|---------|
25+
| `console=ttyS0` | Serial port | Redirect all output to serial console |
26+
| `loglevel=8` | Maximum | Show ALL kernel messages including debug |
27+
| `debug` | Flag | Enable additional kernel debug output |
28+
| `earlyprintk=serial,ttyS0,115200` | Early console | Show messages before regular console initializes |
29+
30+
**Effect:** You will see EVERY kernel message from the earliest boot stage through to application startup.
31+
32+
## Init Script (Debug Mode)
33+
34+
**File:** `tee/scripts/create-initrd.sh` (generates `/init` inside initrd)
35+
36+
The init script now includes:
37+
38+
### Debug Features
39+
40+
1. **Startup banner**
41+
```
42+
==========================================
43+
Katana TEE Init - Starting
44+
==========================================
45+
```
46+
47+
2. **Step-by-step progress messages**
48+
- Each mount operation reports success/failure
49+
- Each setup step shows what's happening
50+
- Warnings shown for non-critical failures
51+
52+
3. **System information dump**
53+
- Mounted filesystems (`mount` output)
54+
- Available binaries (`ls -la /bin/`)
55+
- Environment variables (`env`)
56+
- Kernel command line (`/proc/cmdline`)
57+
58+
4. **Clear launch marker**
59+
```
60+
==========================================
61+
[init] Launching Katana...
62+
==========================================
63+
```
64+
65+
### What You'll See
66+
67+
When the VM boots, you'll see output like:
68+
69+
```
70+
==========================================
71+
Katana TEE Init - Starting
72+
==========================================
73+
[init] Mounting proc...
74+
[init] Mounting sysfs...
75+
[init] Mounting devtmpfs...
76+
[init] Creating essential device nodes...
77+
[init] Setting up loopback interface...
78+
[init] Mounted filesystems:
79+
proc on /proc type proc (rw,relatime)
80+
sysfs on /sys type sysfs (rw,relatime)
81+
devtmpfs on /dev type devtmpfs (rw,relatime)
82+
[init] Available binaries in /bin:
83+
total 2048
84+
drwxr-xr-x 2 0 0 4096 Jan 7 19:00 .
85+
drwxr-xr-x 10 0 0 4096 Jan 7 19:00 ..
86+
-rwxr-xr-x 1 0 0 1024000 Jan 7 19:00 busybox
87+
-rwxr-xr-x 1 0 0 1024000 Jan 7 19:00 katana
88+
[init] Environment variables:
89+
PATH=/bin:/sbin:/usr/bin:/usr/sbin
90+
[init] Kernel command line:
91+
console=ttyS0 loglevel=8 debug earlyprintk=serial,ttyS0,115200
92+
==========================================
93+
[init] Launching Katana...
94+
==========================================
95+
```
96+
97+
## Build Scripts (Debug Mode)
98+
99+
All build scripts now include extensive debug output:
100+
101+
### create-initrd.sh Debug Features
102+
103+
**Location:** `tee/scripts/create-initrd.sh`
104+
105+
- Configuration summary at start
106+
- Katana binary verification and info
107+
- Step-by-step progress for each operation
108+
- Directory structure listing
109+
- File size information
110+
- SHA256 hash of output
111+
- Success/failure indicators (✓ or ERROR)
112+
113+
**Example Output:**
114+
```
115+
==========================================
116+
Creating Initrd (Debug Mode)
117+
==========================================
118+
Configuration:
119+
Katana binary: /katana-binary
120+
Output initrd: /output/initrd.img
121+
SOURCE_DATE_EPOCH: 1736277600
122+
==========================================
123+
124+
Katana binary info:
125+
-rwxr-xr-x 1 root root 1.0M Jan 7 19:00 /katana-binary
126+
/katana-binary: ELF 64-bit LSB executable, x86-64, statically linked
127+
128+
Creating initrd directory structure...
129+
✓ Directories created
130+
131+
Copying busybox...
132+
✓ Busybox copied from /bin/busybox
133+
134+
Creating busybox symlinks...
135+
- bin/sh -> busybox
136+
- bin/mount -> busybox
137+
[...]
138+
✓ Symlinks created
139+
140+
Copying Katana binary...
141+
✓ Katana copied to bin/katana
142+
-rwxr-xr-x 1 root root 1.0M Jan 7 19:00 bin/katana
143+
144+
[... more output ...]
145+
146+
==========================================
147+
✓ Initrd created successfully!
148+
==========================================
149+
Output file: /output/initrd.img
150+
Size: 512K
151+
SHA256: a1b2c3d4e5f6...
152+
==========================================
153+
```
154+
155+
### build-vm-image.sh Debug Features
156+
157+
**Location:** `tee/scripts/build-vm-image.sh`
158+
159+
- Configuration summary with all parameters
160+
- Input file sizes
161+
- Partition creation details
162+
- Loop device information
163+
- Filesystem format progress
164+
- Mount points and status
165+
- File copy operations with sizes
166+
- Kernel command line display
167+
- EFI partition contents listing
168+
- Timestamp normalization status
169+
- Final image hash
170+
171+
**Example Output:**
172+
```
173+
==========================================
174+
Building VM Image (Debug Mode)
175+
==========================================
176+
Configuration:
177+
Output: /output/disk.raw
178+
Kernel: /components/vmlinuz
179+
Initrd: /components/initrd.img
180+
Cmdline: /configs/cmdline.txt
181+
Size: 2G
182+
SOURCE_DATE_EPOCH: 1736277600
183+
==========================================
184+
185+
Input file sizes:
186+
-rw-r--r-- 1 root root 10M Jan 7 19:00 /components/vmlinuz
187+
-rw-r--r-- 1 root root 512K Jan 7 19:00 /components/initrd.img
188+
-rw-r--r-- 1 root root 64 Jan 7 19:00 /configs/cmdline.txt
189+
190+
Creating GPT partition table...
191+
Partition 1: EFI (100MB, type ef00)
192+
Partition 2: ROOT (remaining, type 8300)
193+
✓ Partitions created
194+
195+
✓ Loop device attached: /dev/loop0
196+
197+
Waiting for partition devices...
198+
brw-rw---- 1 root disk 7, 0 Jan 7 19:00 /dev/loop0
199+
brw-rw---- 1 root disk 259, 0 Jan 7 19:00 /dev/loop0p1
200+
brw-rw---- 1 root disk 259, 1 Jan 7 19:00 /dev/loop0p2
201+
202+
Formatting EFI partition (FAT32)...
203+
✓ EFI partition formatted
204+
205+
Formatting root partition (ext4, deterministic)...
206+
✓ ROOT partition formatted
207+
208+
[... more output ...]
209+
210+
==========================================
211+
✓ VM image created successfully!
212+
==========================================
213+
Output file: /output/disk.raw
214+
Image size: 2.0G
215+
SHA256: a1b2c3d4e5f6...
216+
==========================================
217+
```
218+
219+
## Viewing Debug Output
220+
221+
### During Docker Build
222+
223+
When building the VM image with Docker, you'll see all this debug output in real-time:
224+
225+
```bash
226+
docker build -f vm-image.Dockerfile \
227+
--build-arg SOURCE_DATE_EPOCH=$(git log -1 --format=%ct) \
228+
--build-context katana-binary=. \
229+
-t katana-vm-image .
230+
```
231+
232+
### During VM Boot
233+
234+
When booting the VM with QEMU, connect to the serial console to see all boot messages:
235+
236+
```bash
237+
qemu-system-x86_64 \
238+
-enable-kvm \
239+
-m 4G \
240+
-cpu EPYC-v4 \
241+
-bios ovmf.fd \
242+
-drive format=raw,file=disk.raw \
243+
-nographic \
244+
-serial mon:stdio
245+
```
246+
247+
You'll see:
248+
1. OVMF firmware messages
249+
2. Kernel boot messages (very verbose with loglevel=8)
250+
3. Init script debug output
251+
4. Katana startup
252+
253+
### Via GCP Serial Console
254+
255+
For VMs running in GCP Confidential Computing:
256+
257+
```bash
258+
gcloud compute instances get-serial-port-output INSTANCE_NAME
259+
```
260+
261+
Or connect interactively:
262+
```bash
263+
gcloud compute connect-to-serial-port INSTANCE_NAME
264+
```
265+
266+
## Debug vs Production
267+
268+
### Current (Debug) Configuration
269+
270+
**Optimized for:** Development, troubleshooting, testing
271+
272+
**Characteristics:**
273+
- Maximum verbosity
274+
- Detailed progress messages
275+
- System information dumps
276+
- Early boot messages
277+
- Every step logged
278+
279+
**Trade-offs:**
280+
- Slower boot (serial console is slow)
281+
- More console output = more data
282+
- Potential information leakage
283+
- Larger logs
284+
285+
### Production Configuration
286+
287+
When ready for production, change to:
288+
289+
#### cmdline.txt (Production)
290+
```
291+
console=ttyS0 loglevel=3 ro
292+
```
293+
294+
#### Init Script (Production)
295+
Remove or reduce debug messages:
296+
- Keep critical error messages
297+
- Remove info dumps (mount, env, etc.)
298+
- Remove progress indicators
299+
- Keep only what's needed for troubleshooting real issues
300+
301+
**Benefits:**
302+
- Faster boot
303+
- Less information exposure
304+
- Smaller logs
305+
- More professional appearance
306+
307+
## Switching Modes
308+
309+
### To Production Mode
310+
311+
1. **Update cmdline.txt:**
312+
```bash
313+
echo "console=ttyS0 loglevel=3 ro" > tee/configs/cmdline.txt
314+
```
315+
316+
2. **Simplify init script** in `create-initrd.sh`:
317+
- Remove echo statements for progress
318+
- Keep only error messages
319+
- Remove info dumps (mount, ls, env)
320+
321+
3. **Simplify build scripts** (optional):
322+
- Remove "✓" indicators
323+
- Keep only error messages
324+
- Remove detailed listings
325+
326+
### Back to Debug Mode
327+
328+
1. **Update cmdline.txt:**
329+
```bash
330+
echo "console=ttyS0 loglevel=8 debug earlyprintk=serial,ttyS0,115200" > tee/configs/cmdline.txt
331+
```
332+
333+
2. Init script and build scripts are already in debug mode (no changes needed if you kept the debug versions)
334+
335+
## Debugging Tips
336+
337+
### If the VM doesn't boot
338+
339+
1. **Check QEMU output** - Look for the last message before it stops
340+
2. **Try even more verbose kernel:** `loglevel=9`
341+
3. **Add init debug:** Change init to `/bin/sh` to drop to a shell:
342+
```
343+
init=/bin/sh
344+
```
345+
346+
### If Katana fails to start
347+
348+
The init script will show:
349+
- What files are available
350+
- What the environment looks like
351+
- The exact command line being used
352+
353+
### If you can't see any output
354+
355+
1. **Check console parameter** - Make sure `console=ttyS0` is present
356+
2. **Check QEMU serial setup** - Use `-serial mon:stdio` or `-serial file:serial.log`
357+
3. **Try VGA console** - Add `console=tty0 console=ttyS0` (both)
358+
359+
## Current Status
360+
361+
**All debug optimizations complete:**
362+
- Kernel: Maximum verbosity + early boot messages
363+
- Init: Full system information dump + progress tracking
364+
- Build scripts: Comprehensive step-by-step output with success indicators
365+
- All scripts show SHA256 hashes for verification
366+
367+
This configuration gives you complete visibility into every aspect of the build and boot process, making debugging much easier during development.

0 commit comments

Comments
 (0)