giovedì 3 aprile 2008

Installare la distro con uno script

Visto che l'abbiamo realizzata la nostra distro... una volta fatta possiamo anche eventualmente installarla! Per farlo basterà avviare la distro personalizzata sl PC in questione, dopodiché con un partizionatore (leggasi gparted, cfdisk o similari) crearsi almeno 2 partizioni una di swap (di almeno 1,5 volte la dimensione della ram) e una su cui andremo ad installare il nostro bel sistema. E se avevamo preinstallato sul sistema live: grub (che non significa che fosse il bootloader del cd ma solo che fosse presente tra i pacchetti che abbiamo passato alla lista d'installazione) potremo facilmente utilizzare uno script come questo:

maiolinuxinstaller.sh
#!/bin/sh
# maiuzinstaller - installa una distro maiolinux su hd
# Copyright (C) 2007 Francesco Maioli
#
# maiuzinstaller comes with ABSOLUTELY NO WARRANTY;
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# On Debian systems, the complete text of the GNU General Public License
# can be found in /usr/share/common-licenses/GPL-2 file.
#
if [ $# -eq 3 ]
then
PARTIZIONE_SISTEMA=$1
DISCO_AVVIO=$2
NOME_DISTRO=$3
else
echo -e "Uso: `basename $0` partizione_dove_installare disco_di_avvio nome_distro\nes. `basename $0` /dev/hda2 /dev/hda maiolinux\n\nRicorda che questo script funziona solo con partizioni tipo ext3" 1>&2
exit 1
fi
#
echo -e "Copia dei file del sistema\nsarà necessario qualche minuto...\n"
#
touch tmp_file_1
touch tmp_file_2
TMP_FILE_1=tmp_file_1
TMP_FILE_2=tmp_file_2
#
mkdir -p /mnt/disk
mount -t ext3 $PARTIZIONE_SISTEMA /mnt/disk
#
mkdir -p /mnt/squashfs
mount -t squashfs -o loop /live/image/live/filesystem.squashfs /mnt/squashfs
#
cp -a /mnt/squashfs/* /mnt/disk
#
umount /mnt/squashfs
rmdir /mnt/squashfs
#
cp -a /live/cow/etc/* /mnt/disk/etc
#
echo -e "Installazione del sistema di avvio\n"
#
grub-install --root-directory=/mnt/disk $DISCO_AVVIO --no-floppy
#
LIVE_GRUB=/live/image/boot/grub/menu.lst
HD_GRUB="/mnt/disk/boot/grub"
#
echo "timeout 3" > $TMP_FILE_1
echo "default 0" >> $TMP_FILE_1
#
echo "title $NOME_DISTRO" >> $TMP_FILE_1
echo -n "kernel /boot/" >> $TMP_FILE_1
#
cat $LIVE_GRUB | grep "vmlinuz-" > $TMP_FILE_2
while read LINE1
do
echo -n `echo $LINE1 | cut -d ' ' -f2,2 | cut -d '/' -f3,3` >> $TMP_FILE_1
break
done > $TMP_FILE_1
echo " locale=it_IT.UTF-8 keyb=it vga=771" >> $TMP_FILE_1
#
echo -n "initrd /boot/" >> $TMP_FILE_1
#
cat $LIVE_GRUB | grep "initrd.img-" > $TMP_FILE_2
while read LINE1
do
echo -n $LINE1 | cut -d ' ' -f2,2 | cut -d '/' -f3,3 >> $TMP_FILE_1
break
done < $TMP_FILE_2
#
mkdir -p $HD_GRUB
cp $TMP_FILE_1 $HD_GRUB"/menu.lst"
#
rm -f $TMP_FILE_1
rm -f $TMP_FILE_2
#
umount /mnt/disk
#
clear
#
echo -e "\n\n\n\n\nInstallazione del sistema completata\nora potete riavviare il sistema"

Che è un semplice script che ho riadattato alle mie esigenze e che in pratica copia il sistema live sulla partizione che gli passate
Uso: maiolinuxinstaller partizione_dove_installare disco_di_avvio nome_distro
es. maiolinuxinstaller /dev/hda2 /dev/hda maiolinux

Ricorda che questo script funziona solo con partizioni tipo ext3

(e forse anche in partizione ext2 o altre ma non ho provato)

Magari mettete un collegamento sul desktop live così da facilitare l'installazione!
In ogni caso per includere lo script nel sistema live io l'ho posizionato in:
config/chroot_local-includes/usr/local/bin/

Saluti MaiuZ