Jump to content











Photo
- - - - -

Boot either Windows XP or Windows 7 in one option


  • Please log in to reply
12 replies to this topic

#1 ndog37

ndog37

    Member

  • Members
  • 79 posts
  •  
    New Zealand

Posted 22 October 2012 - 03:41 AM

Hi.

I am setting up clonezilla recovery options for some friends and family through g4d. I will only ever have one version of windows installed on their machine, either windows XP or Windows 7.

Is it possible to create a grub4dos entry that will detect if either bootmgr or NTLDR exists and then boot that drive. Otherwise when I setup their machine I have to comment out stuff and I would rather just have a single menu.lst that will work regardless.

Thanks

existing menu.lst

timeout 5

default 0



gfxmenu /message



title Boot Windows 7

find --set-root --devices=h /bootmgr && call set bootmgr=%@root^%

chainloader %bootmgr%/bootmgr



title Boot Windows XP

find --set-root --devices=h /NTLDR && call set bootmgr=%@root^%

map () %bootmgr%

map %bootmgr% ()

map --rehook

find --set-root --ignore-floppies --ignore-cd /ntldr

chainloader /ntldr



title Restore Clonezilla Image

root (hd0,1)

kernel /grub/clonezilla/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset vga=788 ip=frommedia nosplash ocs_live_run="ocs-live-general" ocs_live_keymap="NONE" ocs_lang="en_US.UTF-8" live-media-path=/grub/clonezilla/live bootfrom=/dev/sda2 toram=filesystem.squashfs ocs_live_batch="yes" ocs_prerun="mount /dev/sda2 /mnt" ocs_prerun1="mount --bind /mnt/grub/clonezilla/images /home/partimag/" ocs_live_run="ocs-sr -b -g auto -e1 auto -e2 -j2 -k -p reboot restoreparts ask_user sda1"

initrd /grub/clonezilla/live/initrd.img

boot



title Create Clonezilla Image

root (hd0,1)

kernel /grub/clonezilla/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset vga=788 ip=frommedia nosplash ocs_live_run="ocs-live-general" ocs_live_keymap="NONE" ocs_lang="en_US.UTF-8" live-media-path=/grub/clonezilla/live bootfrom=/dev/sda2 toram=filesystem.squashfs ocs_live_batch="yes" ocs_prerun="mount /dev/sda2 /mnt" ocs_prerun1="mount --bind /mnt/grub/clonezilla/images /home/partimag/" ocs_live_run="ocs-sr -q2 -b -j2 -z1 -i 2000 -sc -rm-win-swap-hib -p reboot saveparts ask_user sda1"

initrd /grub/clonezilla/live/initrd.img

boot



title Clonezilla (manual)

root (hd0,1)

kernel /grub/clonezilla/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_keymap="" ocs_lang="" vga=788 ip=frommedia nosplash live-media-path=/grub/clonezilla/live bootfrom=/dev/sda2 toram=filesystem.squashfs ocs_live_batch="no"

initrd /grub/clonezilla/live/initrd.img

boot


  • mmadani likes this

#2 steve6375

steve6375

    Platinum Member

  • Developer
  • 6598 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 22 October 2012 - 07:32 AM

Why not use iftitle ? See Tutorial #57 - you will need a recent chenall build of grub4dos.

iftitle [find /bootmgr] Boot Windows 7
find --set-root --devices=h /bootmgr
chainloader /bootmgr

iftitle [find /ntldr] Boot Windows XP
find --set-root --devices=h /ntldr
chainloader /ntldr

P.S. See Tutorial 81 for an automatic backup/restore recovery partition solution (ideal for family/friends who are not too computer savvy).

#3 ndog37

ndog37

    Member

  • Members
  • 79 posts
  •  
    New Zealand

Posted 22 October 2012 - 09:21 AM

Hi Steve. Thanks for your advice. Also thanks for your very informative website.

