Portable and persistent Ubuntu

De WikiEducator
Revisión a fecha de 10:46 14 may 2012; Juanda (Discusión | contribuciones)

(dif) ← Revisión anterior | Revisión actual (dif) | Revisión siguiente → (dif)
Saltar a: navegación, buscar

Shell script para crear una distribución linux portable y persistente tipo Debian. Probado con Lubuntu 12.04 y Ubuntu 12.04

#!/bin/bash
device=sdf
iso_file=lubuntu-12.04-desktop-i386.iso
 
echo "Creating a bootable USB stick."
echo "ISO Image: $iso_file"
echo "Device: /dev/$device"
 
echo -n -e "\nAre you sure you want to continue? (y/n): "
read confirm
 
if [ "$confirm" != "y" ]; then
    echo "You have chosen to exit. Goodbye."
    exit 0
fi
 
echo -e "\nVerifying that your USB drive does not have bad blocks"
sudo badblocks "/dev/$device""2"
 
# Format as FAT32
echo -e "\nFormating /dev/$device""1 as FAT32"
sudo mkfs.vfat -F 32 -c "/dev/$device""1"
sudo dosfslabel /dev/$device1 UBUNTULIVE
 
echo -e "\nCreating dir /media/USBDRIVE and mounting $iso_file"
sudo mkdir -p /media/USBDRIVE
sudo mount "/dev/$device""1" /media/USBDRIVE
 
# Install GRUB on the FAT32 partition of your USB drive
echo -e "\nInstalling GRUB to /media/USBDRIVE on /dev/$device"
sudo grub-install --no-floppy --root-directory=/media/USBDRIVE /dev/$device
 
## Copy the kernel and initial RAM disk from the ISO image to your GRUB directory
echo -e "\nCreating directory /mnt/isoimage, mounting $iso_file and copying kernel and RAM disk to /media/USBDRIVE/boot/"
sudo mkdir -p /mnt/isoimage
sudo mount -o loop $iso_file /mnt/isoimage
sudo cp /mnt/isoimage/casper/{vmlinuz,initrd.lz} /media/USBDRIVE/boot/
sudo umount /mnt/isoimage
sudo rmdir /mnt/isoimage
 
# Create a persistent file system to store data and customizations
echo -e "\nCreate a persistent file system to store data and customizations"
sudo dd if=/dev/zero of=/media/USBDRIVE/casper-rw bs=1M count=256
sudo mkfs.ext3 -F /media/USBDRIVE/casper-rw
 
# Write the ISO image to the hidden partition
echo -e "\nWriting IOS image ($iso_file) to /dev/$device""2"
sudo dd if=$iso_file of="/dev/$device""2"
 
echo -e "\nCreating /media/USBDRIVE/boot/grub/grub.cfg"
 
cat <<EOF >>/tmp/grub.cfg
 
set default=0
set timeout=5
### BEGIN /etc/grub.d/10_Linux ###
menuentry "Distro" {
search --set -f /boot/vmlinuz
linux /boot/vmlinuz boot=casper persistent rw file=/preseed/distro.seed
initrd /boot/initrd.lz
}
### END /etc/grub.d/10_Linux ###
 
EOF
 
sudo cp /tmp/grub.cfg /media/USBDRIVE/boot/grub/grub.cfg
rm /tmp/grub.cfg
 
echo -e "\nFinished!"