Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


silent001

grub4dos backup and restore partion table with a script

Recommended Posts

Hi I am looking for a tool that is able to backup the partition table using a scriot in grub4dos and also restore a partition table. I want to use it to rearrange the partion table but on a controlled manner as I will have 4 windows related partions. Please help me

Share this post


Link to post
Share on other sites

Well, you don' t need any "tool" grub4dos (in recent versions) have the needed built-in commands and an almost complete CMD-like batch scripting capability.

 

The only limit (unless you use the fat add-on and you want to save on a FAT volume) is that it cannot create a file.

 

Also if you use any version before one of the latest ones, you must remember that files smaller than around 750 bytes on NTFS are not seen by grub4dos because they are embedded in the $MFT  (only very recent version can find them), in which case a 1024 bytes file is advised as a container.

 

Usually  MBR and partition tables are saved to either the "MBR-hole" (LBA1) if you actually install grldr.mbr to the MBR+first few hidden sectors or to an unused "hidden" sector, usually LBA62.

 

It's just a matter of scripting a series of dd commands, and - if needed/useful, the partnew command, but maybe you can find useful this:

http://reboot.pro/topic/17728-release-mbrviewg4b-a-bat-tool-for-grub4dos/

make sure you get the "pure" grub4dos (no WENV needed) version by Nando4 :).

 

Some hints/examples of grub4dos dd usage are given in this only seemingly unrelated post:

http://reboot.pro/topic/20238-improving-grubinst-and-grubinst-gui-in-windows-and-linux/?p=189578

 

And some more in this thread:

http://reboot.pro/topic/20557-grub-commands-on-bootable-usb-to-completely-ignore-a-partition/

 

jaclaz

Share this post


Link to post
Share on other sites

Thanks for the reply. I have read up a lot on this and read a lot of your replies. Maybe I should explain what I am doing so you can see where my concern comes in. I found setptn1.g4d. It's almost what I need but it raises a concern regarding more than two partitions. I want to have the following

Pt0 Windows to go

Pt1 windows 7 install DVD

Pt2 windows 8 install DVD

Pt3 windows pe for avast

They all use the bootmgr file and all give a error if not on the windows visible partition. I can use setptn1.g4d to change the partition table but then I have to manually reset it to be able to use the usb again. So I was thinking if I can make a backup of the partition table with each partition set to first and just grub4dos load it on selection of each partition then I will have no need to reset it as listed above

Share this post


Link to post
Share on other sites

Well, I don' t see why you would want to have separate partitions for "Windows 7 install DVD" or a "Windows 8 install DVD", let alone for the PE, maybe it is your setup that is overly complicated :unsure: (or too simple :), it depends on points of view), I fear that you might be slipping on a chocolate covered banana (or on the xyz problem) :w00t::ph34r::

http://homepage.ntlworld.com/jonathan.deboynepollard/FGA/put-down-the-chocolate-covered-banana.html

 

jaclaz

Share this post


Link to post
Share on other sites

Jaklaz tryst me there is method to my madness. I can't load the iso of the installs to ram as windows gives driver error. Can't vhd it windows gives driver error. Don't know how to combine the two dvds. Like I said there is method to my madness so please just understand. I don't think my setup is overly complicated and I have read many similar posts with no actual outcome. I'm a newbie to grub4dos. All I ask is for a outcome that allows me to automate the mounting of the correct partition to the first. I might have found a way but I have yet to fully test it using the setptn1.g4d. The avast pe allows for scanning of all drives on the pc from boot wich I need to update regularly. Wli want windows 7 and 8 installs separate so I don't compromise their workingness and I need a bootable o's to extract personal files off a dead pc and I am a windows fan for some stupid reason

Share this post


Link to post
Share on other sites

No prob, I guess that everyone - one way or the other - has his/her own form of madness.

 

If you want to go that way, it is perfectly OK :), as long as you know that there might be other methods.

 

Now what is the problem? :unsure:

 

