起動スクリプト
指定されたネットワーク上の場所から内蔵UEFIシェルが実行できる構成スクリプトの例を以下に示します。このスクリプトを使用してRAMディスクを作成してから、ファイル出力のリダイレクトに使用するRAMディスクのFS
ファイルシステムを検索できます。
@echo -off
#
# Setup the environment variables. All of them are created as volatile.
#
#
# The volume label for the RAMDISK.
#
set -v VolumeLabel MYRAMDISK
#
# Variable to store the file system index that will be looped
# to determine the FS<x> number for the RAMDISK that is created.
#
set -v FsIndex 0
#
# Variable to store the output string of the ramdisk -c command.
# Successful creation of RAMDISK will give the following output:
# "RAM disk 'FSx:' created successfully." where x=0,1,2,...
#
set -v RamDiskStr 0
#
# Size of the RAMDISK in MegaBytes (MB).
#
set -v RamDiskSize 512
#
# Server URL hosting the OS loader and images.
# Can be HTTP or FTP. Names or IP addresses are allowed.
# Ensure DNS service is available and configured (see pre-requisites)
# when server names are used.
#
set -v Url http://192.168.1.1
#
# Files to be downloaded
#
set -v DownloadFile1 efilinux.efi
set -v DownloadFile2 deploy.kernel
set -v DownloadFile3 deploy.ramdisk
#
# Step 1. Create RAMDISK to store the downloaded OS programs.
#
echo "Creating a RAM Disk to save downloaded files..."
ramdisk -c -s %RamDiskSize% -v %VolumeLabel% -t F32 >v RamDiskStr
if %lasterror% ne 0x0 then
echo "Cannot create a RAMDISK of size %RamDiskSize%."
goto EXITSCRIPT
endif
echo "RAM Disk with Volume Label %VolumeLabel% created successfully."
#
# Step 2. Check each word in the output (RamDiskStr) and see if it matches
# the FSx: pattern. The newly created RAMDISK will be FS1: or higher.
# Here the check goes upto FS3: (the inner for loop), but a larger limit
# may be used in case many other file systems already exist before
# the creation of this RAMDISK. The FS for the RAMDISK is found when the
# FsIndex matches the FS<x> in RamDiskStr. Change the working directory
# to FS<FsIndex>:, so all downloads get saved there.
#
# FS0: is ignored. In the worst case, when no other usable
# file system is present, FS0: will map to the file system
# that this script is executing from.
#
#
for %a in %RamDiskStr%
for %b run (1 10)
set -v FsIndex %b
if 'FS%FsIndex%:' == %a then
FS%FsIndex%:
goto RDFOUND
endif
endfor
endfor
#
# The following message appears if the newly created RAMDISK cannot be found.
#
echo "RAMDISK with Volume Label %VolumeLabel% not found!"
goto EXITSCRIPT
#
# The following message appears if the RAMDISK FS<x> has been found and you are in the
# RAMDISK's root folder.
#
:RDFOUND
echo "RAMDISK with Volume Label %VolumeLabel% found at FS%FsIndex%:."
#
# Step 3: Download the required files into the RAMDISK.
#
echo "Downloading %Url%/deploy/%DownloadFile1% (File 1 of 3...)"
webclient -g %Url%/deploy/%DownloadFile1% -o %DownloadFile1%
if %lasterror% ne 0x0 then
goto EXITSCRIPT
endif
echo "Downloading %Url%/deploy/%DownloadFile2% (File 2 of 3...)"
webclient -g %Url%/deploy/%DownloadFile2% -o %DownloadFile2%
if %lasterror% ne 0x0 then
goto EXITSCRIPT
endif
echo "Downloading %Url%/deploy/%DownloadFile3% (File 3 of 3...)"
webclient -g %Url%/deploy/%DownloadFile3% -o %DownloadFile3%
if %lasterror% ne 0x0 then
goto EXITSCRIPT
endif
#
# Step4: Launch the boot loader.
#
echo "Starting the OS..."
%DownloadFile1% -f %DownloadFile2% initrd=%DownloadFile3%
#
# You reach here only if the downloads and booting failed.
#
:EXITSCRIPT
echo "Exiting Script."
このサンプルスクリプトは、以下の操作を行います。
- ダウンロードしたブートローダー、OSカーネル、ファイルシステムのほか、ブートローダーとカーネルの初期化に必要な構成ファイルを保管する一時RAMディスクを作成し、ネットワーク経由のインストールに進みます。
-
新しく作成したRAMディスクの
FS<x>
IDを判別します。 -
作業ディレクトリをRAMディスクのルートに設定します(例:
FS1:\
)。 - OSの起動に必要なファイル(ブートローダー、OSカーネル、OSカーネルのメモリ上のファイルシステム)をダウンロードします。
-
次のいずれかを実行します。
-
必要なすべてのファイルのダウンロードに失敗した場合、クリーンアップを実行し、起動スクリプトを終了します。
-
ダウンロードが成功した場合、ブートローダーを起動し、OSカーネルファイル、そのメモリ上のファイルシステム、およびOSカーネルへのすべての引数(ブートローダーがカーネルの起動時にカーネルに渡す必要がある引数)をコマンドライン引数としてブートローダーに渡します。
UEFIシェルとプリブートスクリプトの役割はここで終了です。これで、OSは、メモリ上のファイルシステムに内蔵されている、OS固有の展開スクリプトを使用して、自身で展開を行うことができます。
-
必要なすべてのファイルのダウンロードに失敗した場合、クリーンアップを実行し、起動スクリプトを終了します。