Creating of disk image for VirtualBox
Simple example.
We have the Linux kernel and the file system.
What shell we do to create the disk image for VirtualBox?
Because this mechanism is implemented in openWrt we will use the tools of
openwrt, so we need to build openWrt for x86 configuration.
All the description is given using the openwrt building for x86. All scripts and utilities which are used here are specified either in target/linux/x86 or in staging_dir/host.
1. Image creating openwrt-x86-generic-combined-ext4.img.
OPENWRT_DIR="/home/user1/MyWork/openWrt_X86/barrier_breaker" cd $OPENWRT_DIR/target/linux/x86/image PADDING="y" ./gen_image_generic.sh \ $OPENWRT_DIR/bin/x86/openwrt-x86-generic-combined-ext4.img 4 \ $OPENWRT_DIR/build_dir/target-i386_i486_uClibc-0.9.33.2/linux-x86_generic/root.grub 48 \ $OPENWRT_DIR/build_dir/target-i386_i486_uClibc-0.9.33.2/linux-x86_generic/root.ext4 256
2. grub-bios-setup
grub-bios-setup --device-map="/home/user1/MyWork/openWrt_X86/barrier_breaker/build_dir/target-i386_i486_uClibc-0.9.33.2/linux-x86_generic/grub2/device.map" -d "/home/user1/MyWork/openWrt_X86/barrier_breaker/build_dir/target-i386_i486_uClibc-0.9.33.2/linux-x86_generic/grub2" -r "hd0,msdos1" "/home/user1/MyWork/openWrt_X86/barrier_breaker/bin/x86/openwrt-x86-generic-combined-ext4.img"
3. VDI image creating
qemu-img convert -f raw -O vdi \ $OPENWRT_DIR/bin/x86/openwrt-x86-generic-combined-ext4.img \ $OPENWRT_DIR/bin/x86/openwrt-x86-generic-combined-ext4.vdi
Script content:
#!/bin/bash OPENWRT_DIR="/home/user1/MyWork/openWrt_X86/barrier_breaker" cd $OPENWRT_DIR/target/linux/x86/image PADDING="y" ./gen_image_generic.sh \ $OPENWRT_DIR/bin/x86/openwrt-x86-generic-combined-ext4.img 4 \ $OPENWRT_DIR/build_dir/target-i386_i486_uClibc-0.9.33.2/linux-x86_generic/root.grub 48 \ $OPENWRT_DIR/build_dir/target-i386_i486_uClibc-0.9.33.2/linux-x86_generic/root.ext4 256 ./grub-bios-setup --device-map="$OPENWRT_DIR/build_dir/target-i386_i486_uClibc-0.9.33.2/linux-x86_generic/grub2/device.map" \ -d "$OPENWRT_DIR/build_dir/target-i386_i486_uClibc-0.9.33.2/linux-x86_generic/grub2" \ -r "hd0,msdos1" "$OPENWRT_DIR/bin/x86/openwrt-x86-generic-combined-ext4.img" qemu-img convert -f raw -O vdi \ $OPENWRT_DIR/bin/x86/openwrt-x86-generic-combined-ext4.img \ $OPENWRT_DIR/bin/x86/openwrt-x86-generic-combined-ext4.vdi
The VDI image will be located in the directory
$OPENWRT_DIR/bin/x86/openwrt-x86-generic-combined-ext4.vdi
The kernel in the format vmlinuz will be located in the directory:
$OPENWRT_DIR/build_dir/target-i386_i486_uClibc-0.9.33.2/linux-x86_generic/root.grub
To get the vmlinuz image we should use while single kernel building the following command:
make bzImage && cp ./arch/x86/boot/bzImage ./arch/x86/boot/vmlinuz
The root file system is represented as an image file in:
$OPENWRT_DIR/build_dir/target-i386_i486_uClibc-0.9.33.2/linux-x86_generic/root.ext4