Skip to content

Commit d9fa592

Browse files
committed
mounting/umounting isn't quite working atm
1 parent f496e3d commit d9fa592

File tree

3 files changed

+81
-13
lines changed

3 files changed

+81
-13
lines changed

builder.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,22 @@ case "$1" in
4545
echo "Setting up deboot"
4646
get_deboot
4747
# could probably split deboot into the two stages it takes
48-
echo "Creating the chroot build environment"
49-
deboot_chroot
50-
# we need to set up locales and probably bind stuff like proc and pts here
48+
# echo "Creating the chroot build environment"
49+
# deboot_chroot
50+
echo "Bootstrapping stage one"
51+
deboot_stage_one
52+
echo "Setting up mountpoints"
53+
do_mount
54+
echo "Bootstrapping stage two"
55+
deboot_stage_two
56+
echo "Doing post install setup"
57+
deboot_setup
5158
echo "Upgrading the chroot system"
5259
upgrade_chroot
5360
echo "Installing build tools"
5461
install_build_tools
62+
echo "Undoing mountpoints"
63+
do_unmount
5564
echo "Restoring PATH"
5665
reset_path
5766
;;

configuration

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ BASE_DIR=`pwd`
2929
DUAL_PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
3030
# target and sources for our chroot
3131
ROOT_TARGET=build_environment
32-
#ROOT_SUITE=wheezy
33-
#ROOT_SOURCE=http://http.debian.net/debian
3432
ROOT_SUITE=saucy
3533
ROOT_SOURCE=http://archive.ubuntu.com/ubuntu/
34+
ROOT_LOCALE=en_US.UTF-8\ UTF-8
35+
ROOT_SOURCES_LIST="
36+
deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE main restricted universe multiverse
37+
deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE-updates main restricted universe multiverse
38+
deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE-security main restricted universe multiverse
39+
"
3640
# these packages will be installed into the chroot build environment
3741
# and are needed to build the kernel
3842
REQUIRED_PACKAGES=gcc-arm-linux-gnueabihf\ ccache\ kernel-wedge\ libncursesw5-dev

functions

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ create_directories ()
3131
mkdir -p $BASE_DIR/$DEBOOT_DIR
3232
mkdir -p $BASE_DIR/$ROOT_TARGET
3333
mkdir -p $BASE_DIR/$KERNEL_DIR
34+
mkdir -p $BASE_DIR/$ROOT_TARGET/$KERNEL_DIR
3435
}
3536

3637
#do path magic
@@ -44,6 +45,24 @@ reset_path ()
4445
{
4546
PATH=$ORIGINAL_PATH
4647
}
48+
#do the mount magic
49+
do_mount ()
50+
{
51+
mount -o bind $BASE_DIR/$KERNEL_DIR $BASE_DIR/$ROOT_TARGET/$KERNEL_DIR;
52+
mount -t proc proc $BASE_DIR/$ROOT_TARGET/proc/;
53+
mount -t sysfs sys $BASE_DIR/$ROOT_TARGET/sys/;
54+
mount -o bind /dev $BASE_DIR/$ROOT_TARGET/dev/;
55+
mount -t devpts pts $BASE_DIR/$ROOT_TARGET/dev/pts/;
56+
}
57+
do_unmount ()
58+
{
59+
umount $BASE_DIR/$ROOT_TARGET/dev/pts/;
60+
umount $BASE_DIR/$ROOT_TARGET/dev/;
61+
umount $BASE_DIR/$ROOT_TARGET/sys/;
62+
umount $BASE_DIR/$ROOT_TARGET/proc/;
63+
umount $BASE_DIR/$ROOT_TARGET/$KERNEL_DIR;
64+
}
65+
4766
# this function gets the debootstrap package and unpacks it into the appropriate directory, all ready to be used
4867
get_deboot ()
4968
{
@@ -55,6 +74,38 @@ get_deboot ()
5574
}
5675

5776
# this function just creates the chroot environment
77+
deboot_stage_one ()
78+
{
79+
# do the bootstrap
80+
DEBOOTSTRAP_DIR=$BASE_DIR/$DEBOOT_DIR/usr/share/debootstrap $BASE_DIR/$DEBOOT_DIR/usr/sbin/debootstrap --foreign --arch=$ROOT_ARCH --variant=buildd --no-check-gpg $ROOT_SUITE $BASE_DIR/$ROOT_TARGET $ROOT_SOURCE;
81+
}
82+
deboot_stage_two ()
83+
{
84+
#do the second stage bootstrap
85+
chroot $BASE_DIR/$ROOT_TARGET /debootstrap/debootstrap --second-stage;
86+
}
87+
deboot_setup ()
88+
{
89+
#stop dpkg from running daemons
90+
cat > $BASE_DIR/$ROOT_TARGET/usr/sbin/policy-rc.d <<EOF
91+
#!/bin/sh
92+
exit 101
93+
EOF
94+
chmod a+x $BASE_DIR/$ROOT_TARGET/usr/sbin/policy-rc.d;
95+
96+
# update the chroot's sources.list
97+
printf '%s' "$ROOT_SOURCES_LIST" >$BASE_DIR/$ROOT_TARGET/etc/apt/sources.list;
98+
99+
#update the locale
100+
printf '%s' "$ROOT_LOCALE" >$BASE_DIR/$ROOT_TARGET/etc/locale.gen;
101+
chroot $BASE_DIR/$ROOT_TARGET /usr/sbin/locale-gen
102+
103+
#divert ischroot
104+
#note that this throws error, my need to be fixed, not sure
105+
chroot $BASE_DIR/$ROOT_TARGET dpkg-divert --divert /usr/bin/ischroot.debianutils --rename /usr/bin/ischroot;
106+
chroot $BASE_DIR/$ROOT_TARGET /bin/ln -s /bin/true /usr/bin/ischroot;
107+
108+
}
58109
deboot_chroot ()
59110
{
60111
# do the bootstrap
@@ -72,11 +123,13 @@ EOF
72123
chmod a+x $BASE_DIR/$ROOT_TARGET/usr/sbin/policy-rc.d;
73124

74125
# update the chroot's sources.list
75-
cat > $BASE_DIR/$ROOT_TARGET/etc/apt/sources.list <<EOF
76-
deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE main restricted universe multiverse
77-
deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE-updates main restricted universe multiverse
78-
deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE-security main restricted universe multiverse
79-
EOF
126+
#cat > $BASE_DIR/$ROOT_TARGET/etc/apt/sources.list <<EOF
127+
#deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE main restricted universe multiverse
128+
#deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE-updates main restricted universe multiverse
129+
#deb http://archive.ubuntu.com/ubuntu $ROOT_SUITE-security main restricted universe multiverse
130+
#EOF
131+
printf '%s' "$ROOT_SOURCES_LIST"
132+
>$BASE_DIR/$ROOT_TARGET/etc/apt/sources.list;
80133

81134
#divert ischroot
82135
#note that this throws error, my need to be fixed, not sure
@@ -88,14 +141,14 @@ EOF
88141
# bring the chroot current
89142
upgrade_chroot ()
90143
{
91-
chroot $BASE_DIR/$ROOT_TARGET apt-get update;
92-
chroot $BASE_DIR/$ROOT_TARGET apt-get dist-upgrade;
144+
chroot $BASE_DIR/$ROOT_TARGET apt-get -qy update;
145+
chroot $BASE_DIR/$ROOT_TARGET apt-get -qy dist-upgrade;
93146
}
94147

95148
# install required packages in the chroot
96149
install_build_tools ()
97150
{
98-
chroot $BASE_DIR/$ROOT_TARGET apt-get install $REQUIRED_PACKAGES;
151+
chroot $BASE_DIR/$ROOT_TARGET apt-get -qy install $REQUIRED_PACKAGES;
99152
}
100153

101154
# this function gets the architecture for our chroot
@@ -117,6 +170,8 @@ get_architecture ()
117170
esac;
118171
}
119172

173+
# this patch was attempting to fix a problem that was actually a path
174+
# problem, so it's currently not used, but left in case it's needed later
120175
# deboot comes out of the box with an offensive mount command.
121176
# this patches it to fix the error when mounting the proc file system
122177
# this patch from http://blog.tsunanet.net/2013/01/using-debootstrap-with-grsec.html?m=1

0 commit comments

Comments
 (0)