You have the setptn1.g4d (which needs WENV, now deprecated, not because it is not good, only because grub4dos now includes most corresponding commands so that WENV now represents an unneeded complication), the "original" mbrview.g4b and a new version of it which uses direct grub4dos commands, all together they provide good related examples, though most probably they are overall more complex than needed, as they represent a "generic/general" script whilst what you actually need are no more than 4 commands that can be actually hardcoded to the location and extents of your wanted partitions.

Personally - if I was to follow your line of reasoning - I would use actually 5 partitions (of which only 1 or 2 actually accessible at the same time).

Follow me please, imagine that you have a device of 1,002,048 blocks and you want to divide it in 4 same size partitions+a very small fifth partition (bear with me).

These partitions would have these data:

a. NTFS ID 07 Start=2048 Extents=250000

b. NTFS ID 07 Start=252048 Extents=250000

c. NTFS ID 07 Start=502048 Extents=250000

d. NTFS ID 07 Start=752048 Extents=250000

e. FAT ID 01 Start=63 Extent=1985

 

Now, let's imagine that you create ONLY the "e." partition and you write its addresses in second slot of the partition table (slot #1) leaving blank the first slot (slot #0), and that you install the grub4dos grldr.mbr to the MBR + a few hidden sectors and copy the grldr (and a menu.lst) to this tiny partition, that will be when booting from the stick (hd0,1).

 

Now what would happen if you have a menu.lst *like*:

 

title partition a.

partnew (hd0,0) 0x07 2048 250000

root (hd0,0)

chainloader /bootmgr

 

title partition b.

partnew (hd0,0) 0x07 252048 250000

root (hd0,0)

chainloader /bootmgr

 

etc.

 

Of course some checks to make absolutely sure that the disk on which operate is actually mapped as (hd0) will be needed (in the rare case that for some reason the USB stick is not recognized as first disk)

But you should get the idea.

 

jaclaz

Edited by jaclaz

Share this post


Link to post
Share on other sites

I just want to ask how can I use setptn1.g4b to sort the partition table according to lba position basically ascending

Share this post


Link to post
Share on other sites

I just want to ask how can I use setptn1.g4b to sort the partition table according to lba position basically ascending

I don't understand the question. :unsure:

 

setptn1.g4b has only a provision to exchange the first two partition entries between them, not to sort (all four of) them.

 

