This repository contains a shell script that creates a fully bootable AMD64 Linux disk image using QEMU. The image, once booted, prints "hello world" to the console and does not include any user/session management or login prompts.
The script is created by Kondreddy Rohith Sai Reddy and performs the following steps:
- Kernel Image Verification: Checks for a kernel image named
vmlinuz
in the current directory. If not found, it downloads a prebuilt AMD64 kernel image from a provided URL (update the URL as needed). - Minimal Init Program: Creates and statically compiles a small C program that prints "hello world".
- Disk Image Creation:
- Creates a 64 MB disk image.
- Uses
parted
to partition the image with an MBR partition table. - Creates a primary ext4 partition and marks it as bootable.
- Filesystem Setup:
- Formats the partition as ext4.
- Mounts the partition and copies the kernel image and the init binary.
- Sets up a minimal GRUB configuration.
- GRUB Bootloader Installation: Installs GRUB onto the disk image to make it fully bootable.
- QEMU Boot: Launches QEMU to boot the disk image, directing console output to the terminal.
Ensure the following tools are installed on your system:
qemu-system-x86_64
gcc
wget
cpio
gzip
dd
parted
mkfs.ext4
losetup
mount
umount
grub-install
Note: Several operations (e.g., mounting, loop device management, GRUB installation) require superuser privileges. It is recommended to run the script using
sudo
.
-
Prepare the Environment:
Verify that all required tools are installed. If not, install them using your package manager. -
Kernel Image:
Place a valid AMD64 Linux kernel image namedvmlinuz
in the current directory.
Alternatively, update theKERNEL_URL
variable in the script with a valid URL to download a kernel image automatically. -
Run the Script:
Execute the script (e.g.,sudo ./script_name.sh
).
The script operates entirely within the current working directory and does not require any additional user input.
-
Kernel Image Verification:
Checks forvmlinuz
in the current directory and downloads it if missing. -
Minimal Init Program:
A C program (hello.c
) is created and compiled statically into an executableinit
that prints "hello world". -
Disk Image Creation and Partitioning:
- A 64 MB disk image (
disk.img
) is created usingdd
. - The disk is partitioned with
parted
(MBR) and a primary partition is set as bootable.
- A 64 MB disk image (
-
Filesystem and GRUB Setup:
- The partition is formatted as ext4.
- The kernel and init binary are copied to the appropriate locations.
- A minimal GRUB configuration is created in
/boot/grub/grub.cfg
to boot the kernel withinit=/init
. - GRUB is installed onto the disk image with
grub-install
.
-
Booting via QEMU:
The disk image is booted with QEMU using the-nographic
option so that all output is sent to the terminal.
- The script is designed for Ubuntu 20.04 LTS or 22.04 LTS (or similar Linux distributions).
- All operations are confined to the current working directory.
- Superuser privileges are required for certain operations such as mounting, loop device management, and GRUB installation.
- The placeholder kernel URL in the script must be updated to a valid URL if no local kernel image is provided.
The script automatically cleans up temporary files and unmounts any mounted partitions after installing GRUB.