Skip to content

Instantly share code, notes, and snippets.

@rscottm
Created August 11, 2013 22:10
Show Gist options
  • Select an option

  • Save rscottm/6207116 to your computer and use it in GitHub Desktop.

Select an option

Save rscottm/6207116 to your computer and use it in GitHub Desktop.
target_disk="`rootdev -d -s`"
# Get the current sizes of ckern, croot, and stateful
ckern_size="`cgpt show -i 6 -n -s -q ${target_disk}`"
croot_size="`cgpt show -i 7 -n -s -q ${target_disk}`"
state_size="`cgpt show -i 1 -n -s -q ${target_disk}`"
#new stateful size will include all but 1 byte from rootc and kernc
stateful_size=$(($state_size + $croot_size + $ckern_size - 2))
#start stateful at the same spot it currently starts
stateful_start="`cgpt show -i 1 -n -b -q ${target_disk}`"
#start kernc after stateful
kernc_start=$(($stateful_start + $stateful_size))
#start rootc after kernc
rootc_start=$(($kernc_start + 1))
echo -e "\n\nModifying partition table to remove Ubuntu."
umount /mnt/stateful_partition
# first, reduce rootc size to 1 and place it after the new kernc
cgpt add -i 7 -b $rootc_start -s 1 -l ROOT-C ${target_disk}
# second, reduce kernc size to 1 and place it after the new stateful
cgpt add -i 6 -b $kernc_start -s 1 -l KERN-C ${target_disk}
# finally, stateful
cgpt add -i 1 -b $stateful_start -s $stateful_size -l STATE ${target_disk}
reboot
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment