Small Virtual Machines

From Free Pascal wiki
Jump to navigationJump to search

Overview

Shows how to create small ReactOS and Debian virtual machines using Qemu on Ubuntu, and then compile and run a Free Pascal program.

The small virtual machines should serve two purposes:
1) They show how a "standard PC" can be used to run a program. So if you are having problems running the program on your PC you can see how it works on a different PC.
2) If the small VM is easy to download and run then you can simply do that. The LevinUx stuff at the bottom of this wiki page shows how easy that could be.

ReactOS virtual machine

Built (on Ubuntu 16.04 on 18 May 2016) a minimal i386 VM with QEMU with ReactOS 0.4.1.

Download from 0.4.1 -iso.zip (103MB) and unzip to .iso (122MB)

qemu-img create -f qcow2 reactos041.img 8G
qemu-system-i386 -enable-kvm -m 512 -hda reactos041.img -cdrom reactos-bootcd.iso -boot d -net nic,model=rtl8139 -net user

For the install just press <Enter> for everything. When it reboots (twice) don't hit any key so it won't boot from the CD.

Shut down ReactOS. The QEMU image file is 336MB.

Make a backup copy then restart:
qemu-system-i386 -enable-kvm -m 512 -hda reactos041.img -boot c -net nic,model=rtl8139 -net user

To see that networking is working, in the VM double-click on the Command Prompt and run ipconfig.

Needs more work but getting there! In command prompt do:
cd \
md test
cd test
This whole line is a comment! dwnl http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe wgetsetup.exe didn't work [[1]]
This whole line is a comment! so I download and put here (which does work):
dwnl http://turbocontrol.com/wget-1.11.4-1-setup.exe wgetsetup.exe
wgetsetup

"c:\program files\gnuwin32\bin\wget" https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/blob/master/bin/i386-win32/fpcup.exe?raw=true --no-check-certificate -O fpcup.exe
dir (verify that fpcup.exe is about 838,144 bytes)

Exit the command prompt, shut down ReactOS, make a backup copy then restart:
qemu-system-i386 -enable-kvm -m 512 -hda reactos041.img -boot c -net nic,model=rtl8139 -net user

fpcup --verbose then y to continue

Stops progressing while compiling jwawindows.pas (with 100% CPU usage, can't Ctrl-C to stop)

Ctrl-Alt then stop QEmu, replace with backup copy, restart (with much larger memory):
qemu-system-i386 -enable-kvm -m 4000 -hda reactos041.img -boot c -net nic,model=rtl8139 -net user

Stops compiling with error, restarted the VM, and did just fpcup several times (no --verbose) and it finished!

This works!

I used dwnl to download the 6 arm-embedded-*.exe files and ran fpcup to compile for arm-embedded (see the Windows XP VM section below and everything seems to work.
Made folder c:\development\cross\bin\arm-embedded and copied 6 files
dwnl http://svn2.freepascal.org/svn/fpcbuild/binaries/i386-win32/arm-embedded-ar.exe then similar for other 5 files
Did: fpcup --ostarget=embedded --cputarget=arm --subarch=armv7em

No, you don't want to use ReactOS for your desktop operating system, but it might be good enough to use for some specific things (like putting in a small VM or in a single-app kiosk or embedded device).

WinXp virtual machine

Temporarily I used a 32-bit WinXp VM (3.8GB) on VMware and got this to work for Teensy:
- (do this if want trunk Lazarus) Copied in fpcup.exe and ran as (~35 minutes, VM increased to 7.3GB): fpcup --skip=lhelp --fpcURL=trunk --lazURL=trunk
- (do this for only FPC) Copied in fpcup.exe and ran as (~11 minutes, VM increased to 5.0GB): fpcup --only=FPC --fpcURL=trunk
- Made folder c:\development\cross\bin\arm-embedded and copied 6 files from [[2]]
- Did (~2.5 minutes): fpcup --ostarget=embedded --cputarget=arm --subarch=armv7em --only=FPCCleanOnly,FPCBuildOnly --fpcURL=trunk
- Made folder and copied in test.pas [[3]], ppcrossarm.exe (from c:\development\fpc\compiler), system.o & system.ppu & mk20d7.o & mk20d7.ppu (from c:\development\fpc\units\arm-embedded\rtl), and the as.exe, ld.exe, and objcopy.exe from the arm-embedded folder (and renamed those 3 after copied).
- Get teensy.exe [[4]] and copy in.
- Compile: ppcrossarm -Oonostackframe -Parm -Tembedded -Cparmv7em -Wpmk20dx256xxx7 test.pas
- Run teensy.exe and load test.hex
- Repeat the last 2 steps while varying the timing (2666666 to 0666666) to show that you are changing the program!

More ASAP!

Files released here: [[5]]

Debian console virtual machine

Built (on Debian 8.2) a minimal i386 VM with QEMU with Debian (new version 8.2 release) Jessie.

Dowload from Debian debian-8.2.0-i386-netinst.iso (315 MB) and rename to debjes.iso

qemu-img create -f qcow2 debjes.img 8G
qemu-system-i386 -enable-kvm -m 512 -hda debjes.img -cdrom debjes.iso -boot d

Networking worked without having to add other command line parameters! Remove the 3 default software collections (near the end of the install). The QEMU image file is about 1.3 GB.

In the VM:
add sudo (There are instruction near the bottom of this page: Control Pascal PicoScope)
sudo apt-get clean

Do these next steps only if you want to minimize the size of the VM:
sudo dd if=/dev/zero of=/mytempfile (note that this is very slow as it fills the entire 8G)
sudo rm -f /mytempfile
sudo halt
qemu-img convert -O qcow2 debjes.img debjesnew.img (reduces file to 595 MB)
Archive with 7z and the file is now 141 MB. Not very big for a nice new Debian console VM.

Make a backup copy then start like this:
qemu-system-i386 -enable-kvm -m 512 -hda debjesnew.img -boot c

Do these steps only if want a simple test In the VM do (see http://turbocontrol.com/helloworld.htm if needed):
wget http://turbocontrol.com/HelloWorld-fpc-2.2.2.i386-linux.tar.gz
tar xzvf HelloWorld-fpc-2.2.2.i386-linux.tar.gz
./ppc386 hello
sudo apt-get install binutils
./ppc386 hello
./hello

Do these steps if want a trunk FPC and then arm-embedded for Teensy In the VM do:
sudo apt-get install build-essential subversion unzip
wget https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/blob/master/bin/i386-linux/fpcup_linux_x86?raw=true --no-check-certificate -O fpcup
chmod u+rx fpcup
./fpcup --fpcURL=trunk --only=FPC This works!
sudo apt-get install binutils-arm-none-eabi
./fpcup --ostarget=embedded --cputarget=arm --subarch=armv7em --only=FPCCleanOnly,FPCBuildOnly --fpcURL=trunk
The above (for Teensy) does work!
Need to find out how to copy files out of VM.

Debian LXDE virtual machine

Built (21 Sept. 2015 on Ubuntu 14.04) a minimal i386 VM with QEMU with Debian.

Dowload from Debian debian-8.2.0-i386-netinst.iso (315 MB) and rename to debjes.iso

qemu-img create -f qcow2 debjes.img 8G
qemu-system-i386 -enable-kvm -m 512 -hda debjes.img -cdrom debjes.iso -boot d

Networking worked without having to add other command line parameters!

For the software collections screen:
Remove Debian desktop environment
Remove print server
Add LXDE
Leave (keep) standard system utilities

When the VM restarts close the qemu window rather that restarting the install. The QEMU image file is now 4.0 GB.

Make a backup copy then start like this:
qemu-system-i386 -enable-kvm -m 512 -hda debjesnew.img -boot c -net nic -net user

In the VM in a (user) terminal:
su (and password for root)
adduser <user name> sudo
exit (exit su)
exit (exit user and terminal)
logout and login again

Reboot and choose recovery then enter root password:
apt-get clean
dd if=/dev/zero of=/mytempfile (note that this is very slow as it fills the entire 8G)
rm -f /mytempfile
halt

After this the new img file is 2.9 GB:
qemu-img convert -O qcow2 debjes.img debjesnew.img

Archive with 7z and the file is now 733 MB. Not very big for a nice new Debian LXDE VM.

Make a backup copy then start like this:
qemu-system-i386 -enable-kvm -m 512 -hda debjesnew.img -boot c -net nic -net user

In the VM in a (user) terminal:
sudo apt-get install build-essential mingw32-binutils subversion unzip libgtk2.0-dev
cd Downloads
wget https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/blob/master/bin/i386-linux/fpcup_linux_x86?raw=true --no-check-certificate -O fpcup
chmod u+rx fpcup

./fpcup --skip=lhelp --verbose then y to continue
This works! Other things (Teensy and Android [[6]]) to be continued ASAP!

Notes

On 32-bit Debian kvm runs qemu-system-x86_64 so get 64-bit which don't want. So changed all of the above calls to qemu-system-i386 -enable-kvm which still runs fast (due to kvm). If your linux system doesn't have kvm then you may need to leave -enable-kvm off.

On qemu-img create the 2G could be larger but then on linux it will be much slower to minimize the size. Any suggestions? (Look at zerofree and also consider wear on SD card)

Add instructions on how to do this on Windows (not just Ubuntu)?

Original forum message where this got started: [[7]]
Add instructions for OS X per discussion there?

Further Reading

Levinux is a small (~20 MB) QEMU download for x86 PCs (Windows, OS X, Linux) that provides a small Tiny Core Linux VM. I'd like to see something similar but with all the files and tools needed to pull the latest source code and cross-compile FPC (also with Debian instead of Tiny Core?).

 http://mikelev.in/ux/
 http://levinux.com (just a slideshow about it)

What is the most simple way to compile an ARM Embedded compiler for Teensy? See this forum message for more details on Teensy: [[8]]
Use fpcup? [[9]]

See also