Skip to content
Snippets Groups Projects
Commit 42f09a19 authored by Nikos Skalkotos's avatar Nikos Skalkotos
Browse files

Add diskdump support in the helper (part 1)

parent 39822c89
No related branches found
No related tags found
No related merge requests found
......@@ -35,6 +35,7 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
# Programs
XMLSTARLET=xmlstarlet
RESIZE2FS=resize2fs
PARTED=parted
CLEANUP=( )
......@@ -92,6 +93,35 @@ get_distro() {
fi
}
get_last_partition() {
local dev="$1"
"$PARTED" -s -m "$dev" unit s print | tail -1
}
get_partition() {
local dev="$1"
local id="$2"
"$PARTED" -s -m "$dev" unit s print | grep "^$id"
}
get_partition_count() {
local dev="$1"
expr $("$PARTED" -s -m "$dev" unit s print | wc -l) - 2
}
get_last_free_sector() {
local dev="$1"
local last_line=$("$PARTED" -s -m "$dev" unit s print free | tail -1)
local type=$(echo "$last_line" | cut -d: -f 5)
if [ "$type" = "free;" ]; then
echo "$last_line" | cut -d: -f 3
fi
}
cleanup() {
# if something fails here, it shouldn't call cleanup again...
trap - EXIT
......
......@@ -64,6 +64,7 @@ target=$(mktemp -d --tmpdir target.XXXXXX)
add_cleanup rmdir "$target"
export SNF_IMAGE_TARGET="$target"
export SNF_IMAGE_ROOTDEV="${SNF_IMAGE_DEV}${SNF_IMAGE_ROOT}"
if [ ! -d "@tasksdir@" ]; then
log_error "snf-image/tasks directory is missing"
......
#! /bin/bash
### BEGIN TASK INFO
# Provides: FixPartitionTable
# RunBefore: FilesystemResizeUnmounted
# Short-Description: Resize filesystem to use all the available space
### END TASK INFO
set -e
. "@commondir@/common.sh"
if [ ! -b "$SNF_IMAGE_DEV" ]; then
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device"
fi
if [ $(get_partition_count "$SNF_IMAGE_DEV") -eq 0 ]; then
log_error "Device: \`${SNF_IMAGE_DEV}' does not contain any partition"
fi
retval=$(get_last_partition "$SNF_IMAGE_DEV")
id=$(echo $retval | cut -d: -f1)
if [ $id -gt 4 ]; then
log_error "We don't support logical volumes"
fi
pstart=$(echo $retval | cut -d: -f2)
pend=$(echo $retval | cut -d: -f3)
ptype=$(echo $retval | cut -d: -f5)
if [ x"$ptype" = "x" ]; then
# Don't know how to handle this
echo "Warning: Last partition with id: \`$id' is empty" \
"or has unknown filesystem"
exit 0
fi
new_pend=$(get_last_free_sector "$SNF_IMAGE_DEV")
#Extend the partition
$PARTED -s -m "$SNF_IMAGE_DEV" rm $id
$PARTED -s -m "$SNF_IMAGE_DEV" mkpart primary "$ptype" "$pstart" "$new_pend"
#inform the kernel about the changes
partprobe "$SNF_IMAGE_DEV"
exit 0
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
#! /bin/bash
### BEGIN TASK INFO
# Provides: ResizeUnmounted
# Provides: FilesystemResizeUnmounted
# RunBefore: MountImage
# RunAfter: FixPartitionTable
# Short-Description: Resize filesystem to use all the available space
### END TASK INFO
......@@ -11,15 +12,20 @@ set -e
if [ ! -b "$SNF_IMAGE_DEV" ]; then
log_error "Device file:\`${SNF_IMAGE_DEV}' is not a block device"
fi
if [ -z "$SNF_IMAGE_TYPE" ]; then
log_error "Image type does not exist"
fi
if [ "$SNF_IMAGE_TYPE" = "extdump" ]; then
"$RESIZE2FS" "$SNF_IMAGE_DEV"
fi
last_partition=$(get_last_partition "$SNF_IMAGE_DEV")
id=$(echo "$last_partition" | cut -d: -f1)
ptype=$(echo "$last_partition" | cut -d: -f5)
if [[ "$ptype" =~ ext[234] ]]; then
device="$SNF_IMAGE_DEV""$id"
"$RESIZE2FS" "$device"
fi
exit 0
......
......@@ -13,11 +13,11 @@ if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target dir:\`$SNF_IMAGE_TARGET' is missing"
fi
if [ ! -b "$SNF_IMAGE_DEV" ]; then
log_error "Device file:\`$SNF_IMAGE_DEV' is not a block device"
if [ ! -b "$SNF_IMAGE_ROOTDEV" ]; then
log_error "Device file:\`$SNF_IMAGE_ROOTDEV' is not a block device"
fi
mount "$SNF_IMAGE_DEV" "$SNF_IMAGE_TARGET"
mount "$SNF_IMAGE_ROOTDEV" "$SNF_IMAGE_TARGET"
exit 0
......
#! /bin/bash
### BEGIN TASK INFO
# Provides: ResizeMounted
# Provides: FilesystemResizeMounted
# RunBefore: UmountImage
# RunAfter: MountImage
# Short-Description: Resize filesystem to use all the available space
......@@ -14,13 +14,17 @@ if [ ! -d "$SNF_IMAGE_TARGET" ]; then
log_error "Target directory \`$SNF_IMAGE_TARGET' is missing"
fi
if [ "$SNF_IMAGE_TYPE" = "ntfsdump" ]; then
last_partition=$(get_last_partition "$SNF_IMAGE_DEV")
id=$(echo "$last_partition" | cut -d: -f1)
ptype=$(echo "$last_partition" | cut -d: -f5)
if [ "$ptype" = "ntfs" ]; then
# Write a diskpart script to %SystemDrive%\Windows\SnfScripts. Sysprep will
# try to execute this script during the specialize pass.
mkdir -p "$SNF_IMAGE_TARGET/Windows/SnfScripts"
cat > "$SNF_IMAGE_TARGET/Windows/SnfScripts/ExtendFilesystem" <<EOF
select disk 0
select volume 1
select volume $id
extend filesystem
exit
EOF
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment