aboutsummaryrefslogtreecommitdiffstats
path: root/freedom-maker/mk_dreamplug_rootfs
blob: 5f11bc940d54282e532398b112d02273605ffa7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/bin/bash
# 
# Copyright 2011 by Bdale Garbee <bdale@gag.com>
# 
# 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 3 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, see <http://www.gnu.org/licenses/>.
# 

# based on work by <ivan@sanchezortega.es>, who released his script under
# the following license terms:
#  ----------------------------------------------------------------------------
#  "THE BEER-WARE LICENSE" (Revision 42):
#  As long as you retain this notice you can do whatever you want with 
#  this stuff. If we meet some day, and you think this stuff is worth it, 
#  you can buy me a beer in return.
#  ----------------------------------------------------------------------------

# mk_dreamplug_rootfs
#
# Runs multistrap and readies the resulting root filesystem to silently 
# complete package configuration on the first boot-up.

# where to build images, etc
basedir=`pwd`/build
target=$basedir/dreamplug
tmpdir=$basedir/tmp
pkgcache=$tmpdir/aptcache

mkdir -p $target
mkdir -p $tmpdir
mkdir -p $pkgcache

hostname='freedombox'
rootpassword='freedom'

kernelimage=http://www.newit.co.uk/kernels/Dreamplug/Dreamplug-prerelease/uImage
kernelmodules=http://www.newit.co.uk/kernels/Dreamplug/Dreamplug-prerelease/Modules.tar.gz

if [ ! -f $tmpdir/uImage ]
then
	wget -c $kernelimage --output-document="$tmpdir/uImage"
fi
if [ ! -f $tmpdir/linux.tar.gz ]
then
	wget -c $kernelmodules --output-document="$tmpdir/linux.tar.gz"
fi

rm -rf $target/*

mkdir -p $target/var/cache/apt/ && mount -o bind $pkgcache $target/var/cache/apt/

echo "Multistrapping..."
multistrap -f fbx-armel.conf --no-auth -d $target 

umount $target/var/cache/apt/
mkdir $target/var/cache/apt/archives

echo "Unpacking kernel modules..."
mkdir -p $target/lib/modules/
tar -C $target/lib/ -zxvf $tmpdir/linux.tar.gz | tail

echo "copy uImage to target filesystem"
mkdir -p $target/boot
cp build/tmp/uImage $target/boot/uImage
echo "copy copy2dream.sh script to target filesystem"
cp bin/copy2dream.sh $target/boot/copy2dream.sh

# Until udev is configured and run for the first time, dev nodes won't be created, but we need some basic ones for spawning a console (console) and creating RSA keys for SSH (urandom).
echo "Creating basic device nodes"
mknod $target/dev/console c 5 1
mknod $target/dev/random c 1 8
mknod $target/dev/urandom c 1 9
mknod $target/dev/null c 1 3
mknod $target/dev/ptmx c 5 2

# Basic fstab & mtab..
echo "Setting up basic fstab & mtab"
echo "
rootfs	/		rootfs	relatime,rw	0	0
proc	/proc		proc	none		0	0
sys	/sys		sysfs	none		0	0
none	/dev/pts	devpts	defaults	0	0
tmpfs   /tmp            tmpfs   rw,nosuid,nodev 0       0
" > $target/etc/fstab

touch $target/etc/mtab

# Set up hostname
echo "Setting up hostname, /etc/network/interfaces, nameservers, persistent-net-generator rules"
echo $hostname > $target/etc/hostname

# Create /etc/network/interfaces
echo "# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp

allow-hotplug eth1
iface eth1 inet dhcp
        " > $target/etc/network/interfaces

# Override the above stuff - we know better
cp ../packages/torouter-prep/configs/interfaces $target/etc/network/interfaces

# Stop the libertas module from loading
cp ../packages/torouter-prep/configs/modprobe.d-blacklist.conf $target/etc/modprobe.d/blacklist.conf

# Setup nameserver (use OpenDNS by default)
echo "nameserver 208.67.222.222
nameserver 208.67.220.220" > $target/etc/resolv.conf

# Touch the net generator udev so that eth0 won't be reassigned in case the user
# changes the MAC address - this may happen if you change the rootfs between plugs.
touch $target/etc/udev/rules.d/75-persistent-net-generator.rules

# generate configuration script

echo "Create script to configure packages in qemu-user-static"

echo "
echo \"Preconfiguring dash - else dash and bash will be left in a broken state\"
/var/lib/dpkg/info/dash.preinst install

echo \"Configuring all packages\"
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
export LC_ALL=C LANGUAGE=C LANG=C
dpkg --configure -a

# Establish an initial root password
echo \"Set root password to \"$rootpassword
echo root:$rootpassword | /usr/sbin/chpasswd

# By default, spawn a console on the serial port
echo \"Adding a getty on the serial port\"
echo \"T0:12345:respawn:/sbin/getty -L ttyS0 115200 vt100\" >> /etc/inittab

echo \"Tweaks to reduce flash writes as per http://www.plugcomputer.org/plugwiki/index.php/Reduce_Flash_Writes\"
echo \"
# Reduce writes to flash drives
vm.laptop_mode=5
vm.swappiness=0
vm.dirty_writeback_centisecs=1500
vm.dirty_expire_centisecs=1500
\" >> /etc/sysctl.conf

echo \"Deleting this very same script\"
rm -f /install.sh

echo \"Syncing filesystem just in case something didn't get written\"
sync

echo \"End configuration progress by exiting from the chroot\"
exit

" > $target/install.sh  

chmod 755 $target/install.sh

echo "Use qemu-user-static to perform first-boot configuration now"

mkdir -p $target/usr/bin
cp /usr/bin/qemu-arm-static $target/usr/bin
chroot $target /install.sh
rm $target/usr/bin/qemu-arm-static

echo "Syncing..."
sync

echo "Finished. You may now copy the rootfs to the plug."