Computer >> 컴퓨터 >  >> 시스템 >> Windows

Windows 샌드박스로 CPU 시간을 안전하게 기부하는 방법

컴퓨팅 파워는 기적을 만들어냅니다. 우리를 둘러싼 다양한 문제를 해결하는 데 막대한 역할을 할 수 있죠. 바로 이런 이유로 마이크로소프트를 포함한 전체 IT 업계가 문제 해결에 더 효율적인 컴퓨터를 만드는 데 도움을 줄 양자 컴퓨팅에 투자하고 있습니다.

Folding@home은 단백질 역학의 분자 동역학 시뮬레이션을 수행하는 대표적인 분산 컴퓨팅 프로젝트입니다. 마이크로소프트는 누구나 자신의 컴퓨터 자원을 이 프로젝트에 기부할 수 있도록 상세한 가이드를 공개했습니다. 이 글에서는 Windows 샌드박스(Windows Sandbox)를 활용해 CPU 시간을 안전하게 기부하는 방법을 알아보겠습니다.

Windows 샌드박스로 CPU 시간을 안전하게 기부하는 방법

Windows 샌드박스로 CPU 시간 안전하게 기부하기

시작하기 전에 먼저 컴퓨터에서 Windows 샌드박스 기능이 활성화되어 있는지 확인해야 합니다. Windows 샌드박스는 격리된 임시 환경에서 프로그램을 실행할 수 있게 해주기 때문에, 호스트 시스템에 영향을 주지 않고 안전하게 작업을 수행할 수 있다는 점이 큰 장점입니다.

1. PowerShell 스크립트 준비

메모장을 열고 아래 코드를 복사하여 붙여넣습니다:

#Requires -RunAsAdministrator

#For a custom username, add -username <your username> to the command execution
param([string]$username=‘wsandbox_anon‘)
$ProgressPreference = ‘SilentlyContinue‘ #Progress bar makes things way slower

# Ensure that virtualization is enabled in BIOS.
Write-Output ‘Verifying that virtualization is enabled in BIOS…‘
if ((Get-WmiObject Win32_ComputerSystem).HypervisorPresent -eq $false) {
Write-Output ‘ERROR: Please Enable Virtualization capabilities in your BIOS settings…‘
exit
}

# Determine if Windows Sandbox is enabled.
Write-Output ‘Checking to see if Windows Sandbox is installed…‘
If ((Get-WindowsOptionalFeature –FeatureName ‘Containers-DisposableClientVM‘ –Online).State -ne ‘Enabled‘) {
Write-Output ‘Windows Sandbox is not installed, attempting to install it (may require reboot)…‘
if ((Enable-WindowsOptionalFeature –FeatureName ‘Containers-DisposableClientVM‘ –All –Online –NoRestart).RestartNeeded) {
Write-Output ‘Please reboot to finish installing Windows Sandbox, then re-run this script…‘
exit
}
} else {
Write-Output ‘Windows Sandbox already installed.‘
}

# Download the latest version of FAH.
Write-Output ‘Checking for latest version of foldingathome…‘
$installer_url = ‘https://download.foldingathome.org/releases/public/release/fah-installer/windows-10-32bit/‘

# Use regex to get the latest version from the FAH website.
$version = ((Invoke-WebRequest –Uri $installer_url –UseBasicParsing).Links | Where-Object {$_.href -match ‘^v\d+([.]\d+)?‘} | ForEach-Object {[float]($_.href -replace ‘[^.\d]‘, ‘‘)} | Measure-Object –Max).Maximum
$installer = “$($installer_url)v$($version)/latest.exe“
$installer_size =(Invoke-WebRequest $installer –Method Head –UseBasicParsing).Headers.‘Content-Length‘
Write-Output “Using FAH v$version.“

# Check if the installer is present, download otherwise.
$working_dir = “$env:USERPROFILE\fah_conf“
$install_fname = ‘folding_installer.exe‘
If (!(test-path “$working_dir\$install_fname“) -or (Get-ChildItem “$working_dir\$install_fname“).Length -ne $installer_size ) {
Remove-Item “$working_dir\$install_fname“ –Force –ErrorAction SilentlyContinue
Write-Output “Downloading latest folding executable: $working_dir\$install_fname“
Write-Output “Saving to $working_dir\$install_fname…“
New-Item –ItemType Directory –Force –Path $working_dir | Out-Null
Invoke-WebRequest –Uri $installer –OutFile “$working_dir\$install_fname“
}

