Archives de catégorie : Debian

WRT1900AC : Créer un système de fichier linux

Objectif

En vue de faire tourner Debian sur le WRT1900AC, en plus de créer un firmware, j’ai du créer un système de fichier linux dont je liste les étapes.

/!\

Stocké le système de fichier linux sur une clef USB est déconseillée sauf si le contrôleur incorpore la technologie du « wear levelling » comme la Sandisk Extrem ou la Corsair voyager GTX. En effet, certains secteurs de stockage s’useront beaucoup trop rapidement à cause des différents fichiers journaux (/var/log), fichier temporaire(/tmp), fichier de pid, etc… Gardez une chose à l’esprit, plus la clef est petite, plus une partie de la clef va s’user rapidement par rapport à l’autre.

Préparation du système

La construction d’un système de fichier se décompose en 2 phases par l’intermediaire du programme debootstrap.

Installation des paquets

apt-get install debootstrap  qemu-user-static arm-none-eabi*
  • Liste des architectures disponible :
alpha amd64 arm arm64 armel armhf hppa hurd-i386 i386 ia64 kfreebsd-amd64 kfreebsd-i386 m68k mipsel mips powerpc ppc64el s390 s390x sh sparc

Phase 1

  • Par exemple :

Pour un routeur WRT1900AC d’architecture armhf :

mkdir  -p /home/WRT1900AC/jessie-armhf
cd /home/WRT1900AC/jessie-armhf
debootstrap --foreign --no-check-gpg --arch=armhf jessie /home/WRT1900AC/jessie-armhf ftp://ftp.debian.org/debian/
cp /usr/bin/qemu-arm-static /home/WRT1900AC/jessie-armhf/usr/bin/
cp /etc/resolv.conf /home/WRT1900AC/jessie-armhf/etc/

Phase 2

  • Avec chroot, on rentre dans le nouveau system de fichier et on exécute la 2e phase.
chroot /home/WRT1900AC/jessie-armhf
echo WRT1900AC > /etc/hostname

/debootstrap/debootstrap --second-stage
  • tweak
passwd -d root

cat << EOF > /etc/apt/sources.list
deb http://ftp.de.debian.org/debian jessie main contrib non-free
deb http://ftp.de.debian.org/debian jessie-updates main contrib non-free
deb http://security.debian.org/debian-security jessie/updates main contrib non-free
EOF

apt-get update
apt-get install ca-certificates  locales localepurge dialog openssh-server ntpdate debconf

dpkg-reconfigure locales # configure la zone
dpkg-reconfigure tzdata #configure la time zone
 
apt-get dist-upgrade

cat << EOF >> /etc/network/interfaces
allow-hotplug br-lan0
iface br-lan0 inet static
address 192.168.10.10
gateway 192.168.10.1
netmask 255.255.255.0
bridge_ports eth0 eth1
EOF
 
apt-get clean
exit

En 1 script

  • Si on factorise, execution des 2 phases en 1 script :
#!/bin/bash
MACHINE=WRT1900AC
ARCH=armhf
DIR=/home/${MACHINE}
DEPOT=http://ftp.debian.org/debian/
CODE=jessie
IP=192.168.0.1
MASK=255.255.255.0
GW=192.168.0.254
PWD_ROOT=MotDePasse

mkdir  -p ${DIR}/${CODE}-${ARCH}
cd ${DIR}/${CODE}-${ARCH}
echo "1e phase..."
debootstrap --foreign --no-check-gpg --arch=${ARCH} ${CODE} ${DIR}/${CODE}-${ARCH} ${DEPOT}
cp /usr/bin/qemu-arm-static ${DIR}/${CODE}-${ARCH}/usr/bin/
cp /etc/resolv.conf ${DIR}/${CODE}-${ARCH}/etc/
echo ${MACHINE} > ${DIR}/${CODE}-${ARCH}/etc/hostname

cat << EOF > ${DIR}/${CODE}-${ARCH}/startup
echo "2e phase..."
/debootstrap/debootstrap --second-stage

echo "root:${PWD_ROOT}" | chpasswd
cat << FILE > /etc/apt/sources.list
deb ${DEPOT} ${CODE} main contrib non-free
deb ${DEPOT} ${CODE}-updates main contrib non-free
deb http://security.debian.org/debian-security ${CODE}/updates main contrib non-free
FILE
apt-get update
apt-get install ca-certificates  locales localepurge dialog openssh-server ntpdate debconf -y
apt-get dist-upgrade -y
cat << FILE >> /etc/network/interfaces
allow-hotplug eth0
iface eth0 inet static
address ${IP}
gateway ${GW}
netmask ${MASK}
FILE
apt-get clean
exit
EOF
chmod +x ${DIR}/${CODE}-${ARCH}/startup
chroot ${DIR}/${CODE}-${ARCH} /startup
echo "Si besoin :
Pour configurer les variables LC   : dpkg-reconfigure locales
Pour configurer la time zone Paris : dpkg-reconfigure tzdata"


Après le firmware, il faut un système de fichier pour le WRT1900AC.

Compiler et configurer hostapd.

Qui n’a jamais rêvé d’avoir un réseau wifi au maximum de ses capacités de fonctionnement malgré plein de box voisines perturbant l’environnement?

Patch a appliquer ici.

Le script d’installation qui s’occupe de tout 😉 :

[code lang= »shell »]

#!/bin/bash
# Definition de quelques couleurs
red=’\e[0;31m’
redhl=’\e[0;31;7m’
RED=’\e[1;31m’
blue=’\e[0;34m’
BLUE=’\e[1;34m’
cyan=’\e[0;36m’
CYAN=’\e[1;36m’
NC=’\e[0m’ # No Colo

if [ $USER != "root" ]
then
echo -e $RED"Vous devez être root pour lancer ce progamme!"$NC
exit 1
fi

VERSION=2.5
apt-get install pkg-config make patch gcc libnl-genl-3-dev libnl-3-dev bridge-utils hostapd libssl-dev -y

brctl addbr br0
brctl addif br0 eth0
echo "DAEMON_CONF=\"/etc/hostapd/wlan0.conf" > /etc/default/hostapd
cd /usr/local/src/
wget http://w1.fi/releases/hostapd-${VERSION}.tar.gz
tar xzvf hostapd-${VERSION}.tar.gz

cd hostapd-${VERSION}/
wget http://jbsky.fr/Download/patch.hostapd
patch -p0 < patch.hostapd

cd ../hostapd-${VERSION}/hostapd
cp defconfig .config
cat << EOF >> .config
CONFIG_ACS=y
CONFIG_IEEE80211R=y
CONFIG_IEEE80211N=y
CONFIG_IEEE80211AC=y
CONFIG_DRIVER_NL80211=y

CONFIG_LIBNL32=y
CONFIG_LIBNL20=y
CONFIG_CTRL_IFACE=y
CONFIG_WPS=y
CONFIG_WPS2=y
CONFIG_P2P=y
CONFIG_AP=y
EOF
make
cp hostapd /usr/sbin/
cp hostapd_cli /usr/sbin/
[/code]

En général, les fichiers de configuration sont à placer dans /etc/hostapd/.

[code lang= »shell »]
interface=wlan0
# bridge=br0
driver=nl80211
ctrl_interface=/var/run/hostapd
ssid=Hotspot_2Ghz
ignore_broadcast_ssid=0
hw_mode=g
channel=11
auth_algs=1
wmm_enabled=1
ieee80211n=1
ht_capab=[LDPC][SHORT-GI-20][SHORT-GI-40][HT40-]
ieee80211ac=0

wpa=2
wpa_passphrase=password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
country_code=FR
[/code]