As a side note, I recommend you try clonezilla than booting into winPE and using imagex, it doesn't require as much RAM (as winPE), you dont have to compile any scripts or PE images, everything can be done on one menu.lst line. Don't have to worry about licensing, distribution eg imagex. It will go a lot faster than 10 minutes for a win7, restore, probably 4-5 minutes. Downside is it cant restore to smaller disks and you can't browse the image file (easily)

I recommend you use a ubuntu precise version eg 20121008-precise.iso and extract to correct folders

DIR structure
clonezilla-live
-vmlinuz
-filesystem.squashfs
-initrd.img

Edited by ndog37, 22 October 2012 - 10:04 AM.


#4 steve6375

steve6375

    Platinum Member

  • Developer
  • 6598 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 22 October 2012 - 09:46 AM

Thanks for the tip and script. I will look into that and maybe pinch your suggestion for yet another tutorial (installing from within XP.7 though) if that is OK with you?

#5 ndog37

ndog37

    Member

  • Members
  • 79 posts
  •  
    New Zealand

Posted 22 October 2012 - 10:14 AM

Yes by all means I think the more information is out there the better!

This is a script you could use in windows PE to silently install the system, although it can be improved.

launch.cmd

@echo off&cls



set _title=install grub4dos + clonezilla sda1 restore system v1.0

rem last updated @ 13/09/2012



title %_title%



cls

echo ARE YOU SURE YOU WANT TO CONTINUE? THIS WILL INSTALL GRUB4DOS TO YOUR MBR.

echo YOU MUST HAVE A D: DATA PARTITION BEFORE PROCEEDING.

pause

echo lis vol | diskpart

pause

pause



echo.

echo Cleanup

attrib -r -a -s -h d:clonezilla 2>nul

attrib -r -a -s -h d:grldr 2>nul

attrib -r -a -s -h d:menu.lst 2>nul

attrib -r -a -s -h d:message 2>nul



echo.

echo Install grub4dos

"%~dp0grub4dosgrubinst.exe" -v (hd0)

copy /y "%~dp0grub4dosgrldr" d:.

copy /y "%~dp0grub4dosmenu.lst" d:.

copy /y "%~dp0grub4dosmessage" d:.



echo.

echo Copy clonezilla stuff

md d:clonezillalive 2>nul

md d:clonezillaimages 2>nul

"%~dp0fsync.exe" "%~dp0clonezilla-live" "d:clonezillalive" /k /f



echo.

echo Hiding important system files

attrib +s +h d:clonezilla

attrib +s +h d:grldr

attrib +s +h d:menu.lst

attrib +s +h d:message



echo.

echo Rebooting...

ping localhost -n 7 >nul

wpeutil reboot




C:PEToolsfsync.exe -> just a tool to copy files
C:PEToolslaunch.cmd

C:PEToolsclonezilla-livefilesystem.squashfs
C:PEToolsclonezilla-liveinitrd.img
C:PEToolsclonezilla-livevmlinuz

C:PEToolsgrub4dosgrldr
C:PEToolsgrub4dosgrubinst.exe
C:PEToolsgrub4dosmenu.lst
C:PEToolsgrub4dosmessage

C:PEWindowsSystem32startnet.cmd -> point it to launch.cmd


menu.lst - needs to be improved for windows detection on sda

timeout 5

default 0

gfxmenu /message

#title Boot Windows 7

#find --set-root --devices=h /bootmgr && call set bootmgr=%@root^%

#chainloader %bootmgr%/bootmgr

title Boot Windows XP

find --set-root --devices=h /NTLDR && call set bootmgr=%@root^%

map () %bootmgr%

map %bootmgr% ()

map --rehook

find --set-root --ignore-floppies --ignore-cd /ntldr

chainloader /ntldr

title Restore Clonezilla Image

root (hd0,1)

