WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: TC Very Quick & Easy Install Script, 1.03  (Read 7530 times)

Offline jonathanbrickman0000

  • Jr. Member
  • **
  • Posts: 71
    • PC TSC:  Easily turn a PC into a terminal server client
TC Very Quick & Easy Install Script, 1.03
« on: October 17, 2010, 10:00:45 PM »
(Last modified 11/24/2010)

It's working quite well.  It is designed to install TC 3.2 to any basic machine with hard drive at either /dev/hda or /dev/sda.  It does wipe the hard drive as part of the task, the idea is to set up a TC machine as quickly and easily as possible.  You'll want exactly one PATA or SATA hard drive in the box.  

Many thanks to roberts in these forums, who helped me get the persistence mode to work, and gerald_clark, who gave me an essential boot tip for hard drive cleanup.  maro and tinypoodle also, for 1.03, cleared up a serious misunderstanding I had concerning persistence needs.

My favorite method of use, is to boot up TC from CD using boot codes "tinycore base norestore", open a command prompt, get to root with 'sudo su', and type:

Code: [Select]
sudo su
wget http://pctsc.ponderworthy.org/2.0/tc.setup.sh
sh tc.setup.sh

The default is for full persistence turned on.  To turn it off, add --nopersist to the end of the command line.  There is also --waitforusb=NN in case it's needed, and --help of course.

There is a bit of user interaction, not much.  Afterwards, reboot from hard drive, make sure it doesn't boot from CD, and I think TC will take it from there.

If anyone has a really reliable way to identify the device name of the source/boot media, that would simplify things a lot :-)

J.E.B.

Code: [Select]
#!/bin/sh

echo ""
echo "****       An Easy Installer for Tiny Core Linux      ****"
echo "****                                                  ****"
echo "****       by Jonathan E. Brickman                    ****"
echo "****       version 1.03     2010-11-24                ****"
echo "****       tested with TC 3.2                         ****"
echo "****                                                  ****"
echo "****  '--nopersist' disables persistence of           ****"
echo "****        package installs and settings.            ****"
echo "****  '--waitforusb=N' waits N seconds for USB        ****"
echo "****        devices.  Use 0 for new, 5 for general,   ****"
echo "****        30 for ancient.  Default is 5.            ****"

# This code requires 4-character tabs for proper viewing

LOG_FILE="./tc-inst.log"
rm -f $LOG_FILE
touch $LOG_FILE
TC_PERSIST=1
TC_WAITFORUSB=5

# TCTMP holds a directoryname for temporary usage
# by this installer.
TCTMP="/tmp/temp$RANDOM"
mkdir $TCTMP &> /dev/null

# Parse command-line parameters.

echo ""

for i in $*; do
case $i in
     --nopersist)
echo "Persistence mode disabled."
TC_PERSIST=0
       ;;
--help)
echo "Usage: sh tc.setup.sh [ --nopersist ] [ --waitforusb=N ]"
exit 1
;;
--waitforusb=*)
TC_WAITFORUSB=`echo $i | sed 's/[-a-zA-Z0-9]*=//'`
;;
*)
echo "Unknown parameter found."
echo "Usage: sh tc.setup.sh [ --nopersist ] [ --waitforusb=N ]"
exit 1
;;
esac
done

echo ""
echo "** Step 1:  Check to see if running as root. **"

if [ $USER == "root" ]; then
echo "root verified."
else
echo "Running as user '"$USER"'."
echo "This script must be run as root."
exit 1
fi

echo ""
echo "** Step 2: Check network. **"

if ping -c 1 -w 3 yahoo.com &> /dev/null
then
echo "Network verified."
else
echo "Network not found."
exit 1
fi

echo ""
echo "** Step 3:  Identify hard drive to use. **"

echo "Step 3" >> $LOG_FILE

fdisk -l | grep /dev/hda >> $LOG_FILE 2>&1

if [ "$?" = "0" ]; then
echo "Found hard drive at /dev/hda.  Designated."
TCHD="hda"
else
fdisk -l | grep /dev/sda >> $LOG_FILE 2>&1
if [ "$?" = "0" ]; then
echo "Found hard drive at /dev/sda.  Designated."
TCHD="sda"
else
echo "Did not find hard drive at /dev/hda or /dev/sda."
echo "One or the other is required for this script."
echo "Exiting."
exit 1
fi
fi

