bcbc / Wubi-move

Migrate a Wubi install to partition
https://help.ubuntu.com/community/MigrateWubi
GNU General Public License v2.0
25 stars 4 forks source link

Script does not support GPT tables with new fdisk version for 14.10 and above #26

Open hakuna-m opened 8 years ago

hakuna-m commented 8 years ago

The output of fdisk 2.20.1 (version for 14.04) is something like this: /dev/sda1 1 9999999999 999999999+ ee GPT

The output of fdisk 2.27.1 (version for 16.04) is something like this:

/dev/sda1  999999999  999999999  999999999  999G Windows recovery environment
/dev/sda2  999999999  999999999  999999999  999G EFI System
/dev/sda3  999999999  999999999  999999999  999G Microsoft reserved
/dev/sda4  999999999  999999999  999999999  999G Microsoft basic data
/dev/sda5  999999999  999999999  999999999  999G Linux filesystem
/dev/sda6  999999999  999999999  999999999  999G Linux Swap
/dev/sda7  999999999  999999999  999999999  999G Windows recovery environment

.i.e fdisk shows all partitions but no IDs like 83 as used for non-GPT tables.

As a result the script fails e.g. with partition /dev/sda5 must be type 83 - Linux.

My suggestion is that the script should accept the ID or the type name:

--- a/check-target.sh
+++ b/check-target.sh
@@ -147,11 +147,11 @@
     elif [ $(fdisk -l "$partition_disk" | grep "$1[ \t]" | grep "[ \t]85[ \t]" | wc -l) -eq 1 ]; then
         error "partition "$1" is an Extended partition."
     elif [ "$2" == "83" ]; then
-      if [ $(fdisk -l "$partition_disk" | grep "$1[ \t]" | grep "[ \t]"$2"[ \t]" | wc -l) -eq 0 ]; then
+      if [ $(fdisk -l "$partition_disk" | grep "$1[ \t]" | grep -i "[ \t]"$2"[ \t]\|[ \t]Linux filesystem" | wc -l) -eq 0 ]; then
         error "partition "$1" must be type "$2" - Linux."
       fi
     else
-      if [ $(fdisk -l "$partition_disk" | grep "$1[ \t]" | grep "[ \t]"$2"[ \t]" | wc -l) -eq 0 ]; then
+      if [ $(fdisk -l "$partition_disk" | grep "$1[ \t]" | grep -i "[ \t]"$2"[ \t]\|[ \t]Linux Swap" | wc -l) -eq 0 ]; then
         error "partition "$1" must be type "$2" - Linux swap."
       fi
     fi
bcbc commented 8 years ago

I seem to recall there was a problem with different languages. In this commit I removed the text part of the check in response to a user (can't recall all the details). Although that wasn't an either or (it was both type and description), so this is better.

hakuna-m commented 8 years ago

Thank you for your response.

I seem to recall there was a problem with different languages.

Currently, the old problem should be not affect the new layout which is only used for GPT tables because the new column has no localization. I tested it with German localization. There was no difference even e.g. "Windows recovery environment" is not German. But maybe, there would be a difference in future releases.

Maybe a solution would be to disable localization for the fdisk commands with a leading LC_ALL=C e.g.:

--- a/check-target.sh
+++ b/check-target.sh
@@ -147,11 +147,11 @@
     elif [ $(fdisk -l "$partition_disk" | grep "$1[ \t]" | grep "[ \t]85[ \t]" | wc -l) -eq 1 ]; then
         error "partition "$1" is an Extended partition."
     elif [ "$2" == "83" ]; then
-      if [ $(fdisk -l "$partition_disk" | grep "$1[ \t]" | grep "[ \t]"$2"[ \t]" | wc -l) -eq 0 ]; then
+      if [ $(LC_ALL=C fdisk -l "$partition_disk" | grep "$1[ \t]" | grep -i "[ \t]"$2"[ \t]\|[ \t]Linux filesystem" | wc -l) -eq 0 ]; then
         error "partition "$1" must be type "$2" - Linux."
       fi
     else
-      if [ $(fdisk -l "$partition_disk" | grep "$1[ \t]" | grep "[ \t]"$2"[ \t]" | wc -l) -eq 0 ]; then
+      if [ $(LC_ALL=C fdisk -l "$partition_disk" | grep "$1[ \t]" | grep -i "[ \t]"$2"[ \t]\|[ \t]Linux Swap" | wc -l) -eq 0 ]; then
         error "partition "$1" must be type "$2" - Linux swap."
       fi
     fi
bcbc commented 8 years ago

That's a great idea. I'll update it when I get a chance. Thanks