[Shield Android TV General] hallydamaster:
[B][I][COLOR="Red"][SIZE="3"]I am not responsible for bricked devices, dead HDDs, animals
activist campaigns, or any H/W damage caused by you following these
directions. YOU are choosing to make these modificiations, and
you, yourself take responsibility for doing these modifications
to your device.
You can do serious H/W damage to your SATV or even your computer
by doing any of this. So, you have been warned! [/SIZE][/COLOR][/I][/B]

First of all, you should pay your thanks to [MENTION=2163004]Luxferro[/MENTION] for mapping out the entire partition array, and building the chart that does all the calculations for using another disk size.

He also proved that it was indeed possible to modify your GPT header to another sized drive.

None of this would have been possible, if it was not for him.

Also thanks to [MENTION=7386697]Tilator[/MENTION] for initiating his thread, and proving it was possible to swap your HDD for something else.

1. Preparations and disassembling the SATV

Well, to begin with you should have a working linux environment set up. This can easily be a live CD/DVD/USB. Or you can do it from a virtual environment. You can use DD for Windows now, follow guide as normally.

You should have a hex editor with CRC32 calculating capabilities. I recommend HxD:

https://mh-nexus.de/en/downloads.php?product=HxD

Yes, that is for Windows, I use Linux for all the writing/dumping, but I prefer my Windows hex editor.

It's worth to know, that your device should be bootloader unlocked, and preferably newly factory reset.

Also, an autotool has been made now to do this GPT header edit. See post #3.

Then you can go open up the SATV by prying off the bottom of the casing. I managed to do this with my fingernails. A small plastic pry tool can be used as well.

[IMG="SATV Opened"]https://i.imgsafe.org/088cdebe48.png[/IMG]

Then you remove the 2 wire sets from the plugs to give more working room. There is 2 sets of tape holding the wires and the HDD in place as well.

There is (on mine at least) just one screw with a small bracket holding the HDD in place, you will need a T6 driver to remove it.

Gently lift the black latch/lock on the connector to the secondary board, then the FCC connector will be easily out.

Then it is just a matter of gently loosening the adhesive on the FCC strip from the HDD and pull out the SATA connector.

With the HDD out, you will have to connect it to your Linux setup somehow. I used an enclosure with a USB3 connection.

With the HDD recognized in the computer, the time has now come to clone you HDD.

You could as well use the bin files Tilator has provided, but if you want your own genuine Netflix ESN, you should use your own.

If you want to use DD for Windows, please continue the guide from post #2. After finishing that part, come back to this post and skip to the hex editing part.

2. Dumping the data from the SATV SSHD

In a terminal window you start by listing the drives:

sudo -s
fdisk -l

This is to determine which drive you are working with. Remember that the DD command does't care which drive you specify, it will destroy your main drive if you ask it to.

The you continue by dumping the first 6899870 blocks of data to a bin file:

dd if=/dev/sd[B]X[/B] of=firstpart.bin count=6899870

This will give you a raw image file of all the partitions up until the /data partition which is better left out (it will come later).

Then continue by dumping the last 5120 bytes of data which contains the partition array and the GPT header:

dd if=/dev/sd[B]X[/B] bs=512 skip=976773158 of=lastpart.bin

EDIT: 26th August 2016, [MENTION=7254357]anchung.chen[/MENTION] has experimented with aligning the partitions to Advanced Format 4096 byte sectors (4K alignment). This supposedly gives better performance especially on SSD drives.

It's worth to know that this most likely breaks the OTA updates, as they might write partitions on block level rather than on a file level. OTA updates seems to be working.

Also, anchung.chen has had problems unlocking the bootloader on the 4K aligned disk.

[MENTION=7449004]ahmed68[/MENTION]

Reports that TWRP doesn't work well when trying to flash SuperSU.

Please see follow these steps to write the bin files with 4K alignment:

Start by downloading the ELF executable programmed by anchung.chen from this post:

http://xdaforums.com/showpost.php?p=68300570&postcount=44

Patch the lastpart.bin the following way (2TB disk size):

./shield_pro_new_disk_gpt_calculator-0.3 lastpart.bin [B]2000398934016[/B] lastpart4k.bin

This will recalculate the GPT header to match the 2TB disk, but also rewrite the partition array.

Then continue by writing the firstpart.bin in 2 steps instead of just one:

if=firstpart.bin of=/dev/sd[B]X[/B] bs=512 count=69888

dd if=firstpart.bin of=/dev/sd[B]X[/B] bs=512 skip=69790 seek=69888 count=6830080

These 3 steps effectively moves the partitions 16-32 to match 4K alignment structure.

And finish off by writing the lastpart4k.bin:

dd if=lastpart4k.bin of=/dev/sda[B]X[/B] bs=512 seek=[B]3907029158[/B]

This completes the guide, no more steps needed.

You can now disconnect your HDD. These 2 files also counts as a backup of your SATV (not with settings as userdata was not copied).

Now connect your new SSD in the enclosure.

You can easily start by writing the firstpart.bin:

dd if=firstpart.bin of=/dev/sd[B]X[/B]

3. Hex-editing the partition array and the GPT header

In your linux terminal load up the block count (called sectors in linux language) of the new drive:

fdisk -l

A 2 TB disk should have a total block count of 3907029168, but a smaller disk would have a smaller block count, so use fdisk -l to determine this.

