2 M_TITLE="Copy rootfs to SD/CF"
8 echo "ERROR: $1" >/dev/tty0
9 exec $SH_SHELL </dev/tty0 >/dev/tty0 2>&1
13 available_disks="`mount | grep "/media" | grep -v ram | awk '{print $3}'`"
15 if test -z "$available_disks"
17 die "No mounted targets found!"
21 for d in $available_disks
27 while test -z "$ROOTFS_TARGET"
33 for d in $available_disks
35 if test "$junk" = "$x"
46 ROOTFS_TARGET_DEV="`mount | grep "$ROOTFS_TARGET " | awk '{print $1}'`"
47 ROOTFS_TARGET_FS="`mount | grep "$ROOTFS_TARGET " | awk '{print $5}'`"
49 echo "Using [$ROOTFS_TARGET] on [$ROOTFS_TARGET_DEV] with [$ROOTFS_TARGET_FS] filesystem"
53 if test "$ROOTFS_TARGET_FS" != ext2
55 echo -e "\nYou are not using the ext2 filesystem on your target ($ROOTFS_TARGET_FS)$.\nYou now have two choices:"
56 echo -e "\t[1] Reformat to ext2"
57 echo -e "\t[2] Use an image-file ontop of the existing filesystem"
61 echo -n "Your choice: "
65 1) ROOTFS_TARGET_TYPE="ext2"
67 2) ROOTFS_TARGET_TYPE="image"
72 echo "Mode: [$ROOTFS_TARGET_TYPE]"
74 echo -e "\nYou are using the ext2 filesystem on your target.\nYou now have two choices:"
75 echo -e "\t[1] Install to the target directly"
76 echo -e "\t[2] Use an image-file ontop of the existing filesystem\n"
80 echo -n "Your choice: "
84 1) ROOTFS_TARGET_TYPE="direct"
86 2) ROOTFS_TARGET_TYPE="image"
91 echo "Mode: [$ROOTFS_TARGET_TYPE]"
97 echo -e "\nYour choices are:"
98 echo -e "\tTarget:\t$ROOTFS_TARGET_DEV (currently mounted as $ROOTFS_TARGET)"
99 case "$ROOTFS_TARGET_TYPE" in
100 direct) echo -e "\tType:\t${C_RED}direct install, reformat if required${C_RESET}";;
101 image) echo -e "\tType:\tinstall into image-file";;
106 echo -n "Continue? [y|n] "
120 echo -n "Creating temporary directory..."
121 mkdir -p /media/temp && echo ok || die "mkdir -p /media/temp failed!"
123 echo -n "Mounting [$ROOTFS_TARGET_DEV] as /media/temp..."
124 mount "$ROOTFS_TARGET_DEV" /media/temp && echo "ok" || die "mount "$ROOTFS_TARGET_DEV" /media/temp FAILED"
130 echo -e "\n\nI'm about to format your target ($ROOTFS_TARGET_DEV) to the ext2 filesystem\n"
131 echo -e "${C_RED}YOU WILL LOSE ALL DATA ON YOUR TARGET IF YOU CONTINUE${C_RESET}\n"
135 echo -n "Continue? [y|n] "
140 n) die "User aborted mkfs"
145 echo -n "Umounting $ROOTFS_TARGET_DEV..."
146 umount "$ROOTFS_TARGET_DEV" && echo "ok" || die "umount $ROOTFS_TARGET_DEV failed!"
150 /sbin/mkfs.ext2 -m0 "$ROOTFS_TARGET_DEV" && echo -e "\nmkfs.ext2 finished" || die "\nmkfs.ext2 FAILED"
154 flash_size="` df -h | grep "/"$| awk '{print $3}'| sed s/M//`"
156 echo -e "\nHow many MB do you want to configure for the image file?"
157 echo -e "It is generally a good idea to use 2.5x the used flash size ($flash_size)\n"
159 while test -z "$ROOTFS_IMAGE_SIZE"
161 echo -n "Size in MegaBytes: "
164 # test fails if $junk isn't a number
165 if test "$junk" -gt 0 >/dev/null 2>&1
167 echo -n "Use [$junk]MB? [y|n] "
171 ROOTFS_IMAGE_SIZE="$junk"
176 echo -e "\nPlease enter a name for the image file."
177 echo "The name must _not_ contain whitespaces or the '-' sign."
179 while test -z "$ROOTFS_IMAGE_NAME"
181 echo -n "File name: "
186 echo -n "Use [$junk] as image name? [y|n] "
191 ROOTFS_IMAGE_NAME="$junk"
196 echo -e "\nDo you want to format [$ROOTFS_TARGET_DEV] to the ext2 filesystem?"
200 echo -n "Format to ext2? [y|n] "
209 /etc/init.d/devices start
211 echo -en "\nCreating image file [$ROOTFS_TARGET/$IMAGE_PATH/$ROOTFS_IMAGE_NAME-rootfs.bin] (${ROOTFS_IMAGE_SIZE}MB)..."
212 mkdir -p "$ROOTFS_TARGET/$IMAGE_PATH"
214 dd if=/dev/zero of="$ROOTFS_TARGET/$IMAGE_PATH/$ROOTFS_IMAGE_NAME-rootfs.bin" bs=1024k count=$ROOTFS_IMAGE_SIZE >/dev/null 2>&1 && echo ok || die "FAILED"
215 losetup /dev/loop1 "$ROOTFS_TARGET/$IMAGE_PATH/$ROOTFS_IMAGE_NAME-rootfs.bin"
217 echo -n "Creating filesystem..."
218 mkfs.ext2 -m0 /dev/loop1 >/dev/null 2>&1 && echo ok || die FAILED
221 mount /dev/loop1 /media/temp || die "mount /dev/loop1 /media/temo FAILED!"
228 echo -e "\nCopying files..."
230 exclude_list="tmp sys proc var dev media root"
231 mkdir_list="var proc sys dev media/card media/cf /media/hdd"
233 if (cat /etc/fstab | grep -q "/home")
235 echo "Note: /home appears to be mounted on a different flash partition: not copying /home"
236 exclude_list="$exclude_list home"
237 mkdir_list="$mkdir_list home/root"
243 source_dirs="`ls -1 /`"
245 echo -n "Excluding ["
246 for d in $exclude_list
249 source_dirs="`echo "$source_dirs" | grep -v "$d"`"
255 for dir in $source_dirs
259 echo -n "Copying [$dir]..."
260 cp -a $dir /media/temp && echo ok || echo FAILED
264 for dir in $mkdir_list
266 mkdir -p /media/temp/$dir
269 rm /media/temp/etc/rcS.s/S39sd
274 test -e /etc/altboot.func && . /etc/altboot.func || die "ERROR: /etc/altboot.func not found. Check your installation!"
276 echo -e "${C_RED}* * * * * WARNING * * * * *${C_RESET}"
277 echo -e "${C_RED}Continueing will delete the content of the selected target device.\nTHIS IS NO JOKE. If you do now know what this menu-item does, exit NOW${C_RESET}"
279 mount -o remount,rw /
283 echo -en "\nContinue? [y|n] "
297 # echo -n "Trying to activate PCMCIA..."
298 # cardmgr -o >/dev/null 2>&1 && echo ok || echo "FAILED"
300 # echo -n "Trying to mount SD card..."
301 # /etc/init.d/sd start >/dev/null 2>&1
303 # /etc/sdcontrol insert >/dev/null 2>&1 && echo ok || echo "FAILED"
306 echo -e "\nPlease select the target device:"
308 # Sets ROOTFS_TARGET*
311 # Sets ROOTFS_TARGET_TYPE ([direct | image]
317 case "$ROOTFS_TARGET_TYPE" in
318 direct) direct_install;;
319 image) image_install;;
324 title) echo "$M_TITLE";;