Advertisement
Guest User

xboxonhddMOD.py

a guest
Jul 29th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Courtesy of GitHub user Juvenal1 (GitHub.com/Juvenal1/xboxonehdd)
  4.  
  5. import os
  6. from stat import *
  7. from os import path
  8. import sys
  9. import gptutil
  10.  
  11.  
  12. DISK_GUID = 'DB4B34A2DED666479EB54109A12228E5'.decode('hex')
  13. TEMP_CONTENT_GUID = 'A57D72B3ACA33D4B9FD62EA54441011B'.decode('hex')
  14. USER_CONTENT_GUID = 'E0B59B865633E64B85F729323A675CC7'.decode('hex')
  15. SYSTEM_SUPPORT_GUID = '477A0DC9B9CCBA4C8C660459F6B85724'.decode('hex')
  16. SYSTEM_UPDATE_GUID = 'D76A059AED324141AEB1AFB9BD5565DC'.decode('hex')
  17. SYSTEM_UPDATE2_GUID = '7C19B224019DF945A8E1DBBCFA161EB2'.decode('hex')
  18.  
  19. PARTITION_SIZES = [
  20. 44023414784,
  21. 0,
  22. 42949672960,
  23. 12884901888,
  24. 7516192768
  25. ]
  26.  
  27.  
  28. def print_parted_commands(device):
  29. temp_end = 1 + (PARTITION_SIZES[0]/1024/1024)
  30. user_end = temp_end + (PARTITION_SIZES[1]/1024/1024)
  31. sys_end = user_end + (PARTITION_SIZES[2]/1024/1024)
  32. upt_end = sys_end + (PARTITION_SIZES[3]/1024/1024)
  33. upt2_end = upt_end + (PARTITION_SIZES[4]/1024/1024)
  34.  
  35. f = open('mkxboxfs.sh', 'w')
  36. f.write('#!/bin/bash\n')
  37. f.write('DEV={0}\n'.format(device))
  38. f.write('parted -s "$DEV" mktable gpt\n')
  39. f.write('parted -s "$DEV" mkpart primary ntfs 1.00MiB {0}MiB\n'.format(temp_end))
  40. f.write('parted -s "$DEV" name 1 "\\"Temp Content\\""\n')
  41. f.write('mkntfs -q "${DEV}1" -f -L "Temp Content"\n')
  42. f.write('parted -s "$DEV" mkpart primary ntfs {0}MiB {1}MiB\n'.format(temp_end, user_end))
  43. f.write('parted -s "$DEV" name 2 "\\"User Content\\""\n')
  44. f.write('mkntfs -q "${DEV}2" -f -L "User Content"\n')
  45. f.write('parted -s "$DEV" mkpart primary ntfs {0}MiB {1}MiB\n'.format(user_end, sys_end))
  46. f.write('parted -s "$DEV" name 3 "\\"System Support\\""\n')
  47. f.write('mkntfs -q "${DEV}3" -f -L "System Support"\n')
  48. f.write('parted -s "$DEV" mkpart primary ntfs {0}MiB {1}MiB\n'.format(sys_end, upt_end))
  49. f.write('parted -s "$DEV" name 4 "\\"System Update\\""\n')
  50. f.write('mkntfs -q "${DEV}4" -f -L "System Update"\n')
  51. f.write('parted -s "$DEV" mkpart primary ntfs {0}MiB {1}MiB\n'.format(upt_end, upt2_end))
  52. f.write('parted -s "$DEV" name 5 "\\"System Update 2\\""\n')
  53. f.write('mkntfs -q "${DEV}5" -f -L "System Update 2"\n')
  54. f.flush()
  55. f.close()
  56. os.chmod('mkxboxfs.sh', 0o777)
  57.  
  58.  
  59. def fixup_header(hdr):
  60. hdr.disk_guid = DISK_GUID
  61. hdr.fix_crc()
  62.  
  63.  
  64. def fixup_part_table(pt):
  65. pt.partitions[0].part_guid = TEMP_CONTENT_GUID
  66. pt.partitions[0].name = u'Temp Content'
  67. pt.partitions[1].part_guid = USER_CONTENT_GUID
  68. pt.partitions[1].name = u'User Content'
  69. pt.partitions[2].part_guid = SYSTEM_SUPPORT_GUID
  70. pt.partitions[2].name = u'System Support'
  71. pt.partitions[3].part_guid = SYSTEM_UPDATE_GUID
  72. pt.partitions[3].name = u'System Update'
  73. pt.partitions[4].part_guid = SYSTEM_UPDATE2_GUID
  74. pt.partitions[4].name = u'System Update 2'
  75.  
  76. if __name__ == '__main__':
  77. if len(sys.argv) != 2:
  78. print 'Usage:'
  79. print '\t{0} [disk]'.format(sys.argv[0])
  80. print 'Example:'
  81. print '\t{0} sdf'.format(sys.argv[0])
  82. print
  83. sys.exit(-1)
  84.  
  85. # open the disk
  86. _path = path.join('/dev', sys.argv[1])
  87. disk = gptutil.Disk.from_path(_path)
  88. partitions = disk.header.partition_table.active_partitions
  89.  
  90. # calculate user partition size to nearest GiB
  91. total_size = int(open(path.join('/sys', 'class', 'block', sys.argv[1], 'size'), 'r').readline()) * 512
  92. user_content_size = (total_size - sum(PARTITION_SIZES))/1024/1024/1024
  93. PARTITION_SIZES[1] = user_content_size*1024*1024*1024
  94.  
  95. # verify partition count
  96. if len(partitions) != 5:
  97. print 'Disk must have 5 partitions'
  98. print 'Create as follows:'
  99. print '\t41 GiB NTFS'
  100. print '\t{0} GiB NTFS'.format(user_content_size)
  101. print '\t40 GiB NTFS'
  102. print '\t12 GiB NTFS'
  103. print '\t7 GiB NTFS'
  104. print_parted_commands(_path)
  105. print 'run ./mkxboxfs.sh to create the correct partitions'
  106. sys.exit(-2)
  107.  
  108. # verify partition sizes
  109. for i in range(5):
  110. correct = PARTITION_SIZES[i]
  111. actual = partitions[i].size
  112. if correct != actual:
  113. print 'Partition {0} must be EXACTLY {1} bytes!'.format(i, correct)
  114. print 'It is {0} bytes'.format(actual)
  115. print_parted_commands(_path)
  116. print 'run ./mkxboxfs.sh to create the correct partitions'
  117. s = raw_input("Si estas usando una particion de 500gb en un disco de 1tb y quieres continuar escribe 'yes' to continue: ")
  118. if s != 'yes':
  119. sys.exit(-3)
  120.  
  121. # confirm actions
  122. print 'The actions performed CANNOT be reversed!'
  123. print 'Are you SURE you want to convert {0} to an Xbox ONE Disk?'.format(_path)
  124. s = raw_input("Enter 'yes' to continue: ")
  125. if s != 'yes':
  126. sys.exit(-4)
  127.  
  128. # change partition table and backup partition table
  129. fixup_part_table(disk.header.partition_table)
  130.  
  131. # change header and backup header
  132. fixup_header(disk.header)
  133.  
  134. print 'Writing changes to disk...'
  135. diskf = open(_path, 'rb+')
  136. disk.commit(f=diskf)
  137. print 'Changes Written!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement