Hades

From CUSF Wiki
Revision as of 21:24, 26 September 2021 by EllieClifford (talk | contribs)
Jump to navigation Jump to search

This page was automatically generated. Please do not edit it

Custom CUSF boot screen, made by Henry

Hades is a minimal Windows virtual machine designed for using SolidWorks on Linux. It is named after Hell itself, as that's what using Windows feels like (in Tim's humble opinion). Hades has been successfully built for both SolidWorks 2018 SP03 and SolidWorks 2020 SP03.

80px-OOjs UI icon information-progressive.svg.png

We are currently in the process of finalising the new image for SolidWorks 2020.

If you have all of the licenses required for Hades (being a student at Cambridge is enough), drop Tim or Henry a message and we will authorize you to access the prebuilt image. Then see Install Hades with our image. The rest of this page is dedicated to installing and optimizing Hades from scratch.

If you are some sort of masochist (read: Gentoo user) and want to do it from scratch "for fun" despite having access to the prebuilt image, we can authorize you to access the proprietary source files too.

A Note on SolidWorks Network Licences

Using this without a SolidWorks Network License contravenes the SolidWorks licensing. However, this procedure does successfully convince SolidWorks that it’s not in a VM. This is justifiable because there are artificial locks against using "unsupported" hypervisors, so you couldn’t do it without tricking SolidWorks even with the correct license. Please don't sue us.

Install Hades with our image

The latest image (Revision 2) is built with: * Solidworks 2020 SP03 * Windows 10 21H1 English International * Virtio 0.1.208

80px-OOjs UI icon notice-warning.svg.png

These links and filenames relate to Revision 1, which has SolidWorks 2018 installed. They will be updated when we finalise Revision 2.

80px-OOjs UI icon notice-warning.svg.png

This image is accessible over SSH from the host, with a publicly available key used by Charon. The key can also be found in keys/. Make sure that this is not accessible to anyone else on the network by making sure that the output of nmap $(hostname -i) does not show port 2200 as open.
  1. Install QEMU, a SPICE viewer, and samba. As an example, on Arch Linux, that would look something like this:
sudo pacman -S qemu virt-viewer samba
  1. Download the image here. If you get a permission error, you will need to message Tim or Henry to get access.

  2. (Optionally) verify the integrity and signature of the files by downloading the checksum and the signature and verifying them:

gpg --import <(curl -L pgp.cusf.co.uk/tim-clifford.asc) # Import Tim's public key
gpg --verify hades-rev1.qcow2.asc hades-rev1.qcow2 # Verify that Tim signed the image
sha256sum -c hades-rev1.qcow2.sha256 # Verify the integrity of the image
  1. Clone the Hades repository and install Hades with the image:
git clone https://github.com/smh-my-head/hades
cd hades
make with-image image=path/to/hades-rev1.qcow2
sudo make install

Then just run hades from a terminal (or in the normal way you would run programs) to start Hades. You may also want to see Start SolidWorks faster to make starting SolidWorks quicker (note that this will decrease portability)

Install Hades from scratch

Prerequisites

On the host (Linux)

On the guest (Windows)

  • SPICE guest tools binary. Can be found here (navigate to Guest->Windows Binaries)
  • SolidWorks installer (this can be downloaded on Linux, the Linux filesystem will be mapped as a network drive later on)

Setup

  1. First, grab the necessary ISOs and place theme at ./src/Win10.iso and ./src/virtio-win.iso
  2. Run make. This will create a new VM image and begin the Windows installation, putting all the modifiable files in run (to keep the git working tree clean). You may need to press a key when it says "Press any key to boot from CD/DVD". It may take a while to boot for the first time, don’t panic! If you get stuck in the VM, note that Ctrl-Alt-G releases the mouse.
  3. Within the Windows VM, install the virtio drivers by following these instructions from the ArchWiki

Windows will detect the fake disk and look for a suitable driver. If it fails, go to Device Manager, locate the SCSI drive with an exclamation mark icon (should be open), click Update driver and select the virtual CD-ROM. Do not navigate to the driver folder within the CD-ROM, simply select the CD-ROM drive and Windows will find the appropriate driver automatically (tested for Windows 7 SP1).

  1. Within the Windows VM, install the SPICE guest tools here (navigate to Guest->Windows Binaries)

  2. Shutdown the VM and optionally edit hades.sh to change the core count and memory allocation to your preference.

  3. Run sudo make install to install Hades (or you can just run it with hades.sh)

  4. Start Hades again, and within Windows, connect to a the host filesystem with a loopback network device, by navigating in the file explorer to This PC -> Computer -> Map network drive and entering \\10.0.2.4\qemu under Folder:. Then map the same device as an administrator by executing net use z: \\10.0.2.4\qemu /persistent:yes in an administrator command prompt.

  5. Install SolidWorks as usual. (If you downloaded it on Linux, you can install directly from the network drive)

  6. Optionally follow the instructions in Start SolidWorks faster to set yourself up for starting SolidWorks quickly.

Suggestions

See the rest of the docs for ways to make the vm even better (including minifying, skipping some of the boot process, and other tweaks)

Start SolidWorks faster

To set up:

  1. Install openbsd-netcat (the name may vary, this is correct on Arch Linux)
  2. Start Hades and open SolidWorks
  3. On the host, open the qemu monitor with hades-monitor
  4. Enter savevm solidworks in the qemu monitor. This will save a snapshot with the name solidworks
  5. Run sudo make solidworks to install solidworks to your PATH

To use:

Start SolidWorks with solidworks and wait for the virtual machine to boot (there will be no feedback except something like “Connecting to graphic server” until it has booted). This usually takes 10-15 seconds, but can vary depending on a few factors.

SSH from the host to the guest

  1. Install msys2 on the guest. You can get the installer here
  2. Inside admin msys2, run //10.0.2.4/qemu/path/to/util/msys2-setup.sh
  3. Open port 22 on the guest
  4. From the host, run ssh -p 2200 windows-username@localhost. The user must have a password for this to work. You can use passwd to create one easily
  5. Lots of things can go wrong. See here for common problems etc. It is possible to use ssh keys, but you will have to generate /etc/passwd and possibly /etc/group with mkpasswd -l > /etc/passwd && mkgroup -l > /etc/group

Clean and Minify

From Guest

Compress Windows OS Files (Optional)

You can try compacting the OS from within Windows to reduce the size taken up by the OS. Whether or not this makes a difference is yet to be proved (see the pidgeon hole principle), so use at your own peril.

To compress the OS files, open an administrator command prompt and run compact.exe /CompactOS:always. To disable OS file compression, run compact.exe /CompactOS:never from an admin prompt.

Clear Data from Previously Uninstalled Programs

If you have installed and then later uninstalled programs, check both AppData and both Program Files folders for any storage used by these programs that’s no longer needed.

In addition, registry entries from uninstalled programs may be found in the registry locations Computer\HKEY_CURRENT_USER\SOFTWARE and Computer\HKEY_LOCAL_MACHINE\SOFTWARE.

Use the Built-In Windows Cleanup Tool

Windows comes pre-packaged with a tool for freeing up space on disk by deleting temporary and/or old system files. While this tool is not as thorough as others in this document, it is still valuable in the pursuit of the smallest possible VM image size.

To use the tool, just search for ‘Disk Cleanup’. The program should be very easy to use from the GUI, and should be run for both user and system files.

Cleanup the WinSxS Folder

Run dism /Online /Cleanup-Image /StartComponentCleanup /ResetBase and then dism /Online /Cleanup-Image /SPSuperseded from an administrator command prompt.

Clear the SoftwareDistribution folder

This folder is safe to remove. Windows will try to redownload it, but of course it can’t if you shrink the drive afterwards. Run the following from an administrator command prompt:

net stop wuauserv
net stop bits

then remove the folder (if you start the services again windows will re-download it)

Remove things from WindowsApps

Go ham deleting things in C:\Program Files\WindowsApps. The easiest way is to mount the image in Linux first:

/path/to/util/qemu_mnt.sh /path/to/img.qcow2
sudo mount /dev/nbd0p3 /path/to/mount/point
# delete the stuff
sudo umount /path/to/mount/point
/path/to/utiu/qemu_umnt.sh

You may then need to go into Settings -> Apps and Features -> [Broken App] -> Advanced options -> Reset for each one.

Defragment the Virtual Disk

Windows has a built-in tool for defragging the disk, defrag.exe. You’ll want to run this on the C: drive from an administrator prompt, and may want to use some of the following useful options: - /u: Print the progress of the operation on the screen. - /v: Print verbose output containing the fragmentation statistics. - /x: Perform free space consolidation on the specified volumes. - /h: Run the operation at normal priority (default is low).

The recommended command (by Henry) is defrag.exe c: /u /x /h. Free space consolidation in particular is recommended in trying to reduce the size of the disk, but your mileage may vary.

Shrink the Windows Partition

Windows could be considered gaseous, in that it tends to fill the volume of whatever container it’s in. To stop Windows from taking any and all free space, you can shrink the partition with the built-in Disk Manager GUI. Make sure to note down the final disk size.

Zero Empty Disk Space

The ‘empty’ space on the virtual hard disk may be full of junk data, and Windows would never tell you. To truly clear this space, you will need to use the Windows sysinternals tool SDelete.

To use SDelete, open an administrator command prompt and run (from within the downloaded folder) sdelete64.exe -c c: followed by sdelete64.exe -z c:. What these commands do is first clean, then zero the free space respectively.

From Host

Shrink VM Image

QEMU provides a tool for resizing a qcow2 image, qemu-img resize. To shrink the size of the disk (make sure not to make it smaller than the Windows partition!), use qemu-img resize --shrink img.qcow2 SIZE (see man qemu-img for SIZE).

Sparsify and Compress VM Image

An important step in minimising image size is to sparsify it. Optionally, you can compress the image at the same time, although this can make disk speeds slower). To sparsify and compress the image, run qemu-img convert -c -O qcow2 img.qcow2 img-compressed.qcow2, and leave the -c flag out if you would rather not compress the image.

