;;
esac
+# find the disk to install to
+find_target()
+{
+ SRC=$1
+
+ for f in /sys/block/[sh]d[a-z]; do
+ bdev=$(basename $f)
+ if [ "$bdev" = "$SRC" ]; then
+ continue
+ fi
+ # the first block device that's not root? take it!
+ echo "$bdev"
+ break
+ done
+}
+
do_install()
{
echo
echo
- echo "Triggering installer!"
+ echo
+ echo "Starting installer!"
+ if [ ! -d /root/etc ]; then
+ echo "Error: /root doesn't appear to have a valid filesystem mounted!"
+ sleep 9999999999
+ fi
+
ROOT_SRC=$(grep ' /root ' /proc/mounts | cut -d' ' -f1)
- ROOT_SRC=$(readlink -f $ROOT_SRC)
+ ROOT_SRC=$(readlink -f $ROOT_SRC | sed 's/.*\/\([hs]d[a-z]\)[0-9]\+$/\1/')
- echo "root src: $ROOT_SRC"
- [ -d /root/etc ] || {
- echo "Error: /root doesn't appear to have a valid filesystem mounted!"
- exit 1
- }
+ TARGET=$(find_target "$ROOT_SRC")
+
+ if [ -z "$TARGET" ]; then
+ echo "Error: couldn't find drive to install to!"
+ sleep 9999999999
+ fi
+
+ # don't keep fs mounted while copying it
+ umount /root
+
+ # wait 15s for user realize that they've made a mistake
+ echo "Copying data from [$ROOT_SRC] => [$TARGET]"
+ echo "IF THIS IS INCORRECT, REBOOT NOW OR YOU WILL LOSE DATA! (waiting 15s)"
+ sleep 15
+
+ echo "Too late, starting copy..."
+ # ideally, we'll resize the filesystem/partitions later..
+ dd if=/dev/$ROOT_SRC of=/dev/$TARGET bs=4k
+ echo "Done. Remove installer media."
+ while [ -d /sys/block/$ROOT_SRC ]; do
+ sleep 1
+ done
+ reboot
}
for x in $(cat /proc/cmdline); do