注:本方法具有一定危险性,会导致失去越狱状态,但是肯定能通过restore模式和dfu模式刷回来,请谨慎操作!
因为自己要安装一堆toolchain和语言解释器,越狱三天System分区就占满了
趁着怎么恢复、更新、刷机都不会丢失越狱,赶紧试一试。
原理:
HFS分区支持动态resize。模仿无损分区,手动将系统分区改大
开始的时候分区是这样的:
===System===|==============Data===============|=BaseBand=`
然后把Data分区截成两个分区(Data分区resize)再把Data1分区(原data分区)的内容复制到Data2
===System===|=Data1=|==========Data2===========|=BaseBand=
再把Data1和System分区融合
======System=======|==========Data2===========|=BaseBand=
这样就调整好了
操作(记得备份!!!!!):
- 准备软件:安装OpenSSH、diskdev-cmds、dualboot disk-utils,最好在纯净的iOS系统上做,不然var分区太大
所需repo(cydia源):
OpenSSH、diskdev-cmds:http://apt.saurik.com
dualboot disk-utils:http://beehind.geeksn0w.it/repo/
- 执行下面的命令得到文件系统信息:
Poor-iPhone:/ root# df -B1
Filesystem 1B-blocks Used Available Use% Mounted on
/dev/disk0s1s1 3699564544 3095396352 567173120 85% /
devfs 49664 49664 0 100% /dev
/dev/disk0s1s2 59707871232 1980329984 57727541248 4% /private/var
/dev/disk0s1s3 10440704 2342912 8097792 23% /private/var/wireless/baseband_data
- 执行下面的命令得到分区分区信息
输入:/dev/rdisk0s1 [Enter] p [Enter] i [Enter] 1 [Enter] i [Enter] 2 [Enter] q [Enter]
这样就得到了分区表和第一个、第二个分区的GUID(Partition unique GUID那行),把他们记下来
Poor-iPhone:/ root# gptfdisk
GPT fdisk (gdisk) version 1.0.0
Type device filename, or press to exit: /dev/rdisk0s1
Warning: Devices opened with shared lock will not have their
partition table automatically reloaded!
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: presentFound valid GPT with protective MBR; using GPT.
Command (? for help): p
Disk /dev/rdisk0s1: 15482891 sectors, 59.1 GiB
Logical sector size: 4096 bytes
Disk identifier (GUID): 691111DD-E7E1-41FE-9728-2A1B9655B387
Partition table holds up to 3 entries
First usable sector is 6, last usable sector is 15482885
Partitions will be aligned on 1-sector boundaries
Total free space is 0 sectors (0 bytes)Number Start (sector) End (sector) Size Code Name
1 6 903219 3.4 GiB AF00 System
2 903220 15480336 55.6 GiB AF00 Data
3 15480337 15482885 10.0 MiB AF00 Baseband DataCommand (? for help): i
Partition number (1-3): 1
Partition GUID code: 48465300-0000-11AA-AA11-00306543ECAC (Apple HFS/HFS+)
Partition unique GUID: 79E21CC0-80E1-45BB-81ED-C1AF93B31C1A
First sector: 6 (at 24.0 KiB)
Last sector: 903219 (at 3.4 GiB)
Partition size: 903214 sectors (3.4 GiB)
Attribute flags: 0000000000000000
Partition name: ‘System’Command (? for help): i
Partition number (1-3): 2
Partition GUID code: 48465300-0000-11AA-AA11-00306543ECAC (Apple HFS/HFS+)
Partition unique GUID: 01445571-4602-4A51-9E51-6651EBCF9E4D
First sector: 903220 (at 3.4 GiB)
Last sector: 1832574 (at 7.0 GiB)
Partition size: 929355 sectors (3.5 GiB)
Attribute flags: 0000000000000000
Partition name: ‘Data’Command (? for help): q
-
确定自己系统分区需要多大,这里我定的是7G
通过上面的数据可知:系统分区从第6扇区开始,扇区大小为4096B,分区大小为7G,即7×1024×1024×1024B,也就是7×1024×1024×1024÷4096=1835008个扇区,我们的Data1分区的结尾应该就在1835008扇区处(注:此处做的时候有误其实应该是1835008+6)。这样Data1分区的大小就是(1835008-903219)扇区。为避免分区结尾发生覆盖的意外情况,这里我们少一个扇区,即Data1分区的大小为(1835008-903219-1)*4096B=3816603648B -
计算好后,进行文件系统的调整:
hfs_resize /private/var 3816603648
Poor-iPhone:~ root# hfs_resize /private/var 3806628224
Resizing /private/var to 3806628224 bytes.
- 调整分区的大小:
进入gptfdisk之后,输入:/dev/rdisk0s1 [Enter]
删除原分区:d [Enter] 2 [Enter]
创建Data1分区: n [Enter] 2 [Enter] [Enter] 1835008 [Enter] [Enter]
设置Data1分区名称:c [Enter] 2 [Enter] Data [Enter]
设置Data1分区属性:x [Enter] a [Enter] 2 [Enter] 48 [Enter] 49 [Enter] [Enter]
设置Data1分区GUID:c [Enter] 2 [Enter] (输入自己的GUID) [Enter]
扩充分区表条目数量:s [Enter] 4 [Enter]
返回主界面:m [Enter]
创建Data2分区:n [Enter] 4 [Enter] [Enter] [Enter] [Enter]
设置Data2分区名称:c [Enter] 4 [Enter] Data [Enter]
设置Data2分区属性:x [Enter] a [Enter] 4 [Enter] 48 [Enter] 49 [Enter] [Enter]
返回主界面并查看分区效果:m [Enter] p [Enter]
检查无误之后,写入分区表:w [Enter] Y [Enter]
Poor-iPhone:~ root# gptfdisk
GPT fdisk (gdisk) version 1.0.0Type device filename, or press to exit: /dev/rdisk0s1
Warning: Devices opened with shared lock will not have their
partition table automatically reloaded!
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: presentFound valid GPT with protective MBR; using GPT.
Command (? for help): d
Partition number (1-3): 2Command (? for help): n
Partition number (2-3, default 2): 2
First sector (903220-15480336, default = 903220) or {±}size{KMGTP}:
Last sector (903220-15480336, default = 15480336) or {±}size{KMGTP}: 1835008
Current type is ‘Apple HFS/HFS+’
Hex code or GUID (L to show codes, Enter = AF00):
Changed type of partition to ‘Apple HFS/HFS+’Command (? for help): c
Partition number (1-3): 2
Enter name: DataCommand (? for help): x
Expert command (? for help): a
Partition number (1-3): 2
Known attributes are:
0: system partition
1: hide from EFI
2: legacy BIOS bootable
60: read-only
62: hidden
63: do not automountAttribute value is 0000000000000000. Set fields are:
No fields setToggle which attribute field (0-63, 64 or to exit): 48
Have enabled the ‘Undefined bit #48’ attribute.
Attribute value is 0001000000000000. Set fields are:
48 (Undefined bit #48)Toggle which attribute field (0-63, 64 or to exit): 49
Have enabled the ‘Undefined bit #49’ attribute.
Attribute value is 0003000000000000. Set fields are:
48 (Undefined bit #48)
49 (Undefined bit #49)Toggle which attribute field (0-63, 64 or to exit):
Expert command (? for help): c
Partition number (1-3): 2
Enter the partition’s new unique GUID (‘R’ to randomize): 01445571-4602-4A51-9E51-6651EBCF9E4D
New GUID is 01445571-4602-4A51-9E51-6651EBCF9E4DExpert command (? for help): s
Current partition table size is 3.
Enter new size (32 up, default 128): 4
Caution: The partition table size should officially be 16KB or larger,
which works out to 128 entries. In practice, smaller tables seem to
work with most OSes, but this practice is risky. I’m proceeding with
the resize, but you may want to reconsider this action and undo it.Adjusting GPT size from 4 to 32 to fill the sector
Expert command (? for help): m
Command (? for help): n
Partition number (4-32, default 4): 4
First sector (3-15482888, default = 1832575) or {±}size{KMGTP}: 1835008
Last sector (1835008-15480336, default = 15480336) or {±}size{KMGTP}:
Current type is ‘Apple HFS/HFS+’
Hex code or GUID (L to show codes, Enter = AF00): 48465300-0000-11AA-AA11-00306543ECAC
Changed type of partition to ‘Apple HFS/HFS+’Command (? for help): c
Partition number (1-4): 4
Enter name: Data2Command (? for help): x
Expert command (? for help): a
Partition number (1-4): 4
Known attributes are:
0: system partition
1: hide from EFI
2: legacy BIOS bootable
60: read-only
62: hidden
63: do not automountAttribute value is 0000000000000000. Set fields are:
No fields setToggle which attribute field (0-63, 64 or to exit): 48
Have enabled the ‘Undefined bit #48’ attribute.
Attribute value is 0001000000000000. Set fields are:
48 (Undefined bit #48)Toggle which attribute field (0-63, 64 or to exit): 49
Have enabled the ‘Undefined bit #49’ attribute.
Attribute value is 0003000000000000. Set fields are:
48 (Undefined bit #48)
49 (Undefined bit #49)Toggle which attribute field (0-63, 64 or to exit):
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/rdisk0s1.
Warning: Devices opened with shared lock will not have their
partition table automatically reloaded!
Warning: The kernel may continue to use old or deleted partitions.
You should reboot or remove the drive.
The operation has completed successfully.
- 执行命令使系统应用新的分区表:
sync; sync; sync;
- 卸载Data1分区并进行拷贝
在上面我们计算Data1分区的大小是3816603648B=1024B×3727152,于是bs=1024b count=3717152
(当然你也可以bs=4096b,不过count需要重新计算)
Poor-iPhone:/ root# umount -f /private/var
Poor-iPhone:/ root# dd if=/dev/rdisk0s1s2 of=/dev/rdisk0s1s4 bs=1024b count=3717152
7260+1 records in
7260+1 records out
3816603648 bytes (3.8 GB) copied, 96.0313 s, 39.6 MB/s
- 将Data1分区删除,并重新建立System分区
这个时候你的设备如果亮了的话,可能会回到激活的界面,不用惊慌,继续进行操作
输入:gptfdisk [Enter] /dev/rdisk0s1 [Enter]
进入专家模式并交换两个分区表项(这样Data2分区就变成了disk0s1s2):x [Enter] t [Enter] 2 [Enter] 4 [Enter]
回到主界面并删除Data1分区(现在是第四个分区):m [Enter] d [Enter] 4 [Enter]
进入专家模式设置Data2分区的GUID:x [Enter] c [Enter] 2 [Enter] (输入你最开始时记下的的Data分区的GUID) [Enter]
返回主界面:m [Enter]
删除System分区:d [Enter] 1 [Enter]
建立新System分区:n [Enter] 1 [Enter] [Enter] [Enter] [Enter]
进入专家模式,并设置新System分区的GUID:x [Enter] c [Enter] 1 [Enter] (输入最开始记下的System分区的GUID))[Enter]
退出专家模式,设置System分区名称,写入分区表:m [Enter] c [Enter] 1 [Enter] System [Enter] w [Enter] Y [Enter]
Poor-iPhone:/ root# gptfdisk
GPT fdisk (gdisk) version 1.0.0Type device filename, or press to exit: /dev/rdisk0s1
Warning: Devices opened with shared lock will not have their
partition table automatically reloaded!
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: presentFound valid GPT with protective MBR; using GPT.
Command (? for help): x
Expert command (? for help): t
Partition number (1-4): 2
New partition number (1-32, default 5): 4Expert command (? for help): m
Command (? for help): d
Partition number (1-4): 4Command (? for help): x
Expert command (? for help): c
Partition number (1-3): 2
Enter the partition’s new unique GUID (‘R’ to randomize): 01445571-4602-4A51-9E51-6651EBCF9E4D
New GUID is 01445571-4602-4A51-9E51-6651EBCF9E4DExpert command (? for help): m
Command (? for help): d
Partition number (1-3): 1Command (? for help): n
Partition number (1-3, default 1): 1
First sector (6-1835007, default = 6) or {±}size{KMGTP}:
Last sector (6-1835007, default = 1835007) or {±}size{KMGTP}:
Current type is ‘Apple HFS/HFS+’
Hex code or GUID (L to show codes, Enter = AF00):
Changed type of partition to 'Apple HFS/HFS+Command (? for help): c
Partition number (1-3): 1
Enter name: SystemCommand (? for help): x
Expert command (? for help): c
Partition number (1-3): 2
Enter the partition’s new unique GUID (‘R’ to randomize): 79E21CC0-80E1-45BB-81ED-C1AF93B31C1A
New GUID is 79E21CC0-80E1-45BB-81ED-C1AF93B31C1ACommand (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/rdisk0s1.
Warning: Devices opened with shared lock will not have their
partition table automatically reloaded!
Warning: The kernel may continue to use old or deleted partitions.
You should reboot or remove the drive.
The operation has completed successfully.
- 扩大System分区的文件系统:
System分区从6扇区开始,至1835008结束,总计(1835008-6+1)扇区,保留最后一个扇区以保证安全,即1835002扇区=1835002×4096B=7516168192B
Poor-iPhone:/var root# hfs_resize / 7516168192
Resizing / to 7516192768 bytes.
- 现在如果打开看手机,会发现在激活页面。不用惊慌,这个界面是由于我们还没有挂载上var目录,系统自动新建了一个/private/var而产生的
执行下面的命令:(出错信息不用管,那个是无法写入IORegistry导致的,不影响目录的挂载。注意不要写成rdisk)
Poor-iPhone:/ root# rm -rf /private/var && mkdir -p /private/var && mount_hfs /dev/disk0s1s2 /private/var
mount_hfs: Could not create property for re-key environment check: No such file or directory
- 现在我们可以看一下我们的成果了
执行命令:df -h
Poor-iPhone:~ root# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/disk0s1s1 7.0G 2.9G 4.1G 42% /
devfs 49K 49K 0 100% /dev
/dev/disk0s1s2 53G 1.9G 51G 4% /private/var
/dev/disk0s1s3 10M 2.3M 7.8M 23% /private/var/wireless/baseband_data
- 把手机重启,然后激活的界面就会消失了,取而代之的是正常而熟悉的界面
Poor-iPhone:/ root# reboot
其他:
参考资料:
- https://github.com/danzatt/ios-dualboot
- https://twitter.com/JJGadgets/status/682567983642750977
感谢:
danzatt的工具:hfs_resize,和他的dualboot教程
beehind的二进制文件:gptfdisk、hfs_resize
gptfdisk by Rod Smith
Misty
2016.8.4