home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / lib / partman / commit.d / 45format_swap < prev    next >
Encoding:
Text File  |  2009-04-19  |  2.4 KB  |  81 lines

  1. #!/bin/sh
  2.  
  3. . /lib/partman/lib/base.sh
  4.  
  5. for dev in $DEVICES/*; do
  6.     [ -d "$dev" ] || continue
  7.     cd $dev
  8.     partitions=
  9.     open_dialog PARTITIONS
  10.     while { read_line num id size type fs path name; [ "$id" ]; }; do
  11.         [ "$fs" != free ] || continue
  12.         partitions="$partitions $id,$num"
  13.     done
  14.     close_dialog
  15.  
  16.     for part in $partitions; do
  17.         id=${part%,*}
  18.         num=${part#*,}
  19.         [ -f $id/method -a -f $id/format ] || continue
  20.         method=$(cat $id/method)
  21.         if [ "$method" = swap ]; then
  22.             if [ -f $id/formatted ] && \
  23.                [ $id/formatted -nt $id/method ]; then
  24.                 continue
  25.             fi
  26.             log "Try to format swap space in $dev/$id"
  27.             template=partman-basicfilesystems/progress_swap_formatting
  28.             open_dialog PARTITION_INFO $id
  29.             read_line x1 x2 x3 x4 x5 device x6
  30.             close_dialog
  31.             rm -f $id/old_uuid
  32.             if [ -f $id/detected_filesystem ]; then
  33.                 old_fs=$(cat $id/detected_filesystem)
  34.                 if [ "$old_fs" = linux-swap ]; then
  35.                     # Save the old UUID so that we can restore it later.
  36.                     dd if=$device of=$id/old_uuid bs=1 skip=1036 count=16 2>/dev/null || true
  37.                 fi
  38.             fi
  39.             db_subst $template PARTITION "$num"
  40.             db_subst $template DEVICE $(humandev $(cat device))
  41.             name_progress_bar $template
  42.             open_dialog CREATE_FILE_SYSTEM $id linux-swap
  43.             read_line status
  44.             close_dialog
  45.             sync
  46.             if [ "$status" != OK ]; then
  47.                 db_progress START 0 3 partman/text/formatting
  48.                 db_progress INFO $template
  49.                 db_progress SET 1
  50.                 # According to Szabolcs Szakacsits, the NTFS-3g author, it is
  51.                 # safer to format the loop file, rather than the device.
  52.                 [ ! -s loop ] || device="$(cat loop)"
  53.                 if log-output -t partman --pass-stdout \
  54.                    mkswap $device >/dev/null; then
  55.                     sync
  56.                     status=OK
  57.                 else
  58.                     status=failed
  59.                 fi
  60.                 db_progress STOP
  61.             fi
  62.  
  63.             if [ "$status" != OK ]; then
  64.                 db_subst partman-basicfilesystems/create_swap_failed TYPE linux-swap
  65.                 db_subst partman-basicfilesystems/create_swap_failed PARTITION "$num"
  66.                 db_subst partman-basicfilesystems/create_swap_failed DEVICE $(humandev $(cat device))
  67.                 db_input critical partman-basicfilesystems/create_swap_failed || true
  68.                 db_go || true
  69.                 exit 1
  70.             fi
  71.             if [ -s "$id/old_uuid" ]; then
  72.                 # Restore the old UUID so that systems using UUIDs in
  73.                 # /etc/fstab don't unexpectedly end up without swap.
  74.                 dd if=$id/old_uuid of=$device bs=1 seek=1036 count=16 conv=notrunc 2>/dev/null || true
  75.             fi
  76.             rm -f $id/old_uuid
  77.             >$id/formatted
  78.         fi
  79.     done
  80. done
  81.