--- trunk/installer-simple/bin/installer.sh.in 2016/06/13 12:37:31 2947 +++ trunk/installer-simple/bin/installer.sh.in 2016/06/13 15:03:52 2948 @@ -290,8 +290,35 @@ export ALL_CDROMS="$(get_hwinfo cdrom)" } +auto_partition_clear_disk() +{ + if [ -e ${HDD} ] + then + dd if=/dev/zero of=${HDD} count=1 &> /dev/null || dialog_die + else + echo "clear disk: device ${HDD} does not exist" >&2 + fi +} + +auto_partition_command() +{ + if [ -e ${HDD} ] + then + fdisk ${HDD} &> /dev/null << EOF +$(echo "${PARTITION_OPTS}") +EOF + else + echo "partition command: device ${HDD} does not exist" >&2 + fi +} + setup_hdd_partitions() { + local partition_number + local partition_type + local partition_start_sector + local partition_size + # sanity check - should not happen if is_mounted --device "${ROOTHDD}" then @@ -321,114 +348,153 @@ fi ## delete disk - dd if=/dev/zero of=${HDD} count=1 &> /dev/null || dialog_die + auto_partition_clear_disk + + # setup partition options + export PARTITION_OPTS - if [[ ${FLASHDISK} = 1 ]] + if [[ -n ${BOOTHDD} ]] then + # create a boot disk with 50meg size - bootable + partition_type="p" + partition_number="1" if [[ ${FDISKPARTIONBELOW256MB} = 1 ]] then - ## setup one bootable partition - # 1. n= new disk - # 2. p= primary disk - # 3. 1= first partition - # 4. 2= default sector start // small disk needs more space for grub2 mbr sector - # 5. ''= defaul sector end - # 6. a= bootable flag - # 7. 1= boot flag for partition 1 - # 8. n= new disk - #10. p= primary disk - #11. 2= second partition - #12. ''= default sector start - #13. ''= defaul sector end - #14. w= write/quit - fdisk ${HDD} &> /dev/null << EOF -n -p -1 -2 -+50M -a -1 -n -p -2 + # 2= default sector start // small disk needs more space for grub2 mbr sector + partition_start_sector="2" + else + # '' use default sector start + partition_start_sector="" + fi + # 50meg size + partition_size="+50M" + # create a boot disk with 50meg size - bootable + # n= new disk + # p= primary disk + # w= write/quit + PARTITION_OPTS="n +${partition_type} +${partition_number} +${partition_start_sector} +${partition_size} +w" + # create the disk + auto_partition_command + + # mark the disk bootable + PARTITION_OPTS="a +${partition_number} +w" + auto_partition_command -w -EOF - else - ## setup one bootable partition - # 1. n= new disk - # 2. p= primary disk - # 3. 1= first partition - # 4. ''= default sector start - # 5. ''= defaul sector end - # 6. a= bootable flag - # 7. 1= boot flag for partition 1 - # 8. n= new disk - #10. p= primary disk - #11. 2= second partition - #12. ''= default sector start - #13. ''= defaul sector end - #14. w= write/quit - fdisk ${HDD} &> /dev/null << EOF -n -p -1 - -+50M -a -1 -n -p -2 + fi + if [[ -n ${SWAPHDD} ]] + then + # p= primary disk + partition_type="p" + if [[ -n ${BOOTHDD} ]] + then + # boot disk exist, partition 2 + partition_number="2" + else + # boot disk does not exist, partition 1 + partition_number="1" + fi + if [[ ${FDISKPARTIONBELOW256MB} = 1 ]] + then + # fake sector 2 and fdisk finds the next free sector which must be selected with enter + partition_start_sector="2 +" + else + # '' use default sector start + partition_start_sector="" + fi + partition_start_sector="" + # +2G disk size + partition_size="+2G" + + # create a swap disk with 2GB size + PARTITION_OPTS="n +${partition_type} +${partition_number} +${partition_start_sector} +${partition_size} +w" + # create the disk + auto_partition_command + + # mark disk as swap space + PARTITION_OPTS=" +t" + if [[ ${partition_number} != 1 ]] + then + PARTITION_OPTS+=" +${partition_number}" + fi + PARTITION_OPTS+=" +82 +w" + auto_partition_command + fi -w -EOF + if [[ -n ${ROOTHDD} ]] + then + # p= primary disk + partition_type="p" + if [[ -z ${BOOTHDD} ]] && [[ -z ${SWAPHDD} ]] + then + # boot and swap disk does not exist, partition 1 + partition_number="1" + fi + if [[ -n ${BOOTHDD} ]] || [[ -n ${SWAPHDD} ]] + then + # boot or swap disk exist, partition 2 + partition_number="2" + fi + if [[ -n ${BOOTHDD} ]] && [[ -n ${SWAPHDD} ]] + then + # boot and swap disk does exist, partition 3 + partition_number="3" fi - else if [[ ${FDISKPARTIONBELOW256MB} = 1 ]] then - ## setup one bootable partition - #1. n= new disk - #2. p= primary disk - #3. 1= first partition - #4. 2= default sector start // small disk needs more space for grub2 mbr sector - #5. ''= defaul sector end - #6. a= bootable flag - #7. 1= boot flag for partition 1 - #8. w= write/quit - fdisk ${HDD} &> /dev/null << EOF -n -p -1 -2 - -a -1 -w -EOF + if [[ -z ${BOOTHDD} ]] + then + # 2= default sector start // small disk needs more space for grub2 mbr sector + partition_start_sector="2" + else + # fake sector 2 and fdisk finds the next free sector which must be selected with enter + partition_start_sector="2 +" + fi else - ## setup one bootable partition - #1. n= new disk - #2. p= primary disk - #3. 1= first partition - #4. ''= default sector start - #5. ''= defaul sector end - #6. a= bootable flag - #7. 1= boot flag for partition 1 - #8. w= write/quit - fdisk ${HDD} &> /dev/null << EOF -n -p -1 - - -a -1 -w -EOF + # '' use default sector start + partition_start_sector="" + fi + # '' default sector end + partition_size="" + + # create system disk with remaining space + # w= write/quit + PARTITION_OPTS="n +${partition_type} +${partition_number} +${partition_start_sector} +${partition_size} +w" + # create the disk + auto_partition_command + + # no boot disk? then this is the boot disk + if [[ -z ${BOOTHDD} ]] + then + # mark the disk bootable + PARTITION_OPTS="a +${partition_number} +w" + auto_partition_command fi fi else