home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / lib / partman / auto-shared.sh next >
Encoding:
Text File  |  2006-11-23  |  7.0 KB  |  302 lines

  1. ## this file contains a bunch of shared code between partman-auto
  2. ## and partman-auto-lvm.
  3.  
  4. # Wipes any traces of LVM from a disk
  5. # Normally you wouldn't want to use this function, 
  6. # but wipe_disk() which will also call this function.
  7. lvm_wipe_disk() {
  8.     local dev realdev vg pvs pv lv tmpdev restart
  9.     dev="$1"
  10.     cd $dev
  11.  
  12.     if [ ! -e /lib/partman/lvm_tools.sh ]; then
  13.         return 0
  14.     fi
  15.  
  16.     . /lib/partman/lvm_tools.sh
  17.  
  18.     # Check if the device already contains any physical volumes
  19.     realdev=$(mapdevfs "$(cat $dev/device)")
  20.     if ! pv_on_device "$realdev"; then
  21.         return 0
  22.     fi
  23.  
  24.     # Ask for permission to erase LVM volumes 
  25.     db_input critical partman-auto/purge_lvm_from_device
  26.     db_go || return 1
  27.     db_get partman-auto/purge_lvm_from_device
  28.     if [ "$RET" != "true" ]; then
  29.         return 1
  30.     fi
  31.  
  32.     # Check all VG's
  33.     for vg in $(vg_list); do
  34.         pvs=$(vg_list_pvs $vg)
  35.         
  36.         # Only deal with VG's on the selected disk
  37.         if ! $(echo "$pvs" | grep -q "$realdev"); then
  38.             continue
  39.         fi
  40.  
  41.         # Make sure the VG don't span any other disks
  42.         if $(echo -n "$pvs" | grep -q -v "$realdev"); then
  43.             log-output -t partman-auto-lvs vgs
  44.             db_input critical partman-auto/cannot_purge_lvm_from_device || true
  45.             db_go || true
  46.             return 1
  47.         fi
  48.  
  49.         # Remove LV's from the VG
  50.         for lv in $(vg_list_lvs $vg); do
  51.             lv_delete $vg $lv
  52.         done
  53.  
  54.         # Remove the VG and its PV's 
  55.         vg_delete $vg
  56.         for pv in $pvs; do
  57.             pv_delete $pv
  58.         done
  59.     done
  60.  
  61.     # Make sure that parted has no stale LVM info
  62.     restart="0"
  63.     for tmpdev in $DEVICES/*; do
  64.         realdev=$(cat $tmpdev/device)
  65.  
  66.         if ! $(echo "$realdev" | grep -q "/dev/mapper/"); then
  67.             continue
  68.         fi
  69.  
  70.         if [ -b "$realdev" ]; then
  71.             continue
  72.         fi
  73.  
  74.         rm -rf $tmpdev
  75.         restart="1"
  76.     done
  77.  
  78.     if [ $restart ]; then
  79.         stop_parted_server
  80.         restart_partman || return 1
  81.     fi
  82.  
  83.     return 0
  84. }
  85.  
  86. wipe_disk() {
  87.     cd $dev
  88.  
  89.     lvm_wipe_disk "$dev" || return 1
  90.  
  91.     open_dialog LABEL_TYPES
  92.     types=$(read_list)
  93.     close_dialog
  94.  
  95.     label_type=$(default_disk_label)
  96.  
  97.     if ! expr "$types" : ".*${label_type}.*" >/dev/null; then
  98.         label_type=msdos # most widely used
  99.     fi
  100.     
  101.     # Use gpt instead of msdos disklabel for disks larger than 2TB
  102.     if expr "$types" : ".*gpt.*" >/dev/null; then
  103.         if [ "$label_type" = msdos ] ; then
  104.             disksize=$(cat size)
  105.             if $(longint_le $(human2longint 2TB) $disksize) ; then
  106.                 label_type=gpt
  107.             fi
  108.         fi
  109.     fi
  110.  
  111.     if [ "$label_type" = sun ]; then
  112.         db_input critical partman/confirm_write_new_label
  113.         db_go || exit 0
  114.         db_get partman/confirm_write_new_label
  115.         if [ "$RET" = false ]; then
  116.             db_reset partman/confirm_write_new_label
  117.             exit 1
  118.         fi
  119.         db_reset partman/confirm_write_new_label
  120.         # TODO: this is a hack around problems with libparted sanity
  121.         # checks; see changelog for partman-auto 45ubuntu6. This
  122.         # makes sure that the partition label is cleared on Sun
  123.         # disks.
  124.         dddevice=$(cat device)
  125.         log-output -t auto-shared dd if=/dev/zero of=$dddevice bs=512 count=1
  126.     fi
  127.     
  128.     open_dialog NEW_LABEL "$label_type"
  129.     close_dialog
  130.     
  131.     if [ "$label_type" = sun ]; then
  132.         # write the partition table to the disk
  133.         disable_swap
  134.         open_dialog COMMIT
  135.         close_dialog
  136.         sync
  137.         # reread it from there
  138.         open_dialog UNDO
  139.         close_dialog
  140.         enable_swap
  141.     fi
  142.  
  143.     # Different types partition tables support different visuals.  Some
  144.     # have partition names other don't have, some have extended and
  145.     # logical partitions, others don't.  Hence we have to regenerate the
  146.     # list of the visuals
  147.     rm -f visuals
  148.  
  149.     free_space=''
  150.     open_dialog PARTITIONS
  151.     while { read_line num id size type fs path name; [ "$id" ]; }; do
  152.         if [ "$fs" = free ]; then
  153.             free_space=$id
  154.             free_size=$size
  155.             free_type=$type
  156.         fi
  157.     done
  158.     close_dialog
  159. }
  160.  
  161. ### XXXX: i am not 100% sure if this is exactly what this code is doing.
  162. ### XXXX: rename is of course an option. Just remember to do it here, in
  163. ### XXXX: perform_recipe and in partman-auto-lvm
  164. create_primary_partitions() {
  165.  
  166.     cd $dev
  167.  
  168.     while
  169.         [ "$free_type" = pri/log ] \
  170.         && echo $scheme | grep '\$primary{' >/dev/null
  171.     do
  172.         pull_primary
  173.         set -- $primary
  174.         open_dialog NEW_PARTITION primary $4 $free_space beginning ${1}000001
  175.         read_line num id size type fs path name
  176.         close_dialog
  177.         if [ -z "$id" ]; then
  178.         db_progress STOP
  179.         autopartitioning_failed
  180.         fi
  181.         neighbour=$(partition_after $id)
  182.         if [ "$neighbour" ]; then
  183.         open_dialog PARTITION_INFO $neighbour
  184.         read_line x1 new_free_space x2 new_free_type fs x3 x4
  185.         close_dialog
  186.         fi
  187.         if 
  188.         [ -z "$neighbour" -o "$fs" != free \
  189.           -o "$new_free_type" = primary -o "$new_free_type" = unusable ]
  190.         then
  191.         open_dialog DELETE_PARTITION $id
  192.         close_dialog
  193.         open_dialog NEW_PARTITION primary $4 $free_space end ${1}000001
  194.         read_line num id size type fs path name
  195.         close_dialog
  196.         if [ -z "$id" ]; then
  197.             db_progress STOP
  198.             autopartitioning_failed
  199.         fi
  200.         neighbour=$(partition_before $id)
  201.         if [ "$neighbour" ]; then
  202.             open_dialog PARTITION_INFO $neighbour
  203.             read_line x1 new_free_space x2 new_free_type fs x3 x4
  204.             close_dialog
  205.         fi
  206.         if 
  207.             [ -z "$neighbour" -o "$fs" != free -o "$new_free_type" = unusable ]
  208.         then
  209.             open_dialog DELETE_PARTITION $id
  210.             close_dialog
  211.             break
  212.         fi
  213.         fi
  214.         shift; shift; shift; shift
  215.         setup_partition $id $*
  216.         primary=''
  217.         scheme="$logical"
  218.         free_space=$new_free_space
  219.         free_type="$new_free_type"
  220.     done
  221. }
  222.  
  223. create_partitions() {
  224. foreach_partition '
  225.     if [ -z "$free_space" ]; then
  226.         db_progress STOP
  227.     autopartitioning_failed
  228.     fi
  229.     open_dialog PARTITION_INFO $free_space
  230.     read_line x1 free_space x2 free_type fs x3 x4
  231.     close_dialog
  232.     if [ "$fs" != free ]; then
  233.         free_type=unusable
  234.     fi
  235.     case "$free_type" in
  236.     primary|logical)
  237.         type="$free_type"
  238.         ;;
  239.     pri/log)
  240.         type=logical
  241.         ;;
  242.     unusable)
  243.             db_progress STOP
  244.         autopartitioning_failed
  245.         ;;
  246.     esac
  247.     if [ "$last" = yes ]; then
  248.         open_dialog NEW_PARTITION $type $4 $free_space full ${1}000001
  249.     else
  250.         open_dialog NEW_PARTITION $type $4 $free_space beginning ${1}000001
  251.     fi
  252.     read_line num id size type fs path name
  253.     close_dialog
  254.     if [ -z "$id" ]; then
  255.         db_progress STOP
  256.     autopartitioning_failed
  257.     fi
  258.     # Mark the partition LVM only if it is actually LVM and add it to vgpath
  259.     if echo "$*" | grep -q "method{ lvm }"; then
  260.     devfspv_devices="$devfspv_devices $path"
  261.     open_dialog GET_FLAGS $id
  262.     flags=$(read_paragraph)
  263.     close_dialog
  264.     open_dialog SET_FLAGS $id
  265.     write_line "$flags"
  266.     write_line lvm
  267.     write_line NO_MORE
  268.     close_dialog
  269.     fi
  270.     shift; shift; shift; shift
  271.     setup_partition $id $*
  272.     free_space=$(partition_after $id)'
  273. }
  274.  
  275. get_auto_disks() {
  276.     local dev device
  277.  
  278.     for dev in $DEVICES/*; do
  279.         [ -d "$dev" ] || continue
  280.  
  281.         # Skip /dev/mapper/X and /dev/mdX devices
  282.         device=$(cat $dev/device)
  283.         $(echo "$device" | grep -q "/dev/md[0-9]*$") && continue
  284.         $(echo "$device" | grep -q "/dev/mapper/") && continue
  285.  
  286.         printf "$dev\t$(device_name $dev)\n"
  287.     done
  288. }
  289.  
  290. select_auto_disk() {
  291.     local DEVS
  292.  
  293.     DEVS=$(get_auto_disks)
  294.     [ -n "$DEVS" ] || return 1
  295.     debconf_select critical partman-auto/select_disk "$DEVS" "" || return 1
  296.     echo "$RET"
  297.     return 0
  298. }
  299.  
  300. # TODO: Add a select_auto_disks() function
  301. # Note: This needs a debconf_multiselect equiv.
  302.