kernel /clonezilla/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ip=frommedia nosplash ocs_live_run="ocs-live-general" keyboard-layouts="NONE" locales="en_US.UTF-8" live-media-path=/clonezilla/live bootfrom=/dev/sda2 toram=filesystem.squashfs ocs_live_batch="yes" ocs_prerun="mount /dev/sda2 /mnt" ocs_prerun1="mount --bind /mnt/clonezilla/images /home/partimag/" ocs_live_run="ocs-sr --batch -g auto -e1 auto -e2 -j2 -k -p reboot restoreparts ask_user sda1"

initrd /clonezilla/live/initrd.img

boot

title Create Clonezilla Image

root (hd0,1)

kernel /clonezilla/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ip=frommedia nosplash ocs_live_run="ocs-live-general" keyboard-layouts="NONE" locales="en_US.UTF-8" live-media-path=/clonezilla/live bootfrom=/dev/sda2 toram=filesystem.squashfs ocs_live_batch="yes" ocs_prerun="mount /dev/sda2 /mnt" ocs_prerun1="mount --bind /mnt/clonezilla/images /home/partimag/" ocs_live_run="ocs-sr -q2 --batch -j2 -z1 -i 2000 -sc -rm-win-swap-hib -p reboot saveparts ask_user sda1"

initrd /clonezilla/live/initrd.img

boot

title Clonezilla (manual)

root (hd0,1)

kernel /clonezilla/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_live_run="ocs-live-general" ocs_live_extra_param="" keyboard-layouts="" locales="" ip=frommedia nosplash live-media-path=/clonezilla/live bootfrom=/dev/sda2 toram=filesystem.squashfs ocs_live_batch="no"

initrd /clonezilla/live/initrd.img

boot



#example create partition

#ocs_live_run="ocs-sr -q -b -j2 -z1 -i 2000000 -p reboot saveparts lastgoodimage sda1"

#example restore partition

#ocs_live_run="ocs-sr -b -g auto -e1 auto -e2 -j2 -k -p reboot restoreparts lastgoodimage sda1"


Edited by ndog37, 22 October 2012 - 10:22 AM.


#6 steve6375

steve6375

    Platinum Member

  • Developer
  • 6598 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 22 October 2012 - 10:22 AM

Thanks!

echo lis vol | diskpart

This is a new one on me! I thought that an 'exit' would be needed but it appears not! It puzzles me slightly that it works??? Very useful!

#7 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13649 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 22 October 2012 - 10:41 AM

Just for the record, you need NOT the /y switch when using COPY in a batch (you may need it on command line, but in batch it is implied).

@Steve
JFYI :), a way to have diskpart commands embedded in a batch:
http://www.msfn.org/...ter-batch-file/
http://www.msfn.org/...post__p__817388
http://www.msfn.org/...post__p__818444

:cheers:
Wonko

#8 ndog37

ndog37

    Member

  • Members
  • 79 posts
  •  
    New Zealand

Posted 22 October 2012 - 10:41 AM

Thanks!

echo lis vol | diskpart

This is a new one on me! I thought that an 'exit' would be needed but it appears not! It puzzles me slightly that it works??? Very useful!

Maybe it crash exited?. I use the same concept for my dd.vbs script. Bit off topic, but meh


' ---=== dd.vbs ===---

' Title: Drive Detect 0.6

' Function: Output connected hard drive volume letters and label to text file

On Error Resume Next

Set objFso = CreateObject("Scripting.FileSystemObject")

Set WshShell = WScript.CreateObject("WScript.Shell")

Set objWMIService = GetObject("winmgmts:.rootcimv2")

' create text file (Working Dir)

strScriptPath = objFso.GetParentFolderName(wscript.scriptfullname)

strFileName = strScriptPath & "dd.txt"

objFSO.CreateTextFile(strFileName)

Set objTs = objFso.OpenTextFile(strFileName,8)

' parse through FileSystem to see if the string 'FAT32' or 'NTFS' is found

' also check it is not a Network Mapped Drive

Set colItems = objWMIService.ExecQuery("Select * from Win32_LogicalDisk")

