Skip to content

Commit

Permalink
Add partition preservation
Browse files Browse the repository at this point in the history
Add --save-partlabel <glob> and --save-partindex <range> options, which
save partition table metadata for existing data partitions and then
restore those partitions after writing the image.  --save-partlabel
takes a glob pattern matching the partition label, and --save-partindex
takes a partition number or range of partition numbers (possibly
single-ended).  For example, to save all partitions with indexes greater
than 4, specify "--save-partindex 5-".  The specified partitions need not
exist.  If no --save-* options are specified, no partitions are saved.

Multiples of each option can be specified, and/or multiple filters can
be specified within a single option argument by separating them with
commas.  There are corresponding kargs coreos.inst.save_partlabel and
coreos.inst.save_partindex, which cannot be repeated but which accept
comma-separated patterns.

Upon restore, try to reuse the original partition number.  If it's not
available, renumber the partition to one more than the highest number
used so far.  For simplicity, never backfill entries earlier in the
partition table, even if the corresponding slot is unused.

If a saved partition overlaps with the image contents, fail.  This can't
be detected in advance, so detect the overrun during fetch and stop
before the saved partition is clobbered.  Also fail if the install image
has a partition extending past the end of the image that overlaps with a
saved partition.

On any failure, after clearing the partition table, restore any saved
partitions.  In addition, augment partition-table clearing to clear the
backup GPT, since some tools may otherwise hallucinate partitions that
were overwritten during the install.

All of this assumes GPT partitioning both in the image and on disk, so
if --save-* options are specified for a DASD target, fail.

Fixes #190.

Co-authored-by: Glenn West <gwest@redhat.com>
  • Loading branch information
bgilbert and glennswest committed Jul 31, 2020
1 parent ae76b86 commit 596e657
Show file tree
Hide file tree
Showing 10 changed files with 897 additions and 22 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Expand Up @@ -36,16 +36,15 @@ required-features = ["rdcore"]
[profile.release]
lto = true

[target.'cfg(target_arch = "s390x")'.dependencies]
gptman = { version = "^0.6", default-features = false }

[dependencies]
bincode = "^1.3"
byte-unit = ">= 3.1.0, < 5.0.0"
clap = "^2.33"
cpio = "^0.2"
error-chain = { version = "^0.12", default-features = false }
flate2 = "^1.0"
glob = "^0.3"
gptman = { version = "^0.6", default-features = false }
hex = "^0.4"
libc = "^0.2"
nix = ">= 0.17, < 0.19"
Expand All @@ -57,6 +56,7 @@ serde = { version = "^1.0", features = ["derive"] }
serde_json = "^1.0"
tempfile = "^3.1"
url = "^2.1"
uuid = { version = "^0.8", features = ["v4"] }
walkdir = "^2.3"
xz2 = "^0.1"

Expand Down
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -107,6 +107,13 @@ line.
CoreOS image is being installed on. Optional; defaults to `metal`.
Normally this should be specified only if installing inside a virtual
machine.
* `coreos.inst.save_partlabel` - Comma-separated labels of partitions to
preserve during the install. Glob-style wildcards are permitted. The
specified partitions need not exist. Optional.
* `coreos.inst.save_partindex` - Comma-separated indexes of partitions to
preserve during the install. Ranges (`m-n`) are permitted, and either `m`
or `n` can be omitted. The specified partitions need not exist.
Optional.
* `coreos.inst.insecure` - Permit the OS image to be unsigned. Optional.
* `coreos.inst.skip_reboot` - Don't reboot after installing. Optional.

Expand Down
2 changes: 2 additions & 0 deletions scripts/coreos-installer-service
Expand Up @@ -89,6 +89,8 @@ fi
copy_arg coreos.inst.image_url --image-url
copy_arg coreos.inst.platform_id --platform
copy_arg coreos.inst.stream --stream
copy_arg coreos.inst.save_partlabel --save-partlabel
copy_arg coreos.inst.save_partindex --save-partindex

# Insecure boolean
if karg_bool coreos.inst.insecure; then
Expand Down

0 comments on commit 596e657

Please sign in to comment.