~ubuntu-branches/ubuntu/trusty/cloud-utils/trusty-201404031857

« back to all changes in this revision

Viewing changes to bin/growpart

  • Committer: Scott Moser
  • Date: 2014-04-03 16:30:11 UTC
  • Revision ID: smoser@ubuntu.com-20140403163011-vbjvnapc54hwl069
* sync to trunk at revno 259
  * fix mount-image-callback args --dev, --sys, or --proc (LP: #1302052)
  * ubuntu-ec2-run: know about more instance types
  * growpart: better --dry-run output for gpt disks

Show diffs side-by-side

added added

removed removed

Lines of Context:
374
374
                fail "${dev}: failed to parse sgdisk details"
375
375
 
376
376
        debug 1 "${dev}: code=${code} guid=${guid} name='${name}'"
 
377
        local wouldrun=""
 
378
        [ "$DRY_RUN" -ne 0 ] && wouldrun="would-run"
377
379
 
378
380
        # Calculate the new size of the partition
379
381
        new_size=$((${pt_max} - ${pt_start}))
381
383
        new="new: size=${new_size},end=${pt_max}"
382
384
        change_info="${dev}: start=${pt_start} ${old} ${new}"
383
385
        
384
 
        # Dry run
385
 
        [ "${DRY_RUN}" -ne 0 ] && change "${change_info}"
386
 
 
387
386
        # Backup the current partition table, we're about to modify it
388
 
        rq sgd_backup sgdisk "--backup=${GPT_BACKUP}" "${DISK}" ||
 
387
        rq sgd_backup $wouldrun sgdisk "--backup=${GPT_BACKUP}" "${DISK}" ||
389
388
                fail "${dev}: failed to backup the partition table"
390
389
 
391
390
        # Modify the partition table. We do it all in one go (the order is
396
395
        #  - set the partition code
397
396
        #  - set the partition GUID
398
397
        #  - set the partition name
399
 
        rq sgdisk_mod sgdisk --move-second-header "--delete=${PART}" \
 
398
        rq sgdisk_mod $wouldrun sgdisk --move-second-header "--delete=${PART}" \
400
399
                "--new=${PART}:${pt_start}:${pt_max}" \
401
400
                "--typecode=${PART}:${code}" \
402
401
                "--partition-guid=${PART}:${guid}" \
403
402
                "--change-name=${PART}:${name}" "${DISK}" &&
404
 
                rq pt_update pt_update "$DISK" "$PART" || {
 
403
                rq pt_update $wouldrun pt_update "$DISK" "$PART" || {
405
404
                RESTORE_FUNC=gpt_restore
406
405
                fail "${dev}: failed to repartition"
407
406
        }
408
407
 
 
408
        # Dry run
 
409
        [ "${DRY_RUN}" -ne 0 ] && change "${change_info}"
 
410
 
409
411
        changed "${change_info}"
410
412
}
411
413
 
435
437
        local label="$1" ret="" efile=""
436
438
        efile="$TEMP_D/$label.err"
437
439
        shift;
438
 
        debug 2 "running[$label][$_capture]" "$@"
 
440
 
 
441
        local rlabel="running"
 
442
        [ "$1" = "would-run" ] && rlabel="would-run" && shift
 
443
 
 
444
        local cmd="" x=""
 
445
        for x in "$@"; do
 
446
                [ "${x#* }" != "$x" -o "${x#* \"}" != "$x" ] && x="'$x'"
 
447
                cmd="$cmd $x"
 
448
        done
 
449
        cmd=${cmd# }
 
450
 
 
451
        debug 2 "$rlabel[$label][$_capture]" "$cmd"
 
452
        [ "$rlabel" = "would-run" ] && return 0
 
453
 
439
454
        if [ "${_capture}" = "erronly" ]; then
440
455
                "$@" 2>"$TEMP_D/$label.err"
441
456
                ret=$?