Let us say that we have the following bash script on a Linux machine, beginning with:
#!/bin/bash #This setsetcor script takes four arguments: setsector a b c d #Both a, b, and c and d are integers a=$1; #The end sector (in 512 byte sectors) of the sdx1 partition b=$2; #The end sector (in 512 byte sectors) of the sdx2 partition c=$3; #The end sector (in 512 byte sectors) of the sdx3 partition d=$4; #The end sector (in 512 byte sectors) of the free space
I have a small SSD disk drive that I copy on to a larger SSD or HD drive in its entirety using the dd utility to make an initial identical copy of the smaller drive to the larger drive.
After that, I want to accomplish the following using calculations made in the script:
- Keep partitions 1 and 2 exactly the same.
- Copy partition 3 contents with the
ddcommand to the end of the large disk drive space.
- Use the
cfdiskcommand to delete the partition in the partition table only, but not its contents for partition 3.
- Expand partition 2 so that its end is right before the beginning of the copy of partition 3.
- Recreate partition 3 with the command
cfdiskat the very end of the disk drive with its original size.
- Use the command
ntfsresizeto expand partition 2.
- I am assuming that if the proper dd options are used, that it will not need any NTFS resizing of the partition number 3 at the end of the drive. If needed, I need help figuring this out.
- Because of the complexity of calculating all this, the script should print out the necessary steps.
I keep on trying to use the command
cfdisk to accomplish this but am still not arriving at the correct formulas to use to type in the start partition sector number and resize partition sector values there when recreating the partition.
Are there any suggestions on how to calculate and re-partition the three partitions using the end of partition sector values given by variables a, b, c and d at the beginning of the bash script?