Small Virtual Machines: what changed
Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | ## Overview | |
| 2 | 2 | ||
| 3 | 3 | Shows how to create small ReactOS and Debian virtual machines using Qemu on Ubuntu, and then compile and run a Free Pascal program. | |
| 4 | 4 | ||
| 5 | 5 | The small virtual machines should serve two purposes:\ | |
| 6 | 6 | 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.\ | |
| 7 | 7 | 2\) 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. | |
| 8 | 8 | ||
| 9 | 9 | ## Windows WSL and WSL2 | |
| 10 | 10 | ||
| 11 | 11 | [Basic Info](https://docs.microsoft.com/en-us/windows/wsl/install-win10) | |
| 12 | 12 | ||
| 13 | 13 | Note that at this time hardware and GUI will not work! | |
| 14 | 14 | ||
| 15 | 15 | If 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)). | |
| 16 | 16 | ||
| 17 | 17 | Note 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. | |
| 18 | 18 | ||
| 19 | 19 | On 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 . | |
| 20 | 20 | ||
| 21 | 21 | **Optional below for FPC 3.2 Beta:** | |
| 22 | 22 | ||
| 23 | 23 | **Enter the command below (to determine your CPU type):** | |
| 24 | 24 | ||
| 25 | 25 | neofetch **(see CPU specs)** | |
| 26 | 26 | ||
| 27 | 27 | **Next we'll download the appropriate zip file (from [here](https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/)):** | |
| 28 | 28 | ||
| 29 | 29 | **(need to get appropriate fpcup release for your CPU type below)** | |
| 30 | 30 | ||
| 31 | 31 | sudo wget <https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.6.2v/fpcup-x86_64-linux> | |
| 32 | 32 | ||
| 33 | 33 | sudo chmod 755 fpcup-x86_64-linux | |
| 34 | 34 | ||
| 35 | 35 | sudo apt install subversion zip unzip build-essential libx11-dev | |
| 36 | 36 | ||
| 37 | 37 | sudo ./fpcup-x86_64-linux --fpcurl=<https://svn.freepascal.org/svn/fpc/branches/fixes_3_2> --verbose | |
| 38 | 38 | ||
| 39 | 39 | **Can run "./fpc" or "./fp" when done if go to: root/development/fpc/bin/x86_64-linux** | |
| 40 | 40 | ||
| 41 | 41 | ## Levinux virtual machine | |
| 42 | 42 | ||
| 43 | 43 | Levinux 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 | - | ||
| 45 | 44 | ||
| 46 | - | ||
| 45 | + | ```text | |
| 46 | + | http://mikelev.in/ux/ | |
| 47 | + | http://levinux.com (just a 21 page JavaScript slideshow about it) | |
| 48 | + | ``` | |
| 47 | 49 | ||
| 48 | 50 | Tried on Windows XP in May 2016 | |
| 49 | 51 | ||
| 50 | 52 | Go to <https://github.com/miklevin/levinux> and click the **Download Zip** or **Clone or download** button near the upper-right corner. | |
| 51 | 53 | ||
| 52 | 54 | Unzip 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) | |
| 53 | 55 | ||
| 54 | 56 | Select 2 - Exit to Console **then** log in (tc and foo, do **sudo poweroff** later to shut down) | |
| 55 | 57 | ||
| 56 | 58 | **Do these steps only if want a simple test**\ | |
| 57 | 59 | See <http://turbocontrol.com/helloworld.htm> if more information is needed.\ | |
| 58 | 60 | **Note** that Linux is case sensitive (unlike Windows) so you must type the letters as shown below!\ | |
| 59 | 61 | In the VM terminal do: (**Note** that we are renaming the filename by using the capital Oh parameter)\ | |
| 60 | 62 | wget http://turbocontrol.com/HelloWorld-fpc-2.2.2.i386-linux.tar.gz -O hello.tar.gz\ | |
| 61 | 63 | tar xzvf hello.tar.gz\ | |
| 62 | 64 | ./ppc386 hello\ | |
| 63 | 65 | tce-load -wi binutils.tcz\ | |
| 64 | 66 | ./ppc386 hello\ | |
| 65 | 67 | ./hello | |
| 66 | 68 | ||
| 67 | 69 | **Do these steps if want a FPC 3.0.0 compiler (doesn't work yet)**\ | |
| 68 | 70 | In the VM terminal do:\ | |
| 69 | 71 | tce-load -wi svn.tcz\ | |
| 70 | 72 | tce-load -wi zip-unzip.tcz\ | |
| 71 | 73 | tce-load -wi compiletc.tcz (**larger**)\ | |
| 72 | 74 | wget https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.4.0k/fpcup-i386-linux?raw=true --no-check-certificate -O fpcup\ | |
| 73 | 75 | chmod u+rx fpcup\ | |
| 74 | 76 | ./fpcup --verbose **Then "y" but this doesn't work** | |
| 75 | 77 | ||
| 76 | 78 | I'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?). | |
| 77 | 79 | ||
| 78 | 80 | ## ReactOS virtual machine | |
| 79 | 81 | ||
| 80 | 82 | Built (on Ubuntu 16.04 on 1 June 2017) a minimal i386 VM with QEMU with ReactOS 0.4.5. | |
| 81 | 83 | ||
| 82 | 84 | Download [ReactOS-0.4.5-iso.zip](http://sourceforge.net/projects/reactos/files/ReactOS/0.4.5/ReactOS-0.4.5-iso.zip) (103MB) | |
| 83 | 85 | ||
| 84 | 86 | qemu-img create -f qcow2 reactos045.img 8G | |
| 85 | 87 | ||
| 86 | 88 | qemu-system-i386 -enable-kvm -m 512 -hda reactos045.img -cdrom ReactOS-0.4.5.iso -boot d -net nic,model=rtl8139 -net user | |
| 87 | 89 | ||
| 88 | 90 | 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. | |
| 89 | 91 | ||
| 90 | 92 | Shut down ReactOS. The QEMU image file is 349MB. | |
| 91 | 93 | ||
| 92 | 94 | Make a backup copy then restart: | |
| 93 | 95 | ||
| 94 | 96 | qemu-system-i386 -enable-kvm -m 512 -hda reactos045.img -boot c -net nic,model=rtl8139 -net user | |
| 95 | 97 | ||
| 96 | 98 | To see that networking is working, in the VM double-click on the Command Prompt and run ipconfig. | |
| 97 | 99 | ||
| 98 | 100 | As a simple test, install PeaZip (a Lazarus application) from the Application Manager in the Tools section, then in command prompt do: | |
| 99 | 101 | ||
| 100 | 102 | cd \\ | |
| 101 | 103 | ||
| 102 | 104 | md test | |
| 103 | 105 | ||
| 104 | 106 | cd test | |
| 105 | 107 | ||
| 106 | 108 | dwnl http://turbocontrol.com/HelloWorld-fpc-2.4.2.i386-win32.zip | |
| 107 | 109 | ||
| 108 | 110 | unzip HelloWorld-fpc-2.4.2.i386-win32.zip | |
| 109 | 111 | ||
| 110 | 112 | ppc386 hello | |
| 111 | 113 | ||
| 112 | 114 | hello | |
| 113 | 115 | ||
| 114 | 116 | On 1 June 2017 I updated text below for the image file name (to reactos045.img) but did not test anything else! | |
| 115 | 117 | ||
| 116 | 118 | **Needs more work** but getting there! In command prompt do: | |
| 117 | 119 | ||
| 118 | 120 | cd \\ | |
| 119 | 121 | ||
| 120 | 122 | md test | |
| 121 | 123 | ||
| 122 | 124 | cd test | |
| 123 | 125 | ||
| 124 | 126 | **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)** | |
| 125 | 127 | ||
| 126 | 128 | **This whole line is a comment!** so I download and put here (which does work): | |
| 127 | 129 | ||
| 128 | 130 | dwnl http://turbocontrol.com/wget-1.11.4-1-setup.exe wgetsetup.exe | |
| 129 | 131 | ||
| 130 | 132 | wgetsetup | |
| 131 | 133 | ||
| 132 | 134 | "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 | |
| 133 | 135 | ||
| 134 | 136 | dir **(verify that fpcup.exe is about 1.09 MB)** | |
| 135 | 137 | ||
| 136 | 138 | Exit the command prompt, shut down ReactOS, make a backup copy then restart: | |
| 137 | 139 | ||
| 138 | 140 | qemu-system-i386 -enable-kvm -m 512 -hda reactos045.img -boot c -net nic,model=rtl8139 -net user | |
| 139 | 141 | ||
| 140 | 142 | fpcup --verbose **then** y to continue\ | |
| 141 | 143 | Stops progressing while **compiling** jwawindows.pas (with **100%** CPU usage, **can't** Ctrl-C to stop) | |
| 142 | 144 | ||
| 143 | 145 | Ctrl-Alt then stop QEmu, replace with backup copy, restart (with **much** larger memory): | |
| 144 | 146 | ||
| 145 | 147 | qemu-system-i386 -enable-kvm -m 4000 -hda reactos045.img -boot c -net nic,model=rtl8139 -net user | |
| 146 | 148 | ||
| 147 | 149 | Stops compiling with error, restarted the VM, and did just fpcup several times (no --verbose) and it finished! | |
| 148 | 150 | ||
| 149 | 151 | **This works!** | |
| 150 | 152 | ||
| 151 | 153 | 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. | |
| 152 | 154 | ||
| 153 | 155 | Made folder c:\development\cross\bin\arm-embedded and copied 6 files | |
| 154 | 156 | ||
| 155 | 157 | dwnl http://svn2.freepascal.org/svn/fpcbuild/binaries/i386-win32/arm-embedded-ar.exe **then** similar for other 5 files | |
| 156 | 158 | ||
| 157 | 159 | Did: fpcup --ostarget=embedded --cputarget=arm --subarch=armv7em | |
| 158 | 160 | ||
| 159 | 161 | 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). | |
| 160 | 162 | ||
| 161 | 163 | ## WinXP virtual machine | |
| 162 | 164 | ||
| 163 | 165 | **Temporarily** I used a 32-bit WinXP VM (3.8GB) on VMware and **got this to work for Teensy**: | |
| 164 | 166 | ||
| 165 | 167 | **- (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 | |
| 166 | 168 | ||
| 167 | 169 | **- (do this for only FPC)** Copied in fpcup.exe and ran as (~11 minutes, VM increased to 5.0GB): fpcup --only=FPC --fpcURL=trunk | |
| 168 | 170 | ||
| 169 | 171 | \- Made folder c:\development\cross\bin\arm-embedded and copied 6 files from [here](http://svn2.freepascal.org/svn/fpcbuild/binaries/i386-win32/) | |
| 170 | 172 | ||
| 171 | 173 | \- Did (~2.5 minutes): fpcup --ostarget=embedded --cputarget=arm --subarch=armv7em --only=FPCCleanOnly,FPCBuildOnly --fpcURL=trunk | |
| 172 | 174 | ||
| 173 | 175 | \- 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). | |
| 174 | 176 | ||
| 175 | 177 | \- Get [teensy.exe](https://www.pjrc.com/teensy/loader_xp.html) and copy in. | |
| 176 | 178 | ||
| 177 | 179 | \- Compile: ppcrossarm -Oonostackframe -Parm -Tembedded -Cparmv7em -Wpmk20dx256xxx7 test.pas | |
| 178 | 180 | ||
| 179 | 181 | \- Run teensy.exe and load test.hex | |
| 180 | 182 | ||
| 181 | 183 | \- Repeat the last 2 steps while varying the timing (2666666 to 0666666) to show that you are changing the program! | |
| 182 | 184 | ||
| 183 | 185 | **Files released [here](http://turbocontrol.com/simpleteensy.htm)** | |
| 184 | 186 | ||
| 185 | 187 | ## Debian console virtual machine | |
| 186 | 188 | ||
| 187 | 189 | Built (on Ubuntu 16.04 on 1 Aug. 2017) a minimal i386 VM with QEMU with Debian (new version 9.1 release) stretch. | |
| 188 | 190 | ||
| 189 | 191 | Dowload from [Debian](https://www.debian.org/) debian-9.1.0-i386-netinst.iso (375 MB) and rename to debstr.iso | |
| 190 | 192 | ||
| 191 | 193 | qemu-img create -f qcow2 debstr.img 8G\ | |
| 192 | 194 | qemu-system-i386 -enable-kvm -m 512 -hda debstr.img -cdrom debstr.iso -boot d | |
| 193 | 195 | ||
| 194 | 196 | 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. | |
| 195 | 197 | ||
| 196 | 198 | In the VM:\ | |
| 197 | 199 | add sudo (There are instruction near the bottom of this page: [Control Pascal PicoScope](http://controlpascal.com/picoscope.htm))\ | |
| 198 | 200 | sudo apt-get clean | |
| 199 | 201 | ||
| 200 | 202 | **Do these next steps only if you want to minimize the size of the VM:**\ | |
| 201 | 203 | sudo dd if=/dev/zero of=/mytempfile (**note** that this is very slow as it fills the entire 8G)\ | |
| 202 | 204 | sudo rm -f /mytempfile\ | |
| 203 | 205 | sudo halt\ | |
| 204 | 206 | qemu-img convert -O qcow2 debstr.img debstrnew.img **(reduces file to 595 MB)**\ | |
| 205 | 207 | Archive with 7z and the file is now 141 MB. Not very big for a nice new Debian console VM. | |
| 206 | 208 | ||
| 207 | 209 | Make a backup copy then start like this:\ | |
| 208 | 210 | qemu-system-i386 -enable-kvm -m 512 -hda debstrnew.img -boot c | |
| 209 | 211 | ||
| 210 | 212 | **Do these steps only if want a simple test** In the VM do (see <http://turbocontrol.com/helloworld.htm> if needed):\ | |
| 211 | 213 | wget http://turbocontrol.com/HelloWorld-fpc-2.2.2.i386-linux.tar.gz\ | |
| 212 | 214 | tar xzvf HelloWorld-fpc-2.2.2.i386-linux.tar.gz\ | |
| 213 | 215 | ./ppc386 hello\ | |
| 214 | 216 | sudo apt-get install binutils\ | |
| 215 | 217 | ./ppc386 hello\ | |
| 216 | 218 | ./hello | |
| 217 | 219 | ||
| 218 | 220 | **Do these steps if want a trunk FPC and then arm-embedded for Teensy** In the VM do:\ | |
| 219 | 221 | sudo apt-get install build-essential subversion unzip\ | |
| 220 | 222 | wget https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.4.0k/fpcup-i386-linux?raw=true --no-check-certificate -O fpcup\ | |
| 221 | 223 | chmod u+rx fpcup\ | |
| 222 | 224 | ./fpcup --fpcURL=trunk --only=FPC **This works!**\ | |
| 223 | 225 | sudo apt-get install binutils-arm-none-eabi\ | |
| 224 | 226 | ./fpcup --ostarget=embedded --cputarget=arm --subarch=armv7em --only=FPCCleanOnly,FPCBuildOnly --fpcURL=trunk\ | |
| 225 | 227 | **The above (for Teensy) does work!**\ | |
| 226 | 228 | Need to find out how to copy files out of VM. | |
| 227 | 229 | ||
| 228 | 230 | ## Debian LXDE virtual machine | |
| 229 | 231 | ||
| 230 | 232 | Built (21 Sept. 2015 on Ubuntu 14.04) a minimal i386 VM with QEMU with Debian. | |
| 231 | 233 | ||
| 232 | 234 | Dowload from [Debian](https://www.debian.org/) debian-8.2.0-i386-netinst.iso (315 MB) and rename to debjes.iso | |
| 233 | 235 | ||
| 234 | 236 | qemu-img create -f qcow2 debjes.img 8G\ | |
| 235 | 237 | qemu-system-i386 -enable-kvm -m 512 -hda debjes.img -cdrom debjes.iso -boot d\ | |
| 236 | 238 | Networking worked without having to add other command line parameters! | |
| 237 | 239 | ||
| 238 | 240 | For the software collections screen:\ | |
| 239 | 241 | Remove **Debian desktop environment**\ | |
| 240 | 242 | Remove **print server**\ | |
| 241 | 243 | Add **LXDE**\ | |
| 242 | 244 | Leave (keep) **standard system utilities**\ | |
| 243 | 245 | When the VM restarts close the qemu window rather that restarting the install. The QEMU image file is now 4.0 GB. | |
| 244 | 246 | ||
| 245 | 247 | Make a backup copy then start like this:\ | |
| 246 | 248 | qemu-system-i386 -enable-kvm -m 512 -hda debjesnew.img -boot c -net nic -net user\ | |
| 247 | 249 | In the VM in a (user) terminal:\ | |
| 248 | 250 | su (and password for root)\ | |
| 249 | 251 | adduser \<user name\> sudo\ | |
| 250 | 252 | exit (exit su)\ | |
| 251 | 253 | exit (exit user and terminal)\ | |
| 252 | 254 | logout and login again | |
| 253 | 255 | ||
| 254 | 256 | Reboot and choose recovery then enter root password:\ | |
| 255 | 257 | apt-get clean\ | |
| 256 | 258 | dd if=/dev/zero of=/mytempfile (**note** that this is very slow as it fills the entire 8G)\ | |
| 257 | 259 | rm -f /mytempfile\ | |
| 258 | 260 | halt | |
| 259 | 261 | ||
| 260 | 262 | After this the new img file is 2.9 GB:\ | |
| 261 | 263 | qemu-img convert -O qcow2 debjes.img debjesnew.img | |
| 262 | 264 | ||
| 263 | 265 | Archive with 7z and the file is now 733 MB. Not very big for a nice new Debian LXDE VM. | |
| 264 | 266 | ||
| 265 | 267 | Make a backup copy then start like this:\ | |
| 266 | 268 | qemu-system-i386 -enable-kvm -m 512 -hda debjesnew.img -boot c -net nic -net user\ | |
| 267 | 269 | In the VM in a (user) terminal:\ | |
| 268 | 270 | sudo apt-get install build-essential mingw32-binutils subversion unzip libgtk2.0-dev\ | |
| 269 | 271 | cd Downloads\ | |
| 270 | 272 | wget https://github.com/LongDirtyAnimAlf/Reiniero-fpcup/releases/download/1.4.0k/fpcup-i386-linux?raw=true --no-check-certificate -O fpcup\ | |
| 271 | 273 | chmod u+rx fpcup | |
| 272 | 274 | ||
| 273 | 275 | ./fpcup --skip=lhelp --verbose **then** y to continue\ | |
| 274 | 276 | **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!** | |
| 275 | 277 | ||
| 276 | 278 | ## Notes | |
| 277 | 279 | ||
| 278 | 280 | 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. | |
| 279 | 281 | ||
| 280 | 282 | 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) | |
| 281 | 283 | ||
| 282 | 284 | ## To do | |
| 283 | 285 | ||
| 284 | 286 | Add instructions on how to do this on Windows (not just Ubuntu)? | |
| 285 | 287 | ||
| 286 | 288 | [Original forum message](http://forum.lazarus.freepascal.org/index.php/topic,26315.0.html) where this got started. | |
| 287 | 289 | ||
| 288 | 290 | Add instructions for macOS per discussion there? | |
| 289 | 291 | ||
| 290 | 292 | ## Further Reading | |
| 291 | 293 | ||
| 292 | 294 | What 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. | |
| 293 | 295 | ||
| 294 | 296 | Use [[fpcup]]? | |
| 295 | 297 | ||
| 296 | 298 | ## See also | |
| 297 | 299 | ||
| 298 | 300 | - [[ReactOS]] | |
| 299 | 301 | - [[Qemu and other emulators]] | |
| 300 | 302 | - [[TARGET Embedded]] | |
| 301 | 303 | - [[Control Pascal Tutorial]] - where we hope this stuff ends up being used | |
| 302 | 304 | - [[Docker Containerization]] | |
| 303 | 305 | ||
| 304 | 306 | --- | |
| 305 | 307 | *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).* | |
| 306 | 308 | Category: FPC |
