source: trunk/debian/rootfs/debian.mk @ 312

Last change on this file since 312 was 312, checked in by amain, 8 years ago

debian/rootfs: several fixes for using second stage install with qemu

File size: 8.0 KB
Line 
1# DebWrt - Debian on Embedded devices
2#
3# Copyright (C) 2010 Johan van Zoomeren <amain@debwrt.net>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18DEBIAN_ROOTFS_INCLUDE_PACKAGES:=$(call qstrip,$(CONFIG_DEBIAN_ROOTFS_INCLUDE_PACKAGES))
19DEBIAN_ROOTFS_QEMU_2ND_STAGE:=$(call qstrip, $(CONFIG_DEBIAN_ROOTFS_QEMU_2ND_STAGE))
20DEBWRT_EXTRA_ROOTFS_FILES_DIR:=$(TOPDIR)/debian/rootfs/files
21DEBWRT_MODULES_ARCHIVE=$(shell ls $(INSTALL_DIR)/debwrt-modules-*.tar.gz 2>/dev/null)
22MODULES_VERSION=$(shell echo `basename $(DEBWRT_MODULES_ARCHIVE) 2>/dev/null` | awk -F '-' '{print $$6}')
23
24define qemu-prepare-enter
25        @if [ ! -x $(QEMU_BIN_STATIC) ]; then echo "E: can't find qemu ($(QEMU_BIN_STATIC))"; fi
26        @if [ ! -e /proc/sys/fs/binfmt_misc/qemu-$(TARGET_ARCH) ]; then echo "E: can't find binfmt_misc qemu-$(TARGET_ARCH) ( /proc/sys/fs/binfmt_misc/qemu-$(TARGET_ARCH)).\nE: install qemu-user-static, or\nE: disable second stage with qemu with menuconfig (DEBIAN_ROOTFS_QEMU_2ND_STAGE)."; fi
27        @if [ ! -x $(QEMU_BIN_STATIC) -o ! -e /proc/sys/fs/binfmt_misc/qemu-$(TARGET_ARCH) ]; then echo "E: abort"; exit 1; fi
28        @sudo cp $(QEMU_BIN_STATIC) $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
29        @if ! sudo chroot $(ROOTFS_BUILD_DIR) /bin/ls >/dev/null; then echo "E: qemu can't execute binaries for $(TARGET_ARCH)"; echo "E: abort"; exit 1; fi
30endef
31
32chr:
33        $(call qemu-prepare-enter)
34        @sudo bash -c "echo "debwrt-$(TARGET_ARCH)" > $(ROOTFS_BUILD_DIR)/etc/debian_chroot"
35        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt
36        @sudo bash -c "cat /etc/resolv.conf | grep nameserver >$(ROOTFS_BUILD_DIR)/etc/resolv.conf"
37        @sudo chroot $(ROOTFS_BUILD_DIR)
38        @sudo rm -f $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
39        @sudo rm -f $(ROOTFS_BUILD_DIR)/etc/debian_chroot
40        @sudo cp $(ROOTFS_BUILD_DIR)/etc/resolv.conf_debwrt $(ROOTFS_BUILD_DIR)/etc/resolv.conf
41
42debian/rootfs: debian/rootfs/bootstrap         \
43               debian/rootfs/unpack            \
44               debian/rootfs/files-install     \
45               debian/rootfs/debwrt-packages   \
46               debian/rootfs/modules-install   \
47               debian/rootfs/post-setup        \
48               debian/rootfs/second-stage-qemu
49        @echo "I: root filesystem $(DEBIAN_BUILD_VERSION) $(TARGET_ARCH) prepared in $(ROOTFS_BUILD_DIR)"
50        @echo "I: don't forget to install the correct kernel modules"
51        @echo "I: kernel modules can be copied manually, or build and copied by:"
52        @echo "I: - make openwrt/all"
53        @echo "I: - make debian/rootfs/modules-install"
54        @echo "I:"
55        @echo "I: install the image to USB-Disk/USB-Stick/SD-Card (make sure it is already mounted at /media/DEBWRT_ROOTFS)"
56        @echo "I: - make debian/rootfs/install"
57        @echo "I:"
58        @echo "I: enter the change root(with qemu) and perform additional post install steps:"
59        @echo "I: - make chr"
60        @echi "I: - apt-get update # example statement ;-) - networking works!"
61        touch $@
62
63debian/rootfs/install: debian/rootfs
64        if [ -d /media/DEBWRT_ROOT ]; then \
65                sudo rm -rf /media/DEBWRT_ROOT/*; \
66                sudo bash -c "tar cf - -C $(ROOTFS_BUILD_DIR) . | tar xf - -C /media/DEBWRT_ROOT"; \
67        fi
68        #touch $@
69
70debian/rootfs/save:
71        if [ -d /media/DEBWRT_ROOT ]; then \
72                sudo bash -c "tar cjf debwrt-rootfs-$(TARGET_ARCH)-$(VERSION).tar.bz2 -C /media/DEBWRT_ROOT ."; \
73        fi
74
75debian/rootfs/files-install: debian/rootfs/bootstrap
76        if [ ! -f $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian -a -e $(ROOTFS_BUILD_DIR)/etc/init.d/rcS ]; then \
77                sudo mv -v $(ROOTFS_BUILD_DIR)/etc/init.d/rcS $(ROOTFS_BUILD_DIR)/etc/init.d/rcS.debian; \
78        fi
79        if [ ! -p $(ROOTFS_BUILD_DIR)/dev/initctl ]; then  \
80                sudo mkdir -p $(ROOTFS_BUILD_DIR)/dev;         \
81                sudo mkfifo   $(ROOTFS_BUILD_DIR)/dev/initctl; \
82        fi
83        chmod 600 $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/etc/ssh/ssh_host_rsa_key
84        chmod 600 $(DEBWRT_EXTRA_ROOTFS_FILES_DIR)/etc/ssh/ssh_host_dsa_key
85        sudo bash -c "tar cf - --exclude=".svn" -C $(DEBWRT_EXTRA_ROOTFS_FILES_DIR) . | tar -xovf - -C $(ROOTFS_BUILD_DIR)"
86        sudo cat $(ROOTFS_BUILD_DIR)/etc/securetty \
87                $(TOPDIR)/debian/rootfs/securetty.tail \
88                >> $(TOPDIR)/securetty.temp
89        sudo mv $(TOPDIR)/securetty.temp $(ROOTFS_BUILD_DIR)/etc/securetty
90        touch $@
91
92debian/rootfs/modules-install: debian/rootfs/bootstrap
93ifneq ($(DEBWRT_MODULES_ARCHIVE),)
94        sudo tar xof $(DEBWRT_MODULES_ARCHIVE) -C $(ROOTFS_BUILD_DIR)
95        #sudo depmod -a -b $(ROOTFS_BUILD_DIR) $(MODULES_VERSION)
96else
97        @echo "W: Can't install kernel module to the change root. Kernel modules archive missing. ($(DEBWRT_MODULES_ARCHIVE))"
98endif
99        touch $@
100
101debian/rootfs/bootstrap: debian/rootfs/clean-rootfs-dir
102        sudo debootstrap --arch=$(TARGET_ARCH)\
103                     --foreign \
104                     --include=$(shell grep -v '^#' \
105                       $(DEBIAN_ROOTFS_INCLUDE_PACKAGES) \
106                         | tr '\n' , | sed -e 's/^/"/' -e 's/,$$/"/' ) \
107                     $(DEBIAN_BUILD_VERSION) \
108                     $(ROOTFS_BUILD_DIR) \
109                     $(CONFIG_DEBIAN_BUILDENV_REPOSITORY)
110        # complete ROOTFS/dev/ with additional device files
111        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v consoleonly"
112        sudo bash -c "cd $(ROOTFS_BUILD_DIR)/dev ; /sbin/MAKEDEV -v sda"
113        touch $@
114
115debian/rootfs/unpack: debian/rootfs/bootstrap
116        find $(ROOTFS_BUILD_DIR) -name "*.deb" | while read deb; do \
117                n=`basename $$deb`; \
118                echo -n "I: Extracting $${n}..."; \
119                sudo bash -c "dpkg --extract "$$deb" $(ROOTFS_BUILD_DIR)" ; \
120                echo "done"; \
121        done
122        touch $@
123
124# install all available cross-compiled debwrt debian packages, except for the kernel-headers package and the cross packages
125debian/rootfs/debwrt-packages: debian/rootfs/bootstrap debian/package/rootfs
126        ls ${INSTALL_DIR_DEBIAN_PACKAGES}/*.deb | grep -v "debwrt-kernel-headers" | grep -v "cross" | while read package; do \
127                pfname=`basename $$package`; \
128                pname=`echo $$pfname | sed 's/_.*//'`; \
129                echo "Installing DebWrt package: $$pname"; \
130                sudo cp $$package $(ROOTFS_BUILD_DIR)/var/cache/apt/archives; \
131                sudo dpkg-deb -x $$package $(ROOTFS_BUILD_DIR); \
132                sudo bash -c "echo \"$$pname /var/cache/apt/archives/$$pfname\" >>$(ROOTFS_BUILD_DIR)/debootstrap/debpaths" ;\
133                sudo sed -i "s/$$/$$pname /" $(ROOTFS_BUILD_DIR)/debootstrap/base ;\
134        done
135        touch $@
136       
137debian/rootfs/clean-rootfs-dir:
138        mkdir -p $(BUILD_DIR_BASE)
139        sudo rm -rf $(ROOTFS_BUILD_DIR)
140        touch $@
141
142debian/rootfs/post-setup: debian/rootfs/bootstrap
143        sudo mkdir -p $(ROOTFS_BUILD_DIR)/etc/apt
144        # note: unfortunately /etc/apt/sources.list is cleaned after running second stage install
145        sudo bash -c "echo \"deb $(call qstrip,$(DEBIAN_BUILDENV_REPOSITORY)) $(DEBIAN_BUILD_VERSION) main\" > $(ROOTFS_BUILD_DIR)/etc/apt/sources.list"
146        sudo bash -c "echo \"$(DEBWRTVERSION)\" >$(ROOTFS_BUILD_DIR)/etc/debwrt_version"
147        sudo bash -c "echo \"$(DEBIAN_BUILD_VERSION)\" >$(ROOTFS_BUILD_DIR)/etc/debian_release"
148        touch $@
149
150ifeq ($(DEBIAN_ROOTFS_QEMU_2ND_STAGE),y)
151debian/rootfs/second-stage-qemu: debian/rootfs/bootstrap debian/buildenv/qemu-build
152        $(call qemu-prepare-enter)
153        sudo chroot $(ROOTFS_BUILD_DIR) /usr/sbin/PostInstall && sudo rm -f $(ROOTFS_BUILD_DIR)/usr/sbin/PostInstall
154        sudo rm -f $(ROOTFS_BUILD_DIR)$(QEMU_INTERPRETER)
155else
156debian/rootfs/second-stage-qemu: debian/rootfs/bootstrap
157        @echo "I: Qemu 2nd stage install disabled. Second stage needs now to be performend on the target device itself."
158        @echo "I: Qemu 2nd stage install can be enabled using menuconfig (DEBIAN_ROOTFS_QEMU_2ND_STAGE)."
159endif
160        touch $@
161
162debian/rootfs/clean: 
163        sudo rm -rf $(ROOTFS_BUILD_DIR)
164        rm -f debian/rootfs/debwrt-packages
165        rm -f debian/rootfs/bootstrap
166        rm -f debian/rootfs/install
167        rm -f debian/rootfs/files-install
168        rm -f debian/rootfs/modules-install
169
Note: See TracBrowser for help on using the repository browser.