Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Yes, there is, but it involves a lot of "hacking". I can only give you instructions for Mac OS (might work onLinux as well).
- Prerequisits:
- 1. Install `gdisk`.
- 2. Install perl if not already installed.
- 3. Create a file "prearrange" containing below content.
- 4. Adjust the path to `gdisk` in line 9 in the file.
- 5. Make "prearrange" executable. `chmod +x prearrange`.
- 6. Run `prearrange` giving it the images filename: \
- `/prearange.sh RG35XXH-V1.1.4-EN16GB-240626.IMG` \
- This will do a Partition REARRANGE:
- ```
- Reading 7: 27777024 -> 30226431 ..
- Reading 2: 2381824 -> 2447359 .
- Reading 3: 2447360 -> 2480127 .
- Reading 4: 2480128 -> 2611199 .
- Reading 5: 2611200 -> 19388415 ........
- Reading 6: 19388416 -> 27777023 ....
- Reading 1: 73728 -> 2381823 ..
- ... and then some more output ...
- ```
- Now the partitions are rearrange in the file `ordered-RG35XXH-V1.1.4-EN16GB-240626.IMG` and you can flash it to your sdcard.
- When flashed, check for the correct disk ID of your sdcard and unmount it.
- On Mac for example:
- ```shell
- diskutil list
- .. lots of output and then, for my 32GB sdcard ...
- /dev/disk4 (external, physical):
- #: TYPE NAME SIZE IDENTIFIER
- 0: GUID_partition_scheme *31.9 GB disk4
- 1: Microsoft Basic Data 1.3 GB disk4s7
- 2: Microsoft Basic Data Volumn 33.6 MB disk4s2
- 3: Microsoft Basic Data 16.8 MB disk4s3
- 4: Microsoft Basic Data 67.1 MB disk4s4
- 5: Microsoft Basic Data 8.6 GB disk4s5
- 6: Microsoft Basic Data 4.3 GB disk4s6
- 7: Microsoft Basic Data NO NAME 17.6 GB disk4s1
- ```
- So here it's /dev/disk4.
- Unmount:
- `diskutil unmountDisk /dev/disk4`
- Start `gdisk` to extend the partition. Be double sure to use the correct disk id (4 in the example)).
- After `# <- ` below I gave explanations.
- ```shell
- sudo gdisk /dev/rdisk4
- p # <- Enter p to print the partition.
- Number Start (sector) End (sector) Size Code Name
- 1 27918336 30226431 1.1 GiB 0700 Roms
- 2 2523136 2588671 32.0 MiB 0700 boot-resource
- 3 2588672 2621439 16.0 MiB 0700 env
- 4 2621440 2752511 64.0 MiB 0700 boot
- 5 2752512 19529727 8.0 GiB 0700 rootfs
- 6 19529728 27918335 4.0 GiB 0700 appfs
- 7 73728 2523135 1.2 GiB 0700 UDISK
- x # <- eXpert Mode
- e # <- rElocate Backup to disk's end
- m # <- Back to main menu
- d # <- Delete Partition
- 1 # <- Number 1
- n # <- New Partition
- 1 # <- Number 1
- # For Start and end block use the given defaults
- # 27918336 for start and in my case, something around 62332927 for a 32 GB sdcard
- 0700 # <- as the code
- c # <- change the name
- 1 # <- of partition 1
- Roms # <- To "Roms"
- w # <- write new partition table
- Y # <- YES! Do it.
- sync
- diskutil unmountDisk /dev/disk4
- ```
- You're done.
- Finally here is the `prearrange` programm
- ```perl
- #!/usr/bin/perl
- use strict;
- use warnings;
- use IPC::Open2;
- use File::Copy;
- use bigint;
- # Path to gdisk
- my $gdisk_path = '/usr/local/bin/gdisk';
- # Device that is to be edited
- my $device = shift @ARGV;
- # Open a pipe to gdisk
- my $pid = open2(my $reader, my $writer, $gdisk_path, $device);
- # Check whether open2 was successful
- if (!$pid) {
- die "Error when starting gdisk: $!";
- }
- # Send commands to gdisk
- print $writer "p\n"; # Display partition table
- print $writer "q\n"; # Exit gdisk
- # Close the write handle
- close($writer);
- my @partitions;
- my $minblock;
- # Read the output of gdisk
- while (my $line = <$reader>) {
- next unless $line =~ /^\s*(?<partition>\d)\s+(?<start>\d+)\s+(?<end>\d+)\s+\S+\s+\S+\s+(?<code>[[:xdigit:]]{4})\s+(?<name>\S+)/;
- $partitions[$+{partition}] = { %+ };
- if (! defined $minblock or $minblock > $+{start}) {
- $minblock = $+{start};
- }
- }
- # Close the read handle
- close($reader);
- # Wait for the end of the gdisk process
- waitpid($pid, 0);
- $|=1;
- copy($device, "ordered-" . $device) or die "Copy failed: $!";
- open my $target, "+<ordered-$device" or die $!;
- binmode $target;
- open my $source, "<$device" or die $!;
- binmode $source;
- my @targetlayout;
- my $pos = 512 * Math::BigInt->new($minblock );
- sysseek($target, $pos, 0);
- my $targetpartition = 1;
- foreach my $sourcepartition (7,2,3,4,5,6,1) {
- my $sb = $partitions[$sourcepartition]->{start};
- my $eb = $partitions[$sourcepartition]->{end};
- print "Reading $sourcepartition: $sb -> $eb ";
- my $blocks = $eb+1-$sb;
- my $readpos = 512 * Math::BigInt->new($sb);
- my $readbytes = 512 * Math::BigInt->new($blocks);
- my $rp = sysseek($source, $readpos, 0);
- if (not defined $rp or $rp != $readpos) {
- die "Failed to seek to $readpos\n";
- }
- my $buffer;
- my $toread = $readbytes;
- my $maxbuf = 1073741824;
- while ($toread > 0) {
- my $readbytes = $toread;
- $readbytes = $maxbuf if $readbytes > $maxbuf;
- my $r = sysread $source, $buffer, $readbytes;
- if (not defined $r) {
- die "Couldn't read $readbytes bytes";
- }
- if ($r != $readbytes) {
- die "read $r instead of $readbytes bytes"
- }
- my $w = syswrite $target, $buffer, $readbytes ;
- if (not defined $w) {
- die "Couldn't write $readbytes bytes";
- }
- if ($w != $readbytes) {
- die "wrote $w instead of $readbytes bytes"
- }
- $toread -= $readbytes;
- print ".";
- }
- print "\n";
- my $newpos = $pos + $readbytes;
- $targetlayout[$sourcepartition] = {
- partition => $sourcepartition,
- start => $pos / 512,
- end => $newpos / 512 - 1,
- code => $partitions[$sourcepartition]->{code},
- name => $partitions[$sourcepartition]->{name},
- };
- ++$targetpartition;
- $pos = $newpos;
- }
- open my $repartition, '|-', $gdisk_path, "ordered-$device" or die $!;
- # Delete all partitions
- foreach my $partition (@targetlayout) {
- next unless $partition->{partition};
- print $repartition "d\n", $partition->{partition}, "\n";
- }
- # Create new partitions
- foreach my $partition (@targetlayout) {
- next unless $partition->{partition};
- print $repartition "n\n", $partition->{partition}, "\n";
- print $repartition $partition->{start}, "\n";
- print $repartition $partition->{end}, "\n";
- print $repartition $partition->{code}, "\n";
- }
- # name the partitions
- foreach my $partition (@targetlayout) {
- next unless $partition->{partition};
- print $repartition "c\n", $partition->{partition}, "\n";
- print $repartition $partition->{name}, "\n";
- }
- # Expert mode
- print $repartition "x\ne\nw\nY\n";
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement