Commit 88406207 authored by Vangelis Koukis's avatar Vangelis Koukis
Browse files

Introduce support for offline NTFS resize

snf-image already supports online resizing of NTFS; it creates
an appopriate DISKPART script inside the target NTFS and assumes
it will be called by SYSPREP via a pre-existing <RunSynchronousCommand>
entry in the unattend.xml answer file. This is generally the safest
option, since it uses native Windows code, but has two drawbacks:
a) It is only supported by Windows Vista and later,
b) It is possible the Image will fail before SYSPREP has a chance
to run the DISKPART script, because it does not have enough free space.

Extend snf-image to also support offline resize of NTFS via ntfsresize,
before the Image is booted. This works with all Windows versions and
ensures the Image is resized to the right size even before booting.

To be on the safe side, offline NTFS resize is not the default:

The user must set the OFFLINE_NTFSRESIZE property explicitly.
Running ntfsresize leaves the filesystem dirty, i.e., a CHKDSK is
performed during the next boot. The user may set the
OFFLINE_NTFSRESIZE_NOCHECK property to skip this.
parent 8a9f78eb
......@@ -154,6 +154,23 @@ All image formats properties
exists in the above-mentioned location. For more information on "answer
files" please refer to :ref:`windows-deployment`.
* **OFFLINE_NTFSRESIZE**
When deploying a Windows Image, perform an offline NTFS resize, instead
of setting up the Unattend.xml file so SYSPREP executes a custom DISKPART
script to perform an online resize during the first boot. Note NTFS is
left dirty and will be checked automatically on first boot when performing
an offline NTFS resize. Define the *OFFLINE_NTFSRESIZE_NOCHECK* property
to a non-empty value to disable this behavior (this is dangerous).
For more information on "answer files" please refer to
:ref:`windows-deployment`.
* **OFFLINE_NTFSRESIZE_NOCHECK**
Set this property to a non-empty value to skip the NTFS check performed by
Windows upon the first boot when performing an offline NTFS resize (see the
*OFFLINE_NTFSRESIZE* property). Skipping the initial filesystem check is
dangerous, as it may lead to bugs of the offline NTFS resize procedure going
undetected.
* **PASSWD_HASHING_METHOD=md5|sha1|blowfish|sha256|sha512**
This property can be used on Unix instances to specify the method to be used
to hash the users password. By default this is determined by the type of the
......
......@@ -42,6 +42,8 @@ HIVEXREGEDIT=hivexregedit
BTRFS=btrfs
XFS_GROWFS=xfs_growfs
NTFSINFO=ntfsinfo
NTFSRESIZE=ntfsresize
NTFSFIX=ntfsfix
CLEANUP=( )
ERRORS=( )
......
#! /bin/bash
# Copyright (C) 2011 GRNET S.A.
# Copyright (C) 2011, 2015 GRNET S.A. and individual contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -84,6 +84,25 @@ if [[ "$ptype" == ext[234] ]]; then
fi
elif [[ "$ptype" == "freebsd-ufs" ]]; then
$GROWFS_UFS -y "$device"
elif [[ "$ptype" == "ntfs" ]]; then
# For NTFS, only perform an offline resize if forced
if [ -n "$SNF_IMAGE_PROPERTY_OFFLINE_NTFSRESIZE" ]; then
# Be extra safe: Refuse to work on Image with a dirty NTFS
if ! $NTFSINFO -m "$device"; then
log_error "NTFS is dirty, refusing to continue"
fi
$NTFSRESIZE -f "$device"
if [ -n "$SNF_IMAGE_PROPERTY_OFFLINE_NTFSRESIZE_NOCHECK" ]; then
warn "Clearing dirty bit after NTFS resize"
warn "Please run CHKDSK manually after boot"
$NTFSFIX -d "$device"
else
warn "NTFS filesystem set to dirty after offline resize"
warn "Disable with OFFLINE_NTFSRESIZE_NOCHECK (dangerous)"
fi
else
warn "Not performing offline file system resize for NTFS unless forced"
fi
else
warn "Don't know how to resize unmounted partition \`$id' with file system \`$ptype'."
fi
......
#! /bin/bash
# Copyright (C) 2011 GRNET S.A.
# Copyright (C) 2011, 2015 GRNET S.A. and individual contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -53,6 +53,10 @@ ptype=$(cut -d: -f5 <<< "$partition")
device="${SNF_IMAGE_DEV}${id}"
if [ "$ptype" = "ntfs" -a "$SNF_IMAGE_PROPERTY_OSFAMILY" = "windows" ]; then
if [ -n "$SNF_IMAGE_PROPERTY_OFFLINE_NTFSRESIZE" ]; then
warn "Task ${PROGNAME:2} will not run. Offline NTFS resize requested."
exit 0
fi
# Write a diskpart script to %SystemDrive%\Windows\SnfScripts. Sysprep will
# try to execute this script during the specialize pass.
cat > "$SNF_IMAGE_TARGET/Windows/SnfScripts/ExtendFilesystem" <<EOF
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment