Jump to Main Content
Content > Linux > Fedora 7 on a Stick
Fedora 7 on a Stick

How to make a bootable version of Fedora 7 on a USB thumb drive.

This information was passed along by a friend and based it on this article. The .sh is part of the LiveCD tools. (Note that syslinux is now included in F7-Test4 LiveCD).

Fedora 7 now includes a "live" bootable CD image, which can be loaded to and booted from a USB stick. I.e. you can boot and run Fedora Linux without installing it to a hard drive, which makes it a great system and network troubleshooting tool.

The process of copying the image to a USB drive is a little intricate, as you have to run it on Fedora 7 itself, which means you need a bootable CD to start with. Here's how to do it using a Windows system as the starting point.

Requirements

  • Windows system
  • USB drive, 1GB or larger, formatted FAT32
  • Bootable Fedora 7 Live CD or DVD

Summary

  1. Copy the following files from the software share to a directory on the Windows system:
    F-6.93-i386-Live.iso
    creator-isotostick.sh
  2. Obtain a bootable copy of the Fedora 7 Live CD
  3. Shutdown Windows and boot Fedora 7 Live from the CD
  4. Mount the NTFS partition from step (1)
  5. Insert (and mount) the USB drive, and make note of its device name
  6. Run the creator-isotostick.sh shell script to copy the Fedora Live
    image to the USB drive
  7. Boot from the USB drive

Detail


1) In the following explanations we'll assume that you copied the Fedora
7 Live ISO image and the shell script to D:\temp.

2) There are several Fedora 7 Test 4 (Fedora 6.93) bootable CDs on my
desk. You can make your own bootable CD by writing the
F-6.93-i386-Live.iso file to a CD-R using any available CD writing
tool. Note that you want to "make a CD from an image"; don't just
copy the .iso file to a data CD.

3) Boot from the Fedora 7 Live CD and login as "root" with no password

4) Mount the Windows hard disk containing the files from step (1):

mkdir /mnt/ntfs
mount -t ntfs /dev/sda2 /mnt/ntfs

The device name is probably /dev/sda2, but may be different depending
on where you wrote the files in step 2 (C: or D: or some other partition)
and whether or not your disk has a maintenance partition. Generally:

With Maintenance Partition:
c: = /dev/sda2
d: = /dev/sda3
etc.

Without Maintenance Partition
c: = /dev/sda1
d: = /dev/sda2
etc

You may have to experiment and mount different partitions until you
find the one containing the right directory. To unmount, use the
command

umount /dev/sda[n]

5) When you insert the USB drive, Fedora should automatically recognize
it and mount it on the desktop (an icon will appear). In this case,
you can obtain the device name using the 'df' command. It will most
likely be /dev/sdb1 or /dev/sdc1, depending on how many hard drives
your system contains. You will need the device name later.

If Fedora does not mount it automatically for some reason, you can
mount it manually, and may have to guess the device name.

Fedora names disks /dev/sda, /dev/sdb, /dev/sdc and so on. The hard
drives present at boot are assigned device names in order, so when
you insert the USB drive it will get the next available device name.
If you have one hard disk drive, the USB drive will almost certainly
be /dev/sdb. Try mounting it with the commands:

mkdir /mnt/usb
mount /dev/sdb1 /mnt/usb

If this doesn't work, try /dev/sdc1.

6) Execute the creator-isotostick.sh shell script as follows (assuming
the USB drive's device name is /dev/sdb1, and the files were copied
to d:\temp in step 1; substitute the correct device name and
directory if different)

cd /mnt/ntfs/temp
./creator-isotostick.sh F-6.93-i386-Live.iso /dev/sdb1

The script takes about 3 minutes to run. When it's complete you
should be able to boot Fedora 7 from the USB drive on any system that
supports USB booting.

7) Most modern system support booting from USB drives, but you may have
to turn this option on in the BIOS configuration system that is
accessible during the boot process.



#!/bin/bash
# Convert a live CD iso so that it's bootable off of a USB stick
# Copyright 2007 Red Hat, Inc.
# Jeremy Katz <katzj@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


export PATH=/sbin:/usr/sbin:$PATH

usage() {
echo "$0 <isopath> <usbstick device>"
exit 1
}

cleanup() {
[ -d $CDMNT ] && umount $CDMNT && rmdir $CDMNT
[ -d $USBMNT ] && umount $USBMNT && rmdir $USBMNT
}

exitclean() {
echo "Cleaning up to exit..."
cleanup
exit 1
}

getdisk() {
DEV=$1

p=$(udevinfo --query=path --name=$DEV)
if [ -e /sys/$p/device ]; then
device=$(basename /sys/$p)
else
device=$(basename $(readlink -f /sys/$p/../))
fi
if [ ! -e /sys/block/$device -o ! -e /dev/$device ]; then
echo "Error finding block device of $DEV. Aborting!"
exitclean
fi

device="/dev/$device"
}

