LDP/LDP/howto/docbook/Linux-Complete-Backup-and-R.../scripts/make.dev.hda

73 lines
1.9 KiB
Bash
Executable File

#! /bin/sh
# A script to restore the partition data of a hard drive and format
# the partitions. Created at bare metal backup time by the Perl script
# make.fdisk.
# Copyright 2001 through the last date of modification Charles Curley.
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA
# You can also contact the Free Software Foundation at http://www.fsf.org/
# For more information contact the author, Charles Curley, at
# http://www.charlescurley.com/.
export blockcheck=$1;
if [ "$blockcheck" != "-c" ] && [ -n "$blockcheck" ]
then
echo "${0}: automated restore with no human interaction."
echo "${0}: -c: block check during file system making."
exit 1;
fi
dd if=/dev/zero of=/dev/hda bs=512 count=2
swapoff -a
sync
# see if we have sfdisk & if so use it.
if which sfdisk ; then
echo "Using sfdisk."
sfdisk -H 128 -S 63 -C 523 /dev/hda < dev.hda.sfd
else
echo "using fdisk."
fdisk -H 128 -S 63 -C 523 /dev/hda < dev.hda
fi
sync
echo
echo formatting /dev/hda1
mkdosfs $blockcheck /dev/hda1
# restore FAT boot sector.
dd if=dev.hda1 of=/dev/hda1 bs=512 count=1
echo
echo formatting /dev/hda2
mke2fs -j $blockcheck -L /boot /dev/hda2
echo
echo formatting /dev/hda3
mke2fs -j $blockcheck -L / /dev/hda3
echo Making /dev/hda5 a swap partition.
mkswap $blockcheck /dev/hda5
fdisk -l "/dev/hda"