# For NTFS E2B USB drive (or FAT32)
# Create a FAT32 partition image file from a folder containing the kernel and system files from OpenElec using MPI Tool -> OpenElec.img
# Make ext2 FS file in root of E2B drive - FileName=OpenElec-rw  VolumeName=DATA
# Copy this .mnu file and OpenElecUSB.img to \_ISO\MAINMENU\MNU folder

iftitle [if exist not /system if not exist /kernel] OpenElec Live\n Boot OpenElec with persistence
set IMG=$HOME$/OpenElec.img
set PER=/OpenElec-rw

if "%E2BDEV%"=="" set E2BDEV=hd0 && pause E2BDEV forced to hd0!
if exist CD echo WARNING: Cannot use partnew command! && pause && configfile (bd)/menu.lst
partnew (%E2BDEV%,3) 0x0c %IMG%
debug 1
parttype (%E2BDEV%,2) | set check=
debug off
set check=%check:~-5,4%
# make empty table entry in 3rd position in ptn table
if "%check%"=="0x00" partnew (%E2BDEV%,2) 0 0 0
if not "%check%"=="0x00" echo WARNING: PTN TABLE 3 IS ALREADY IN USE! && pause
debug 1
if not exist %PER% echo WARNING: %PER% persistence file not found! && pause
errorcheck off
if "%check%"=="0x00" partnew (%E2BDEV%,2) 0x0 %PER%
errorcheck on

root (hd0,3)
uuid () > nul
set UUID=%?%
echo %UUID%
kernel /kernel boot=UUID=%UUID% disk=LABEL=DATA quiet
# if it exists, change the type 0C 4th ptn entry to 0
cat --locate=\x0c --number=1 --length=1 --skip=0x1f2 --replace=\x00 (hd0)+1
