Sign in Join
Wiki copytemporary

Small Virtual Machines: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Overview
22
33Shows how to create small ReactOS and Debian virtual machines using Qemu on Ubuntu, and then compile and run a Free Pascal program.
44
55The small virtual machines should serve two purposes:\
661\) 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.\
772\) If the small VM is easy to download and run then you can simply do that. The LevinUx stuff below shows how easy that could be.
88
99## Windows WSL and WSL2
1010
1111[Basic Info](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
1212
1313Note that at this time hardware and GUI will not work!
1414
1515If upgrade to Win10 Insider Preview can install WSL2: [wsl2 install](https://docs.microsoft.com/en-us/windows/wsl/wsl2-install) but be aware that other virtual machine software (like VMware, Parallels) may no longer work (may eventually work [they are working together](https://techcommunity.microsoft.com/t5/Virtualization/VMware-Workstation-and-Hyper-V-Working-Together/ba-p/825831)).
1616
1717Note that the WSL command may not work in Powershell but might work in Command Prompt. After exit from the terminal (in Linux) do **WSL --shutdown** to free lots of memory.
1818
1919On July 29, 2019 I've installed Ubuntu 18.04 LTS and Debian (stretch = 9). **sudo apt install fpc** on Ubuntu gets 3.0.4 whereas the same on Debian only gets 3.0.0 .
2020
2121**Optional below for FPC 3.2 Beta:**
2222
2323**Enter the command below (to determine your CPU type):**
2424
2525neofetch **(see CPU specs)**
2626
2727**Next we'll download the appropriate zip file (from [here](https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/)):**
2828
2929**(need to get appropriate fpcup release for your CPU type below)**
3030
3131sudo wget <https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.6.2v/fpcup-x86_64-linux>
3232
3333sudo chmod 755 fpcup-x86_64-linux
3434
3535sudo apt install subversion zip unzip build-essential libx11-dev
3636
3737sudo ./fpcup-x86_64-linux --fpcurl=<https://svn.freepascal.org/svn/fpc/branches/fixes_3_2> --verbose
3838
3939**Can run "./fpc" or "./fp" when done if go to: root/development/fpc/bin/x86_64-linux**
4040
4141## Levinux virtual machine
4242
4343Levinux is a small (~20 MB) QEMU download for x86 PCs (Windows, macOS, Linux) that provides a small Tiny Core Linux VM. You can visit the two links below to read more about it, or just follow the simple instructions below (on Windows) to try it out with Free Pascal.\
44-<http://mikelev.in/ux/>
4544
46-` `[`http://levinux.com`](http://levinux.com)` (`**`just`**` a 21 page JavaScript slideshow about it)`
45+```text
46+ http://mikelev.in/ux/
47+ http://levinux.com (just a 21 page JavaScript slideshow about it)
48+```
4749
4850Tried on Windows XP in May 2016
4951
5052Go to <https://github.com/miklevin/levinux> and click the **Download Zip** or **Clone or download** button near the upper-right corner.
5153
5254Unzip the small (18.6 MB) file levinux-master.zip and run WindowsLevinux.vbs (may need to **unblock** for the firewall). **If you need to learn how to operate things in Windows to do this** you might want to read a tutorial that introduces the Pascal programming language, file managers, the command prompt, the Free Pascal compiler, and the minimal files needed to compile a program. The Win32 Hello World Tutorial is available in three formats: [doc](http://turbocontrol.com/Hello%20World%20Tutorial.doc) - [PDF](http://turbocontrol.com/Hello%20World%20Tutorial.pdf) - [web](http://turbocontrol.com/Hello%20World%20Tutorial.htm)
5355
5456Select 2 - Exit to Console **then** log in (tc and foo, do **sudo poweroff** later to shut down)
5557
5658**Do these steps only if want a simple test**\
5759See <http://turbocontrol.com/helloworld.htm> if more information is needed.\
5860**Note** that Linux is case sensitive (unlike Windows) so you must type the letters as shown below!\
5961In the VM terminal do: (**Note** that we are renaming the filename by using the capital Oh parameter)\
6062wget http://turbocontrol.com/HelloWorld-fpc-2.2.2.i386-linux.tar.gz -O hello.tar.gz\
6163tar xzvf hello.tar.gz\
6264./ppc386 hello\
6365tce-load -wi binutils.tcz\
6466./ppc386 hello\
6567./hello
6668
6769**Do these steps if want a FPC 3.0.0 compiler (doesn't work yet)**\
6870In the VM terminal do:\
6971tce-load -wi svn.tcz\
7072tce-load -wi zip-unzip.tcz\
7173tce-load -wi compiletc.tcz (**larger**)\
7274wget https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.4.0k/fpcup-i386-linux?raw=true --no-check-certificate -O fpcup\
7375chmod u+rx fpcup\
7476./fpcup --verbose **Then "y" but this doesn't work**
7577
7678I'd like to change levinux to have all the files and tools needed to pull the latest source code and cross-compile FPC (also with Debian instead of Tiny Core?).
7779
7880## ReactOS virtual machine
7981
8082Built (on Ubuntu 16.04 on 1 June 2017) a minimal i386 VM with QEMU with ReactOS 0.4.5.
8183
8284Download [ReactOS-0.4.5-iso.zip](http://sourceforge.net/projects/reactos/files/ReactOS/0.4.5/ReactOS-0.4.5-iso.zip) (103MB)
8385
8486qemu-img create -f qcow2 reactos045.img 8G
8587
8688qemu-system-i386 -enable-kvm -m 512 -hda reactos045.img -cdrom ReactOS-0.4.5.iso -boot d -net nic,model=rtl8139 -net user
8789
8890For the install just press \<Enter\> for everything. When it reboots (twice) don't hit any key so it won't boot from the CD.
8991
9092Shut down ReactOS. The QEMU image file is 349MB.
9193
9294Make a backup copy then restart:
9395
9496qemu-system-i386 -enable-kvm -m 512 -hda reactos045.img -boot c -net nic,model=rtl8139 -net user
9597
9698To see that networking is working, in the VM double-click on the Command Prompt and run ipconfig.
9799
98100As a simple test, install PeaZip (a Lazarus application) from the Application Manager in the Tools section, then in command prompt do:
99101
100102cd \\
101103
102104md test
103105
104106cd test
105107
106108dwnl http://turbocontrol.com/HelloWorld-fpc-2.4.2.i386-win32.zip
107109
108110unzip HelloWorld-fpc-2.4.2.i386-win32.zip
109111
110112ppc386 hello
111113
112114hello
113115
114116On 1 June 2017 I updated text below for the image file name (to reactos045.img) but did not test anything else!
115117
116118**Needs more work** but getting there! In command prompt do:
117119
118120cd \\
119121
120122md test
121123
122124cd test
123125
124126**This whole line is a comment!** dwnl http://downloads.sourceforge.net/gnuwin32/wget-1.11.4-1-setup.exe wgetsetup.exe **[didn't work](https://www.reactos.org/forum/viewtopic.php?f=2&t=14370)**
125127
126128**This whole line is a comment!** so I download and put here (which does work):
127129
128130dwnl http://turbocontrol.com/wget-1.11.4-1-setup.exe wgetsetup.exe
129131
130132wgetsetup
131133
132134"c:\program files\gnuwin32\bin\wget" https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.4.0k/fpcup-i386-win32.exe?raw=true --no-check-certificate -O fpcup.exe
133135
134136dir **(verify that fpcup.exe is about 1.09 MB)**
135137
136138Exit the command prompt, shut down ReactOS, make a backup copy then restart:
137139
138140qemu-system-i386 -enable-kvm -m 512 -hda reactos045.img -boot c -net nic,model=rtl8139 -net user
139141
140142fpcup --verbose **then** y to continue\
141143Stops progressing while **compiling** jwawindows.pas (with **100%** CPU usage, **can't** Ctrl-C to stop)
142144
143145Ctrl-Alt then stop QEmu, replace with backup copy, restart (with **much** larger memory):
144146
145147qemu-system-i386 -enable-kvm -m 4000 -hda reactos045.img -boot c -net nic,model=rtl8139 -net user
146148
147149Stops compiling with error, restarted the VM, and did just fpcup several times (no --verbose) and it finished!
148150
149151**This works!**
150152
151153I 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.
152154
153155Made folder c:\development\cross\bin\arm-embedded and copied 6 files
154156
155157dwnl http://svn2.freepascal.org/svn/fpcbuild/binaries/i386-win32/arm-embedded-ar.exe **then** similar for other 5 files
156158
157159Did: fpcup --ostarget=embedded --cputarget=arm --subarch=armv7em
158160
159161No, 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).
160162
161163## WinXP virtual machine
162164
163165**Temporarily** I used a 32-bit WinXP VM (3.8GB) on VMware and **got this to work for Teensy**:
164166
165167**- (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
166168
167169**- (do this for only FPC)** Copied in fpcup.exe and ran as (~11 minutes, VM increased to 5.0GB): fpcup --only=FPC --fpcURL=trunk
168170
169171\- Made folder c:\development\cross\bin\arm-embedded and copied 6 files from [here](http://svn2.freepascal.org/svn/fpcbuild/binaries/i386-win32/)
170172
171173\- Did (~2.5 minutes): fpcup --ostarget=embedded --cputarget=arm --subarch=armv7em --only=FPCCleanOnly,FPCBuildOnly --fpcURL=trunk
172174
173175\- Made folder and copied in [test.pas](http://forum.lazarus.freepascal.org/index.php/topic,28561.msg179240.html#msg179240), 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).
174176
175177\- Get [teensy.exe](https://www.pjrc.com/teensy/loader_xp.html) and copy in.
176178
177179\- Compile: ppcrossarm -Oonostackframe -Parm -Tembedded -Cparmv7em -Wpmk20dx256xxx7 test.pas
178180
179181\- Run teensy.exe and load test.hex
180182
181183\- Repeat the last 2 steps while varying the timing (2666666 to 0666666) to show that you are changing the program!
182184
183185**Files released [here](http://turbocontrol.com/simpleteensy.htm)**
184186
185187## Debian console virtual machine
186188
187189Built (on Ubuntu 16.04 on 1 Aug. 2017) a minimal i386 VM with QEMU with Debian (new version 9.1 release) stretch.
188190
189191Dowload from [Debian](https://www.debian.org/) debian-9.1.0-i386-netinst.iso (375 MB) and rename to debstr.iso
190192
191193qemu-img create -f qcow2 debstr.img 8G\
192194qemu-system-i386 -enable-kvm -m 512 -hda debstr.img -cdrom debstr.iso -boot d
193195
194196Networking 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.
195197
196198In the VM:\
197199add sudo (There are instruction near the bottom of this page: [Control Pascal PicoScope](http://controlpascal.com/picoscope.htm))\
198200sudo apt-get clean
199201
200202**Do these next steps only if you want to minimize the size of the VM:**\
201203sudo dd if=/dev/zero of=/mytempfile (**note** that this is very slow as it fills the entire 8G)\
202204sudo rm -f /mytempfile\
203205sudo halt\
204206qemu-img convert -O qcow2 debstr.img debstrnew.img **(reduces file to 595 MB)**\
205207Archive with 7z and the file is now 141 MB. Not very big for a nice new Debian console VM.
206208
207209Make a backup copy then start like this:\
208210qemu-system-i386 -enable-kvm -m 512 -hda debstrnew.img -boot c
209211
210212**Do these steps only if want a simple test** In the VM do (see <http://turbocontrol.com/helloworld.htm> if needed):\
211213wget http://turbocontrol.com/HelloWorld-fpc-2.2.2.i386-linux.tar.gz\
212214tar xzvf HelloWorld-fpc-2.2.2.i386-linux.tar.gz\
213215./ppc386 hello\
214216sudo apt-get install binutils\
215217./ppc386 hello\
216218./hello
217219
218220**Do these steps if want a trunk FPC and then arm-embedded for Teensy** In the VM do:\
219221sudo apt-get install build-essential subversion unzip\
220222wget https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.4.0k/fpcup-i386-linux?raw=true --no-check-certificate -O fpcup\
221223chmod u+rx fpcup\
222224./fpcup --fpcURL=trunk --only=FPC **This works!**\
223225sudo apt-get install binutils-arm-none-eabi\
224226./fpcup --ostarget=embedded --cputarget=arm --subarch=armv7em --only=FPCCleanOnly,FPCBuildOnly --fpcURL=trunk\
225227**The above (for Teensy) does work!**\
226228Need to find out how to copy files out of VM.
227229
228230## Debian LXDE virtual machine
229231
230232Built (21 Sept. 2015 on Ubuntu 14.04) a minimal i386 VM with QEMU with Debian.
231233
232234Dowload from [Debian](https://www.debian.org/) debian-8.2.0-i386-netinst.iso (315 MB) and rename to debjes.iso
233235
234236qemu-img create -f qcow2 debjes.img 8G\
235237qemu-system-i386 -enable-kvm -m 512 -hda debjes.img -cdrom debjes.iso -boot d\
236238Networking worked without having to add other command line parameters!
237239
238240For the software collections screen:\
239241Remove **Debian desktop environment**\
240242Remove **print server**\
241243Add **LXDE**\
242244Leave (keep) **standard system utilities**\
243245When the VM restarts close the qemu window rather that restarting the install. The QEMU image file is now 4.0 GB.
244246
245247Make a backup copy then start like this:\
246248qemu-system-i386 -enable-kvm -m 512 -hda debjesnew.img -boot c -net nic -net user\
247249In the VM in a (user) terminal:\
248250su (and password for root)\
249251adduser \<user name\> sudo\
250252exit (exit su)\
251253exit (exit user and terminal)\
252254logout and login again
253255
254256Reboot and choose recovery then enter root password:\
255257apt-get clean\
256258dd if=/dev/zero of=/mytempfile (**note** that this is very slow as it fills the entire 8G)\
257259rm -f /mytempfile\
258260halt
259261
260262After this the new img file is 2.9 GB:\
261263qemu-img convert -O qcow2 debjes.img debjesnew.img
262264
263265Archive with 7z and the file is now 733 MB. Not very big for a nice new Debian LXDE VM.
264266
265267Make a backup copy then start like this:\
266268qemu-system-i386 -enable-kvm -m 512 -hda debjesnew.img -boot c -net nic -net user\
267269In the VM in a (user) terminal:\
268270sudo apt-get install build-essential mingw32-binutils subversion unzip libgtk2.0-dev\
269271cd Downloads\
270272wget https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.4.0k/fpcup-i386-linux?raw=true --no-check-certificate -O fpcup\
271273chmod u+rx fpcup
272274
273275./fpcup --skip=lhelp --verbose **then** y to continue\
274276**This works! Other things (Teensy and Android [[http://forum.lazarus.freepascal.org/index.php/topic,29605.msg187827.html|http://forum.lazarus.freepascal.org/index.php/topic,29605.msg187827.html#msg187827]]) to be continued ASAP!**
275277
276278## Notes
277279
278280On 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.
279281
280282On **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)
281283
282284## To do
283285
284286Add instructions on how to do this on Windows (not just Ubuntu)?
285287
286288[Original forum message](http://forum.lazarus.freepascal.org/index.php/topic,26315.0.html) where this got started.
287289
288290Add instructions for macOS per discussion there?
289291
290292## Further Reading
291293
292294What is the most simple way to compile an ARM Embedded compiler for Teensy? See [this forum message](http://forum.lazarus.freepascal.org/index.php/topic,28561.msg178816.html) for more details on Teensy.
293295
294296Use [[fpcup]]?
295297
296298## See also
297299
298300- [[ReactOS]]
299301- [[Qemu and other emulators]]
300302- [[TARGET Embedded]]
301303- [[Control Pascal Tutorial]] - where we hope this stuff ends up being used
302304- [[Docker Containerization]]
303305
304306---
305307*From the Free Pascal wiki, page "Small Virtual Machines", as it stood on 2020-10-14 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
306308Category: FPC

Back to history