Advertisement
5keeve

Untitled

Jul 5th, 2024 (edited)
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.89 KB | Help | 0 0
  1. Yes, there is, but it involves a lot of "hacking". I can only give you instructions for Mac OS (might work onLinux as well).
  2.  
  3. Prerequisits:
  4.  
  5. 1. Install `gdisk`.
  6. 2. Install perl if not already installed.
  7. 3. Create a file "prearrange" containing below content.
  8. 4. Adjust the path to `gdisk` in line 9 in the file.
  9. 5. Make "prearrange" executable. `chmod +x prearrange`.
  10. 6. Run `prearrange` giving it the images filename: \
  11. `/prearange.sh RG35XXH-V1.1.4-EN16GB-240626.IMG` \
  12. This will do a Partition REARRANGE:
  13.  
  14. ```
  15. Reading 7: 27777024 -> 30226431 ..
  16. Reading 2: 2381824 -> 2447359 .
  17. Reading 3: 2447360 -> 2480127 .
  18. Reading 4: 2480128 -> 2611199 .
  19. Reading 5: 2611200 -> 19388415 ........
  20. Reading 6: 19388416 -> 27777023 ....
  21. Reading 1: 73728 -> 2381823 ..
  22. ... and then some more output ...
  23. ```
  24.  
  25. Now the partitions are rearrange in the file `ordered-RG35XXH-V1.1.4-EN16GB-240626.IMG` and you can flash it to your sdcard.
  26.  
  27. When flashed, check for the correct disk ID of your sdcard and unmount it.
  28.  
  29. On Mac for example:
  30.  
  31. ```shell
  32. diskutil list
  33. .. lots of output and then, for my 32GB sdcard ...
  34. /dev/disk4 (external, physical):
  35. #: TYPE NAME SIZE IDENTIFIER
  36. 0: GUID_partition_scheme *31.9 GB disk4
  37. 1: Microsoft Basic Data 1.3 GB disk4s7
  38. 2: Microsoft Basic Data Volumn 33.6 MB disk4s2
  39. 3: Microsoft Basic Data 16.8 MB disk4s3
  40. 4: Microsoft Basic Data 67.1 MB disk4s4
  41. 5: Microsoft Basic Data 8.6 GB disk4s5
  42. 6: Microsoft Basic Data 4.3 GB disk4s6
  43. 7: Microsoft Basic Data NO NAME 17.6 GB disk4s1
  44. ```
  45.  
  46. So here it's /dev/disk4.
  47.  
  48. Unmount:
  49.  
  50. `diskutil unmountDisk /dev/disk4`
  51.  
  52. Start `gdisk` to extend the partition. Be double sure to use the correct disk id (4 in the example)).
  53.  
  54. After `# <- ` below I gave explanations.
  55.  
  56. ```shell
  57. sudo gdisk /dev/rdisk4
  58. p # <- Enter p to print the partition.
  59. Number Start (sector) End (sector) Size Code Name
  60. 1 27918336 30226431 1.1 GiB 0700 Roms
  61. 2 2523136 2588671 32.0 MiB 0700 boot-resource
  62. 3 2588672 2621439 16.0 MiB 0700 env
  63. 4 2621440 2752511 64.0 MiB 0700 boot
  64. 5 2752512 19529727 8.0 GiB 0700 rootfs
  65. 6 19529728 27918335 4.0 GiB 0700 appfs
  66. 7 73728 2523135 1.2 GiB 0700 UDISK
  67. x # <- eXpert Mode
  68. e # <- rElocate Backup to disk's end
  69. m # <- Back to main menu
  70. d # <- Delete Partition
  71. 1 # <- Number 1
  72. n # <- New Partition
  73. 1 # <- Number 1
  74. # For Start and end block use the given defaults
  75. # 27918336 for start and in my case, something around 62332927 for a 32 GB sdcard
  76. 0700 # <- as the code
  77. c # <- change the name
  78. 1 # <- of partition 1
  79. Roms # <- To "Roms"
  80. w # <- write new partition table
  81. Y # <- YES! Do it.
  82. sync
  83. diskutil unmountDisk /dev/disk4
  84. ```
  85.  
  86. You're done.
  87.  
  88. Finally here is the `prearrange` programm
  89.  
  90. ```perl
  91. #!/usr/bin/perl
  92. use strict;
  93. use warnings;
  94. use IPC::Open2;
  95. use File::Copy;
  96. use bigint;
  97.  
  98. # Path to gdisk
  99. my $gdisk_path = '/usr/local/bin/gdisk';
  100.  
  101. # Device that is to be edited
  102. my $device = shift @ARGV;
  103.  
  104. # Open a pipe to gdisk
  105. my $pid = open2(my $reader, my $writer, $gdisk_path, $device);
  106.  
  107. # Check whether open2 was successful
  108. if (!$pid) {
  109. die "Error when starting gdisk: $!";
  110. }
  111.  
  112. # Send commands to gdisk
  113. print $writer "p\n"; # Display partition table
  114. print $writer "q\n"; # Exit gdisk
  115.  
  116. # Close the write handle
  117. close($writer);
  118.  
  119. my @partitions;
  120. my $minblock;
  121. # Read the output of gdisk
  122. while (my $line = <$reader>) {
  123. next unless $line =~ /^\s*(?<partition>\d)\s+(?<start>\d+)\s+(?<end>\d+)\s+\S+\s+\S+\s+(?<code>[[:xdigit:]]{4})\s+(?<name>\S+)/;
  124. $partitions[$+{partition}] = { %+ };
  125. if (! defined $minblock or $minblock > $+{start}) {
  126. $minblock = $+{start};
  127. }
  128. }
  129.  
  130. # Close the read handle
  131. close($reader);
  132.  
  133. # Wait for the end of the gdisk process
  134. waitpid($pid, 0);
  135.  
  136. $|=1;
  137.  
  138. copy($device, "ordered-" . $device) or die "Copy failed: $!";
  139.  
  140. open my $target, "+<ordered-$device" or die $!;
  141. binmode $target;
  142. open my $source, "<$device" or die $!;
  143. binmode $source;
  144. my @targetlayout;
  145. my $pos = 512 * Math::BigInt->new($minblock );
  146. sysseek($target, $pos, 0);
  147. my $targetpartition = 1;
  148. foreach my $sourcepartition (7,2,3,4,5,6,1) {
  149. my $sb = $partitions[$sourcepartition]->{start};
  150. my $eb = $partitions[$sourcepartition]->{end};
  151. print "Reading $sourcepartition: $sb -> $eb ";
  152. my $blocks = $eb+1-$sb;
  153. my $readpos = 512 * Math::BigInt->new($sb);
  154. my $readbytes = 512 * Math::BigInt->new($blocks);
  155.  
  156. my $rp = sysseek($source, $readpos, 0);
  157. if (not defined $rp or $rp != $readpos) {
  158. die "Failed to seek to $readpos\n";
  159. }
  160. my $buffer;
  161. my $toread = $readbytes;
  162. my $maxbuf = 1073741824;
  163. while ($toread > 0) {
  164. my $readbytes = $toread;
  165. $readbytes = $maxbuf if $readbytes > $maxbuf;
  166. my $r = sysread $source, $buffer, $readbytes;
  167. if (not defined $r) {
  168. die "Couldn't read $readbytes bytes";
  169. }
  170. if ($r != $readbytes) {
  171. die "read $r instead of $readbytes bytes"
  172. }
  173. my $w = syswrite $target, $buffer, $readbytes ;
  174. if (not defined $w) {
  175. die "Couldn't write $readbytes bytes";
  176. }
  177. if ($w != $readbytes) {
  178. die "wrote $w instead of $readbytes bytes"
  179. }
  180. $toread -= $readbytes;
  181. print ".";
  182. }
  183. print "\n";
  184. my $newpos = $pos + $readbytes;
  185. $targetlayout[$sourcepartition] = {
  186. partition => $sourcepartition,
  187. start => $pos / 512,
  188. end => $newpos / 512 - 1,
  189. code => $partitions[$sourcepartition]->{code},
  190. name => $partitions[$sourcepartition]->{name},
  191. };
  192. ++$targetpartition;
  193. $pos = $newpos;
  194. }
  195.  
  196. open my $repartition, '|-', $gdisk_path, "ordered-$device" or die $!;
  197.  
  198. # Delete all partitions
  199. foreach my $partition (@targetlayout) {
  200. next unless $partition->{partition};
  201. print $repartition "d\n", $partition->{partition}, "\n";
  202. }
  203.  
  204. # Create new partitions
  205. foreach my $partition (@targetlayout) {
  206. next unless $partition->{partition};
  207. print $repartition "n\n", $partition->{partition}, "\n";
  208. print $repartition $partition->{start}, "\n";
  209. print $repartition $partition->{end}, "\n";
  210. print $repartition $partition->{code}, "\n";
  211. }
  212.  
  213. # name the partitions
  214. foreach my $partition (@targetlayout) {
  215. next unless $partition->{partition};
  216. print $repartition "c\n", $partition->{partition}, "\n";
  217. print $repartition $partition->{name}, "\n";
  218. }
  219.  
  220. # Expert mode
  221. print $repartition "x\ne\nw\nY\n";
  222. ```
  223.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement