Revision 42f09a19
b/snf-image-helper/common.sh | ||
---|---|---|
35 | 35 |
# Programs |
36 | 36 |
XMLSTARLET=xmlstarlet |
37 | 37 |
RESIZE2FS=resize2fs |
38 |
PARTED=parted |
|
38 | 39 |
|
39 | 40 |
CLEANUP=( ) |
40 | 41 |
|
... | ... | |
92 | 93 |
fi |
93 | 94 |
} |
94 | 95 |
|
96 |
get_last_partition() { |
|
97 |
local dev="$1" |
|
98 |
|
|
99 |
"$PARTED" -s -m "$dev" unit s print | tail -1 |
|
100 |
} |
|
101 |
|
|
102 |
get_partition() { |
|
103 |
local dev="$1" |
|
104 |
local id="$2" |
|
105 |
|
|
106 |
"$PARTED" -s -m "$dev" unit s print | grep "^$id" |
|
107 |
} |
|
108 |
|
|
109 |
get_partition_count() { |
|
110 |
local dev="$1" |
|
111 |
|
|
112 |
expr $("$PARTED" -s -m "$dev" unit s print | wc -l) - 2 |
|
113 |
} |
|
114 |
|
|
115 |
get_last_free_sector() { |
|
116 |
local dev="$1" |
|
117 |
local last_line=$("$PARTED" -s -m "$dev" unit s print free | tail -1) |
|
118 |
local type=$(echo "$last_line" | cut -d: -f 5) |
|
119 |
|
|
120 |
if [ "$type" = "free;" ]; then |
|
121 |
echo "$last_line" | cut -d: -f 3 |
|
122 |
fi |
|
123 |
} |
|
124 |
|
|
95 | 125 |
cleanup() { |
96 | 126 |
# if something fails here, it shouldn't call cleanup again... |
97 | 127 |
trap - EXIT |
b/snf-image-helper/snf-image-helper.in | ||
---|---|---|
64 | 64 |
add_cleanup rmdir "$target" |
65 | 65 |
|
66 | 66 |
export SNF_IMAGE_TARGET="$target" |
67 |
export SNF_IMAGE_ROOTDEV="${SNF_IMAGE_DEV}${SNF_IMAGE_ROOT}" |
|
67 | 68 |
|
68 | 69 |
if [ ! -d "@tasksdir@" ]; then |
69 | 70 |
log_error "snf-image/tasks directory is missing" |
b/snf-image-helper/tasks/10FixPartitionTable.in | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: FixPartitionTable |
|
5 |
# RunBefore: FilesystemResizeUnmounted |
|
6 |
# Short-Description: Resize filesystem to use all the available space |
|
7 |
### END TASK INFO |
|
8 |
|
|
9 |
set -e |
|
10 |
. "@commondir@/common.sh" |
|
11 |
|
|
12 |
if [ ! -b "$SNF_IMAGE_DEV" ]; then |
|
13 |
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device" |
|
14 |
fi |
|
15 |
|
|
16 |
if [ $(get_partition_count "$SNF_IMAGE_DEV") -eq 0 ]; then |
|
17 |
log_error "Device: \`${SNF_IMAGE_DEV}' does not contain any partition" |
|
18 |
fi |
|
19 |
|
|
20 |
retval=$(get_last_partition "$SNF_IMAGE_DEV") |
|
21 |
|
|
22 |
id=$(echo $retval | cut -d: -f1) |
|
23 |
|
|
24 |
if [ $id -gt 4 ]; then |
|
25 |
log_error "We don't support logical volumes" |
|
26 |
fi |
|
27 |
|
|
28 |
pstart=$(echo $retval | cut -d: -f2) |
|
29 |
pend=$(echo $retval | cut -d: -f3) |
|
30 |
ptype=$(echo $retval | cut -d: -f5) |
|
31 |
|
|
32 |
if [ x"$ptype" = "x" ]; then |
|
33 |
# Don't know how to handle this |
|
34 |
echo "Warning: Last partition with id: \`$id' is empty" \ |
|
35 |
"or has unknown filesystem" |
|
36 |
|
|
37 |
exit 0 |
|
38 |
fi |
|
39 |
|
|
40 |
new_pend=$(get_last_free_sector "$SNF_IMAGE_DEV") |
|
41 |
|
|
42 |
#Extend the partition |
|
43 |
|
|
44 |
$PARTED -s -m "$SNF_IMAGE_DEV" rm $id |
|
45 |
$PARTED -s -m "$SNF_IMAGE_DEV" mkpart primary "$ptype" "$pstart" "$new_pend" |
|
46 |
|
|
47 |
#inform the kernel about the changes |
|
48 |
partprobe "$SNF_IMAGE_DEV" |
|
49 |
|
|
50 |
exit 0 |
|
51 |
|
|
52 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: ResizeUnmounted |
|
5 |
# RunBefore: MountImage |
|
6 |
# Short-Description: Resize filesystem to use all the available space |
|
7 |
### END TASK INFO |
|
8 |
|
|
9 |
set -e |
|
10 |
. "@commondir@/common.sh" |
|
11 |
|
|
12 |
if [ ! -b "$SNF_IMAGE_DEV" ]; then |
|
13 |
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device" |
|
14 |
|
|
15 |
fi |
|
16 |
if [ -z "$SNF_IMAGE_TYPE" ]; then |
|
17 |
log_error "Image type does not exist" |
|
18 |
fi |
|
19 |
|
|
20 |
if [ "$SNF_IMAGE_TYPE" = "extdump" ]; then |
|
21 |
"$RESIZE2FS" "$SNF_IMAGE_DEV" |
|
22 |
fi |
|
23 |
|
|
24 |
exit 0 |
|
25 |
|
|
26 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
b/snf-image-helper/tasks/20FilesystemResizeUnmounted.in | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: FilesystemResizeUnmounted |
|
5 |
# RunBefore: MountImage |
|
6 |
# RunAfter: FixPartitionTable |
|
7 |
# Short-Description: Resize filesystem to use all the available space |
|
8 |
### END TASK INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. "@commondir@/common.sh" |
|
12 |
|
|
13 |
if [ ! -b "$SNF_IMAGE_DEV" ]; then |
|
14 |
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device" |
|
15 |
fi |
|
16 |
|
|
17 |
if [ -z "$SNF_IMAGE_TYPE" ]; then |
|
18 |
log_error "Image type does not exist" |
|
19 |
fi |
|
20 |
|
|
21 |
last_partition=$(get_last_partition "$SNF_IMAGE_DEV") |
|
22 |
id=$(echo "$last_partition" | cut -d: -f1) |
|
23 |
ptype=$(echo "$last_partition" | cut -d: -f5) |
|
24 |
|
|
25 |
if [[ "$ptype" =~ ext[234] ]]; then |
|
26 |
device="$SNF_IMAGE_DEV""$id" |
|
27 |
"$RESIZE2FS" "$device" |
|
28 |
fi |
|
29 |
|
|
30 |
exit 0 |
|
31 |
|
|
32 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
b/snf-image-helper/tasks/30MountImage.in | ||
---|---|---|
13 | 13 |
log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing" |
14 | 14 |
fi |
15 | 15 |
|
16 |
if [ ! -b "$SNF_IMAGE_DEV" ]; then |
|
17 |
log_error "Device file:\`$SNF_IMAGE_DEV' is not a block device" |
|
16 |
if [ ! -b "$SNF_IMAGE_ROOTDEV" ]; then
|
|
17 |
log_error "Device file:\`$SNF_IMAGE_ROOTDEV' is not a block device"
|
|
18 | 18 |
fi |
19 | 19 |
|
20 |
mount "$SNF_IMAGE_DEV" "$SNF_IMAGE_TARGET" |
|
20 |
mount "$SNF_IMAGE_ROOTDEV" "$SNF_IMAGE_TARGET"
|
|
21 | 21 |
|
22 | 22 |
exit 0 |
23 | 23 |
|
b/snf-image-helper/tasks/40FilesystemResizeMounted.in | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: FilesystemResizeMounted |
|
5 |
# RunBefore: UmountImage |
|
6 |
# RunAfter: MountImage |
|
7 |
# Short-Description: Resize filesystem to use all the available space |
|
8 |
### END TASK INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. "@commondir@/common.sh" |
|
12 |
|
|
13 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
14 |
log_error "Target directory \`$SNF_IMAGE_TARGET' is missing" |
|
15 |
fi |
|
16 |
|
|
17 |
last_partition=$(get_last_partition "$SNF_IMAGE_DEV") |
|
18 |
id=$(echo "$last_partition" | cut -d: -f1) |
|
19 |
ptype=$(echo "$last_partition" | cut -d: -f5) |
|
20 |
|
|
21 |
if [ "$ptype" = "ntfs" ]; then |
|
22 |
# Write a diskpart script to %SystemDrive%\Windows\SnfScripts. Sysprep will |
|
23 |
# try to execute this script during the specialize pass. |
|
24 |
mkdir -p "$SNF_IMAGE_TARGET/Windows/SnfScripts" |
|
25 |
cat > "$SNF_IMAGE_TARGET/Windows/SnfScripts/ExtendFilesystem" <<EOF |
|
26 |
select disk 0 |
|
27 |
select volume $id |
|
28 |
extend filesystem |
|
29 |
exit |
|
30 |
EOF |
|
31 |
fi |
|
32 |
|
|
33 |
cleanup |
|
34 |
trap - EXIT |
|
35 |
|
|
36 |
exit 0 |
|
37 |
|
|
38 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
/dev/null | ||
---|---|---|
1 |
#! /bin/bash |
|
2 |
|
|
3 |
### BEGIN TASK INFO |
|
4 |
# Provides: ResizeMounted |
|
5 |
# RunBefore: UmountImage |
|
6 |
# RunAfter: MountImage |
|
7 |
# Short-Description: Resize filesystem to use all the available space |
|
8 |
### END TASK INFO |
|
9 |
|
|
10 |
set -e |
|
11 |
. "@commondir@/common.sh" |
|
12 |
|
|
13 |
if [ ! -d "$SNF_IMAGE_TARGET" ]; then |
|
14 |
log_error "Target directory \`$SNF_IMAGE_TARGET' is missing" |
|
15 |
fi |
|
16 |
|
|
17 |
if [ "$SNF_IMAGE_TYPE" = "ntfsdump" ]; then |
|
18 |
# Write a diskpart script to %SystemDrive%\Windows\SnfScripts. Sysprep will |
|
19 |
# try to execute this script during the specialize pass. |
|
20 |
mkdir -p "$SNF_IMAGE_TARGET/Windows/SnfScripts" |
|
21 |
cat > "$SNF_IMAGE_TARGET/Windows/SnfScripts/ExtendFilesystem" <<EOF |
|
22 |
select disk 0 |
|
23 |
select volume 1 |
|
24 |
extend filesystem |
|
25 |
exit |
|
26 |
EOF |
|
27 |
fi |
|
28 |
|
|
29 |
cleanup |
|
30 |
trap - EXIT |
|
31 |
|
|
32 |
exit 0 |
|
33 |
|
|
34 |
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai : |
Also available in: Unified diff