Partitioning

Now comes most dangerous part. I highly recommend to try on something you don't afraid to lose iOS on (e.g. iPhone 4) first

In the first instance, we have to decrease size of /private/var (also known as Data) volume (HFS filesystem, not partition itself) just like iOS does before OTA-update. After that, we'll edit partition table to create 2 new partitions in space freed after resizing Data volume

Resizing Data-partition's HFS

As mentioned above, we need to decrease size of Data volume. There is tiny utility written by @danzatt for this purpose - hfs_resize. Its syntax is simple:

hfs_resize mount_point new_size

Calculating new size

Formula is obvious and clear (where size_os_second_os is both for System and Data partitions):

new_size = original_volume_size - size_of_second_os

All values are in bytes

But there are few nuances

Before talking about them, let's check for free space:

ssh root@device_ip

df -B1

Here's example of output:


So, nuances:

In this guide I'll use 768 MB as new size. 768*1024*1024 = 805306368 bytes:

hfs_resize /private/var 805306368


This process may take a while, no worries

After it succeeds run df again:


As you see values have changed. Let's compare this info with info from Settings app. df reports 489119744/1024/1024 = 466 MB is free, but settings thinks it's only 266 MB:


As I mentioned above it's OK, but please consider all these nuances when you'll do it yourself!

Editing partition table

Now we're ready to edit our partition table. Since 5.0 iOS has two partition tables:

To edit GPT, modified gptfdisk can be used. At first, let's open partition table in it:

gptfdisk /dev/rdisk0s1

Print table:

p Enter


Keep in mind value of Logical sector size (also known as block size), we'll need its value in next parts of guide too. For iPad 2 and older devices it should be 8192 bytes and for newer it's 4096 bytes


Let's request info about second partition:

i Enter 2 Enter


Write down somewhere value of Partition unique GUID and Attribute flags, it's important


Delete second partition. No worries, we'll create new one on previous place, but with decreased size:

d Enter 2 Enter


Create new partition:

n Enter


Leave default first sector by pressing Enter:


Your size you passed to hfs_resize could be not blocksize-aligned, so it could complain: [-] Adjusting size to xyz to match next block. In this case you must use xyz value in following calculations!

Divide your new size (805306368 bytes in my case) by blocksize (we found it before when pressed p): 805306368/8192 = 98304 blocks. Now add it to default first sector (176339 in my case): 176339+98304=274643. Pass this value and leave default Hex code by pressing Enter:


Change its name back to "Data":

c Enter 2 Enter Data Enter



Make sure we did all this well:

p Enter


Now we need to restore default attributes and GUID. If attribute flags were 0003000000000000:

x Enter a Enter 2 Enter 48 Enter 49 Enter Enter


...and if they were 0001000000000000:

x Enter a Enter 2 Enter 48 Enter Enter

You'll know you did it properly if Attribute value is 0003000000000000 (or Attribute value is 0001000000000000)

Restore previous GUID:

c Enter 2 Enter


Copy it here. As you remember we wrote down it before deletion (745CA95D-00F7-4DD9-8CCE-5DD59F2B6A1B in my case)



Resize partition table itself to allow it hold more than 2 partitions:

s Enter 4 Enter



Now back to Basic mode:

m Enter




Create third partition, this will be System partition for our second OS:

n Enter 3 Enter Enter



To calculate last sector, we need to mount DMG image we created in previous part and open its partition in Disk Utility


It reveals partition's size in bytes (1271169024 in case of iOS 6.1.3 for N90AP). And as we did for Data partition, we need to divide this size by blocksize (8192 in this case): 1271169024/8192 = 155172 blocks. Then add obtained value to default first sector: 274644+155172 = 429816. Pass this value and leave default Hex code


Change partition's name:

c Enter 3 Enter iOS6FTW Enter


Important note: never use System as name here! It may lead to unexpected behaviour of restore daemon on pre-iOS 10.3, so you'll be unable to restore your device!


Create fourth partition, this will be Data for our second OS:

n Enter 4 Enter Enter


Calculation last sector is easier here. Just subtract 3 or 2 from default value: 1947652-3 = 1947649. If you'll chose last sector of whole storage, gptfdisk may not save changes, that happened to me few times. Pass this value and leave default Hex code:


Change partition's name:

c Enter 4 Enter iOS6Data Enter


Important note above still aplies

Make sure we did all of this well:

p Enter


Now we'll change second Data partition's attributes. Process is same as we did to first Data:

x Enter a Enter 4 Enter 48 Enter 49 Enter Enter


You'll know you did it properly if Attribute value is 0003000000000000

Important note: sometimes (pretty rare, I only had such issues on iPhone 3GS and iPod touch 5) iOS 6 wants different attributes than you have for main OS'es Data-partition! E.g. it's 0001000000000000 for iPhone 3GS on iOS 6.1.6 or 0000000000000000 for iPod touch 5 on iOS 6.1.3. If you get something like this when your second OS tries to mount Data:

mount_hfs: Invalid argument

or this...

mount_hfs: Input/output error

...then try to change attribute flags (0003000000000000 or 0001000000000000 or 0000000000000000)


Finally, last step! We need to write our changes. But before check everything once again. If you feel you mistook somewhere, it's better to start it from scratch. Just type q press Enter and start again

If you're sure you did everything properly:

w Enter Y Enter


If your device is still alive, execute sync few times:


Now make sure our new partitions have appeared:

ls /dev/disk*


If you see this, my congratulations! Partitioning is done!

> Part 3: Restoring Root FS