home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / lib / partman / auto-shared.sh next >
Encoding:
Text File  |  2006-07-03  |  4.7 KB  |  188 lines

  1. ## this file contains a bunch of shared code between partman-auto
  2. ## and partman-auto-lvm.
  3.  
  4. wipe_disk() {
  5.     cd $dev
  6.  
  7.     open_dialog LABEL_TYPES
  8.     types=$(read_list)
  9.     close_dialog
  10.  
  11.     label_type=$(default_disk_label)
  12.  
  13.     if ! expr "$types" : ".*${label_type}.*" >/dev/null; then
  14.         label_type=msdos # most widely used
  15.     fi
  16.     
  17.     # Use gpt instead of msdos disklabel for disks larger than 2TB
  18.     if expr "$types" : ".*gpt.*" >/dev/null; then
  19.         if [ "$label_type" = msdos ] ; then
  20.             disksize=$(cat size)
  21.             if $(longint_le $(human2longint 2TB) $disksize) ; then
  22.                 label_type=gpt
  23.             fi
  24.         fi
  25.     fi
  26.  
  27.     if [ "$label_type" = sun ]; then
  28.         db_input critical partman/confirm_write_new_label
  29.         db_go || exit 0
  30.         db_get partman/confirm_write_new_label
  31.         if [ "$RET" = false ]; then
  32.             db_reset partman/confirm_write_new_label
  33.             exit 1
  34.         fi
  35.         db_reset partman/confirm_write_new_label
  36.         # XXX hack of death. This will make sure that the partiton label is cleared
  37.         # and only on sun labels otherwise bad things can happen.
  38.         dddevice=$(cat device)
  39.         log-output -t auto-shared dd if=/dev/zero of=$dddevice bs=512 count=1
  40.     fi
  41.     
  42.     open_dialog NEW_LABEL "$label_type"
  43.     close_dialog
  44.     
  45.     if [ "$label_type" = sun ]; then
  46.         # write the partition table to the disk
  47.         disable_swap
  48.         open_dialog COMMIT
  49.         close_dialog
  50.         sync
  51.         # reread it from there
  52.         open_dialog UNDO
  53.         close_dialog
  54.         enable_swap
  55.     fi
  56.  
  57.     # Different types partition tables support different visuals.  Some
  58.     # have partition names other don't have, some have extended and
  59.     # logical partitions, others don't.  Hence we have to regenerate the
  60.     # list of the visuals
  61.     rm -f visuals
  62.  
  63.     free_space=''
  64.     open_dialog PARTITIONS
  65.     while { read_line num id size type fs path name; [ "$id" ]; }; do
  66.         if [ "$fs" = free ]; then
  67.             free_space=$id
  68.             free_size=$size
  69.             free_type=$type
  70.         fi
  71.     done
  72.     close_dialog
  73. }
  74.  
  75. ### XXXX: i am not 100% sure if this is exactly what this code is doing.
  76. ### XXXX: rename is of course an option. Just remember to do it here, in
  77. ### XXXX: perform_recipe and in partman-auto-lvm
  78. create_primary_partitions() {
  79.  
  80.     cd $dev
  81.  
  82.     while
  83.         [ "$free_type" = pri/log ] \
  84.         && echo $scheme | grep '\$primary{' >/dev/null
  85.     do
  86.         pull_primary
  87.         set -- $primary
  88.         open_dialog NEW_PARTITION primary $4 $free_space beginning ${1}000001
  89.         read_line num id size type fs path name
  90.         close_dialog
  91.         if [ -z "$id" ]; then
  92.         db_progress STOP
  93.         autopartitioning_failed
  94.         fi
  95.         neighbour=$(partition_after $id)
  96.         if [ "$neighbour" ]; then
  97.         open_dialog PARTITION_INFO $neighbour
  98.         read_line x1 new_free_space x2 new_free_type fs x3 x4
  99.         close_dialog
  100.         fi
  101.         if 
  102.         [ -z "$neighbour" -o "$fs" != free \
  103.           -o "$new_free_type" = primary -o "$new_free_type" = unusable ]
  104.         then
  105.         open_dialog DELETE_PARTITION $id
  106.         close_dialog
  107.         open_dialog NEW_PARTITION primary $4 $free_space end ${1}000001
  108.         read_line num id size type fs path name
  109.         close_dialog
  110.         if [ -z "$id" ]; then
  111.             db_progress STOP
  112.             autopartitioning_failed
  113.         fi
  114.         neighbour=$(partition_before $id)
  115.         if [ "$neighbour" ]; then
  116.             open_dialog PARTITION_INFO $neighbour
  117.             read_line x1 new_free_space x2 new_free_type fs x3 x4
  118.             close_dialog
  119.         fi
  120.         if 
  121.             [ -z "$neighbour" -o "$fs" != free -o "$new_free_type" = unusable ]
  122.         then
  123.             open_dialog DELETE_PARTITION $id
  124.             close_dialog
  125.             break
  126.         fi
  127.         fi
  128.         shift; shift; shift; shift
  129.         setup_partition $id $*
  130.         primary=''
  131.         scheme="$logical"
  132.         free_space=$new_free_space
  133.         free_type="$new_free_type"
  134.     done
  135. }
  136.  
  137. create_partitions() {
  138. foreach_partition '
  139.     if [ -z "$free_space" ]; then
  140.         db_progress STOP
  141.     autopartitioning_failed
  142.     fi
  143.     open_dialog PARTITION_INFO $free_space
  144.     read_line x1 free_space x2 free_type fs x3 x4
  145.     close_dialog
  146.     if [ "$fs" != free ]; then
  147.         free_type=unusable
  148.     fi
  149.     case "$free_type" in
  150.     primary|logical)
  151.         type="$free_type"
  152.         ;;
  153.     pri/log)
  154.         type=logical
  155.         ;;
  156.     unusable)
  157.             db_progress STOP
  158.         autopartitioning_failed
  159.         ;;
  160.     esac
  161.     if [ "$last" = yes ]; then
  162.         open_dialog NEW_PARTITION $type $4 $free_space full ${1}000001
  163.     else
  164.         open_dialog NEW_PARTITION $type $4 $free_space beginning ${1}000001
  165.     fi
  166.     read_line num id size type fs path name
  167.     close_dialog
  168.     if [ -z "$id" ]; then
  169.         db_progress STOP
  170.     autopartitioning_failed
  171.     fi
  172.     # Mark the partition LVM only if it is actually LVM and add it to vgpath
  173.     if echo "$*" | grep -q "method{ lvm }"; then
  174.     devfspv_devices="$devfspv_devices $path"
  175.     open_dialog GET_FLAGS $id
  176.     flags=$(read_paragraph)
  177.     close_dialog
  178.     open_dialog SET_FLAGS $id
  179.     write_line "$flags"
  180.     write_line lvm
  181.     write_line NO_MORE
  182.     close_dialog
  183.     fi
  184.     shift; shift; shift; shift
  185.     setup_partition $id $*
  186.     free_space=$(partition_after $id)'
  187. }
  188.