TCHDP=$TCHD""1

# If a partition is already mounted, must
# begin at beginning, booting TC with codes "base norestore"
mount | grep $TCHD >> $LOG_FILE 2>&1
if [ "$?" = "0" ]; then
echo ""
echo "Error:  A TC partition already exists on the designated"
echo "hard drive, and must be removed using special Tiny Core"
echo "Linux boot setup."
echo ""
echo "Please reboot specifying 'tinycore base norestore'",
echo "and try again."
echo ""
echo "Exiting."
exit 1
fi

echo ""
echo "** Step 4:  Install packages. **"

# tce-load will not run as root.  Use 'sudo' to run it as user 'tc'.

# 'cfdisk' is used for auto-repartitioning.  In the future, this
# will probably be replaced with just 'fdisk' which requires no
# package and will therefore speed things up and shrink them down.

# 'Xvesa' is reportedly required for the numeric keypad to work.
# It also permits the -nozap disabling of Ctrl-Alt-Backspace.

sudo -u tc tce-load -wi cfdisk.tcz \
grub-0.97-splash.tcz \
Xvesa.tcz \
kmaps.tcz

if [ "$?" != "0" ]; then
echo "Could not install packages.  Perhaps your Internet"
echo "connection is down?"
exit 1
fi

echo ""
echo "** Step 5:  Verify with user before continuing. **"

echo ""
echo "The next step is to wipe hard drive /dev/"$TCHD" and install Tiny Core"
echo "Linux in a 1000M first partition.  ALL EXISTING DATA ON THIS DRIVE IS ABOUT"
echo "TO BE WIPED.  Are you sure this is what you want to do?"
echo ""

echo "Step 5" >> $LOG_FILE

read -p "Type 'yes' (no quotes) if you are certain: "
if [ "$REPLY" != "yes" ]; then
echo "Did not receive a response of 'yes'.  Terminating."
echo ""
exit
else
echo "Received clear affirmative.  Proceeding."
echo ""
fi

echo ""
echo "** Step 6:  Remove all existing partitions if any, and **"
echo "** create new 1000M Linux partition at beginning of drive. **"

echo "Step 6" >> $LOG_FILE

echo -n "Partitioning..."

# Unmount if mounted.
if [ `mount | grep $TCHDP` ]; then
umount /mnt/$TCHDP &> /dev/null
fi

# Remove old partition(s).
echo -e -n "Wyes\nq" | cfdisk -z /dev/$TCHD >> $LOG_FILE 2>&1

# Repartition.
echo -e -n "np900M\nbbWyes\nq" | cfdisk -z /dev/$TCHD >> $LOG_FILE 2>&1

echo "done."

echo -n "Waiting for udev to settle..."
udevadm settle

echo "done."

# In case automounting doesn't happen, format and mount.

echo -n "Checking to see if format is required..."
mount | grep $TCHDP >> $LOG_FILE 2>&1
if [ "$?" != "0" ]; then
echo -n "Format is required.  Formatting..."
mkfs.ext3 /dev/$TCHDP >> $LOG_FILE 2>&1
if [ "$?" != "0" ]; then
echo "Error during format.  Exiting."
exit
fi
udevadm settle
echo "done."
fi

echo -n "Checking to see if mount point exists..."
if [ ! -d /mnt/$TCHDP ]; then
echo "done."
echo -n "Creating mount point..."
mkdir /mnt/$TCHDP
fi
echo "done."

echo -n "Checking to see if mount is needed..."
mount | grep $TCHDP >> $LOG_FILE 2>&1
if [ "$?" != "0" ]; then
echo "done."
echo -n "Mounting..."
mount /dev/$TCHDP /mnt/$TCHDP >> $LOG_FILE 2>&1
if [ "$?" != "0" ]; then
echo "Mount failed.  Exiting."
exit
fi
fi
echo "done."

echo ""
echo "** Step 7:  Mount the source/boot media. **"

echo "Step 7" >> $LOG_FILE

echo "We now need to identify your source/boot media."

TRY_AGAIN=1
while [ $TRY_AGAIN == "1" ]; do

echo "Here are the possibles:"
echo "---"
ls /mnt
echo "---"
echo "If your CD-ROM is set up as a secondary master IDE, it's almost"
echo "certainly hdc.  If it's SATA, it will be something with an 'sd'"
echo "prefix, perhaps sdb or sdc.  Please study the above and enter your"
echo "best thought below."
echo ""
read -p "Device name for the CD or other media you booted from: "

