All Articles

How to Use QEMU's nographic Option to Run a 30-Day OS Boot Image in the CUI

This page has been machine-translated from the original page.

This article summarizes QEMU’s nographic option for running a DIY OS in the CUI.

The binary used here is the do-nothing boot image created on day 1 of 30-Day OS.

One difference from the 30-Day OS book is that I use NASM, a general-purpose assembler, instead of the author’s custom tools.

Running QEMU in the CUI

To start with the conclusion, I was able to run the boot image in QEMU’s CUI with the following command:

@@BT@@@@BT@@@bash qemu-system-x86_64 -drive file=boot.img,format=raw -nographic @@BT@@@@BT@@

I think this is probably the minimum set of options needed to run a binary in QEMU’s CUI.

The meaning of each option is as follows:

@@BT@@@@BT@@ -drive:
An option for using a file as a drive image Takes [file=file] as a required argument

[file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i]
[,cache=writethrough|writeback|none|directsync|unsafe][,format=f]
[,snapshot=on|off][,rerror=ignore|stop|report]
[,werror=ignore|stop|report|enospc][,id=name][,aio=threads|native]
[,readonly=on|off][,copy-on-read=on|off]
[,discard=ignore|unmap][,detect-zeroes=on|off|unmap]
[[,bps=b]|[[,bps_rd=r][,bps_wr=w]]]
[[,iops=i]|[[,iops_rd=r][,iops_wr=w]]]
[[,bps_max=bm]|[[,bps_rd_max=rm][,bps_wr_max=wm]]]
[[,iops_max=im]|[[,iops_rd_max=irm][,iops_wr_max=iwm]]]
[[,iops_size=is]]
[[,group=g]]

-nographic: Disable the GUI and redirect serial I/O to the console @@BT@@@@BT@@

As noted above, the @@BT@@-drive@@BT@@ option is used to specify the boot image (@@BT@@boot.img@@BT@@) created with NASM as a drive image.

@@BT@@file@@BT@@ and @@BT@@format@@BT@@ are arguments for the @@BT@@-drive@@BT@@ option.

@@BT@@@@BT@@@bash -drive file=boot.img,format=raw @@BT@@@@BT@@

The only required argument for @@BT@@-drive@@BT@@ is [file=file], but here I also specify format=raw.

Even without format=raw, you can start QEMU in the CUI, but it will print the following warning:

WARNING:
Image format was not specified for '/haribote/boot.img' and probing guessed raw.Specify the 'raw' format explicitly to remove the restrictions.

Next is the @@BT@@-nographic@@BT@@ option. This is the option for starting QEMU in the CUI. As the help says, it redirects serial I/O (data communicated between devices) to the console.

Stopping QEMU in the CUI

Once QEMU has started in the CUI, return to the original console. To return to the console, enter the following keys in sequence:

Ctrl + A
X

After pressing @@BT@@Ctrl + A@@BT@@, release the keys and then press @@BT@@X@@BT@@. This will stop QEMU.