For Each objDrive in colItems

FileSystem = objDrive.FileSystem

Description = objDrive.Description

VolumeName = objDrive.VolumeName

If FileSystem = "FAT32" Or FileSystem = "NTFS" Then

If Description <> "Network Connection" Then

DriveLetter = objDrive.DeviceID

objTS.Write DriveLetter & " " & VolumeName &vbNewLine

End If

End If

Next



test.cmd

set _srcLABEL=DATA

set _dstLABEL=DEV

set _ddvbs=%~dp0dd.vbs

set _ddtxt=%~dp0dd.txt



start "" /wait "%_ddvbs%"

for /f "usebackq tokens=1-2* delims= " %%g in ("%_ddtxt%") do (

if "%%h" == "%_srcLABEL%" set _srcLTR=%%g

if "%%h" == "%_dstLABEL%" set _dstLTR=%%g

)

if not defined _srcLTR echo Source not found - %_srcLABEL%&pause&exit

if not defined _dstLTR echo Destination not found - %_dstLABEL%&pause&exit





Just for the record, you need NOT the /y switch when using COPY in a batch (you may need it on command line, but in batch it is implied).

:cheers:
Wonko

Well I kinda always suspected that would be the case, but I only wanted to be safe, guess it was not neccesary!

Edited by ndog37, 22 October 2012 - 10:47 AM.


#9 steve6375

steve6375

    Platinum Member

  • Developer
  • 6598 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 22 October 2012 - 06:13 PM

I am guessing that the backup/restore parameters are set for Windows being on sda1 and the backup partition being sda2?
But won't most Windows 7 installations have sda1 as the boot partition and sda2 the system partition and sda3 the backup partition?
We could check for say \windows\explorer.exe on each partition and set a variable for the volume to backup and another for the backup volume, like this...

e.g.



if exist (hd0,3)/windows/explorer.exe set WDRV=sda4

if exist (hd0,2)/windows/explorer.exe set WDRV=sda3

if exist (hd0,1)/windows/explorer.exe set WDRV=sda2

if exist (hd0,0)/windows/explorer.exe set WDRV=sda1

if exist (hd0,0)/clonezilla/live/vmlinuz set BAKDRV=sda1

if exist (hd0,1)/clonezilla/live/vmlinuz set BAKDRV=sda2

if exist (hd0,2)/clonezilla/live/vmlinuz set BAKDRV=sda3

if exist (hd0,3)/clonezilla/live/vmlinuz set BAKDRV=sda4



title Restore Clonezilla Image to %WDRV%

find --set-root /clonezilla/live/vmlinuz

kernel /clonezilla/live/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ip=frommedia nosplash ocs_live_run="ocs-live-general" keyboard-layouts="NONE" locales="en_US.UTF-8" live-media-path=/clonezilla/live bootfrom=/dev/%BAKDRV% toram=filesystem.squashfs ocs_live_batch="yes" ocs_prerun="mount /dev/%BAKDRV% /mnt" ocs_prerun1="mount --bind /mnt/clonezilla/images /home/partimag/" ocs_live_run="ocs-sr --batch -g auto -e1 auto -e2 -j2 -k -p reboot restoreparts ask_user %WDRV%"

initrd /clonezilla/live/initrd.img


Is there a way to preselect a keymap in the cheat codes, etc. so the end user does not have to choose one each time?
Can the text messages on boot up be suppressed or a splash screen be displayed?

#10 steve6375

steve6375

    Platinum Member

  • Developer
  • 6598 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 23 October 2012 - 01:27 PM

I have written a tutorial which I hope will make sense! See here - it seems to work OK. :dubbio:

#11 ndog37

ndog37

    Member

  • Members
  • 79 posts
  •  
    New Zealand

Posted 24 October 2012 - 08:55 AM

Hi steve6375, yes you can customise the menu to autorestore from inside the line. For example you can automate it to create an image of sda1 called "lastgoodimage" and restore "lastgoodimage".

