Skip to content

Commit

Permalink
remove PARTITION_ALIGNMENT and fix 4k block size instance disks
Browse files Browse the repository at this point in the history
Since sfdisk doesn't supprot forced chs geometry any more, in situations
where underlaying storage has 4k block, this script will create correct
partition table for host, but not for guest which expects 512b blocks.

This will make machine unbootable, since once kvm starts partition will
be at wrong offset and it won't boot.

Solution is to re-create partition table at end using losetup which has
512b blocks.

Since PARTITION_ALIGNMENT is created using 4k block as base, it will
create filesystem at wrong place if you are using default value of 2048.
This hard-codes host partition table to 1M (which will work on hosts
with both 512b and 4k blocks) and then use 2048 when using 512b blocks.
  • Loading branch information
dpavlin committed Oct 6, 2018
1 parent e145396 commit de37352
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions common.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ format_disk0() {
if sfdisk --help | fgrep -q -- '--no-reread'; then
ARGS="--no-reread $ARGS"
fi

ARGS="--label dos $ARGS"
sfdisk $ARGS --quiet "$1" <<EOF
${PARTITION_ALIGNMENT},,L,*
1M,,L,*
EOF
}

Expand All @@ -127,6 +127,18 @@ map_disk0() {

unmap_disk0() {
kpartx -d -p- $1

if sfdisk --help | fgrep -q -- '--no-reread'; then
ARGS="--no-reread $ARGS"
fi

# loopback device has correct 512b blocks
blockdev=$(losetup --show -f $1)
sfdisk $ARGS --delete "$blockdev"
sfdisk $ARGS --label dos --quiet $blockdev <<EOF
2048,,L,*
EOF
losetup -d $blockdev
}

cleanup() {
Expand Down

0 comments on commit de37352

Please sign in to comment.