Or if you use DD for Windows you have the output from dd --list to work with.

The lastpart.bin must be edited before we can write it on the new disk.

So use the spreadsheet provided by [MENTION=2163004]Luxferro[/MENTION] in this post:

http://xdaforums.com/showpost.php?p=67996717&postcount=189

In the column at the buttom right that says disk size, you change the value to match you new disk. In this example for the 2TB it should be 2000398934016 (bytes). This value should be taken from fdisk -l as well.

Now it gets a little hairy!

In the spreadsheet you should start with the buttom value marked out in purple under the row called "Last LBA". This should be E8E0888E:

[IMG="Chart Last LBA"]https://i.imgsafe.org/dc65e8f1d7.png[/IMG]

Open up lastpart.bin in HxD and navigate to offset 00000FA8. There you should find the 4 bytes 0E 60 38 3A illustrated in this picture:

[IMG="UDA Partition Last LBA"]https://i.imgsafe.org/dc675ca9e9.png[/IMG]

This value is in a format called reverse byte ordering, so to put in your new calculated value, you will have to arrange it like this: 8E 88 E0 E8. Input that value instead of the bytes already there like this picture:

[IMG="UDA Partition Edited"]https://i.imgsafe.org/dc884ceb4c.png[/IMG]

While we are in this particular position in the lastpart.bin we might as well do the CRC32 of the partition array.

Now make a selection containing the 64 bytes or 4 empty lines underneath the line having UDA written in ASCII, and all the way to the top of the file, offset 00000000 to 00000FF0 like in this picture:

[IMG="Partition Array Selection + CRC32"]https://i.imgsafe.org/dcea590c79.png[/IMG]

In the drop-down menu, choose Analyzis->Checksums and generate a CRC-32 checksum (Not checksum-32).

It will come up in the buttom screen of HxD, and should read 6B CF E5 7D

Navigate to the buttom of the file which contains the GPT header. It should start with an ANSI text reading "EFI PART".

In offset 00001258 you should find the value of the original CRC-32 value containing the bytes 0E 02 C5 DC.

Replace this, again reversing the bytes from your newly calculated CRC-32 value like this: 7D E5 CF 6B:

[IMG="CRC32 of Partition Array"]https://i.imgsafe.org/067dc12477.png[/IMG]

Now we are actually almost finished! In the spreadsheet all the way to the right, you will find 4 hexadecimal values marked in purple.

First is the position of the GPT header, and the second is the position of the backup GPT header. Since there is only 1 on the SATV, these values are both the same.

Write them into the GPT header on offset 00001218, and 00001220, again reversing the bytes like illustrated in the picture:

[IMG="GPT Pointers"]https://i.imgsafe.org/067dc3304e.png[/IMG]

Same goes for offset 00001230, Last Usable LBA, and offset 00001248, Starting LBA of array of partition entries.

This brings us to the last thing on the table, the CRC32 of the GPT header itself.

The CRC is located on offset 00001210 and should have the bytes 46 C9 88 78 already there.

Just write 00 00 00 00 to blank them out:

[IMG="CRC32 Zeroed out"]https://i.imgsafe.org/06df641cfe.png[/IMG]

Now make a selection of the GPT header containing the beginning of the header, and to the last written byte before all the zeroes:

[IMG="CRC32 of GPT header"]https://i.imgsafe.org/06df74f054.png[/IMG]

In the drop-down menu, choose Analyzis->Checksums and generate a CRC-32 checksum (Not checksum-32).

It will come up in the buttom screen of HxD, and should read 46 9F 24 38

Again, write it instead of the 4 bytes with zeroes reversed like this:

[IMG="CRC32 New"]https://i.imgsafe.org/06df5f2486.png[/IMG]

This completes the matter, now just save your work in HxD and write it to the end of your drive.

To do this we need the total block count from the HDD that you fetched in the beginning of the guide from the fdisk -l output, should be 3907029168

The lastpart.bin is 5120 bytes which is the same as 10 blocks of 512 byte length.

So, 3907029168 minus 10 is 3907029158 and put into your DD-line like this:

dd if=lastpart.bin of=/dev/sda[B]X[/B] bs=512 seek=[B]3907029158[/B]

Or like this if you use DD for Windows:

dd if=lastpart.bin of=\\?\Device\Harddisk[B]X[/B]\Partition0 bs=512 seek=[B]3907029158[/B]

4. Assembling SATV and finishing up

Now at last, put in your new disk in the SATV and assemble everything back together.

If it doesn't boot in the first try, you could try another cold boot (give it 15 min.).

If that won't do it, you might have to wipe the DATA partition from the fastboot menu.

To cold boot into fastboot, follow this (taken from "http://developer.download.nvidia.com/mobile/shield/ROM/SHIELD_ATV/OTA-1.1/HowTo-Flash-Recovery-Image.txt"):

HW method:
- Disconnect power cable
- Insert USB OTG cable and make sure to connect other end to a host PC
- Connect power cable to SHIELD
- Quickly start pressing power button for ~3 seconds
- Do not hold the button and connect power supply afterwards
- HDMI TV should be always connected to SHIELD

And format the /DATA partition from fastboot like this:

fastboot format FS:EXT4 /data

Or do a fastboot oem unlock of the SATV.

Hopefully you will now have a SATV with an upgraded SSD/HDD! :D