#example create image of sda1

#ocs_live_run="ocs-sr -q --batch -j2 -z1 -i 2000000 -p reboot saveparts lastgoodimage sda1"



#example restore image to sda1

#ocs_live_run="ocs-sr --batch -g auto -e1 auto -e2 -j2 -k -p reboot restoreparts lastgoodimage sda1"


Here is a slightly different version for grub2


menuentry "Clonezilla Precise Manual" {

parttool (hd0,1) hidden-

parttool (hd0,2) hidden-

root (hd0,2)

linux /vboot/clonezilla/precise/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_live_run="ocs-live-general" ocs_live_extra_param="" keyboard-layouts="" ocs_live_batch="no" locales="" video=uvesafb:mode_option=1024x768-32 ip=frommedia nosplash live-media-path=/vboot/clonezilla/precise bootfrom=/dev/sda2 toram=filesystem.squashfs

initrd /vboot/clonezilla/precise/initrd.img

}

menuentry " Clonezilla Precise Restore Image WinXP sda1" {

parttool (hd0,1) hidden-

parttool (hd0,2) hidden-

root (hd0,2)

linux /vboot/clonezilla/precise/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_live_run="ocs-live-general" keyboard-layouts="NONE" ocs_live_batch="yes" locales="en_US.UTF-8" video=uvesafb:mode_option=1024x768-32 ip=frommedia nosplash live-media-path=/vboot/clonezilla/precise bootfrom=/dev/sda2 toram=filesystem.squashfs ocs_prerun1="mount /dev/sda2 /mnt" ocs_prerun2="mount --bind /mnt/backup/clonezilla /home/partimag/" ocs_live_run="/usr/sbin/ocs-sr --batch -g auto -e1 auto -e2 -j2 -k -p reboot restoreparts ask_user sda1"

initrd /vboot/clonezilla/precise/initrd.img

}

menuentry " Clonezilla Precise Create Image WinXP sda1" {

parttool (hd0,1) hidden-

parttool (hd0,2) hidden-

root (hd0,2)

linux /vboot/clonezilla/precise/vmlinuz boot=live live-config noswap nolocales edd=on nomodeset ocs_live_run="ocs-live-general" keyboard-layouts="NONE" ocs_live_batch="yes" locales="en_US.UTF-8" video=uvesafb:mode_option=1024x768-32 ip=frommedia nosplash live-media-path=/vboot/clonezilla/precise bootfrom=/dev/sda2 toram=filesystem.squashfs ocs_prerun1="mount /dev/sda2 /mnt" ocs_prerun2="mount --bind /mnt/backup/clonezilla /home/partimag/" ocs_live_run="/usr/sbin/ocs-sr -q2 --batch -j2 -z1 -i 2000 -sc -rm-win-swap-hib -p reboot saveparts ask_user sda1"

initrd /vboot/clonezilla/precise/initrd.img

}


I like you tutorial, it is very useful and I am glad to have helped your wonderful site.

Kind regards

Edited by ndog37, 24 October 2012 - 08:56 AM.


#12 steve6375

steve6375

    Platinum Member

  • Developer
  • 6598 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 24 October 2012 - 10:42 AM

Thanks.
I have found that adding ocs_live_keymap="NONE" suppresses the keymap menu. Also adding quiet seems to suppress most (but not all) boot text.
All I need now is to find out how to get a splash screen so no text at all is seen on boot.... any ideas ????

P.S. You have two entries for ocs_live_run in the preseed lines - is the ocs_live_run="ocs-live-general" actually needed?

#13 Mohanna

Mohanna
  • Members
  • 1 posts
  •  
    Syria

Posted 13 March 2016 - 12:06 PM

Dear Ndog37

 

just I need to make Auto restore for the partition image

 

so how can I do that with full automatic and scheduler (weakly at mid night of Saturday the computer will reboot then install saved image then start windows)

 

Thank you

................ 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users