This is actually becoming a XYZ problem :(, setptn1.g4b has not such a provision, you need to write a new, dedicated grub4dos batch, which again might be pretty much complex to write if you want to make it a "generic" or "general" utility. or extremely easy in a "specific" case.

 

jaclaz

Share this post


Link to post
Share on other sites
Using the method
These partitions would have these data:
a. NTFS ID 07 Start=2048 Extents=250000
b. NTFS ID 07 Start=252048 Extents=250000
c. NTFS ID 07 Start=502048 Extents=250000
d. NTFS ID 07 Start=752048 Extents=250000
e. FAT ID 01 Start=63 Extent=1985
 
Now, let's imagine that you create ONLY the "e." partition and you write its addresses in second slot of the partition table (slot #1) leaving blank the first slot (slot #0), and that you install the grub4dos grldr.mbr to the MBR + a few hidden sectors and copy the grldr (and a menu.lst) to this tiny partition, that will be when booting from the stick (hd0,1).
 
Now what would happen if you have a menu.lst *like*:
 
title partition a.
partnew (hd0,0) 0x07 2048 250000
root (hd0,0)
chainloader /bootmgr
 
title partition b.
partnew (hd0,0) 0x07 252048 250000
root (hd0,0)
chainloader /bootmgr
 
etc.

 

 

Will it cause problems if say i select parition b then reboot and select parition a? Will it be possible? What is this method called so I can read more on it please?

 

Share this post


Link to post
Share on other sites

It's a nameless method :w00t::ph34r:

 

But we can call it the "4 shot" or - maybe nicer - the "pepper box".(as you may use more than 4 partitions in such a setup) :yes:

 

Basically the second partition entry (or partition entry #1) is never changed (and it contains the needed grldr and menu.lst file).

Every time you boot and select one of the four menu.lst entry you effectively re-write first partition entry (aka the partition entry #0) with the chosen one.

 

If you access the device without booting from it (or if you boot from it but you do not choose any of the 4 menu.lst items) you will be able to access the last written entry (i.e. the one corresponding to the menu.lst item you chose last time).

 

jaclaz

Share this post


Link to post
Share on other sites

So let me understand this. What this does is basically change reorder the partition entries? Explain how it works because honestly I dont fully understand what happens. Lets work off this

post-403892-0-57939000-1440357976_thumb.

It is the layout I have from how I understand your Post. Please try dumb it down

Edited by silent001

Share this post


Link to post
Share on other sites

You have one partition entry that is "fixed", never changed, that is written to partition entry #1 and that allows to boot to grub4dos (because it contains grldr and menu.lst).

 

Then you have the partition entry #0 to which NEW values are written each time you boot and select one of the (4) menu.lst entries, menu.lst choice "a" will write values related to partition "a", menu.lst choice "b" will write values related to partition "b", etc.

 

No partition entry is "ordered" or "reordered", the second partition entry never changes, the values in the first one (i.e. the only one that Windows will see and mount on "removable" media) are written depending on your choice.

 

What is the "difficult" part?

 

jaclaz

Share this post


Link to post
Share on other sites

So if I get you correctly if the table looks like this labels wise

0

1 grub

2 part 1

3 part 2

4 part 3

5 part 4

And say I want to load part 1 the table will them look like so

0 part 1

1 grub

2 part 1

3 part 2

4 part 3

5 part 4

Am I understanding you correctly?

Share this post


Link to post
Share on other sites

Not really, but almost :), you are missing a tiny detail (which actually could become  a point of strength in the solution :w00t:), there are ONLY 4 partition entries in a MBR, #0 to #3, i.e. you cannot have more than 4 (four) primary partitions or 3 primary partitions + 1 extended partition.

As a matter of fact what you created (your screenshot) are:

3 primary partitions (whose data is in slots #0 to #2)

1 Extended partition (whose data is in slot #3) containing two volumes (whose data is in the EPBR chain or "virtual slots" #4 and #5)

 

So what you can have is:

 

0
1 grub
2 EXTENDED part containing:

Volume 1

Volume 2

Volume 3

Volume 4

and:

0 Volume 1 re-mapped as first partition

1 grub
2 EXTENDED part containing:

Volume 1

Volume 2

Volume 3

Volume 4

or:

0 Volume 2 re-mapped as first partition

1 grub
2 EXTENDED part containing:

Volume 1

Volume 2

Volume 3

Volume 4

...

and of course you can also have a "mixed" mode of primaries+logical volumes.

 

The point here is that any (arbitrary) extent (by extent I mean an area of the hard disk identified by its first sector LBA and the amount of sectors) can be "indexed" in the MBR by the partnew command, which has also a specific function that will correct the "sectors before" or "hidden sectors" in the BPB of a logical volume so that it becomes bootable, see here for the details on the idea of correcting the number of sectors with the offset form the MBR (as opposed to the offset from the EPBR)  

http://www.goodells.net/multiboot/

http://www.goodells.net/multiboot/ptable.shtml

 

My original proposal was about mapping on the fly some extents (not otherwise indexed *anywhere*) one at the time but nothing prevents to have the same extents indexed as logical volumes inside extended and index/map one of them at the time as first partition.

 

As a side note even the volume containing the grub4dos could be a logical volume inside extended, as if I recall correctly the grldr.mbr (the part installed to the MBR+a few hidden sectors) looks for grldr in all volumes, including those in an extended partition.

 

jaclaz

  • Upvote 1

Share this post


Link to post
Share on other sites

Now for the tricky question. How do I leave the first partition table entry blank?

Nevermind. I have success!!!!!! jaclaz you are a true genius. Your Method works like a bomb and could not have thought of anything better. I would I use this in windows so that I can remap within windows? 

Edited by silent001

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×