Commit 3a4e13b0 by HiPhish

Initial commit.

parents
# Ignore the build directory
build/
This diff is collapsed. Click to expand it.
# =========================================================================
# Copyright (C) 2016 Alejandro Sanchez
#
# NTFS-Clone is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# NTFS-Clone is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# =========================================================================
# --- Public variables -------------------------------------------------------
PREFIX = './build'
# --- Internal variables -----------------------------------------------------
SRC_DIR = './src'
MAN_DIR = './man'
BINARIES = $(addprefix $(PREFIX)/bin/, ntfs-dump ntfs-restore)
MANPAGES = $(addprefix $(PREFIX)/man/, ntfs-dump.1 ntfs-restore.1)
# --- Phony targets ----------------------------------------------------------
.PHONY: all help bin man clean
all: bin man
bin: $(BINARIES)
man: $(MANPAGES)
help:
@echo "Accepted make targets:"
@echo " all Build all executables and manual pages (default)"
@echo " bin Build binaries only"
@echo " man Build manual pages only"
@echo " help Display this information"
@echo " clean Remove all build products"
@echo ""
@echo "Settable make variables:"
@echo " PREFIX Where to place final build products (default './build')"
clean:
@rm -rf ${PREFIX}
# --- Binaries ---------------------------------------------------------------
$(PREFIX)/bin/ntfs-dump: $(SRC_DIR)/ntfs-dump.sh
@mkdir -p $(PREFIX)/bin/
@cp $< $@
@chmod +x $@
$(PREFIX)/bin/ntfs-restore: $(SRC_DIR)/ntfs-restore.sh
@mkdir -p $(PREFIX)/bin/
@cp $< $@
@chmod +x $@
# --- Manpages ---------------------------------------------------------------
$(PREFIX)/man/ntfs-dump.1: $(MAN_DIR)/ntfs-dump.rst
@mkdir -p $(PREFIX)/man/
@rst2man.py $< $@
$(PREFIX)/man/ntfs-restore.1: $(MAN_DIR)/ntfs-restore.rst
@mkdir -p $(PREFIX)/man/
@rst2man.py $< $@
###########
ntfs-dump
###########
==================================================
Dump all the required images of an NTFS hard drive
==================================================
:Author: Alejandro Sanchez
:Date: 2016-05-30
:Copyright: 2016 Alejandro Sanchez
:Version: 1.0
:Manual section: 1
:Manual group: disc images
SYNOPSIS
########
ntfs-dump [<options>] <disc> <part-1> <part-2> ... <part-n>
DESCRIPTION
###########
Dump a set of disc image files required for producing perfect 1:1 clones of
NTFS hard drives. This tool will produce the images while 'ntfs-restore'
applies them.
The number of partitions is at least one, with no upper limit. The disc has to
be unmounted before dumping it. Options need to be specified before the
arguments. The script assumes that the file names of the partition- and disc
images are the same as their identifier (except for the file extension).
All images will be written to the directory specified by the '--dir' option. If
no option is specified the files will be written to the current working
directory.
OPTIONS
#######
The following options can be given in any order, but they must be given before
the positional arguments.
--dir <directory>
Directory to dump the images to, the default is './'.
NOTE
####
The disc and all of its partitions must not be mounted. Depending on your
system 'ntfsclone' might need superuser permissions, so in that case you will
have to run this script as superuser.
SEE ALSO
########
* ntfs-restore
* fdisk
* dd
* ntfsclone
##############
ntfs-restore
##############
=====================================================
Restore all the required images of an NTFS hard drive
=====================================================
:Author: Alejandro Sanchez
:Date: 2016-05-30
:Copyright: 2016 Alejandro Sanchez
:Version: 1.0
:Manual section: 1
:Manual group: disc images
SYNOPSIS
########
ntfs-restore [<options>] <disc> <part-1> <part-2> ... <part-n>
DESCRIPTION
###########
Restore a set of disc image files required for producing perfect 1:1 clones of
NTFS hard drives. This tool will apply the images while 'ntfs-dump' produces
them.
The number of partitions is at least one, with no upper limit. The disc has to
be unmounted before restoring it. Options need to be specified before the
arguments. The script assumes that the file names of the partition- and disc
images are the same as their identifier (except for the file extension).
All images will be read from the directory specified by the '--dir' option. If
no option is specified the files will be read from the current working
directory.
OPTIONS
#######
The following options can be given in any order, but they must be given before
the positional arguments.
--dir <directory>
Directory to dump the images to, the default is './'.
NOTE
####
The disc and all of its partitions must not be mounted. Depending on your
system 'ntfsclone' might need superuser permissions, so in that case you will
have to run this script as superuser.
SEE ALSO
########
* ntfs-dump
* fdisk
* dd
* ntfsclone
.. default-role:: code
##################################################################
NTFS-Clone: Create perfect 1:1 copies of NTFS hard discs on Unix
##################################################################
NTFS-Clone is a collection of Unix shell scripts for creating perfect 1:1
copies of NTFS hard discs on Unix. If you have one PC installation and want to
run it on a number of similar PCs these tools will allow you to clone the disc
and get your PCs running out of the box.
Motivation
##########
At my workplace we had a number of notebooks that needed identical Windows
setups. The workflow was to set up one PC, make an image of its hard disc and
then manually apply that image to every other PC using a Windows GUI
application. This process was very slow and tedious, requiring one of us to
babysit the machines all day.
This toolset was created to automate the process. A suitable solution would
have to meet the following requirements:
- Produce perfect 1:1 copies that don't need any Windows repair to be run
- Be able to clone multiple drives either in parallel or in sequence
- The cloning process must be able to be automated
- Ideally the solution would be Free Software
After a lot of searching we found no solution that would satisfy all of these
criteria. In response I decided to do it myself by doing things the Unix way:
combine a number of small programs with very specialised tasks to solve a
larger problem.
Requirements
############
The following command-line tools must be present on the executing machine:
`fdisk`, `dd` and `ntfsclone`. The latter is part of the NTFS-3G_ packge from
Tuxera Inc. and is Free Software.
.. _NTFS-3G: http://www.tuxera.com/community/open-source-ntfs-3g/
Building
########
NTFS-Clone is a set of shell-scripts, so there is technically nothing to build,
but for the sake of consistency there is a makefile provided that copies the
scripts to a `PREFIX` directory and removes their file extensions. These are
the make targets available:
.. code-block:: sh
make all # Build the entire suite (default)
make bin # Build the scripts only
make man # Build the manual pages only
make help # Print build instructions
make clean # Remove all build products
You can set the `PREFIX` (default `./build/`) variable to have the build
products be placed in a directory of your choice.
The manual pages are written in reStructedText_ and require `rst2man.py` from
Docutils_ installed to be compiled.
.. _reStructedText: http://docutils.sourceforge.net/rst.html
.. _Docutils: http://docutils.sourceforge.net
Usage
#####
NTFS-Clone consists of two programs: `ntfs-dump` and `ntfs-restore`. The task
of the former is to dump all the necessary images of the hard disc we wish to
clone while the latter allows us to apply these images again. Both programs
complement each other and each is the reverse of the other. This is the reason
why their syntax is the same:
.. code-block:: sh
ntfs-dump [ --dir <directory> ] <disc> <part-1> <part-2> ... <part-n>
ntfs-restore [ --dir <directory> ] <disc> <part-1> <part-2> ... <part-n>
Both have an optional directory for specifying where to write the images to or
where to read from. The positional arguments are the identifier for the disc
followed by the partitions. Options must come before the mandatory arguments.
Depending on your operating system some of the commands contained in these
scripts might require superuser privileges. In that case you will have to run
them as superuser.
The file names are `<disc>.ptab` for the partition table, `<disc>.mbr` for the
master boot record and `<part>.ntfs` for the individual partition. `ntfs-dump`
will write files under those names `ntfs-restore` will read the files under
those names.
Acknowledgements
================
NTFS-Clone has been written based on the following articles:
- `<http://ebalaskas.gr/wiki/ntfsclone>`_
- `<http://bahut.alma.ch/2005/04/cloning-xp-with-linux-and-ntfsclone_23.html>`_
License
#######
**Copyright (C) 2016 Alejandro Sanchez**
NTFS-Clone is free software: you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see `<http://www.gnu.org/licenses/>`_.
#!/bin/sh
# Copyright (C) 2016 Alejandro Sanchez
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
print_usage() {
cat <<- EOF
Usage: ntfs-dump [<options>] <disc> <part-1> <part-2> ... <part-n>
Options:
--dir <dir> Directory to write the images to. Default './'
Positional Arguments:
<disc> Disc identifier of the disc to dump
<part-1> Partition identifier of the first partition
<part-2> Partition identifier of the second partition
...
<part-n> Partition identifier of the last partition
The number of partitions is at least one, with no upper limit. The disc has to
be unmounted before dumping it. Options need to be specified before the
arguments. The script assumes that the file names of the partition- and disc
images are the same as their identifier (except for the file extension).
NOTE:
The disc and all of its partitions must not be mounted. Depending on your
system 'ntfsclone' might need superuser permissions, so in that case you will
have to run this script as superuser.
EOF
}
# How it works: The user first specifies a number of optional options, followed
# by the identifier of the disc and a sequence of partitions. The options are
# processed first, setting the corresponding variables. After processing each
# argument we 'shift' the variables so that '$1' always contains the current
# option.
#
# After the options have been processed we do the same for the positional
# arguments where the first argument is the identifier of the disc and all
# remaining arguments are partitions. We will still keep shifting arguments so
# that '$1' always contains the identifier of the current partition.
# === Variables ===============================================================
DIR='./'
DISC=''
# === Processing Arguments ====================================================
# Parse options
while [ -n "$1" ]; do
case $1 in
--dir) shift; DIR=$1;;
*) break;;
esac
shift
done
# If there are not enough arguments print usage instructions.
if [ $# -lt 2 ]; then print_usage; exit 1; fi
DISC="$1"
shift
# === Actual dumping process ==================================================
# Dump the permission table
fdisk -d /dev/"$DISC" > "$DIR"/"$DISC".ptab
if [ $? != 0 ] ; then
echo >&2 "Error dumping partition table, aborting dumping process."
return 1;
fi
# Dump the master boot record
dd if=/dev/"$DISC" of="$DIR"/"$DISC".ptab bs=512 count=1
if [ $? != 0 ] ; then
echo >&2 "Error dumping master boot record, aborting process."
return 2;
fi
# Dump all the partitions
while [ -n "$1" ]; do
ntfsclone --save-image --output "$DIR"/"$1".ntfs /dev/"$1"
if [ $? != 0 ] ; then
echo >&2 "Error dumping partition $1, aborting dumping process."
return 3;
fi
shift
done
return 0
#!/bin/sh
# Copyright (C) 2016 Alejandro Sanchez
#
# 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
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
print_usage() {
cat <<- EOF
Usage: ntfs-restore [<options>] <disc> <part-1> <part-2> ... <part-n>
Options:
--dir <dir> Directory to read the images from. Default './'
Positional Arguments:
<disc> Disc identifier of the disc to restore
<part-1> Partition identifier of the first partition
<part-2> Partition identifier of the second partition
...
<part-n> Partition identifier of the last partition
The number of partitions is at least one, with no upper limit. The disc has to
be unmounted before dumping it. Options need to be specified before the
arguments. The script assumes that the file names of the partition- and disc
images are the same as their identifier (except for the file extension).
NOTE:
The disc and all of its partitions must not be mounted. Depending on your
system 'ntfsclone' might need superuser permissions, so in that case you will
have to run this script as superuser.
EOF
}
# === Variables ===============================================================
DIR='./'
DISC=''
# === Processing Arguments ====================================================
# Parse options
while [ -n "$1" ]; do
case $1 in
--dir) shift; DIR=$1;;
*) break;;
esac
shift
done
# If there are not enough arguments print usage instructions.
if [ $# -lt 2 ]; then print_usage; exit 1; fi
DISC="$1"
shift
# === Actual restoration process ==============================================
# Restore partition table
fdisk /dev/"$DISC" < "$DIR"/"$DISC".ptab
if [ $? != 0 ] ; then
echo >&2 "Error restoring partition table, aborting restoration process."
return 1;
fi
# Restore master boot record
dd if="$DIR"/"$DISC".mbr of=/dev/"$DISC"
if [ $? != 0 ] ; then
echo >&2 "Error restoring MBR, aborting restoration process."
return 2;
fi
# Restore all the partitions
while [ -n "$1" ]; do
ntfsclone --restore-image --overwrite /dev/"$1" "$DIR"/"$1".ntfs
if [ $? != 0 ] ; then
echo >&2 "Error restoring partition $1, restoring dumping process."
return 3;
fi
shift
done
return 0
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