Erasing GPT backup header block, if expr is good enough

This commit is contained in:
Thomas Schmitt 2020-01-07 16:47:41 +01:00
parent 43d5804db3
commit 5a335e5594
4 changed files with 123 additions and 50 deletions

View File

@ -15,7 +15,7 @@
# announces.
xdt_print_version() {
echo "xorriso-dd-target , version 1.5.3 , 2020.01.06.204949"
echo "xorriso-dd-target , version 1.5.3 , 2020.01.07.123808"
}
@ -225,6 +225,10 @@ xdt_reset_job() {
xdt_sudo_cmd=
xdt_have_su_power=
xdt_end_after_setup=
xdt_dev_bytes=
xdt_dev_end=
xdt_dd_bs="bs=1M"
xdt_dd_silent=
return 0
}
@ -350,7 +354,9 @@ xdt_arg_interpreter() {
done
xdt_predict_su_power || return "$?"
# Prepare for using dd pacifier if desired and available
# Prepare for using silent dd with GPT backup erasure if available
xdt_dd_bs="bs=1M"
xdt_dd_silent=
if test -n "$xdt_dd_cmd"
then
if test -z "$xdt_no_pacifier" && \
@ -359,6 +365,11 @@ xdt_arg_interpreter() {
then
xdt_dd_bs="bs=1M status=progress oflag=dsync"
fi
if "$xdt_dd_cmd" if=/dev/zero of=/dev/null count=1 bs=512 status=none \
2>/dev/null
then
xdt_dd_silent="status=none"
fi
fi
return 0
}
@ -615,8 +626,8 @@ xdt_list_devices() {
# Optional tests for size
if test -n "$xdt_max_size" || test -n "$xdt_min_size"
then
xdt_size=$("$xdt_lsblk_cmd" -n -b -o SIZE /dev/"$xdt_name" \
| head -1 | xdt_round_down_div_million)
xdt_dev_bytes=$("$xdt_lsblk_cmd" -n -b -o SIZE /dev/"$xdt_name" | head -1)
xdt_size=$(echo "$xdt_dev_bytes" | xdt_round_down_div_million)
if test -z "$xdt_size"
then
xdt_yucky=y
@ -752,12 +763,37 @@ xdt_write_image() {
echo "No executable program dd found in: $xdt_sudo_x_dir_list" >&2
return 6
fi
# Erase possible GPT backup table at end of device
# if expr can properly divide device size by 512
if test -n "$xdt_dev_bytes"
then
xdt_dev_end=$(expr "$xdt_dev_bytes" / 512 2>/dev/null)
if test "$(expr "$xdt_dev_end" '*' 512 2>/dev/null)" = "$xdt_dev_bytes"
then
xdt_dev_end=$(expr "$xdt_dev_end" - 1)
else
xdt_dev_end=
fi
fi
xdt_gpt_erase_line="$xdt_sudo_cmd $xdt_dd_cmd if=/dev/zero of=/dev/'${2}' bs=512 seek='$xdt_dev_end' count=1 $xdt_dd_silent"
xdt_copy_line="$xdt_sudo_cmd $xdt_dd_cmd if='${1}' of=/dev/'${2}' $xdt_dd_bs ; sync"
if test -n "$xdt_dummy_run"
then
echo " $xdt_sudo_cmd $xdt_dd_cmd if='${1}' of=/dev/'${2}' $xdt_dd_bs ; sync"
if test -n "$xdt_dev_end"
then
echo " $xdt_gpt_erase_line"
fi
echo " $xdt_copy_line"
else
echo "Performing:"
echo " $xdt_sudo_cmd $xdt_dd_cmd if='${1}' of=/dev/'${2}' $xdt_dd_bs ; sync"
if test -n "$xdt_dev_end"
then
echo " $xdt_gpt_erase_line"
$xdt_sudo_cmd "$xdt_dd_cmd" if=/dev/zero of=/dev/"${2}" bs=512 seek="$xdt_dev_end" count=1 $xdt_dd_silent
fi
echo " $xdt_copy_line"
$xdt_sudo_cmd "$xdt_dd_cmd" if="${1}" of=/dev/"${2}" $xdt_dd_bs
xdt_ret="$?"
sync
@ -768,8 +804,6 @@ xdt_write_image() {
fi
fi
# >>> ??? Erase possible GPT backup table at end of device ?
if test -n "$xdt_dummy_force"
then
echo "BE SMART. BE CAUTIOUS. BEWARE."

View File

@ -9,7 +9,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH XORRISO-DD-TARGET 1 "Version 1.5.3, Jan 6, 2020"
.TH XORRISO-DD-TARGET 1 "Version 1.5.3, Jan 7, 2020"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -48,7 +48,7 @@ If a single plausible candidate is detected, then the program is willing to
copy a disk image file onto it. This will overwrite or make inaccessible the
previous partition table and all previous data content of the target device.
.br
\fBSuperuser power\fR is normally needed for filesystem type identification,
\fBSuperuser power\fR is often needed for filesystem type identification,
for possible unmounting, and for possible image writing.
Option \fB\-with_sudo\fR offers a way to gain this power only for those
tasks and to run the program elsewise with a normal user's power.
@ -173,13 +173,14 @@ sdc : NO : usb+ no_fs_while_not_su\-
Option \fB\-plug_test\fR triggers an interactive method to unambiguously
determine the intended target device candidate. It consists of 2 or 3 steps.
.br
\fBStep 1\fR is to have the intended storage device unplugged and
\fBStep 1\fR is to have the intended storage device \fBunplugged\fR and
to confirm this by pressing the Enter key at the program's prompt. The program
will then assess the list of not wanted devices.
.br
\fBStep 2\fR is to plug in the intended storage device and to confirm this
by pressing the Enter key a second time. The program will wait up to 10 seconds
for a disk\-like storage device which is not in the list of not wanted devices.
\fBStep 2\fR is to \fBplug in\fR the intended storage device and to
confirm this by pressing the Enter key a second time. The program will wait
up to 10 seconds for a disk\-like storage device which is not in the list of
not wanted devices.
The user may wait with key pressing until the device blinking looks like it
is ready.
.br
@ -270,9 +271,18 @@ Unmounted: /dev/sde2
.br
Performing:
.br
sudo /bin/dd if='debian\-live\-10.0.0\-amd64\-xfce.iso' of=/dev/sde bs=1M status=progress oflag=dsync ; sync
sudo /bin/dd if=/dev/zero of=/dev/'sde' bs=512 seek='245759999'
.br
count=1 status=none
.br
sudo /bin/dd if='debian\-live\-10.0.0\-amd64\-xfce.iso' of=/dev/'sde'
.br
bs=1M status=progress oflag=dsync ; sync
.br
... dd messages ...
.br
The first dd run shall erase a possible GPT backup header. It is performed only
if the local program "expr" can deal with the byte size of the device.
.SS
\fBShow commands for writing to a not advised device:\fR
.br
@ -326,7 +336,13 @@ AGAINST THE ADVICE BY THIS PROGRAM, a daring user could do:
.br
sudo /bin/umount /dev/sdd3
.br
sudo /bin/dd if='debian\-live\-10.0.0\-amd64\-xfce.iso' of=/dev/sdd bs=1M status=progress oflag=dsync ; sync
sudo /bin/dd if=/dev/zero of=/dev/'sdd' bs=512 seek='7864318'
.br
count=1 status=none
.br
sudo /bin/dd if='debian\-live\-10.0.0\-amd64\-xfce.iso' of=/dev/sdd
.br
bs=1M status=progress oflag=dsync ; sync
.br
BE SMART. BE CAUTIOUS. BEWARE.
.SS
@ -538,7 +554,7 @@ Thomas Schmitt <scdbackup@gmx.net>
.br
for libburnia\-project.org
.SH COPYRIGHT
Copyright (c) 2019 Thomas Schmitt
Copyright (c) 2019 \- 2020 Thomas Schmitt
.br
Permission is granted to distribute this text freely. It shall only be
modified in sync with the technical properties of xorriso\-dd\-target.

View File

@ -50,7 +50,7 @@ If a single plausible candidate is detected, then the program is willing
to copy a disk image file onto it. This will overwrite or make
inaccessible the previous partition table and all previous data content
of the target device.
*Superuser power* is normally needed for filesystem type identification,
*Superuser power* is often needed for filesystem type identification,
for possible unmounting, and for possible image writing. Option
*-with_sudo* offers a way to gain this power only for those tasks and to
run the program elsewise with a normal user's power.
@ -157,10 +157,10 @@ File: xorriso-dd-target.info, Node: Plugtest, Next: Dowrite, Prev: Givendevic
Option *-plug_test* triggers an interactive method to unambiguously
determine the intended target device candidate. It consists of 2 or 3
steps.
*Step 1* is to have the intended storage device unplugged and to confirm
this by pressing the Enter key at the program's prompt. The program
will then assess the list of not wanted devices.
*Step 2* is to plug in the intended storage device and to confirm this
*Step 1* is to have the intended storage device *unplugged* and to
confirm this by pressing the Enter key at the program's prompt. The
program will then assess the list of not wanted devices.
*Step 2* is to *plug in* the intended storage device and to confirm this
by pressing the Enter key a second time. The program will wait up to 10
seconds for a disk-like storage device which is not in the list of not
wanted devices. The user may wait with key pressing until the device
@ -224,9 +224,14 @@ Looking for mount points of sde:
Unmounted: /dev/sde1
Unmounted: /dev/sde2
Performing:
sudo /bin/dd if='debian-live-10.0.0-amd64-xfce.iso' of=/dev/sde bs=1M
status=progress oflag=dsync ; sync
sudo /bin/dd if=/dev/zero of=/dev/'sde' bs=512 seek='245759999'
count=1 status=none
sudo /bin/dd if='debian-live-10.0.0-amd64-xfce.iso' of=/dev/'sde'
bs=1M status=progress oflag=dsync ; sync
... dd messages ...
The first dd run shall erase a possible GPT backup header. It is
performed only if the local program "expr" can deal with the byte size
of the device.

File: xorriso-dd-target.info, Node: Unwise, Next: Reasons, Prev: Dowrite, Up: Overview
@ -263,8 +268,10 @@ AGAINST THE ADVICE BY THIS PROGRAM, a daring user could do:
sudo /bin/umount /dev/sdd1
sudo /bin/umount /dev/sdd2
sudo /bin/umount /dev/sdd3
sudo /bin/dd if='debian-live-10.0.0-amd64-xfce.iso' of=/dev/sdd bs=1M
status=progress oflag=dsync ; sync
sudo /bin/dd if=/dev/zero of=/dev/'sdd' bs=512 seek='7864318'
count=1 status=none
sudo /bin/dd if='debian-live-10.0.0-amd64-xfce.iso' of=/dev/sdd
bs=1M status=progress oflag=dsync ; sync
BE SMART. BE CAUTIOUS. BEWARE.

@ -462,7 +469,7 @@ for libburnia-project.org
14.2 Copyright
==============
Copyright (c) 2019 Thomas Schmitt
Copyright (c) 2019 - 2020 Thomas Schmitt
Permission is granted to distribute this text freely. It shall only be
modified in sync with the technical properties of xorriso-dd-target. If
you make use of the license to derive modified versions of
@ -541,20 +548,20 @@ File: xorriso-dd-target.info, Node: ConceptIdx, Next: Top, Prev: CommandIdx,
Tag Table:
Node: Top429
Node: Overview996
Node: Simplenames2792
Node: Listall3516
Node: Givendevices5089
Node: Plugtest6053
Node: Dowrite7954
Node: Unwise9097
Node: Reasons10637
Node: Options13218
Node: Examples16315
Node: Files16488
Node: Seealso16646
Node: Bugreport16812
Node: Legal17399
Node: CommandIdx18103
Node: ConceptIdx19369
Node: Simplenames2789
Node: Listall3513
Node: Givendevices5086
Node: Plugtest6050
Node: Dowrite7955
Node: Unwise9336
Node: Reasons10958
Node: Options13539
Node: Examples16636
Node: Files16809
Node: Seealso16967
Node: Bugreport17133
Node: Legal17720
Node: CommandIdx18431
Node: ConceptIdx19697

End Tag Table

View File

@ -50,7 +50,7 @@
@c man .\" First parameter, NAME, should be all caps
@c man .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
@c man .\" other parameters are allowed: see man(7), man(1)
@c man .TH XORRISO-DD-TARGET 1 "Version 1.5.3, Jan 6, 2020"
@c man .TH XORRISO-DD-TARGET 1 "Version 1.5.3, Jan 7, 2020"
@c man .\" Please adjust this date whenever revising the manpage.
@c man .\"
@c man .\" Some roff macros, for reference:
@ -128,7 +128,7 @@ If a single plausible candidate is detected, then the program is willing to
copy a disk image file onto it. This will overwrite or make inaccessible the
previous partition table and all previous data content of the target device.
@*
@strong{Superuser power} is normally needed for filesystem type identification,
@strong{Superuser power} is often needed for filesystem type identification,
for possible unmounting, and for possible image writing.
Option @strong{-with_sudo} offers a way to gain this power only for those
tasks and to run the program elsewise with a normal user's power.
@ -275,13 +275,14 @@ sdc : NO : usb+ no_fs_while_not_su-
Option @strong{-plug_test} triggers an interactive method to unambiguously
determine the intended target device candidate. It consists of 2 or 3 steps.
@*
@strong{Step 1} is to have the intended storage device unplugged and
@strong{Step 1} is to have the intended storage device @strong{unplugged} and
to confirm this by pressing the Enter key at the program's prompt. The program
will then assess the list of not wanted devices.
@*
@strong{Step 2} is to plug in the intended storage device and to confirm this
by pressing the Enter key a second time. The program will wait up to 10 seconds
for a disk-like storage device which is not in the list of not wanted devices.
@strong{Step 2} is to @strong{plug in} the intended storage device and to
confirm this by pressing the Enter key a second time. The program will wait
up to 10 seconds for a disk-like storage device which is not in the list of
not wanted devices.
The user may wait with key pressing until the device blinking looks like it
is ready.
@*
@ -375,9 +376,18 @@ Unmounted: /dev/sde2
@*
Performing:
@*
sudo /bin/dd if='debian-live-10.0.0-amd64-xfce.iso' of=/dev/sde bs=1M status=progress oflag=dsync ; sync
sudo /bin/dd if=/dev/zero of=/dev/'sde' bs=512 seek='245759999'
@*
count=1 status=none
@*
sudo /bin/dd if='debian-live-10.0.0-amd64-xfce.iso' of=/dev/'sde'
@*
bs=1M status=progress oflag=dsync ; sync
@*
... dd messages ...
@*
The first dd run shall erase a possible GPT backup header. It is performed only
if the local program "expr" can deal with the byte size of the device.
@c man .SS
@node Unwise, Reasons, Dowrite, Overview
@chapter Show commands for writing to a not advised device
@ -434,7 +444,13 @@ AGAINST THE ADVICE BY THIS PROGRAM, a daring user could do:
@*
sudo /bin/umount /dev/sdd3
@*
sudo /bin/dd if='debian-live-10.0.0-amd64-xfce.iso' of=/dev/sdd bs=1M status=progress oflag=dsync ; sync
sudo /bin/dd if=/dev/zero of=/dev/'sdd' bs=512 seek='7864318'
@*
count=1 status=none
@*
sudo /bin/dd if='debian-live-10.0.0-amd64-xfce.iso' of=/dev/sdd
@*
bs=1M status=progress oflag=dsync ; sync
@*
BE SMART. BE CAUTIOUS. BEWARE.
@c man .SS
@ -704,7 +720,7 @@ Thomas Schmitt <scdbackup@@gmx.net>
for libburnia-project.org
@c man .SH COPYRIGHT
@section Copyright
Copyright (c) 2019 Thomas Schmitt
Copyright (c) 2019 - 2020 Thomas Schmitt
@*
Permission is granted to distribute this text freely. It shall only be
modified in sync with the technical properties of xorriso-dd-target.