Installare una distro da penna USB
Questa breve guida vi spiegherà come installare la vostra immagine ISO contenente una distribuzione Linux senza dover masterizzare un CD ma semplicemente utilizzando una normale pennina USB.
Prima di tutto avrete bisogno di una USB stick che riesca a contenere l’immagine, che però non andrà copiata direttamente, e di un BIOS che sia predisposto per il boot da dispositivi rimovibili (per l’appunto la nostra penna USB). Una volta scaricata l’immagine ISO della nostra distribuzione installiamo syslinux ed mtools:
# apt-get install syslinux mtools
Una volta fatto ciò scarichiamo lo script isostick.sh:
#!/bin/bash ## Rende avviabile una USB stick con una immagine ISO ## Tradotto da skydiamond nel novembre 2008 (http://skydiamond.org) # Copyright 2007 Red Hat, Inc. # Jeremy Katz # Jani Monoses (slightly adapted to Ubuntu LiveCD) # # 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 [--reset-mbr] [--noverify] " exit 1 } cleanup() { [ -d "$CDMNT" ] && umount $CDMNT && rmdir $CDMNT [ -d "$USBMNT" ] && umount $USBMNT && rmdir $USBMNT } exitclean() { echo "Pulendo prima di uscire..." cleanup exit 1 } getdisk() { DEV=$1 p=$(udevinfo -q path -n $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" } resetMBR() { getdisk $1 cat /usr/lib/syslinux/mbr.bin > $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 sembra vuoto." echo "Vuoi rimpiazzare il MBR su questo dispositivo?" echo "Premi INVIO per continuare o CTRL-C per abortire" read resetMBR $1 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 "La partizione non appare segnata come avviabile!" echo "Puoi rendere avviabile la partizione con " echo " # /sbin/parted $device" echo " (parted) toggle N boot" echo " (parted) quit" 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 "Il filesystem USB deve essere vfat o 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 "Bisogna impostare un'etichetta per il tuo dispositivo USB o una UUID" if [ "$USBFS" = "vfat" -o "$USBFS" = "msdos" ]; then echo "L'etichetta puo' essere impostata tramite /sbin/dosfslabel" elif [ "$USBFS" = "ext2" -o "$USBFS" = "ext3" ]; then echo "L'etichetta puo' essere impostata tramite /sbin/e2label" fi exitclean fi fi } checkSyslinuxVersion() { if [ ! -x /usr/bin/syslinux ]; then echo "Hai bisogno di avere installato syslinux per eseguire questo script" exit 1 fi if ! syslinux 2>&1 | grep -qe -d; then SYSLINUXPATH="" else SYSLINUXPATH="syslinux" #menu texts are trimmed when syslinux is not in / no idea why SYSLINUXPATH="" fi } if [ $(id -u) != 0 ]; then echo "Devi essere root per eseguire questo script" exit 1 fi while [ $# -gt 2 ]; do case $1 in --noverify) noverify=1 ;; --reset-mbr|--resetmbr) resetmbr=1 ;; *) usage ;; esac shift done ISO=$1 USBDEV=$2 if [ -z "$ISO" -o ! -e "$ISO" ]; then usage fi if [ -z "$USBDEV" -o ! -b "$USBDEV" ]; then usage fi if [ -z "$noverify" ]; then # verify the image echo "Non sto verificando l'immagine...(no checkisomd5 in Ubuntu so skipping)!" #checkisomd5 --verbose $ISO if [ $? -ne 0 ]; then echo "Sei sicuro di voler continuare?" echo "Premi INVIO per continuare o CTRL-C per abortire" read fi fi # do some basic sanity checks. checkSyslinuxVersion checkFilesystem $USBDEV checkPartActive $USBDEV checkMBR $USBDEV [ -n $resetmbr ] && resetMBR $USBDEV # 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 trap exitclean SIGINT SIGTERM if [ -d $USBMNT/casper ]; then echo "Gia' presente una immagine live. Cancellando la vecchia immagine in quindici secondi..." sleep 15 rm -rf $USBMNT/casper fi echo "Copiando l'immagine live sulla USB stick" if [ ! -d $USBMNT/$SYSLINUXPATH ]; then mkdir $USBMNT/$SYSLINUXPATH ; fi for file in \ README.diskdefines md5sum.txt \ .disk casper pool dists preseed install;do cp -a $CDMNT/$file $USBMNT/ done cp $CDMNT/isolinux/* $USBMNT/$SYSLINUXPATH echo "Installando il 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/$SYSLINUXPATH/isolinux.cfg $USBMNT/$SYSLINUXPATH/syslinux.cfg cleanup if [ -n "$SYSLINUXPATH" ]; then syslinux -d $SYSLINUXPATH $USBDEV else syslinux $USBDEV fi 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/$SYSLINUXPATH/isolinux.cfg $USBMNT/$SYSLINUXPATH/extlinux.conf extlinux -i $USBMNT/$SYSLINUXPATH cleanup fi echo "Adesso sulla tua penna USB hai una immagine live!"
Rendiamolo poi eseguibile tramite il comando:
chmod +x isostick.shE infire lanciamo il comando:
# ./isostick.sh IMMAGINE.iso /dev/sdX1
Dove sdX1 è il nome della risorsa dove è collegata la pennina USB (per conoscerla basta dare un mount). Al resto pensa lo script.
Si potrebbero riscontrare errori del tipo:
cp: impossibile preservare il proprietario di
Il problema è dovuto al fatto che il filesystem su penna USB è di tipo FAT32 il quale non conserva i permessi dei file se copiati da un filesystem quale ext3.














Tags:
Categorie: 







esce questo errore appena scivo l’ultimo comando:
./isostick.sh: line 29: syntax error near unexpected token `&’
./isostick.sh: line 29: ` [ -d "$CDMNT" ] && umount $CDMNT && rmdir $CDMNT’