Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qemu gets stuck at booting from hard disk

Tags:

linux

qemu

I am trying to load a simple kernel using the qemu emulator but, qemu gets stuck at "Booting from hard disk". A screenshot of the problem

The source code for the kernel can be found in the following link: https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-828-operating-system-engineering-fall-2012/ , in the lab 1 assignment in the directory obj/kern/kernel.img. Pdf of lab1, tar.gz of lab1, pointers1.c. The task was:

The first part concentrates on getting familiarized with x86 assembly language, the QEMU x86 emulator, and the PC's power-on bootstrap procedure. The second part examines the boot loader for our 6.828 kernel, which resides in the boot directory of the lab tree ...

 % cd lab
 % make
 ...
 + mk obj/kern/kernel.img 

.. Now you're ready to run QEMU, supplying the file obj/kern/kernel.img, created above, as the contents of the emulated PC's "virtual hard disk." This hard disk image contains both our boot loader (obj/boot/boot) and our kernel (obj/kernel).

 % make qemu 
like image 549
eng140 Avatar asked May 30 '17 19:05

eng140


3 Answers

eng140,you could use a 32-bit Linux. I had the same problem. After having used a 32-bit Linux, this problem was solved. In the following web https://pdos.csail.mit.edu/6.828/2017/tools.html in the section "Using a virtual Machine", they recommend that we should use a 32-bit Linux.

like image 101
zhihang he Avatar answered Oct 19 '22 17:10

zhihang he


It also may be issue with gcc version. Latest available Fall(2018) has fix for this

Author: Jonathan Behrens <[email protected]>
Date:   Tue Sep 4 14:10:42 2018 -0400

Tweak kernel.ld linker script so edata and end are set correctly

This change should hopefully resolve issues when compiling with newer versions
of GCC.

commit a56269d4beefc7d0b3672180aa46c654cfb63af4
diff --git a/kern/kernel.ld b/kern/kernel.ld
index 45a0b6a..a219d1d 100644
--- a/kern/kernel.ld
+++ b/kern/kernel.ld
@@ -47,13 +47,13 @@ SECTIONS
                *(.data)
    }
-       PROVIDE(edata = .);
-
        .bss : {
+               PROVIDE(edata = .);
                *(.bss)
+               PROVIDE(end = .);
+               BYTE(0)
        }
-       PROVIDE(end = .);
        /DISCARD/ : {
                *(.eh_frame .note.GNU-stack)
like image 36
Yagami Light Avatar answered Oct 19 '22 19:10

Yagami Light


eng140, as explained in the course pdf MIT6_828F12_lab1.pdf - https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-828-operating-system-engineering-fall-2012/labs/MIT6_828F12_lab1.pdf, You should start qemu from the makefile with make qemu:

This executes QEMU with the options required to set the hard disk and direct serial port output to the terminal. Some text should appear in the QEMU window: ...

You should not start it with manual procedure like you did (qemu-system-x86_64 ..). This target is implemented in lab GNUmakefile as

qemu: $(IMAGES) pre-qemu
    $(QEMU) $(QEMUOPTS)

and QEMU var is qemu on most platforms and i386-softmmu on MacOS. To, try to use 32-bit system version of qemu or standard qemu command. The options from makefile are like:

QEMUOPTS = -hda $(OBJDIR)/kern/kernel.img -serial mon:stdio -gdb tcp::$(GDBPORT)
QEMUOPTS += $(shell if $(QEMU) -nographic -help | grep -q '^-D '; then echo '-D qemu.log'; fi)
IMAGES = $(OBJDIR)/kern/kernel.img
QEMUOPTS += $(QEMUEXTRA)

The lab options have -serial mon:stdio which is ... http://download.qemu.org/qemu-doc.html

-serial dev -- Redirect the virtual serial port to host character device dev. .. This option can be used several times to simulate up to 4 serial ports. ...

mon:dev_string

This is a special option to allow the monitor to be multiplexed onto another serial port. The monitor is accessed with key sequence of Control-a and then pressing c. dev_string should be any one of the serial devices specified above. An example to multiplex the monitor onto a telnet server listening on port 4444 would be:

Probably your image to be boot uses serial port, not display to print things. Try adding to your command like:

qemu-system-i386 -drive format=raw,file=obj/kern/kernel.img -serial mon:stdio

or

qemu-system-i386 -hda obj/kern/kernel.img -serial mon:stdio
like image 1
osgx Avatar answered Oct 19 '22 19:10

osgx