Bash script for installing Puppy to USB

Promote Puppy !
Post Reply
Message
Author
raffy
Posts: 4798
Joined: Wed 25 May 2005, 12:20
Location: Manila

Bash script for installing Puppy to USB

#1 Post by raffy »

Here's from the mailbox - an auto-installer to USB using Bash. Are there changes needed to make this work in Puppy?
Abhay Chinivar wrote:I'm an engineering student from India, I use Ubuntu as my main linux OS. I have tried Puppy linux on a CD, and also on a USB and I liked it a lot, esp. cos of it's small size and "amazing speed", it's a really good work by you people (my old outdated 128 mb usb device suddenly was in demand, thanks to Puppy :-) ). And when many of my friends started to come with their USBs to have puppy installed, I thought of writing a bash script to do the installation right from my host OS (ubuntu) so that I don't have to insert the Puppy Linux CD and restart my computer every time just to have Puppy installed on a friend's USB. So this motivated me to learn and write my first bash script - "a script which would install Puppy Linux on a USB flash drive from a host linux OS" (something like the one which the SLAX distro has). This is my first bash script, so it might not be the most efficient way of doing the job, but it definitely works and I guess it's quite simple to use it too (I've tested it on Puppy 4.2.1 release). Later I shared this script on our college lug site (linux users group) for college students to download and run. Now I thought of posting it to you people hoping it will be of some use on the site. Hope to hear from you soon, thank you.
I couldn't find a place on the site to upload the file, so i'm copying the code below, here it is:
* Snip * ---> See the corrected code below.
Last edited by raffy on Wed 09 Dec 2009, 23:01, edited 1 time in total.
Puppy user since Oct 2004. Want FreeOffice? [url=http://puppylinux.info/topic/freeoffice-2012-sfs]Get the sfs (English only)[/url].

Abhay
Posts: 23
Joined: Wed 09 Dec 2009, 20:36

Bash script to install Puppy on usb without a cd..

#2 Post by Abhay »

There was a small error while copying the code above i guess.. Here's the correct code, one can install Puppy on usb without having to burn/write a cd.. It's also attached with this post..

Yes, it runs from Puppy also, I just checked, but then it might not be of much use there since Puppy already has the universal installer to install from within Puppy to other devices..

Pls do post ur feedback if this was useful, i'd like to know about whether it was a comfortable install and/or any suggestions on corrections/improvements.. Thank you..

Code: Select all

#!/bin/sh
# install_pup.sh


# This script will install Puppy linux on a usb flash drive.
# The traditional way of doing this is by burning an iso cd,
# then running the live cd to do the installation on a usb flash drive.
# This script will help you install Puppy directly onto a usb drive
# from a host system (i.e. the current linux distro on your computer)
# without having to burn a cd.
# Basically it'll help you save some time and money which you would 
# have otherwise spent on the cd :-)


# Brief of tasks done for the installation
# 1. Extracting the iso files
# 2. Finding the devices present and choosing of the device
# 3. Formatting the partition into "fat16" or "fat32"
# 4. Setting boot flag and making boot sector (syslinux)
# 5. Copying files
# 6. Making the config file (syslinux.cfg)
# 7. Ready to Reboot


# Make sure the 2 files, the puppy iso image and this file 'install_pup.sh' are in the
# same directory. Then "cd" to that directory and run the code as a sudoer, or as root.


# 	Author: Abhay Chinivar
#	Electrical dept, Final year
#	NIT-Surathkal, Karnataka, India



clear
echo
echo "********Installation of Puppy Linux on a USB drive*********"
echo

# Extracting Files from the iso image

mkdir tempdir
mkdir /mnt/puppy
read -p "Make sure the iso file is in the same directory as the script and pls enter it's name	:" isofile
printf "Extracting files..."
mount -o loop $isofile ./tempdir
echo "						Done"
echo

# Finding the Devices using 'parted'

parted -l | grep Model > file1
num=$(wc -l file1 | awk '{print $1}')
var=$(expr $num - 1)
parted -l | grep Model | tail -$var | cat > file1
parted -l | grep Disk | tail -$var | cat > file2
sdiff -w 100 file1 file2 | cat > file3

var=$(wc -c file3 | head -c 1)
if [ "$var" = "0" ]; then
	echo "There are no usb devices found, Installation will be terminated"
else

	echo "Below are the devices found"
	echo
	cat -n file3

	echo
	echo "Choose the device on which you wnat to install Puppy"
	read -p "Enter the number of the device from the list above	:" num
	echo

	echo "The chosen device is"
	cat file3 | head -$num | tail -1
	partition=$(cat file2 | head -$num | tail -1 | awk '{print $2}' | head -c 8)
	partnum=1

	echo
	echo "The following mounted partitions are found on $partition"
	printf "	"
	df -Th | head -1
	df -Th | grep $partition | cat -n
	echo
	echo "If you don't find the partition you are looking for in the list above,"
	echo "Mount it and run the code again"
	read -p "Choose one:" num 
	df -Th | grep $partition | head -$num | tail -1 > file1
	partnum=$(cat file1 | head -c 9 | tail -c 1)


	echo
	echo "The chosen partition is: "$partition""$partnum""

# Formatting the Partition

	echo
	echo "The partition "$partition""$partnum" will now be formatted, any data in it will be lost"
	echo "Choose 'n' if you want to do a backup of files on your usb drive first"
	read -p "Format the partition? (y/n)		:" choice

	if [ "$choice" = "y" ]; then
		echo
		echo "Choose from the list below the filesystem that you want on your device"
cat > file1 <<"EOF"
fat16
fat32
EOF
		cat -n file1
		read -p "1 or 2?	:" fsnum
		echo "OK..."

		fs=$(cat file1 | head -$fsnum | tail -1)
		echo "The partition "$partition""$partnum" is being formatted to $fs"
		umount "$partition""$partnum"
		parted $partition mkfs Y $partnum $fs > file1
		sleep 3
		umount "$partition""$partnum"
		echo "								Done"
	else
		echo
		echo "Partition has not been formatted, hence Installation might not happen properly"
	fi

sleep 3

# Installation of Puppy

	echo
	echo "Installation will now start..."
	read -p "Continue? (y/n)	:" choice

	if [ "$choice" = "y" ]; then
		read -p "Do you want Puppy to run on ram?(faster)(y/n)	:" ram
	
		echo
		printf "Setting the boot flag"
		parted $partition set $partnum boot on > file1
		echo "						Done"

		mount -t vfat "$partition""$partnum" /mnt/puppy

		echo
		printf "Creating boot sector"
		syslinux "$partition""$partnum"
		echo "						Done"

		echo
		printf "Copying Puppy files onto the usb drive"
		cd tempdir
		var=$(ls)
		cp $var /mnt/puppy
		cd ..
		rm /mnt/puppy/isolinux.cfg /mnt/puppy/isolinux.bin
		echo "				Done"

		touch /mnt/puppy/USBFLASH

		echo
		printf "Creating the configuration file, syslinux.cfg"

cat > /mnt/puppy/syslinux.cfg <<"EOF"
default puppy
display boot.msg
prompt 1  
timeout 80

F1 boot.msg
F2 help.msg

label puppy
kernel vmlinuz
EOF

		if [ "$ram"="y" ]; then
			echo "append initrd=initrd.gz pmedia=usbflash pfix=copy nosmp" >> /mnt/puppy/syslinux.cfg
		else
			echo "append initrd=initrd.gz pmedia=usbflash pfix=noram nosmp" >> /mnt/puppy/syslinux.cfg
		fi
		echo "			Done"

		umount /mnt/puppy

		echo
		echo "***System is ready, you can now reboot and try the new installation***"
		echo "If any error message like 'Missing Operating System' is found when chosen filesystem is 'fat32', try reinstalling by choosing 'fat16' as the filesysem"
	else
		echo "Installation has been terminated"
	fi
fi
echo
printf "Cleaning up..."
umount tempdir
rm -r tempdir
rm -r /mnt/puppy
rm file1 file2 file3
echo "							Done"
echo


Abhay
Posts: 23
Joined: Wed 09 Dec 2009, 20:36

#3 Post by Abhay »

Extremely sorry if the above script did not work for any of you, when you tried with the newest puppy release, pup-431.. Cos i recently downloaded n installed pup-431.iso n had a problem myself... It was cos the old script searched for a file with name puppy, while t downloaded file was named pup, so it wasn't able to detect t iso file.. now it's corrected in t above post and has been attached with this post.. thank you..
Attachments
install_pup.tar.gz
The above script is attached here..
(2.1 KiB) Downloaded 1264 times

raffy
Posts: 4798
Joined: Wed 25 May 2005, 12:20
Location: Manila

Thanks

#4 Post by raffy »

Thanks, Abhay, and Happy New Year!
Puppy user since Oct 2004. Want FreeOffice? [url=http://puppylinux.info/topic/freeoffice-2012-sfs]Get the sfs (English only)[/url].

bill
Posts: 490
Joined: Wed 28 May 2008, 15:32

Thanks for this information

#5 Post by bill »

I managed to get a USB memory stick loaded with 4.3.1 and it works a treat.I do however notice an occasional popup saying "Saving ram to pup-save file" My question is,Is this a temporary file ? that is removed on
shutdown or am I supposed to ferret out the "saves" for deletion.Thanks

User avatar
hillside
Posts: 633
Joined: Sun 02 Sep 2007, 18:59
Location: Minnesota, USA. The frozen north.

#6 Post by hillside »

"Saving ram to pup-save file"

When shutting down from the first bootup, you were given the option to build a pup-save file. You apparently said yes. The pup-save file holds all your settings and anything you save inside the operating system. This is a good thing. Instead of saving continually as you work, it does the saves on a schedule to reduce wear on the usb device. You can easily delete things that you don't want to save, for instance, cookies and such.

If you don't want any saves, boot as pfix=ram or don't tell the system to build a save file.

Abhay
Posts: 23
Joined: Wed 09 Dec 2009, 20:36

#7 Post by Abhay »

@raffy: hi raffy, thanks.. wish u too a happy new year :) i guess, u r one in t puppy developement team right?..
i must say, pup-431 has got nice new features, some of which were very much required by me to start using puppy.. my AMD CPUs get really really hot when run on 1.6 GHz, so much that i've to turn my laptop upside down, n get a table fan pointing at t exhaust place.. now with SMP n t cpu-frequency scaling enabled with this version of puppy kernel, plus t ext4 support, i can happily use it :) another thing i wanted is some very fast booting OS also installed along with t ones i have, so that i can do some urgent work like checking mails etc.. i made a small, 2GB, extended partition on my hard drive n made a full install of puppy (yes, 2 GB is more than enuf for a full install of puppy :) ) now i have like 4 OSes on my hard disk :) - Kubuntu 9.10, Puppy, Vista n ENGInux (an ubuntu based distro filled with frequently required engineering tools that i had built for my college)
After installing, I boot puppy, n i find t most amazing feature of them all, a 23 second 'boot + login' time, never seen something booting this fast on my comp.. yes, this means, i press t start button on my laptop n exactly 23 seconds later i can click on "browse" to start browsing :) n another thing, connecting to my motorola mobile's gprs modem was also very easy.. something which my vista could never succeed in.. so thanks a lot guys for this OS, hope to have a good Puppy experience ahead..

@bill: yes bill, as hillside said, that's what is mostly happening.. in frugal install, puppy saves t configuration changes made when u r logged in, (xorg.conf, wallpaper n theme change etc) n t new softwares installed, into a file called "pup-save.2fs" (correct me if t file name is wrong), which is then used every time u boot to set up t same configuration which u had before shutting down.. basically nothing to worry about :)

bill
Posts: 490
Joined: Wed 28 May 2008, 15:32

http://murga-linux.com/puppy/viewtopic.php?t=49881

#8 Post by bill »

Thanks gentlemen,I appreciate the info.I think I am squared away for the moment,until next time . :wink:

User avatar
piratesmack
Posts: 100
Joined: Wed 16 Sep 2009, 14:22

#9 Post by piratesmack »

I've written a similar script.

Mine has a few extra features like reformatting the USB drive and copying additional SFS modules. It's attached to this post if anybody is interested.

Code: Select all

Usage:
        pup2usb.sh <OPTIONS>
Options:
-h | --help)
        Display this message.
-f | --format)
        Format USB device.
-i | --infile)
        Specify ISO image.
-o | --outfile)
        Specify USB device.
-s | --safe)
        Use the "safe, slow, and stupid" verion of syslinux. (More compatible)
-m | --modules)
        Copy additional SFS modules to the USB device.
Example:
        pup2usb.sh -f -i pup-431.iso -o /dev/sdc -m devx_431.sfs
Requires syslinux and util-linux-ng
Attachments
pup2usb.sh.gz
Create bootable Puppy Linux USB
(2.12 KiB) Downloaded 1082 times

Post Reply