Building Fatdog inside QEMU
===========================

------------

Introduction
------------

Inside this script you will find directory `qemu`. It contains two
scripts, `runiso.sh` and `runsfs.sh`.  These are simple wrapper scripts
to launch and run Fatdog ISO or SFS under qemu.

Just put fatdog.iso or fd64.sfs under `iso` directory and launch the script,
e.g. `./iso/runiso.sh`. It will launch a 1GB qemu instance.

For this to work, you need to have qemu installed. Qemu comes in `devx.sfs`,
so if you use `devx.sfs` then it's already installed for you.

You can adjust the memory by adding MEM=xxxx env variable before launching
the script, e.g. `MEM=2048 ./runiso.sh` to launch a qemu instance with
2GB RAM.

___________________________________


Virtual Disk in Qemu
--------------------

You can also create a file called `disk.ext3` inside `iso` and this
will be mounted as a virtual disk, which you can then use for savefile
or savedir or whatever have you. With `runiso.sh` this virtual disk
will show in as "sda", with `runsfs.sh` it will show up as "sdd".

To make a 1GB virtual disk:

```
dd if=/dev/zero of=iso/disk.ext3 bs=1G count=0 seek=1
mkfs.ext3 iso/disk.ext3
```

___________________________________


Building Fatdog inside QEMU - the Steps
---------------------------------------

If you system is able to run a 2GB qemu instance, and you can create
4GB virtual disk, it is possible to build Fatdog64 using this instance.

1. Get a working Fatdog ISO, name it fatdog.iso and put it under `iso`.
Create 4GB virtual disk.

2. Launch qemu to run Fatdog ISO with 2GB RAM, like this: `MEM=2048 ./iso/runsfs.sh`

Once you have desktop running inside qemu, follow these steps (all of these
are done inside the qemu instance, not on the host).

3. I launched seamonkey and downloaded ISO builder dated 2016.2 from ibiblio.

4. I downloaded package list for 710, also from ibiblio.

5. I mounted the 4GB virtual disk (in my qemu, it showed up as "sda") using Rox - so the mount point is /mnt/sda

6. I right-click the iso builder tarball and choose extract. I did the same to the package list tarball.

7. I moved extracted contents of the pkglist tarball (`sfs*list` files) to replace those files in the extracted iso builder folder. 6 & 7 is done using Rox.

8. I mounted the virtual CDROM drive that contains the Fatdog64 710 ISO. In my qemu this is "sr0" so it is mounted under /mnt/sr0.

9. From /mnt/sr0 folder, I dragged and dropped (=copying) efiboot.img to "fatdog-iso-root" inside the extracted iso builder folder.

10. Using rox, I navigated to the "fatdog-initrd" folder inside the extracted iso builder folder.

11. I deleted everything under that folder (init, and "bin" folder) - still using Rox

12. I launched terminal in that folder, by typing back-quote.

13. In the terminal, I typed "cpio -i < /mnt/sr0/initrd" to extract the initrd from the Fatdog64 710. I can see that folder was populated with stuff extracted from initrd.

14. I deleted "fd64.sfs" and "kernel-modules.sfs" using Rox.

15. Now on the terminal I opened in step 12, I typed "cd .." to move up to the root folder of the iso builder.

16. I typed "geany build-iso.conf" and edited the file. I added

```
BASE_ROOTFS_DIR=/mnt/sda/build
WORKDIR=/mnt/sda/build-iso
```

to the end of the file. And I saved the file, and quit geany.

17. Then in the terminal I typed "mkdir -p /mnt/sda/build". Remember, "/mnt/sda" is where my virtual disk is mounted.

18. Then I typed "./build-iso.sh iso".

19. It will start downloading files. When all files have been downloaded, it will start instaling them. When installation is done, it will build fd64.sfs. When the basesfs is done, it will build the ISO in the "iso" folder.

Note: Go for coffee. Downloading from ibiblio is slow. Doing mksquashfs with XZ compression is also slow.
All these can be configured later using build-iso.conf (downloading from elsewhere, and changing the compression to use gzip/bzip2/lzo/lz4 etc) once you've got the basic steps right and working.

20. When it is done, shutdown qemu.

21. Loop-mount the virtual disk by clicking it in Rox.

22. I copied over the created fatdog.iso to my physical disk - just the usual Rox drag and drop.

23. Then I unmounted the virtual disk (clicking it again)

24. I tested booting the resulting fatdog.iso using qemu again (qemu-system-x86 -enable-kvm -m 1024 -cdrom fatdog.iso).

25. It works.

Note: all done with pristine Fatdog64 710 boot, no savefile needed, no devx needed, in a machine with 2GB RAM and 4GB free space (Linux filesystem). 

Tip: If you need to build again with a new `pkgtlist` file, you can keep folders `pkgcache` and `kernel` in the fatdog-iso-builder folder to avoid downloading their contents again. Everything else should start from scratch according tho the steps above.

Tip2: BASE_ROOTFS_DIR and WORKDIR cannot be located anywhere inside /root/Downloads.