# Check data entry, try to mount, and try to verify

ls /mnt | grep "$REPLY" &> /dev/null

if [ "$?" != "0" ]; then
echo ""
echo "Sorry, you did not enter a valid device name.  Please try again."
echo ""
continue
elif [ $REPLY == $TCHDP ]; then
echo ""
echo "Sorry, your source/boot medium cannot equal your hard drive."
echo "Please try again."
echo ""
continue
fi

TCSOURCE=$REPLY

# Try to unmount the device first, just in case.  Useful in debugging if nought else.
umount /dev/$TCSOURCE >> $LOG_FILE 2>&1

echo ""
echo "Trying to mount /dev/"$TCSOURCE"..."

mount /dev/$TCSOURCE /mnt/$TCSOURCE

if [ "$?" != "0" ]; then
echo ""
echo "Cannot mount /dev/"$TCSOURCE" .  Please try again."
echo ""
continue
fi

echo "Medium successfully mounted.  Checking..."

ls /mnt/$TCSOURCE/boot/tinycore.gz >> $LOG_FILE 2>&1
if [ "$?" != "0" ]; then
echo ""
echo "Mounted medium does not contain Tiny Core Linux."
echo "Please try again."
echo ""
continue
fi

echo "Source/boot medium mounted and verified!"

TRY_AGAIN=0
done

echo ""
echo "** Step 8:  Create directories and copy files. **"

echo "Step 8" >> $LOG_FILE

echo -n "Working..."

echo -n "8a..."
mkdir -p /mnt/$TCHDP/boot/grub
if [ "$?" != "0" ]; then
echo "Error in creation of boot directory on hard drive (/mnt/"$TCHDP"/boot/grub)."
echo "Exiting."
exit 1
fi