checkMBR() {
getdisk $1

bs=$(mktemp /tmp/bs.XXXXXX)
dd if=$device of=$bs bs=512 count=1 2>/dev/null || exit 2

mbrword=$(hexdump -n 2 $bs |head -n 1|awk {'print $2;'})
rm -f $bs
if [ "$mbrword" = "0000" ]; then
echo "MBR appears to be blank."
echo "You can add an MBR to this device with "
echo " # cat /usr/lib/syslinux/mbr.bin > $device"
exitclean
fi

return 0
}

checkPartActive() {
dev=$1
getdisk $dev

# if we're installing to whole-disk and not a partition, then we
# don't need to worry about being active
if [ "$dev" = "$device" ]; then
return
fi

if [ "$(/sbin/fdisk -l $device 2>/dev/null |grep $dev |awk {'print $2;'})" != "*" ]; then
echo "Partition isn't marked bootable!"
echo "You can mark the partition as bootable with "
echo " # /sbin/parted $device"
echo " (parted) toggle N boot"
exitclean
fi
}

checkFilesystem() {
dev=$1

USBFS=$(/lib/udev/vol_id -t $dev)
if [ "$USBFS" != "vfat" -a "$USBFS" != "msdos" -a "$USBFS" != "ext2" -a "$USBFS" != "ext3" ]; then
echo "USB filesystem must be vfat or ext[23]"
exitclean
fi

USBLABEL=$(/lib/udev/vol_id -u $dev)
if [ -n "$USBLABEL" ]; then
USBLABEL="UUID=$USBLABEL" ;
else
USBLABEL=$(/lib/udev/vol_id -l $dev)
if [ -n "$USBLABEL" ]; then
USBLABEL="LABEL=$USBLABEL"
else
echo "Need to have a filesystem label or UUID for your USB device"
if [ "$USBFS" = "vfat" -o "$USBFS" = "msdos" ]; then
echo "Label can be set with /sbin/dosfslabel"
elif [ "$USBFS" = "ext2" -o "$USBFS" = "ext3" ]; then
echo "Label can be set with /sbin/e2label"
fi
exitclean
fi
fi
}

checkSyslinuxVersion() {
if ! syslinux 2>&1 | grep -qe -d; then
echo "Your syslinux is too old for this."
exitclean
fi
}

if [ $(id -u) != 0 ]; then
echo "You need to be root to run this script"
exit 1
fi

if [ $# -ne 2 ]; then
usage
fi

ISO=$1
USBDEV=$2

if [ ! -f $ISO ]; then
usage
fi

if [ ! -b $USBDEV ]; then
usage
fi

# FIXME: would be better if we had better mountpoints
CDMNT=$(mktemp -d /media/cdtmp.XXXXXX)
mount -o loop $ISO $CDMNT || exitclean
USBMNT=$(mktemp -d /media/usbdev.XXXXXX)
mount $USBDEV $USBMNT || exitclean

# do some basic sanity checks.
checkSyslinuxVersion
checkFilesystem $USBDEV
checkPartActive $USBDEV
checkMBR $USBDEV

trap exitclean SIGINT SIGTERM

if [ -d $USBMNT/syslinux -o -d $USBMNT/LiveOS ]; then
echo "Already set up as live image. Deleting old in fifteen seconds..."
sleep 15

rm -rf $USBMNT/syslinux $USBMNT/LiveOS
fi

echo "Copying live image to USB stick"
mkdir $USBMNT/syslinux $USBMNT/LiveOS
cp $CDMNT/squashfs.img $USBMNT/LiveOS/squashfs.img || exitclean
cp $CDMNT/isolinux/* $USBMNT/syslinux/

echo "Updating boot config file"
# adjust label and fstype
sed -i -e "s/CDLABEL=[^ ]*/$USBLABEL/" -e "s/rootfstype=[^ ]*/rootfstype=$USBFS/" $USBMNT/syslinux/isolinux.cfg

echo "Installing boot loader"
if [ "$USBFS" = "vfat" -o "$USBFS" = "msdos" ]; then
# syslinux expects the config to be named syslinux.cfg
# and has to run with the file system unmounted
mv $USBMNT/syslinux/isolinux.cfg $USBMNT/syslinux/syslinux.cfg
cleanup
syslinux -d syslinux $USBDEV
elif [ "$USBFS" = "ext2" -o "$USBFS" = "ext3" ]; then
# extlinux expects the config to be named extlinux.conf
# and has to be run with the file system mounted
mv $USBMNT/syslinux/isolinux.cfg $USBMNT/syslinux/extlinux.conf
extlinux -i $USBMNT/syslinux
cleanup
fi

echo "USB stick set up as live image!

Other Pages
Previous Page Ubuntu - Server MySQL Configuration Notes Next Page
 
Comments are solely the opionion of the author and not to be construed as the opinion of anyone else.

Poster Thread
Anonymous
Posted: 2007/9/13 11:35  Updated: 2007/11/3 19:40
 Re: Fedora 7 on a Stick
Guide is dead easy to use. Once you get your head around the simple commands, everything gels together like a dream. Thanks.
Reply
Login
 

 

 

(c) 2006-2007 - Mark Boyden
Privacy - Legal Stuff - Contacts