16
16
17
17
set -e -u -C
18
18
19
+ base_image=fedora-41
20
+
21
+ # The array below open-codes the partition:filesystem layout of the
22
+ # virt-builder disk template used above. Whenever you bump the Fedora
23
+ # version, update the array below as needed.
24
+ #
25
+ # We cannot use inspection either before or after the filesystem UUID
26
+ # changes:
27
+ #
28
+ # - the UUID of a mounted filesystem cannot be changed (at least with
29
+ # - XFS);
30
+ #
31
+ # - right after the UUID changes, inspection does not work correctly,
32
+ # as the new fs UUIDs are out of sync with the UUID references in
33
+ # those config files that inspection relies upon.
34
+ #
35
+ # Note that the order of entries is important too: the mount points
36
+ # must be listed in dependency order (put the dependees first, the
37
+ # dependants last).
38
+ fsdevs=(/dev/sda3:/ /dev/sda2:/boot)
39
+
19
40
GUESTFISH_PID=
20
41
disk=
21
42
@@ -39,41 +60,26 @@ outdir=$(dirname -- "$output")
39
60
disk=$( mktemp -p " $outdir " physical-machine.tmp.XXXXXXXXXX)
40
61
# Delay the SELinux relabeling.
41
62
virt-builder --format raw -o " $disk " --root-password password:p2v-phys \
42
- --no-selinux-relabel fedora-39
63
+ --no-selinux-relabel $base_image
43
64
44
- # Start a guestfish server on the disk image, so that each of the several
45
- # UUID-manipulation commands below not need a separate guestfish launch.
65
+ # Start a guestfish server on the disk image, so that each of the
66
+ # several UUID-manipulation commands below not need a separate
67
+ # guestfish launch.
46
68
guestfish_set_pid=$( guestfish --listen --format=raw --add " $disk " )
47
69
eval " $guestfish_set_pid "
48
70
guestfish --remote -- run
49
71
50
- # The array below open-codes the partition:filesystem layout of the virt-builder
51
- # disk template used above. Whenever you bump the Fedora version, update the
52
- # array below as needed.
53
- #
54
- # We cannot use inspection either before or after the filesystem UUID changes:
55
- #
56
- # - the UUID of a mounted filesystem cannot be changed (at least with XFS);
57
- #
58
- # - right after the UUID changes, inspection does not work correctly, as the new
59
- # fs UUIDs are out of sync with the UUID references in those config files that
60
- # inspection relies upon.
61
- #
62
- # Note that the order of entries is important too: the mount points must be
63
- # listed in dependency order (put the dependees first, the dependants last).
64
- fsdevs=(/dev/sda3:/ /dev/sda2:/boot)
65
-
66
72
# For each filesystem:
67
73
#
68
74
# - regenerate the UUID,
69
75
#
70
- # - produce a sed command (scriptlet) that performs the same UUID replacement in
71
- # a text file,
76
+ # - produce a sed command (scriptlet) that performs the same UUID
77
+ # replacement in a text file,
72
78
#
73
79
# - mount the filesystem.
74
80
#
75
- # Note that later we're going to rely on the fact that the generated sed
76
- # commands *require no quoting* on the shell command line.
81
+ # Note that later we're going to rely on the fact that the generated
82
+ # sed commands *require no quoting* on the shell command line.
77
83
declare -a sed_script
78
84
sed_idx=0
79
85
for fsdev in " ${fsdevs[@]} " ; do
94
100
refresh_uuid_refs=(find /boot /etc -type f -print0 ' |'
95
101
xargs -0 -r -- sed -i " ${sed_script[@]} " --)
96
102
97
- # Passing the shell command to the appliance is where we rely on the fact that
98
- # the sed commands for replacing UUIDs require no quoting.
103
+ # Passing the shell command to the appliance is where we rely on the
104
+ # fact that the sed commands for replacing UUIDs require no quoting.
99
105
guestfish --remote -- sh " ${refresh_uuid_refs[*]} "
100
106
101
107
# Tear down the guestfish server before we use virt-customize.
@@ -106,12 +112,14 @@ while kill -s 0 -- "$waitpid" 2>/dev/null; do
106
112
sleep 1
107
113
done
108
114
109
- # Reapply the SELinux labels now. Use virt-customize for this, rather than
110
- # guestfish's "selinux-relabel", as virt-customize contains some heavy logic
111
- # related to "specfile". Inspection does work here, because the config files are
112
- # in sync again with the filesystem UUIDs.
115
+ # Reapply the SELinux labels now. Use virt-customize for this, rather
116
+ # than guestfish's "selinux-relabel", as virt-customize contains some
117
+ # heavy logic related to "specfile". Inspection does work here,
118
+ # because the config files are in sync again with the filesystem
119
+ # UUIDs.
113
120
virt-customize --format raw --add " $disk " --selinux-relabel
114
121
115
- # We're done; rename the temporary disk image to the expected output file.
122
+ # We're done; rename the temporary disk image to the expected output
123
+ # file.
116
124
mv -- " $disk " " $output "
117
125
disk=
0 commit comments