echo -n "8b..."
cp -p /mnt/$TCSOURCE/boot/* /mnt/$TCHDP/boot/ &> /dev/null
# There is an "omitting directory" error here which we need to ignore

echo -n "8c..."
mkdir -p /mnt/$TCHDP/tce
if [ "$?" != "0" ]; then
echo "Error in creation of 'tce' folder (/mnt/"$TCHDP"/tce)."
echo "Exiting."
exit 1
fi

# From here:
# http://forum.tinycorelinux.net/index.php?topic=7608.msg40511#msg40511
echo -n "8d..."
touch /mnt/$TCHDP/tce/copy2fs.flg
if [ "$?" != "0" ]; then
echo "Error in creation of 'copy2fs.flg' (/mnt/"$TCHDP"/tce/copy2fs.flg)."
echo "Exiting."
exit 1
fi

echo -n "8e..."
touch /mnt/$TCHDP/tce/mydata.tgz
if [ "$?" != "0" ]; then
echo "Error in creation of 'mydata.tgz' (/mnt/"$TCHDP"/tce/mydata.tgz)."
echo "Exiting."
exit 1
fi

echo -n "8f..."
cp -p /usr/lib/grub/i386-pc/* /mnt/$TCHDP/boot/grub
if [ "$?" != "0" ]; then
echo "Error in copy of grub files to folder '/mnt/"$TCHDP"/boot/grub'."
echo "Exiting."
exit 1
fi

echo "done."

echo ""
echo "** Step 9:  Configuring the GRUB boot loader. **"

echo "Step 9" >> $LOG_FILE

# Create the menu.lst for GRUB.  Includes USB support on the kernel line.  

echo "Creating '/mnt/"$TCHDP"/boot/grub/menu.lst'..."

if [ "$TC_PERSIST" -eq 1 ]; then
echo -n "Setting persistence in 'grub' configuration..."

# Persisting /opt, /home, and /local using boot codes.

# The method is from here:
# http://forum.tinycorelinux.net/index.php?topic=7608.msg40511#msg40511
# Thanks to Robert Shingledecker for the help!

# the tce/opt/home/local items will persist most things
# but not passwords or anything else in /etc
TC_KERNEL_LINE="kernel /boot/bzImage quiet waitusb=$TC_WAITFORUSB tce=$TCHDP opt=$TCHDP home=$TCHDP"
else
echo -n "Setting nonpersistence in 'grub' configuration..."
TC_KERNEL_LINE="kernel /boot/bzImage quiet waitusb=$TC_WAITFORUSB"
fi

echo "default 0" > $TCTMP/grub.menu.lst
echo "timeout 3" >> $TCTMP/grub.menu.lst
echo "title Tiny Core Linux" >> $TCTMP/grub.menu.lst
echo $TC_KERNEL_LINE >> $TCTMP/grub.menu.lst
echo "initrd /boot/tinycore.gz" >> $TCTMP/grub.menu.lst
mv $TCTMP/grub.menu.lst /mnt/$TCHDP/boot/grub/menu.lst

echo "done."

echo ""
echo "** Step 10:  Activating the GRUB boot loader. **"

echo "Step 10" >> $LOG_FILE

echo    "Activating GRUB.  On some older/rarer hardware this can take"
echo -n "between 3 and 30 minutes, but it will still work..."

echo -e -n "root (hd0,0)\nsetup (hd0)\nquit\n" | grub >> $LOG_FILE 2>&1
if [ "$?" != "0" ]; then
echo "Error in GRUB activation."
echo "Exiting."
exit 1
fi

echo "done."

echo ""
echo "All done!!!"
echo ""

echo "**** Tiny Core Linux is now installed.  You will need to make sure your  ****"
echo "**** system does not boot from source media, at next reboot.             ****"
« Last Edit: November 26, 2010, 09:39:58 AM by jonathanbrickman0000 »

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: TC Very Quick Install Script ready for testing
« Reply #1 on: October 18, 2010, 08:54:38 AM »
It does wipe the hard drive, so don't test unless you're prepared!

I couldn't see any reason why a hard drive would needed to be wiped, at least not if any FAT* or ext* partition with sufficient space is already existing.

Also I couldn't understand what the relation between mounting and cfdisk could be   ???
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline jonathanbrickman0000

  • Jr. Member
  • **
  • Posts: 71
    • PC TSC:  Easily turn a PC into a terminal server client
Re: TC Very Quick Install Script ready for testing
« Reply #2 on: October 18, 2010, 02:14:30 PM »
It does wipe the hard drive, so don't test unless you're prepared!

I couldn't see any reason why a hard drive would needed to be wiped, at least not if any FAT* or ext* partition with sufficient space is already existing.

The idea of the quick install, is to get Tiny Core running on simple hardware quickly and easily.  If the script has to move or dodge existing partitions and/or GRUB entries, that's not quick or easy :-)  More seriously, I don't like promising something I can't deliver, and I cannot certainly set up to automatically install something which will coexist safely with pre-existing partitions, there is always the risk, and any risk in this zone is severe.

Quote
Also I couldn't understand what the relation between mounting and cfdisk could be   ???

I don't understand the mounting/cfdisk thing either, but it's there:  if the script runs and an ext3 partition existed beforehand, I find that it was automounted...and I also find that cfdisk knows how to tell the automounter to dismount it and then resume afterwards.  Autofs isn't there, so I have no idea how all this is happening, but it sure is neat.  As it is, the script just doesn't seem to have to do an explicit format at all!  I'd love to know exactly when and how this is being done though :-)
« Last Edit: October 18, 2010, 02:19:00 PM by jonathanbrickman0000 »

Offline gerald_clark

  • TinyCore Moderator
  • Hero Member
  • *****
  • Posts: 4254
Re: TC Very Quick Install Script ready for testing
« Reply #3 on: October 18, 2010, 06:38:57 PM »
There is already a usbinstall that is an easy install to USB or HD.
The only partitions that are automounted are persistent ( tce, opt, home ) referenced partitions.

Offline jonathanbrickman0000

  • Jr. Member
  • **
  • Posts: 71
    • PC TSC:  Easily turn a PC into a terminal server client
Re: TC Very Quick Install Script ready for testing
« Reply #4 on: October 18, 2010, 07:04:46 PM »
Sorry, I can't agree that usbinstall is very easy.  :) Easier than some methods, OK, but the goal for this is "a basic install, as easy as possible for as many people as possible".

J.E.B.
« Last Edit: October 18, 2010, 07:06:44 PM by jonathanbrickman0000 »

Offline pix

  • Newbie
  • *
  • Posts: 5
Re: TC Very Quick & Easy Install Script, 1.03
« Reply #5 on: December 02, 2010, 08:58:14 AM »
Agreed! The USB/HDD installer isn't as clear as it could be. I will try this out as soon as I can on my setup, since it is exactly what I want to happen. Thanks.

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: TC Very Quick & Easy Install Script, 1.03
« Reply #6 on: December 02, 2010, 04:10:15 PM »
(Last modified 11/24/2010)
My favorite method of use, is to boot up TC from CD using boot codes "tinycore base norestore", open a command prompt, get to root with 'sudo su', and type:

Code: [Select]
sudo su
wget http://pctsc.ponderworthy.org/2.0/tc.setup.sh
sh tc.setup.sh

This method as well as successfully running the script appears to depend on internet connectivity, yet it is suggested to boot 'base norestore' and imminent next step to run the script.   ???

Am i missing something here?
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline jonathanbrickman0000

  • Jr. Member
  • **
  • Posts: 71
    • PC TSC:  Easily turn a PC into a terminal server client
Re: TC Very Quick & Easy Install Script, 1.03
« Reply #7 on: December 02, 2010, 07:15:17 PM »
It does depend on Internet connectivity; this seemed the simplest method of approach.  Sooner or later I am going to need an offline version, but I haven't figured out a straightforward way to do it yet.  Multiple ways are obvious -- but none straightforward (i.e., very easy, this being the goal).  I could, theoretically, put in a two-device requirement, one for boot and one for packages, and I probably will, but only after partition-less USB sticks work without the current tremendous fuss.

The 'tinycore base norestore', by the way, is there to prevent automount of any existing Tiny Core persistence areas.  I tried fairly hard to find a way to script my way out of the automount, but it didn't happen, and the boot codes are a quick way to eliminate the question.

J.E.B.

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: TC Very Quick & Easy Install Script, 1.03
« Reply #8 on: December 02, 2010, 08:48:08 PM »
What I meant is that personally I have never yet seen a box having internet when booting 'base norestore', either at least wireless drivers/tools or ethernet NIC firmware were required.
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline simpleblue

  • Newbie
  • *
  • Posts: 2
Re: TC Very Quick & Easy Install Script, 1.03
« Reply #9 on: February 20, 2011, 07:53:59 PM »
I'm booting from my USB stick and I am not sure what to enter. When I enter in sdb1 as the boot media I get this error:

Code: [Select]
Device name for the CD or other media you booted from: sdb1

Trying to mount /dev/sdb1...
mount: mounting /dev/sdb1 on /mnt/sdb1 failed: Invalid argument

Cannot mount /dev/sdb1 . Please try again.

Here are the possibles:
---
sda1  sdb1
---
If your CD-ROM is set up as a secondary master IDE, it's almost
certainly hdc.  If it's SATA, it will be something with an 'sd'
prefix, perhaps sdb or sdc.  Please study the above and enter your
best thought below.

Device name for the CD or other media you booted from:


When I enter sda1 I get this error:

Code: [Select]
Device name for the CD or other media you booted from: sda1

Sorry, your source/boot medium cannot equal your hard drive.
Please try again.

Here are the possibles:
---
sda1  sdb1
---
If your CD-ROM is set up as a secondary master IDE, it's almost
certainly hdc.  If it's SATA, it will be something with an 'sd'
prefix, perhaps sdb or sdc.  Please study the above and enter your
best thought below.

Device name for the CD or other media you booted from:

Any suggestions?

Offline maro

  • Hero Member
  • *****
  • Posts: 1228
Re: TC Very Quick & Easy Install Script, 1.03
« Reply #10 on: February 20, 2011, 08:51:35 PM »
@simpleblue: To get a better idea of which device has what name I'd suggest you use the blkid /dev/[sh][dr]* command. That should list the labels (and UUIDs) of all IDE, SATA (and SCSI) devices.

Offline simpleblue

  • Newbie
  • *
  • Posts: 2
Re: TC Very Quick & Easy Install Script, 1.03
« Reply #11 on: February 20, 2011, 10:07:46 PM »
@simpleblue: To get a better idea of which device has what name I'd suggest you use the blkid /dev/[sh][dr]* command. That should list the labels (and UUIDs) of all IDE, SATA (and SCSI) devices.
Thanks. This is the exact information I was looking for!

It appears that sdb1 is my USB drive. Though I'm not sure why it won't mount it.