VirtualBox

source: vbox/trunk/src/VBox/Main/include/UnattendedImpl.h@ 91692

Last change on this file since 91692 was 91502, checked in by vboxsync, 3 years ago

Main/Unattended: Add UEFI support (needed for Windows 11 which this also adds), and make it work for the Windows case. This requires moving the aux files to a DVD image, because Windows booted in UEFI mode is unable to access a legacy floppy drive (hardcoded by Microsoft). The partitioning needs to be very different with UEFI and follows Microsoft's recommendations. Needs also a bit more flexibility with knowing on which drive letter the script will end up. Additionally contains registry tweaking to skip the TPM and secure boot checks in the Windows 11 installer (just in Windows PE, for later upgrading the same needs to be applied in the final install).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1/* $Id: UnattendedImpl.h 91502 2021-09-30 20:32:24Z vboxsync $ */
2/** @file
3 * Unattended class header
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef MAIN_INCLUDED_UnattendedImpl_h
19#define MAIN_INCLUDED_UnattendedImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <VBox/ostypes.h>
25#include <iprt/time.h>
26#include "UnattendedWrap.h"
27
28/* Forward declarations. */
29class UnattendedInstaller;
30struct UnattendedInstallationDisk;
31struct ControllerSlot;
32
33
34/**
35 * Class implementing the IUnattended interface.
36 *
37 * This class is instantiated on the request by IMachine::getUnattended.
38 */
39class ATL_NO_VTABLE Unattended
40 : public UnattendedWrap
41{
42public:
43 DECLARE_COMMON_CLASS_METHODS(Unattended)
44
45 HRESULT FinalConstruct();
46 void FinalRelease();
47
48 // public initializer/uninitializer for internal purposes only
49 HRESULT initUnattended(VirtualBox *aParent);
50 void uninit();
51
52 // public methods for internal purposes
53 Utf8Str const &i_getIsoPath() const;
54 Utf8Str const &i_getUser() const;
55 Utf8Str const &i_getPassword() const;
56 Utf8Str const &i_getFullUserName() const;
57 Utf8Str const &i_getProductKey() const;
58 Utf8Str const &i_getProxy() const;
59 Utf8Str const &i_getAdditionsIsoPath() const;
60 bool i_getInstallGuestAdditions() const;
61 Utf8Str const &i_getValidationKitIsoPath() const;
62 bool i_getInstallTestExecService() const;
63 Utf8Str const &i_getTimeZone() const;
64 PCRTTIMEZONEINFO i_getTimeZoneInfo() const;
65 Utf8Str const &i_getLocale() const;
66 Utf8Str const &i_getLanguage() const;
67 Utf8Str const &i_getCountry() const;
68 bool i_isMinimalInstallation() const;
69 Utf8Str const &i_getHostname() const;
70 Utf8Str const &i_getAuxiliaryBasePath() const;
71 ULONG i_getImageIndex() const;
72 Utf8Str const &i_getScriptTemplatePath() const;
73 Utf8Str const &i_getPostInstallScriptTemplatePath() const;
74 Utf8Str const &i_getPostInstallCommand() const;
75 /** The directory where the unattended install config and script is
76 * located, from the perspective of the running unattended install. */
77 Utf8Str const &i_getAuxiliaryInstallDir() const;
78 Utf8Str const &i_getExtraInstallKernelParameters() const;
79
80 bool i_isRtcUsingUtc() const;
81 bool i_isGuestOs64Bit() const;
82 bool i_isFirmwareEFI() const;
83 VBOXOSTYPE i_getGuestOsType() const;
84 Utf8Str const &i_getDetectedOSVersion();
85
86
87private:
88 ComPtr<VirtualBox> const mParent; /**< Strong reference to the parent object (VirtualBox/IMachine). */
89 ComPtr<Machine> mMachine; /**< Strong reference to the machine object (Machine/IMachine). */
90 Guid mMachineUuid; /**< The machine UUID. */
91 RTNATIVETHREAD mhThreadReconfigureVM; /**< Set when reconfigureVM is running. */
92 Utf8Str mStrGuestOsTypeId; /**< Guest OS type ID (set by prepare). */
93 bool mfRtcUseUtc; /**< Copy of IMachine::RTCUseUTC (locking reasons). */
94 bool mfGuestOs64Bit; /**< 64-bit (true) or 32-bit guest OS (set by prepare). */
95 FirmwareType_T menmFirmwareType; /**< Firmware type BIOS/EFI (set by prepare). */
96 VBOXOSTYPE meGuestOsType; /**< The guest OS type (set by prepare). */
97 UnattendedInstaller *mpInstaller; /**< The installer instance (set by prepare, deleted by done). */
98
99 /** @name Values of the IUnattended attributes.
100 * @{ */
101 Utf8Str mStrUser;
102 Utf8Str mStrPassword;
103 Utf8Str mStrFullUserName;
104 Utf8Str mStrProductKey;
105 Utf8Str mStrIsoPath;
106 Utf8Str mStrAdditionsIsoPath;
107 bool mfInstallGuestAdditions;
108 bool mfInstallTestExecService;
109 Utf8Str mStrValidationKitIsoPath;
110 Utf8Str mStrTimeZone;
111 PCRTTIMEZONEINFO mpTimeZoneInfo;
112 Utf8Str mStrLocale;
113 Utf8Str mStrLanguage; /**< (only relevant for windows at the moment) */
114 Utf8Str mStrCountry;
115 RTCList<RTCString, RTCString *> mPackageSelectionAdjustments;
116 Utf8Str mStrHostname;
117 Utf8Str mStrAuxiliaryBasePath;
118 bool mfIsDefaultAuxiliaryBasePath;
119 ULONG midxImage;
120 Utf8Str mStrScriptTemplatePath;
121 Utf8Str mStrPostInstallScriptTemplatePath;
122 Utf8Str mStrPostInstallCommand;
123 Utf8Str mStrExtraInstallKernelParameters;
124
125 bool mfDoneDetectIsoOS; /**< Set by detectIsoOS(), cleared by setIsoPath(). */
126 Utf8Str mStrDetectedOSTypeId;
127 Utf8Str mStrDetectedOSVersion;
128 Utf8Str mStrDetectedOSFlavor;
129 RTCList<RTCString, RTCString *> mDetectedOSLanguages; /**< (only relevant for windows at the moment) */
130 Utf8Str mStrDetectedOSHints;
131 Utf8Str mStrProxy;
132 /** @} */
133
134 // wrapped IUnattended functions:
135
136 /**
137 * Checks what mStrIsoPath points to and sets the detectedOS* properties.
138 */
139 HRESULT detectIsoOS();
140
141 /**
142 * Prepare any data, environment, etc.
143 */
144 HRESULT prepare();
145
146 /**
147 * Prepare installation ISO/floppy.
148 */
149 HRESULT constructMedia();
150
151 /**
152 * Prepare a VM to run an unattended installation
153 */
154 HRESULT reconfigureVM();
155
156 /**
157 * Done with all media construction and VM configuration and stuff.
158 */
159 HRESULT done();
160
161 // wrapped IUnattended attributes:
162 HRESULT getIsoPath(com::Utf8Str &isoPath);
163 HRESULT setIsoPath(const com::Utf8Str &isoPath);
164 HRESULT getUser(com::Utf8Str &user);
165 HRESULT setUser(const com::Utf8Str &user);
166 HRESULT getPassword(com::Utf8Str &password);
167 HRESULT setPassword(const com::Utf8Str &password);
168 HRESULT getFullUserName(com::Utf8Str &user);
169 HRESULT setFullUserName(const com::Utf8Str &user);
170 HRESULT getProductKey(com::Utf8Str &productKey);
171 HRESULT setProductKey(const com::Utf8Str &productKey);
172 HRESULT getAdditionsIsoPath(com::Utf8Str &additionsIsoPath);
173 HRESULT setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath);
174 HRESULT getInstallGuestAdditions(BOOL *installGuestAdditions);
175 HRESULT setInstallGuestAdditions(BOOL installGuestAdditions);
176 HRESULT getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath);
177 HRESULT setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath);
178 HRESULT getInstallTestExecService(BOOL *aInstallTestExecService);
179 HRESULT setInstallTestExecService(BOOL aInstallTestExecService);
180 HRESULT getTimeZone(com::Utf8Str &aTimezone);
181 HRESULT setTimeZone(const com::Utf8Str &aTimezone);
182 HRESULT getLocale(com::Utf8Str &aLocale);
183 HRESULT setLocale(const com::Utf8Str &aLocale);
184 HRESULT getLanguage(com::Utf8Str &aLanguage);
185 HRESULT setLanguage(const com::Utf8Str &aLanguage);
186 HRESULT getCountry(com::Utf8Str &aCountry);
187 HRESULT setCountry(const com::Utf8Str &aCountry);
188 HRESULT getProxy(com::Utf8Str &aProxy);
189 HRESULT setProxy(const com::Utf8Str &aProxy);
190 HRESULT getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments);
191 HRESULT setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments);
192 HRESULT getHostname(com::Utf8Str &aHostname);
193 HRESULT setHostname(const com::Utf8Str &aHostname);
194 HRESULT getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath);
195 HRESULT setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath);
196 HRESULT getImageIndex(ULONG *index);
197 HRESULT setImageIndex(ULONG index);
198 HRESULT getMachine(ComPtr<IMachine> &aMachine);
199 HRESULT setMachine(const ComPtr<IMachine> &aMachine);
200 HRESULT getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath);
201 HRESULT setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath);
202 HRESULT getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath);
203 HRESULT setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath);
204 HRESULT getPostInstallCommand(com::Utf8Str &aPostInstallCommand);
205 HRESULT setPostInstallCommand(const com::Utf8Str &aPostInstallCommand);
206 HRESULT getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters);
207 HRESULT setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters);
208 HRESULT getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId);
209 HRESULT getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion);
210 HRESULT getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages);
211 HRESULT getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor);
212 HRESULT getDetectedOSHints(com::Utf8Str &aDetectedOSHints);
213 //internal functions
214
215 /**
216 * Worker for detectIsoOs().
217 *
218 * @returns COM status code.
219 * @retval S_OK if detected.
220 * @retval S_FALSE if not detected.
221 *
222 * @param hVfsIso The ISO file system handle.
223 */
224 HRESULT i_innerDetectIsoOS(RTVFS hVfsIso);
225 typedef union DETECTBUFFER
226 {
227 char sz[4096];
228 char ach[4096];
229 uint8_t ab[4096];
230 uint32_t au32[1024];
231 } DETECTBUFFER;
232 HRESULT i_innerDetectIsoOSWindows(RTVFS hVfsIso, DETECTBUFFER *puBuf, VBOXOSTYPE *penmOsType);
233 HRESULT i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *puBuf, VBOXOSTYPE *penmOsType);
234
235 /**
236 * Worker for reconfigureVM().
237 * The caller makes sure to close the session whatever happens.
238 */
239 HRESULT i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
240 ComPtr<IMachine> const &rPtrSessionMachine);
241 HRESULT i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
242 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
243 ComPtr<IMachine> const &rPtrSessionMachine,
244 AutoMultiWriteLock2 &rAutoLock);
245 HRESULT i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
246 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
247 ComPtr<IMachine> const &rPtrSessionMachine,
248 AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus);
249
250 /**
251 * Adds all free slots on the controller to @a rOutput.
252 */
253 HRESULT i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
254 ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
255 std::list<ControllerSlot> &rDvdSlots);
256
257 /**
258 * Attach to VM a disk
259 */
260 HRESULT i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
261 AutoMultiWriteLock2 &rLock);
262
263 /*
264 * Wrapper functions
265 */
266
267 /**
268 * Check whether guest is 64bit platform or not
269 */
270 bool i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId);
271};
272
273#endif /* !MAIN_INCLUDED_UnattendedImpl_h */
274
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette