Wiki Home » vmx25 » debian7

debian7

Last modified by Administrator on 2014/11/28 13:20
Debian is a free operating system (OS) for your computer. An operating system is the set of basic programs and utilities that make your computer run.
https://www.debian.org/

Initial steps

Create working directory

mkdir -pv ~/workdir/vmx25/rootfs/debian7
cd ~/workdir/vmx25/rootfs/debian7

Download instalation files

wget http://ftp.debian.org/debian/dists/stable/main/installer-armel/current/images/versatile/netboot/initrd.gz
wget http://ftp.debian.org/debian/dists/stable/main/installer-armel/current/images/versatile/netboot/vmlinuz-3.2.0-4-versatile

Install Debian into emulated machine

Create virtual HDD

qemu-img create -f raw ramdisk.img 2G

Install Debian

qemu-system-arm -m 256 -machine versatileab \
       -kernel vmlinuz-3.2.0-4-versatile \
       -initrd initrd.gz \
       -hda ramdisk.img -append "root=/dev/ram"

Extract installed filesystem

Find partition start offset

hexdump -C ramdisk.img | less

00000000  fa b8 00 10 8e d0 bc 00  b0 b8 00 00 8e d8 8e c0  |................|
00000010  fb be 00 7c bf 00 06 b9  00 02 f3 a4 ea 21 06 00  |...|.........!..|
00000020  00 be be 07 38 04 75 0b  83 c6 10 81 fe fe 07 75  |....8.u........u|
00000030  f3 eb 16 b4 02 b0 01 bb  00 7c b2 80 8a 74 01 8b  |.........|...t..|
00000040  4c 02 cd 13 ea 00 7c 00  00 eb fe 00 00 00 00 00  |L.....|.........|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001b0  00 00 00 00 00 00 00 00  0d 0e 07 00 00 00 80 20  |............... |
000001c0  21 00 83 f3 6f 04 00 08  00 00 00 f0 3f 00 00 00  |!...o.......?...|
000001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa  |..............U.|
00000200  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00100000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................| << here starts first partition
*
00100400  00 00 02 00 00 fe 07 00  4c 66 00 00 74 cb 05 00  |........Lf..t...|
00100410  9c 97 01 00 00 00 00 00  02 00 00 00 02 00 00 00  |................|

Copy the filesystem

mkdir -pv mount
mkdir -pv rootfs-debian7    
sudo chown root:root  rootfs-debian7
sudo mount -t ext4 -o loop,offset=1048576 ramdisk.img mount/
sudo cp -arvpf mount/* rootfs-debian7/
sudo umount mount/

Modifications

Remove persistent rules

sudo rm rootfs-debian7/etc/udev/rules.d/70-persistent*
sudo sed -i '/^#/!d' rootfs-debian7/etc/fstab
#sudo sed -i 's/iface eth0/#iface eth0/g' rootfs-debian7/etc/network/interfaces

Enable serial console

sudo su

cat >> rootfs-debian7/etc/inittab << EOF
# VMX25 serial console
T0:2345:respawn:/sbin/getty -L ttymxc0 115200 vt100
EOF


exit

Add valid nameservers

sudo su

cat > rootfs-debian7/etc/resolv.conf << EOF
domain example.org
search example.org
nameserver 8.8.8.8
nameserver 8.8.4.4
EOF


exit

Disable some services

sudo su

sed -i 's/^test -x \/usr\/lib\/exim4\/exim4/test ! -x \/usr\/lib\/exim4\/exim4/' rootfs-debian7/etc/init.d/exim4

exit
sudo su

cat << EOF > rootfs-debian7/etc/logo.sh
#!/bin/sh

NORMAL="\\\\033[0;39m"         # Standard console grey
SUCCESS="\\\\033[1;32m"        # Success is green
WARNING="\\\\033[1;33m"        # Warnings are yellow
FAILURE="\\\\033[1;31m"        # Failures are red
INFO="\\\\033[1;36m"           # Information is light cyan
BRACKET="\\\\033[1;34m"        # Brackets are blue

ramt=\$(cat /proc/meminfo | grep MemTotal | awk '{print \$2}')
ramt=\$((ramt/1024))
ramf=\$(cat /proc/meminfo | grep MemFree  | awk '{print \$2}')
ramf=\$((ramf/1024))

romt=\$(df -h | grep root | head -n1 | awk '{print \$2"B"}')
romf=\$(df -h | grep root | head -n1 | awk '{print \$4"B"}')

root=\$(mount | grep -v '^rootfs' | grep root | awk '{print \$5}')
ipaddr=\$(ifconfig eth0 | grep "inet addr" | cut -d ":" -f2 | cut -d " " -f1)

echo "             _                    "
echo -n "            :_;                   "
echo "  \$(cat /proc/cpuinfo | grep -i 'Hardware' | awk '{print \$1": "\$3" "\$4}')"
echo ".-..-. .--. .-..---.  .--.   .--. "
echo -n ": \\\`; :' .; :: :: .; \\\`' .; ; '  ..'"
printf "  RAM:%06sMB FREE:%06sMB\n" \${ramt} \${ramf}
echo -n "\\\`.__.'\\\`.__.':_;: ._.'\\\`.__,_;\\\`.__.'"
printf "  ROM:%08s FREE:%08s\n" \${romt} \${romf}
echo -n "               : :                "
echo "  ROOT: \${SUCCESS}\${root}\${NORMAL}"
echo -n "               :_;                "
echo "  IP:   \${ipaddr}"
EOF

chmod a+x rootfs-debian7/etc/logo.sh
sed -i '/^exit/d' rootfs-debian7/etc/rc.local
cat << EOF >> rootfs-debian7/etc/rc.local
# Voipac logo
. /etc/logo.sh
exit 0
EOF


exit

Strip down filesystem even more

sudo cp -arvp rootfs-debian7 rootfs-debian7-tiny

sudo apt-get install qemu-user-static
sudo cp /usr/bin/qemu-arm-static rootfs-debian7-tiny/usr/bin
sudo chroot rootfs-debian7-tiny apt-get install localepurge
sudo chroot rootfs-debian7-tiny localepurge
#sudo chroot rootfs-debian7-tiny dpkg --get-selections
sudo chroot rootfs-debian7-tiny apt-get purge linux-image-versatile
sudo chroot rootfs-debian7-tiny apt-get purge linux-image-3.2.0-4-versatile

Package final filesystem

NFS

sudo cp -arvpf rootfs-debian7/ /srv/nfs/rootfs-debian7-vmx25
/srv/nfs/rootfs-debian7-vmx25 *(rw,no_root_squash,no_all_squash,no_subtree_check,sync)
sudo exportfs -ra

TAR

cd rootfs-debian7-tiny/
sudo tar cvJpf ../rootfs-debian7-nfs_vmx25_$(date "+%Y%m%d").tar.xz *
Tags:
Created by Administrator on 2014/10/05 14:35

This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 6.1 - Documentation