# pmtools - partition map toolset



## telemark (Nov 12, 2013)

This is the toolset I use to create 32bit Roamio Partition Maps. If there's demand, 64bit and Premiere support could be added.

Usage Examples

```
Setup environment:
export PATH="~/pmtools/bin:$PATH"
mkdir sdX
cd sdX

Reorder partition map
--
# splits a partition map into individual records
> pmdice /dev/sdX

ls -tr  | grep -v order.txt > order.txt

# combines individual records into a single map, in the order of the input file.
> pmix order.txt > NEW-PM.bin

New Roamio Map From Scratch
--
Create text file in 4 or 5 column format
(use disk order if offsets are unknown)
[line numbers are for illustration only]

> nl part-list.txt 
     1   MP : Apple_partition_map :                    'Apple' :        63 : 1
     2   MP :                 MFS :       'MFS media region 2' : 537225040 
     3   MP :               Image :              'Bootstrap 1' :         8 
     4   MP :               Image :                 'Kernel 1' :         8 
     5   MP :                Ext2 :                   'Root 1' :         8 
     6   MP :               Image :              'Bootstrap 2' :         8 
     7   MP :               Image :                 'Kernel 2' :         8 
     8   MP :                Ext2 :                   'Root 2' :         8 
     9   MP :                Swap :               'Linux swap' :   1048576 
    10   MP :                Ext2 :                     '/var' :   1572864 
    11   MP :                Ext2 :                   'SQLite' :   6291456 
    12   MP :                 MFS :   'MFS application region' :   1638400 
    13   MP :                 MFS : 'MFS application region 2' :   1638400 
    14   MP :                 MFS :         'MFS media region' : 427358320 

Check size for alignment (size was column 4 in above example)
> cat part-list.txt | cut -d":" -f 4 | divtest  *512 %512  %1024 %4096 %8192 
        N:            *512  %512 %1024 %4096 %8192
       63:           32256     0   512  3584  7680
537225040:    275059220480     0     0     0     0
        8:            4096     0     0     0  4096
        8:            4096     0     0     0  4096
        8:            4096     0     0     0  4096
        8:            4096     0     0     0  4096
        8:            4096     0     0     0  4096
        8:            4096     0     0     0  4096
  1048576:       536870912     0     0     0     0
  1572864:       805306368     0     0     0     0
  6291456:      3221225472     0     0     0     0
  1638400:       838860800     0     0     0     0
  1638400:       838860800     0     0     0     0
427358320:    218807459840     0     0     0     0

Create record files, and propagate autogenerated offset:
> chainexec pcreate part-list.txt
Executing:
pcreate  MP   Apple_partition_map                      'Apple'          63   1 
pcreate  MP                   MFS         'MFS media region 2'   537225040 64
pcreate  MP                 Image                'Bootstrap 1'           8 537225104
pcreate  MP                 Image                   'Kernel 1'           8 537225112
pcreate  MP                  Ext2                     'Root 1'           8 537225120
pcreate  MP                 Image                'Bootstrap 2'           8 537225128
pcreate  MP                 Image                   'Kernel 2'           8 537225136
pcreate  MP                  Ext2                     'Root 2'           8 537225144
pcreate  MP                  Swap                 'Linux swap'     1048576 537225152
pcreate  MP                  Ext2                       '/var'     1572864 538273728
pcreate  MP                  Ext2                     'SQLite'     6291456 539846592
pcreate  MP                   MFS     'MFS application region'     1638400 546138048
pcreate  MP                   MFS   'MFS application region 2'     1638400 547776448
pcreate  MP                   MFS           'MFS media region'   427358320 549414848
Last output: 976773168

Specify the ordering for the map [line numered for illustration]
> nl order.txt 
     1  0
     2  Apple
     3  Bootstrap_1
     4  Kernel_1
     5  Root_1
     6  Bootstrap_2
     7  Kernel_2
     8  Root_2
     9  Linux_swap
    10  _var
    11  MFS_application_region
    12  MFS_media_region
    13  MFS_application_region_2
    14  MFS_media_region_2
    15  SQLite

Mix the records together to form new map
> pmix order.txt > NEW-PM.bin

Write new map (and block0) to disk
> dd if=NEW-PM.bin of=/dev/sdb bs=512 count=15

Overwrite bootpage params:
> echo -ne "root=/dev/sda4\x0" > 4.patch
> hexdump -C 4.patch
> bpatch 0.bin 4.patch

(re)Set guid:
> random16 > 304.patch
> hexdump -C 304.patch
> bpatch 0.bin 304.patch
```
Languages used:
perl, C++, bash

Copyright 2014 by telemark of tivocommunitiy.com
License granted under GPL 3 or later.


----------



## nooneuknow (Feb 5, 2011)

telemark said:


> > dd if=NEW-PM.bin of=/dev/sdb bs=512 *count=15*


Wouldn't this ideally be 16 so 512*16=8096, instead of 512*15=7680?

Or, is this one of those 0 counts as 1 things?

It's my understanding that ggieseke's DVRBARS does 8192 at a time, and that also seems to be the minimum chunk size TiVo writes to media partitions with.

Thanks for all your time and effort, as well as doing it for free.


----------



## telemark (Nov 12, 2013)

That's a good point.

That partition map is 14 partitions, and 14 blocks long. The block0 is 1 block long. Together makes 15. So you need to copy and there only is 15 (or 14 skipping the block0) of good data.

A partition map can go up to at least 16 though, so it's more proper and safer to zero out the later records.

One way is to zero out the Partition Map+Block0, before copying the new map over.
dd if=/dev/zero of=/dev/sdX count=17

Or you can add Zero-ed records to the end, until you get to 16 records in the map. (17 if you're including a Block0)


----------



## nooneuknow (Feb 5, 2011)

telemark said:


> That's a good point.
> 
> That partition map is 14 partitions, and 14 blocks long. The block0 is 1 block long. Together makes 15. So you need to copy and there only is 15 (or 14 skipping the block0) of good data.
> 
> ...


Ok, I get it now (I think, which can be dangerous).


----------