# Create the FAH configuration file with the Windows Sandbox FAH team #251561.
Write-Output ‘Creating init command…‘
$conf_file = ‘fah_sandbox_conf.xml‘
Write-Output “Saved [email protected] configuration file to $working_dir\$conf_file“
New-Item –Force –Path “$working_dir\$conf_file“ –ItemType File
Set-Content –Path “$working_dir\$conf_file“ –Value @”
<config>
<user v=’$username‘/>
<team v=’251561’/>
<core-priority v=’low’/>
<power v=’full’ />
<priority v=’realtime’/>
<smp v=’true’/>
<gpu v=’true’/>
<open-web-control v=’true’/>
</config>
“@

<#
Create the script that runs at logon. This script:
1. Starts the installer
2. Creates a volatile working directory
3. Copies the config into the working directory
4. Sets the firewall policies to let FAH run
5. Starts the FAH client
#>
Write-Output ‘Creating init command…‘
$logon_cmd = “$working_dir\init.cmd“
$wdg_install_dir = ‘C:\users\wdagutilityaccount\desktop\fah_conf‘
$wdg_working_dir = ‘C:\users\wdagutilityaccount\desktop\fah_working_dir‘
Write-Output “Saved logon script to $logon_cmd, this will be run upon starting Sandbox.“
New-Item –Force –Path $logon_cmd –ItemType File
Set-Content –Path $logon_cmd –Value @”
start $wdg_install_dir\$install_fname /S
goto WAITLOOP

:WAITLOOP
if exist “C:\Program Files (x86)\FAHClient\FAHClient.exe” goto INSTALLCOMPLETE
ping -n 6 127.0.0.1 > nul
goto WAITLOOP

:INSTALLCOMPLETE
mkdir $wdg_working_dir
cd $wdg_working_dir
echo \”Copying config file to $wdg_working_dir\”
copy $wdg_install_dir\$conf_file $wdg_working_dir
netsh advfirewall firewall Add rule name=”FAHClient” program=”C:\Program Files (x86)\FAHClient\FAHClient.exe” action=allow dir=out
netsh advfirewall firewall Add rule name=”FAHClient” program=”C:\Program Files (x86)\FAHClient\FAHClient.exe” action=allow dir=in
start C:\”Program Files (x86)”\FAHClient\FAHClient.exe –config $wdg_working_dir\$conf_file
“@

# Create the Sandbox configuration file with the new working dir & LogonCommand.
$sandbox_conf = “$working_dir\fah_sandbox.wsb“
Write-Output “Creating sandbox configuration file to $sandbox_conf“
New-Item –Force –Path $sandbox_conf –ItemType File
Set-Content –Path $sandbox_conf –Value @”
<Configuration>
<VGpu>Enable</VGpu>
<MappedFolders>
<MappedFolder>
<HostFolder>$working_dir</HostFolder>
<ReadOnly>true</ReadOnly>
</MappedFolder>
</MappedFolders>
<LogonCommand>
<Command>$wdg_install_dir\init.cmd</Command>
</LogonCommand>
</Configuration>
“@

# For convenience, start the Sandbox.
Write-Output ‘Starting sandbox…‘
Start-Process ‘C:\WINDOWS\system32\WindowsSandbox.exe‘ –ArgumentList $sandbox_conf

2. GitHub에서 직접 다운로드

스크립트를 직접 복사하는 것이 번거롭다면, 마이크로소프트의 GitHub 저장소에서 해당 파일을 바로 내려받을 수도 있습니다.

Windows 샌드박스로 CPU 시간을 안전하게 기부하는 방법

3. 스크립트 실행

준비가 끝났다면 Windows PowerShell에서 스크립트를 실행하기만 하면 됩니다. 그러면 Windows 샌드박스 환경이 시작되고, 샌드박스 내부에서 자동으로 Folding@home 클라이언트가 구동되어 컴퓨터의 자원을 분산 컴퓨팅 프로젝트에 기부하게 됩니다.

샌드박스 환경은 종료 시 모든 데이터가 삭제되므로, 호스트 PC에는 어떤 흔적도 남지 않는다는 점에서 매우 안전한 기부 방식이라 할 수 있습니다. 여유로운 컴퓨팅 자원으로 과학 연구에 보탬이 되어 보세요!

All the best!

Windows 샌드박스로 CPU 시간을 안전하게 기부하는 방법