Created
November 12, 2012 20:33
-
-
Save shawe/4061702 to your computer and use it in GitHub Desktop.
Pequeño script para generar una imagen Debian Wheezy en SD para Hackberry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Creamos carpeta para archivos requeridos | |
mkdir -p ~/Hackberryan/uboot_files | |
cd ~/Hackberryan/uboot_files | |
# Descargamos archivos requeridos | |
wget -c http://dl.miniand.com/jas-hacks/uboot/1gb/sunxi-spl.bin | |
wget -c http://dl.miniand.com/jas-hacks/uboot/1gb/u-boot.bin | |
wget -c http://dl.miniand.com/jas-hacks/new_tv_t100/script.bin | |
# Renombramos archivo | |
mv script.bin evb.bin | |
cd ~/Hackberryan | |
# Formatear completamente una tarjeta SD de 32GB (cambiar 32 por el tamaño de la tarjeta) | |
# NOTA: 32Mx1M=32G Puede necesitar mucho tiempo | |
# Solo es necesario formatear el entorno de u-boot | |
#sudo dd if=/dev/zero of=/dev/mmcblk0 bs=1MB count=32M conv=fsync | |
sudo dd if=/dev/zero of=/dev/mmcblk0 bs=512 count=2047 conv=fsync | |
sudo sync | |
# Expulsar la tarjeta, esperar unos segundos e introducirla de nuevo | |
sudo partprobe | |
# Creamos una tabla de particiones vacía | |
(echo o; echo w) | sudo fdisk /dev/mmcblk0 | |
sudo partprobe | |
# Creamos 2 particiones, la primera de 16M y la segunda con el resto de espacio libre | |
(echo n; echo p; echo "1"; echo; echo "+16M"; echo n; echo p; echo "2"; echo; echo; echo w) | sudo fdisk /dev/mmcblk0 | |
sudo partprobe | |
# Formateamos las 2 particiones que acabamos de crear | |
sudo mkfs.vfat -n BOOT_FS /dev/mmcblk0p1 | |
sudo mkfs.ext4 -L ROOT_FS /dev/mmcblk0p2 | |
sudo sync | |
# Instalamos paquetes necesarios | |
sudo apt-get -y --force-yes install debootstrap qemu-user-static qemu-kvm-extras-static binfmt-support libusb-1.0-0-dev | |
# Iniciamos entorno debootstrap | |
sudo debootstrap --verbose --arch armhf --variant=minbase --foreign wheezy Debian-Wheezy_debootstrap http://ftp.debian.org/debian | |
sudo modprobe binfmt_misc | |
sudo cp /usr/bin/qemu-arm-static ~/Hackberryan/Debian-Wheezy_debootstrap/usr/bin | |
sudo mkdir -p ~/Hackberryan/Debian-Wheezy_debootstrap/dev/pts | |
sudo mount -t devpts devpts ~/Hackberryan/Debian-Wheezy_debootstrap/dev/pts | |
sudo mount -t proc proc ~/Hackberryan/Debian-Wheezy_debootstrap/proc | |
# Continuamos con el entorno desde chroot | |
sudo chroot ~/Hackberryan/Debian-Wheezy_debootstrap/ /bin/bash <<CHROOTEOF | |
# You should see "I have no name!@hostname:/#" | |
/debootstrap/debootstrap --second-stage | |
wait | |
# At the end, you should see "I: Base system installed successfully." | |
cd /root | |
cat <<END > /etc/apt/sources.list | |
deb http://ftp.debian.org/debian/ wheezy main contrib non-free | |
deb-src http://ftp.debian.org/debian/ wheezy main contrib non-free | |
END | |
apt-get update | |
export LANG=C | |
apt-get -y install apt-utils | |
wait | |
apt-get -y install dialog | |
wait | |
apt-get -y install locales | |
wait | |
sed -i 's/# es_ES.UTF-8 UTF-8/es_ES.UTF-8 UTF-8/' //etc/locale.gen | |
echo “es_ES.UTF-8 UTF-8” >> /etc/locale.gen | |
cat <<END > /etc/default/locale | |
LANGUAGE=es_ES | |
LC_ALL=es_ES.UTF-8 | |
LC_PAPER=es_ES.UTF-8 | |
LC_NUMERIC=es_ES.utf8 | |
LC_IDENTIFICATION=es_ES.UTF-8 | |
LC_MEASUREMENT=es_ES.utf8 | |
LC_NAME=es_ES.UTF-8 | |
LC_TELEPHONE=es_ES.UTF-8 | |
LC_ADDRESS=es_ES.UTF-8 | |
LC_MONETARY=es_ES.utf8 | |
LC_TIME=es_ES.utf8 | |
LANG=C | |
END | |
cat <<END > /etc/apt/apt.conf.d/71hackberry | |
APT::Install-Recommends "0"; | |
APT::Install-Suggests "0"; | |
END | |
apt-get -y install isc-dhcp-common udev netbase ifupdown iproute openssh-server | |
wait | |
apt-get -y install iputils-ping wget net-tools ntpdate uboot-mkimage uboot-envtools vim mount | |
wait | |
apt-get -y install nano less module-init-tools wpasupplicant dhcpcd5 dbus perl-modules | |
wait | |
### Set up network | |
cat <<END > /etc/network/interfaces | |
auto lo eth0 wlan0 | |
iface lo inet loopback | |
iface eth0 inet dhcp | |
hwaddress ether 00:11:22:33:44:55 | |
iface wlan0 inet dhcp | |
wpa-essid YOUR_WIFI | |
wpa-psk YOUR_WIFI_PASS | |
END | |
### Set hostname in image | |
echo "HackBerryan" > //etc/hostname | |
### File system mounts. | |
cat <<END > //etc/fstab | |
# /etc/fstab: static file system information. | |
# | |
# <file system> <mount point> <type> <options> <dump> <pass> | |
/dev/root / ext4 noatime,errors=remount-ro 0 1 | |
tmpfs /tmp tmpfs defaults 0 0 | |
END | |
## Activate remote console and disable local consoles. | |
echo 'T0:2345:respawn:/sbin/getty -L ttyS0 115200 linux' >> //etc/inittab | |
sed -i 's/^\([1-6]:.* tty[1-6]\)/#\1/' //etc/inittab | |
echo root:hackberry|chpasswd | |
wait | |
CHROOTEOF | |
sudo umount ~/Hackberryan/Debian-Wheezy_debootstrap/proc | |
sudo umount ~/Hackberryan/Debian-Wheezy_debootstrap/dev/pts | |
sudo dd if=~/Hackberryan/uboot_files/sunxi-spl.bin of=/dev/mmcblk0 bs=1024 seek=8 | |
sudo dd if=~/Hackberryan/uboot_files/u-boot.bin of=/dev/mmcblk0 bs=1024 seek=32 | |
git clone git://github.com/linux-sunxi/linux-sunxi.git | |
cd linux-sunxi | |
git checkout sunxi-3.0 | |
make clean | |
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- sun4i_defconfig | |
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j16 uImage modules | |
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=optional modules_install | |
sudo cp optional/* ~/Hackberryan/Debian-Wheezy_debootstrap/ | |
mkdir -p ~/Hackberryan/mountpoints/BOOTFS | |
sudo mount /dev/mmcblk0p1 ~/Hackberryan/mountpoints/BOOTFS | |
sudo cp arch/arm/boot/uImage ~/Hackberryan//mountpoints/BOOTFS/ | |
cd ~/Hackberryan/uboot_files | |
cat <<END > boot.cmd | |
setenv console 'ttyS0,115200' | |
setenv root '/dev/mmcblk0p2' | |
setenv panicarg 'panic=10' | |
setenv extra 'rootfstype=ext4 rootwait' | |
setenv loglevel '8' | |
setenv setargs 'setenv bootargs console=${console} root=${root} loglevel=${loglevel} ${panicarg} ${extra}' | |
setenv kernel 'uImage' | |
setenv boot_mmc 'fatload mmc 0 0x43000000 script.bin; fatload mmc 0 0x48000000 ${kernel}; bootm 0x48000000' | |
setenv bootcmd 'run setargs boot_mmc' | |
END | |
mkimage -A arm -O u-boot -T script -C none -n "boot" -d boot.cmd boot.scr | |
sudo cp boot.scr ~/Hackberryan/mountpoints/BOOTFS/ | |
cd ~/Hackberryan | |
git clone https://github.com/linux-sunxi/sunxi-tools | |
cd sunxi-tools | |
make clean | |
make | |
cd ~/Hackberryan/uboot_files | |
~/sunxi-tools/bin2fex evb.bin evb.fex | |
sed s/000000000000/001122334455/ evb.fex >evbmac.fex | |
~/sunxi-tools/fex evb.bin evb.fex | |
~/sunxi-tools/fex2bin evbmac.fex evb-custom.bin | |
sudo cp evb-custom.bin ~/Hackberryan/mountpoints/BOOTFS/evb.bin | |
sudo cp evb-custom.bin ~/Hackberryan/mountpoints/BOOTFS/script.bin | |
sudo sync | |
mkdir -p mountpoints/ROOTFS | |
sudo mount /dev/mmcblk0p2 mountpoints/ROOTFS | |
cd ~/Hackberryan/Debian-Wheezy_debootstrap | |
sudo cp -a * ~/Hackberryan/mountpoints/ROOTFS/ | |
sudo sync | |
sudo umount ~/Hackberryan/mountpoints/BOOTFS | |
sudo umount ~/Hackberryan/mountpoints/ROOTFS | |
sudo dd if=~/Hackberryan/uboot_files/sunxi-spl.bin of=/dev/mmcblk0 bs=1024 seek=8 | |
sudo dd if=~/Hackberryan/uboot_files/u-boot.bin of=/dev/mmcblk0 bs=1024 seek=32 | |
sudo sync |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment