-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stage1 working. virtio drivers, ssh keys, new user
- Loading branch information
Showing
3 changed files
with
145 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 1,10 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
.venv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
# Build outputs | ||
ssh_host* | ||
sshpass | ||
stage?-complete | ||
downloaded | ||
temporary | ||
*.qcow2 | ||
|
||
# Editor files | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,81 @@ | ||
port=22022 | ||
password="Passw0rd!" | ||
d=downloaded | ||
t=temporary | ||
privkey=ssh_host_ed25519_key | ||
pubkey=$(privkey).pub | ||
|
||
|
||
$(privkey) $(pubkey): | ||
ssh-keygen -f $(privkey) -t ed25519 -N '' | ||
|
||
sshpass: | ||
@which $@ > /dev/null || bash -c 'echo "$@ not found, please install it" && false' | ||
touch $@ | ||
|
||
$d: | ||
mkdir $@ | ||
|
||
$d/virtio.iso: | ||
# Google for RedHat Windows virtio drivers | ||
wget -c -O $@ https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.141-1/virtio-win-0.1.141.iso | ||
|
||
$d/win10.zip: | $d | ||
# New URLS to be found at modern.ie | ||
wget -c -O $@ https://az792536.vo.msecnd.net/vms/VMBuild_20171019/VirtualBox/MSEdge/MSEdge.Win10.VirtualBox.zip | ||
|
||
$d/win10.ova: $d/win10.zip | ||
unzip -p $^ > $@ | ||
|
||
$d/win10.vmdk: $d/win10.ova | ||
tar xOf $^ "MSEdge - Win10-disk001.vmdk" > $@ | ||
|
||
win10.qcow2: $d/win10.vmdk | ||
qemu-img convert -O qcow2 $^ $@ | ||
|
||
$t: | ||
mkdir $@ | ||
|
||
$t/helper.qcow2: | $t | ||
qemu-img create -f qcow2 $@ 1G | ||
|
||
$t/ssh_host_ecdsa_key.pub: $d/win10.vmdk | $t | ||
7z e -so $^ 'Program Files/OpenSSH/etc/ssh_host_ecdsa_key.pub' > $@ | ||
|
||
.ONESHELL: stage1-complete | ||
stage1-complete: | $d/virtio.iso sshpass $t/ssh_host_ecdsa_key.pub $(pubkey) $(privkey) win10.qcow2 $t/helper.qcow2 | ||
set -m | ||
echo "[localhost]:$(port) $$(cut -d' ' -f1,2 $t/ssh_host_ecdsa_key.pub)" > $t/known_host | ||
qemu-system-x86_64 \ | ||
-drive file=win10.qcow2,if=ide \ | ||
-drive file=$t/helper.qcow2,if=virtio \ | ||
-drive file=$d/virtio.iso,media=cdrom \ | ||
-machine type=q35,accel=kvm \ | ||
-m 8G -smp cores=2,threads=1 \ | ||
-net nic -net user -redir tcp:$(port)::22 \ | ||
-vga std -display sdl & | ||
while ! nc -z localhost $(port); do sleep 1; done | ||
while ! sshpass -p 'Passw0rd!' ssh -p $(port) -o UserKnownHostsFile=$t/known_host -o ConnectTimeout=1 IEUser@localhost 'echo "Machine is up"' 2> /dev/null; do sleep 1; done | ||
sshpass -p 'Passw0rd!' ssh -p $(port) -o UserKnownHostsFile=$t/known_host IEUser@localhost 'mkdir -p /cygdrive/c/stage1' | ||
sshpass -p 'Passw0rd!' scp -P $(port) -o UserKnownHostsFile=$t/known_host stage1.ps1 $(pubkey) $(privkey) IEUser@localhost:/cygdrive/c/stage1 | ||
sshpass -p 'Passw0rd!' ssh -p $(port) -o UserKnownHostsFile=$t/known_host IEUser@localhost 'powershell C:\\stage1\\stage1.ps1 -Password $(password)' | ||
fg | ||
touch $@ | ||
|
||
.ONESHELL: stage2-complete | ||
stage2-complete: stage1-complete | win10.qcow2 $(pubkey) $t | ||
set -m | ||
echo "[localhost]:$(port) $$(cut -d' ' -f1,2 $(pubkey))" > $t/known_host | ||
qemu-system-x86_64 \ | ||
-drive file=win10.qcow2,if=virtio \ | ||
-machine type=q35,accel=kvm \ | ||
-m 8G -smp cores=2,threads=1 \ | ||
-net nic -net user -redir tcp:$(Port)::22 \ | ||
-vga std -display sdl & | ||
fg | ||
|
||
|
||
|
||
.INTERMEDIATE: $d/win10.zip $d/win10.ova $d/win10.vmdk $d/virtio.iso $t/helper.qcow2 $(privkey) $t/ssh_host_ecdsa_key.pub | ||
|
||
.PRECIOUS: $d/win10.vmdk $d/virtio.iso |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,54 @@ | ||
param( | ||
[String]$Hostname = "win10", | ||
[String]$Username = "chantal", | ||
[String]$Password = "Passw0rd!" | ||
) | ||
|
||
$ScriptDir = Split-Path $MyInvocation.InvocationName | ||
|
||
Start-Transcript "${ScriptDir}\stage1.log" | ||
|
||
# Kill Windows Update and make sure it stays dead | ||
Stop-Service wuauserv | ||
Set-Service wuauserv -StartupType Disabled | ||
|
||
# Change hostname and user | ||
Rename-Computer -NewName "${Hostname}" | ||
$SecurePassword = ConvertTo-SecureString -String "${Password}" -AsPlainText -Force | ||
New-LocalUser -Name "${Username}" -Password $SecurePassword | ||
Add-LocalGroupMember -Group Administrators -Member "${Username}" | ||
Disable-LocalUser IEUser | ||
Set-ItemProperty "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" DefaultPassword "${Password}" | ||
Set-ItemProperty "HKLM:\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" DefaultUserName "${Username}" | ||
|
||
# Reconfigure OpenSSHd | ||
$SID = Get-LocalUser $Username | select -ExpandProperty SID | ||
$PasswdLine = "${Username}:*:197612:197121:U-${Hostname}\${Username},${SID}:/cygdrive/c/Users/${Username}:/bin/sh" | ||
|
||
Push-Location "${env:programfiles}\OpenSSH\etc" | ||
Add-Content -Path .\passwd "${PasswdLine}" | ||
Remove-Item ssh_host* | ||
Copy-Item "${ScriptDir}\ssh_host_*" . | ||
Pop-Location | ||
|
||
# Install virtio storage driver | ||
# Thanks to https://stackoverflow.com/questions/36775331/extract-certificate-from-sys-file | ||
$InfFile = "D:\viostor\w10\amd64\viostor.inf" | ||
$SysFile = "D:\viostor\w10\amd64\viostor.sys" | ||
$CerFile = "${ScriptDir}\RedHat.cer" | ||
$ExportType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Cert | ||
$Cert = (Get-AuthenticodeSignature $SysFile).SignerCertificate | ||
[System.IO.File]::WriteAllBytes($CerFile, $Cert.Export($ExportType)) | ||
Import-Certificate -FilePath "$CerFile" -CertStoreLocation Cert:\LocalMachine\TrustedPublisher | ||
Start-Process $InfFile -Verb Install | ||
Start-Sleep 5 | ||
|
||
# Initialize virtio dummy disk, so that virtio will work for the boot drive | ||
Get-Disk | ?{ $_.PartitionStyle -eq "RAW" } | ` | ||
Initialize-Disk -PartitionStyle MBR -PassThru | ` | ||
New-Partition -AssignDriveLetter -UseMaximumSize | ` | ||
Format-Volume -FileSystem NTFS -NewFileSystemLabel "dummy" -Confirm:$false | ||
|
||
# We are done. | ||
Start-Process -NoNewWindow "shutdown.exe" -ArgumentList "/s /t 0" | ||
Stop-Transcript |