Skip to content
Browse files

Initial Commit

Seems to work, though it's a little crappy.
  • Loading branch information...
0 parents commit b1d202e913b6b60612d0cbb3b2826b0e5b52d653 @psycotica0 committed
Showing with 113 additions and 0 deletions.
  1. +24 −0 README
  2. +15 −0 breakdown_mirror
  3. +68 −0 build_mirror
  4. +6 −0 enter_mirror
24 README
@@ -0,0 +1,24 @@
+This is a few scripts to build a quick chroot mirror of your whole system.
+It allows you to build up a mirror, enter into it, and then break it down.
+
+They all need to be run as root.
+
+So:
+
+sudo ./build_mirror
+This makes a file called cache.img.
+It then mounts it to /mnt/cache and /mnt/union.
+If cache.img exists, it mounts it.
+
+sudo ./enter_mirror
+This logs you in to the new image.
+
+sudo ./breakdown_mirror
+This unmounts all the areas.
+It does not delete cache.img
+You can do whatever you want with cache.img
+
+
+Tip:
+I tend to change .bashrc when I make a new image to put CHROOT in the PS1.
+That way I can tell when I'm in and when I'm not.
15 breakdown_mirror
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+CACHE_LOCATION="/mnt/cache"
+UNION_LOCATION="/mnt/union"
+
+# This is inelegant, but I don't care
+umount "$UNION_LOCATION"/tmp
+umount "$UNION_LOCATION"/proc
+umount "$UNION_LOCATION"/sys
+umount "$UNION_LOCATION"/dev/shm
+umount "$UNION_LOCATION"/dev/pts
+umount "$UNION_LOCATION"/dev
+umount "$UNION_LOCATION"/
+
+umount "$CACHE_LOCATION"
68 build_mirror
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+IMAGE_FILE="/home/psycotica0/cache.img"
+IMAGE_SIZE="400M"
+CACHE_LOCATION="/mnt/cache"
+UNION_LOCATION="/mnt/union"
+
+if [ "$(whoami)" != "root" ]; then
+ echo "You're going to want to be root" >&2;
+ exit 2
+fi
+
+if [ ! -e "$IMAGE_FILE" ]; then
+ # Creating Image
+ truncate -s "$IMAGE_SIZE" "$IMAGE_FILE"
+ if [ "$?" -ne 0 ]; then
+ rm "$IMAGE_FILE"
+ echo "Failed To Allocate ${IMAGE_SIZE} for Image" >&2;
+ exit 1
+ fi
+
+ mkfs.ext2 "$IMAGE_FILE"
+ echo "Image Created"
+fi
+
+if [ -z "$(mount | grep -w "$CACHE_LOCATION")" ]; then
+ # Mounting Image
+ mkdir -p "$CACHE_LOCATION"
+ mount -t ext2 "$IMAGE_FILE" "$CACHE_LOCATION" -o loop
+ if [ "$?" -ne 0 ]; then
+ echo "Failed to Mount Image" >&2;
+ exit 1
+ fi
+ echo "Mounted Image"
+fi
+
+if [ -z "$(mount | grep -w "$UNION_LOCATION")" ]; then
+ # Create Union
+ mount -t aufs -o dirs="$CACHE_LOCATION:/=ro" none "$UNION_LOCATION"
+ if [ "$?" -ne 0 ]; then
+ echo "Failed to Mount Union" >&2;
+ exit 1
+ fi
+ echo "Mounted Union"
+fi
+
+if [ -z "$(mount | grep -w "$UNION_LOCATION"/dev)" ]; then
+ mount --bind /dev "$UNION_LOCATION"/dev 2> /dev/null
+fi
+
+if [ -z "$(mount -t devpts | grep -w "$UNION_LOCATION"/dev/pts)" ]; then
+ mount -t devpts devpts "$UNION_LOCATION"/dev/pts 2> /dev/null
+fi
+if [ -z "$(mount -t tmpfs | grep -w "$UNION_LOCATION"/dev/shm)" ]; then
+ mount -t tmpfs shm "$UNION_LOCATION"/dev/shm 2> /dev/null
+fi
+
+if [ -z "$(mount -t sysfs | grep -w "$UNION_LOCATION"/sys)" ]; then
+ mount -t sysfs sysfs "$UNION_LOCATION"/sys 2> /dev/null
+fi
+
+if [ -z "$(mount -t proc | grep -w "$UNION_LOCATION"/proc)" ]; then
+ mount -t proc proc "$UNION_LOCATION"/proc 2> /dev/null
+fi
+if [ -z "$(mount | grep -w "$UNION_LOCATION"/tmp)" ]; then
+ mount --bind /tmp "$UNION_LOCATION"/tmp 2> /dev/null
+fi
+
6 enter_mirror
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+UNION_LOCATION="/mnt/union"
+USER="psycotica0"
+
+chroot "$UNION_LOCATION" su -l "$USER"

0 comments on commit b1d202e

Please sign in to comment.
Something went wrong with that request. Please try again.