To undo this change, you can use qemu-img convert -O qcow2 img-compressed.qcow2 img.qcow2.

Tweak Windows for a better user experience

Run the Windows 10 Debloater

To easily remove much of the pre-packaged bloatware in Windows 10, you can use this debloating script. A full guide to using the script can be found in the repo, but if you’re unsure, you can’t go wrong with the GUI. Except maybe bricking your system. Probably not though.

Disable UAC

Although often controversial, no one really likes UAC. Don’t lie, you always just click allow anyway, so you might as well save yourself the trouble and disable it altogether. This can be done through the Control Panel, under User Account and Family Safety -> User Accounts -> Change User Account Control settings, by dragging the slider to the bottom (‘Never notify’).

Clean up the Taskbar

The taskbar serves very little purpose on a virtual machine, so it’s recommended to clean it up a bit (read: almost completely). To do this, open Settings and navigate to Taskbar -> Turn System Icons On and Off.

Hide the Recycle Bin Icon from the Desktop

If you’re using the remote mounted host filesytem (and you should be), the Windows recycle bin serves little purpose and blocks out some of the wallpaper, which should be appreciated in its full glory. To disable it, open Settings and navigate to Personalization -> Themes, Desktop Icon Settings and disable it from there.

Disable Notifications

A desktop operating system should not need notifications. If you feel you need to be notified the instant someone wants to contact you, buy a phone. Notifications should be disabled through Settings -> System -> Notifications & actions, and toggling the switch under ‘Get notifications from apps and other senders’ to the off position.

Disable Action Center

Following on from the previous point, the quick settings do not belong in a notification center. That is what the taskbar is for. The cloest way to disable this particular piece of bloat by ensuring the ‘Action Center’ taskbar icon is disabled, and then make sure to ignore its existence. Unfortunately Windows does not currently allow users to completely disable the Action Center, but consider it out of sight and out of mind.

Disable Unneeded Startup Programs

Download autoruns from sysinternals here, and use the included GUI to disable startup programs at your own discretion.

Set the Holy Wallpaper

Download this wallpaper and set it as the desktop picture. This is a vital configuration step.

Enable ‘Ultimate Performance’

To maximise Windows performance, first launch the built-in utility powercfg to enable the ‘Ultimate Performance’ setting, by running powercfg.exe -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61 from an administrator command prompt. After making the option visible, open Control Panel and select the option under Hardware and Sound -> Power Options -> Choose a power plan.

Additionally, you can also go to Settings -> System -> About -> Advanced system settings -> Performance Options and select ‘Adjust for best performance’.

Disable All Telemetry

No explanation needed. Just make your way on over to Settings -> Privacy and go HAM from there. In addition, there are numerous tutorials available online describing several additional steps to disable Microsoft Telemetry.

In all honesty, the subject of disabling Microsoft telemetry could constitute and entire document of its own, and this section should, at some point in the future, be updated with a more detailed guide.

Disable Search Indexing

To disable Windows search indexing, and stop the service regularly consuming valuable resources, run services.msc and locate the ‘Windows Search’ service. Double click the service, and under the drop-down menu entitled ‘startup type’, select ‘Disable’.

Disable Hibernation

Hibernation isn’t really needed for a virtual machine, and can be disabled by running the command powercfg.exe /hibernate off as an administrator.

Disable Visual Effects

We don’t need animations or glossy finishes; while these options make for cool screenshots, they really only make the VM run slower. Disable them under Settings -> Ease of Access -> Display -> Simplify and personalise Windows.

Disable Lock Screen

A computer does not need a lock screen. It is not a cell phone. Disable the lock screen (and jump straight to the login prompt) by first opening regedit and navigating to HKLM\SOFTWARE\Policies\Microsoft\Windows. From here, create a new key called Personalization, and give this key a single DWORD called NoLockScreen with the value 0x00000000 (0).

Disable Swap

Disabling the swapfile (pagefile) is a hotly-debated topic. If you would like to do it, it can be done by opening Settings -> System -> About -> Advanced system settings -> Performance Options -> Advanced -> Virtual memory, clicking ‘Change’ and clicking the checkbox for ‘Automatically manage paging file size for all drives’ followed by the radio button for ‘No paging file’. Then click Ok back through all the menus.

Install the SolidWorks Dracula theme

This is an essential step if you value the sustained function of your eyes. Full instructions can be found here.

  1. Generate the right type of bitmap with ./util/make_boot_logo.sh. The result will be at ./img/Logo.bmp.
  2. Compile EDK2, replacing edk2/MdeModulePkg/Logo/Logo.bmp with ./img/Logo.bmp.
  3. Convert ./OVMF_VARS.fd (the compilation output) to qcow2 format with qemu-img convert -0 qcow2 OVMF_VARS.fd OVMF_VARS.qcow2
  4. Replace ./OVMF_VARS.qcow2 with the new file you have just created
  5. ???
  6. Profit