#!/bin/bash # # $Id: modified-iso-install-raid,v 1.2 2004/06/19 11:49:32 suter Exp $ # Copyright (C) 2003 Mark Suter # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## Which build to install build=ebbe ## Our "die" function (think perl) function die () { echo "$@" 1>&2 ; exit 1 ; } ## Set our PATH and test for needed binaries export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin hash test date cat sfdisk modprobe mkraid mkfs mkswap mkdir mount umount bzip2 cpio chmod sync chroot || die $0: required binaries not present ## Record our starting time start=$(date +%s) ## Are you sure? test "$( id -u )" == "0" || die $0: Please run this script as root cat <&2 ################################################################# This script will repartition /dev/hda and /dev/hdc to install a base system using GNU/Linux's disk mirroring (raid1). You will lose all existing data on both drives. Enter "Wipe the Two Disks" at the prompt below to proceed. EOF while [ "${resp}" != "Wipe the Two Disks" ] ; do read -p "? " resp done cat <&2 Proceeding with installation... ################################################################# EOF ## Exit on any error, display the commands set -x -e ## Umount any auto-detected filesystems /etc/init.d/mount.local stop ## Wipe the partitions, then load the module: this avoids any existing md devices echo -e "0,,L\n" | sfdisk /dev/hda echo -e "0,,L\n" | sfdisk /dev/hdc modprobe raid1 ## Partition the disk echo -e "0,5120,fd\n,2048,S\n,10240,fd\n,,fd\n;" | sfdisk -uM /dev/hda || die $0: You should copy this script and edit the sfdisk input echo -e "0,5120,fd\n,2048,S\n,10240,fd\n,,fd\n;" | sfdisk -uM /dev/hdc || die $0: You should copy this script and edit the sfdisk input ## Prepare a raidtab describing the multiple disk (md) devices ## The chunksize is needed but not used and mkraid complains about it (Yes, I've checked) cat < /tmp/raidtab raiddev /dev/md0 raid-level 1 nr-raid-disks 2 nr-spare-disks 0 persistent-superblock 1 chunk-size 8 device /dev/hda1 raid-disk 0 device /dev/hdc1 raid-disk 1 raiddev /dev/md1 raid-level 1 nr-raid-disks 2 nr-spare-disks 0 persistent-superblock 1 chunk-size 8 device /dev/hda3 raid-disk 0 device /dev/hdc3 raid-disk 1 raiddev /dev/md2 raid-level 1 nr-raid-disks 2 nr-spare-disks 0 persistent-superblock 1 chunk-size 8 device /dev/hda4 raid-disk 0 device /dev/hdc4 raid-disk 1 EOF ## Create them (please don't mention the --really-force option, see "mkraid -f" for why. mkraid --really-force --configfile /tmp/raidtab /dev/md0 mkraid --really-force --configfile /tmp/raidtab /dev/md1 mkraid --really-force --configfile /tmp/raidtab /dev/md2 ## Make the filesystems mkfs -t ext3 -L root -O filetype /dev/md0 mkswap /dev/hda2 mkswap /dev/hdc2 mkfs -t ext3 -L var -O filetype /dev/md1 mkfs -t ext3 -L home -O filetype /dev/md2 ## Mount the new system mkdir /mnt/rw/$build mount /dev/md0 /mnt/rw/$build mkdir /mnt/rw/$build/var mkdir /mnt/rw/$build/home mount /dev/md1 /mnt/rw/$build/var mount /dev/md2 /mnt/rw/$build/home ## Copy the files over (or from an existing server using ssh?) # ( cd /mnt/rw/$build ; ssh XXX cd / \; find . -print0 \| cpio --null --format=crc --create | cpio --make-directories --preserve-modification-time --extract ) ( cd /mnt/rw/$build ; bzip2 --stdout --decompress /mnt/media/$build | cpio --make-directories --preserve-modification-time --extract ) ## Fix the /etc/fstab to refer to the multiple disk devices cat < /mnt/rw/$build/etc/fstab # /etc/fstab: static file system information. # # /dev/md0 / ext3 errors=remount-ro 0 1 /dev/hda2 none swap sw 0 0 /dev/hdc2 none swap sw 0 0 /dev/md1 /var ext3 defaults 0 2 /dev/md2 /home ext3 defaults 0 2 /dev/ram /tmp tmpfs defaults 0 0 proc /proc proc defaults 0 0 /dev/fd0 /media/floppy auto user,noauto 0 0 /dev/cdrom /media/cdrom iso9660 ro,user,noauto 0 0 # # Working directory for MIMEDefang /dev/ram /var/spool/MIMEDefang tmpfs defaults,uid=defang,mode=0700 0 0 EOF ## Copy the raidtab file cp /tmp/raidtab /mnt/rw/$build/etc/raidtab ## Make the system bootable sync ; sync ; sync chroot /mnt/rw/$build /sbin/grub --batch --device-map=/dev/null <&2 ################################################################# Done in ${elapsed}s with the newly prepared system now under /mnt/rw/$build for you to examine, then reboot and remove the cd. ################################################################# EOF