1 commit 13ab06fc005d4e2325ac459032d9a5fbbaa7a383
2 Author: Dobrica Pavlinusic <dpavlin@rot13.org>
3 Date: Thu Oct 4 12:21:51 2018 +0200
5 remove PARTITION_ALIGNMENT and fix 4k block size instance disks
7 Since sfdisk doesn't supprot forced chs geometry any more, in situations
8 where underlaying storage has 4k block, this script will create correct
9 partition table for host, but not for guest which expects 512b blocks.
11 This will make machine unbootable, since once kvm starts partition will
12 be at wrong offset and it won't boot.
14 Solution is to re-create partition table at end using losetup which has
17 Since PARTITION_ALIGNMENT is created using 4k block as base, it will
18 create filesystem at wrong place if you are using default value of 2048.
19 This hard-codes host partition table to 1M (which will work on hosts
20 with both 512b and 4k blocks) and then use 2048 when using 512b blocks.
22 diff --git a/common.sh.in b/common.sh.in
23 index 8caeffc..0029d1e 100644
26 @@ -99,8 +99,9 @@ format_disk0() {
27 if sfdisk --help | fgrep -q -- '--no-reread'; then
28 ARGS="--no-reread $ARGS"
30 + ARGS="--label dos $ARGS"
31 sfdisk $ARGS --quiet "$1" <<EOF
32 -${PARTITION_ALIGNMENT},,L,*
37 @@ -124,6 +125,18 @@ map_disk0() {
42 + if sfdisk --help | fgrep -q -- '--no-reread'; then
43 + ARGS="--no-reread $ARGS"
46 + # loopback device has correct 512b blocks
47 + blockdev=$(losetup --show -f $1)
48 + sfdisk $ARGS --delete "$blockdev"
49 + sfdisk $ARGS --label dos --quiet $blockdev <<EOF
52 + losetup -d $blockdev