Search
SailfishOS Open Build Service
>
Projects
>
home:notmart
:
CE:Adaptation:x86-generic
>
installer-shell
> installer-shell-expand-extended-partition-to-get-enough-free-space.patch
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File installer-shell-expand-extended-partition-to-get-enough-free-space.patch of Package installer-shell
diff -Naur a/installer-shell b/installer-shell --- a/installer-shell 2011-07-12 18:17:09.416908025 +0800 +++ b/installer-shell 2011-07-12 18:31:33.505149804 +0800 @@ -1,5 +1,8 @@ #!/bin/bash +# expand extended partition to here +EXPAND_EXTENDED_END=0 + # fdisk different version FDISK_FLAGS="" # geometry info @@ -156,7 +159,9 @@ do dbglg "sfdisk_loop($1) \"$2\" \"$SFDISK_FORCE $3\"" tmp_str="$(echo -ne "$STR" |sfdisk $SFDISK_FORCE /dev/$DEV $3 2>&1 |tee -a $LOGFILE | - sed -n -e '/Checking that no-one is using this disk right now/{N;/Device or resource busy/p}' -e '/Warning:.*cylinder boundary/{N;N;/sfdisk: I don/p}')" + sed -n -e '/Checking that no-one is using this disk right now/{N;/Device or resource busy/p}' \ + -e '/Warning:.*cylinder boundary/{N;N;/sfdisk: I don/p}' \ + -e '/Warning:.*bad partition start/{N;N;/sfdisk: bad input/p}')" if echo $tmp_str |grep "Device or resource busy" > /dev/null 2>&1; then output "Device is busy, sleep a while and try again, please wait..." sleep $INTERVAL @@ -166,7 +171,7 @@ fail_exit "sfdisk failed." fi sync - elif echo $tmp_str |grep "Warning:.*cylinder boundary" >/dev/null 2>&1; then + elif echo $tmp_str |grep "Warning:.*cylinder boundary\|Warning:.*bad partition start" >/dev/null 2>&1; then OLD_FLAG=$SFDISK_FORCE SFDISK_FORCE="--force" else @@ -194,7 +199,7 @@ fi } -# Not used now, will be removed +# default behavior is going on wait_user () { local first_char answer NUM PROMPT TMP_PROMPT NUM=9 @@ -327,7 +332,8 @@ choose_device () { local OLD_PS3 OLD_PS3=$PS3 - PS3="Please select one disk to install MeeGo:" + output "\033[32mStep 1 Select one disk to install MeeGo\033[0m" + PS3="Please choose:" select tmp_dev in "${DISK_MENU[@]}" "CANCEL"; do if [ -n "${REPLY//[0-9]/}" ]; then continue @@ -354,7 +360,8 @@ is_whole_disk () { local OLD_PS3 OLD_PS3=$PS3 - PS3="Please Choose:" + output "\033[32mStep 2 Full disk install or not\033[0m" + PS3="Please choose:" select tmp_whole_disk in "Free space install" "Full disk install" "Cancel"; do if [ -n "${REPLY//[0-9]/}" ]; then continue @@ -373,6 +380,7 @@ # Roll back partition table rollback () { local ANSWER + output "\033[32mStep 3 Roll back\033[0m" echo -ne "\033[31mThis is the last chance to rollback, Are you sure you want to continue?(y/n)[y]\033[0m" read ANSWER ANSWER=$(echo $ANSWER |tr 'A-Z' 'a-z') @@ -430,14 +438,17 @@ has_extended () { if sfdisk -l /dev/$DEV 2>/dev/null |grep "Extended" >/dev/null 2>&1; then HAS_EXTENDED=1 + EXTENDED_NR=$(sfdisk -l /dev/$DEV 2>/dev/null |grep "^/dev/" |grep "Extended" |awk '{print $1}' |rev |cut -c1) EXTENDED_START=$(sfdisk -l /dev/$DEV 2>/dev/null |grep "^/dev/" |grep "Extended" |awk '{printf "%d", $2}') EXTENDED_END=$(sfdisk -l /dev/$DEV 2>/dev/null |grep "^/dev/" |grep "Extended" |awk '{printf "%d", $3}') + dbglg "EXTENDED_START=$EXTENDED_START, EXTENDED_END=$EXTENDED_END" PART_TABLE[0]=$EXTENDED_START else if ! sfdisk -l /dev/$DEV 2>/dev/null |grep "^/dev/" |grep "Empty" > /dev/null 2>&1; then fail_exit "Can't create extended partition, there are already 4 primary partitions." fi HAS_EXTENDED=0 + EXTENDED_NR=$(sfdisk -l /dev/$DEV 2>/dev/null |grep "^/dev/" |grep "Empty" |head -1 |awk '{print $1}' |rev |cut -c1) PART_TABLE[0]=0 fi } @@ -457,11 +468,12 @@ get_partition_table () { local INDEX=1 - for tmp_str in $(fdisk -H$NR_HEADER -S$NR_SECTOR $FDISK_FLAGS -l /dev/$DEV 2>/dev/null|grep "^/dev/" |grep -v "Extended" |grep -v "Empty" | - awk '{if(NF<=8){printf "%d,%d\n", $((NF-4)),$((NF-3))}else{printf "%d,%d\n", $((NF-7)),$((NF-6))}}' |sort -n); do + for tmp_str in $(sfdisk -l /dev/$DEV 2>/dev/null|grep "^/dev/" |grep -v "Extended" |grep -v "Empty" | + awk '{if(NF<=8){printf "%d,%d\n", $((NF-5)),$((NF-4))}else{printf "%d,%d\n", $((NF-8)),$((NF-7))}}' |sort -n); do tmp_s=$(echo $tmp_str |cut -d',' -f1) tmp_e=$(echo $tmp_str |cut -d',' -f2) if [ $HAS_EXTENDED -eq 0 ]; then + EXPAND_EXTENDED_END=-1 PART_TABLE[$INDEX]=$tmp_s PART_TABLE[$(($INDEX+1))]=$tmp_e INDEX=$(($INDEX+2)) @@ -471,10 +483,17 @@ PART_TABLE[$(($INDEX+1))]=$tmp_e INDEX=$(($INDEX+2)) fi + if [ $tmp_s -gt $EXTENDED_END ]; then + EXPAND_EXTENDED_END=$(($tmp_s-1)) + break + fi else fail_exit "Never should be here." fi done + if [ $EXPAND_EXTENDED_END -eq 0 ]; then + EXPAND_EXTENDED_END=$(($NR_CYLINDER-1)) + fi unset tmp_s tmp_e tmp_str if [ $HAS_EXTENDED -eq 0 ]; then PART_TABLE[$INDEX]=$NR_CYLINDER @@ -489,7 +508,7 @@ get_max_hole () { local INDEX=1 while [ $INDEX -lt ${#PART_TABLE[*]} ]; do - tmp_hole=$((${PART_TABLE[$(($INDEX))]}-${PART_TABLE[$(($INDEX-1))]})) + tmp_hole=$((${PART_TABLE[$INDEX]}-${PART_TABLE[$(($INDEX-1))]})) if [ $tmp_hole -gt $HOLE_MAX ]; then HOLE_MAX=$tmp_hole HOLE_START=${PART_TABLE[$(($INDEX-1))]} @@ -500,6 +519,16 @@ unset tmp_hole dbglg "Find free space ${HOLE_MAX} at [$HOLE_START,$HOLE_END]" if [ $(($HOLE_MAX*$CYLINDER_SIZE/1024/1024)) -lt $SMALLEST_SPACE ]; then + #expand extended partition if we can + if [ $EXPAND_EXTENDED_END -gt 0 ]; then + HOLE_START=${PART_TABLE[$(($INDEX-3))]} + HOLE_MAX=$(($EXPAND_EXTENDED_END-$HOLE_START)) + if [ $(($HOLE_MAX*$CYLINDER_SIZE/1024/1024)) -ge $SMALLEST_SPACE ]; then + output "Expands extended partition to get enought free space." + sfdisk_loop "expands extended partition" ",$(($EXPAND_EXTENDED_END-$EXTENDED_START)),\n" "-N$EXTENDED_NR" + return + fi + fi fail_exit "Can't find suitable free space, at least ${SMALLEST_SPACE}MB, please partitioning yourself." fi } @@ -507,7 +536,6 @@ prepare_extended_partition () { local LOGICAL_CUR_MAX TMP_START TMP_SIZE if [ $HAS_EXTENDED -eq 0 ]; then - EXTENDED_NR=$(sfdisk -l /dev/$DEV 2>/dev/null |grep "^/dev/" |grep "Empty" |head -1 |awk '{print $1}' |rev |cut -c1) if [ -z "$EXTENDED_NR" ]; then fail_exit "Never should be here." fi @@ -659,6 +687,8 @@ if [ $SILENT_MODE -eq 0 ]; then rollback fi + + output "\033[32mAll the works will done by computer in several minutes, you are free now.\033[0m" } create_fs () { @@ -991,7 +1021,7 @@ local CMDLINE # Clean environent before start clean_env - output "Welcome to MeeGo `head -1 /etc/meego-release`" + output "Welcome to `head -1 /etc/meego-release`" # Should not be present in install mode, but in case of ... dbglg_exec "killall -9 automountd >/dev/null 2>&1"