]>
Commit | Line | Data |
---|---|---|
52ca8220 AF |
1 | ############################################################################### |
2 | # # | |
3 | # IPFire.org - A linux based firewall # | |
ea9d53c8 | 4 | # Copyright (C) 2007-2018 IPFire Team <info@ipfire.org> # |
52ca8220 AF |
5 | # # |
6 | # This program is free software: you can redistribute it and/or modify # | |
7 | # it under the terms of the GNU General Public License as published by # | |
8 | # the Free Software Foundation, either version 3 of the License, or # | |
9 | # (at your option) any later version. # | |
10 | # # | |
11 | # This program is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
18 | # # | |
19 | ############################################################################### | |
20 | ||
21 | ############################################################################### | |
22 | # Definitions | |
23 | ############################################################################### | |
24 | ||
25 | include Config | |
26 | ||
27 | VER = ipfire | |
28 | ||
29 | THISAPP = flash-image | |
30 | TARGET = $(DIR_INFO)/$(THISAPP) | |
31 | ||
c42cbc86 MT |
32 | DEVICE = $(shell losetup -f) |
33 | PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1 | |
05656571 | 34 | PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3 |
c42cbc86 | 35 | |
b302b9a6 | 36 | IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).2gb-ext4.$(BUILD_ARCH)-full-core$(CORE).img.xz |
c42cbc86 MT |
37 | |
38 | FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n | |
39 | ||
52ca8220 AF |
40 | ############################################################################### |
41 | # Top-level Rules | |
42 | ############################################################################### | |
43 | ||
44 | install : $(TARGET) | |
45 | ||
46 | check : | |
47 | ||
48 | download : | |
49 | ||
50 | md5 : | |
51 | ||
52 | ############################################################################### | |
53 | # Installation Details | |
54 | ############################################################################### | |
52ca8220 | 55 | MNThdd := /install/harddisk |
c42cbc86 | 56 | IMG := /install/images/image.img |
8a5ef45f SS |
57 | |
58 | # All sizes in blocks | |
dc7d6b20 | 59 | ifeq "$(BUILD_PLATFORM)" "arm" |
c42cbc86 | 60 | BOOTLOADER = |
8a5ef45f SS |
61 | S_OFFSET = 8192 |
62 | ||
63 | # FAT32 | |
64 | PART_TYPE = c | |
65 | else | |
c42cbc86 MT |
66 | BOOTLOADER = grub |
67 | S_OFFSET = 8192 | |
8a5ef45f SS |
68 | |
69 | # Logical | |
70 | PART_TYPE = L | |
71 | endif | |
72 | ||
0a21d63f | 73 | # /boot: 100MB - OFFSET |
02c36af4 | 74 | # / : 1200 MB |
0a21d63f | 75 | S_BOOT := $(shell echo $$(( 204800 - $(S_OFFSET) ))) |
02c36af4 | 76 | S_ROOT := 2477600 |
52ca8220 | 77 | |
7051d2af MT |
78 | PADDING = 100 # MB |
79 | ||
52ca8220 | 80 | $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) |
c42cbc86 MT |
81 | # Stop if $(MNThdd) is still mounted |
82 | mountpoint $(MNThdd) && exit 1 || exit 0 | |
83 | ||
84 | rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd) | |
85 | ||
86 | # Allocate image on disk | |
87 | dd if=/dev/zero of=$(IMG) bs=512 count=$$(( $(S_OFFSET) + $(S_BOOT) + $(S_ROOT) )) | |
88 | losetup $(DEVICE) $(IMG) | |
52ca8220 | 89 | |
c42cbc86 | 90 | # Write Partition table |
05656571 | 91 | echo -e "$(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n,0,0\n$$(( $(S_BOOT) + $(S_OFFSET) )),$(S_ROOT),L\n" \ |
f3e86ec5 | 92 | | sfdisk -uS $(DEVICE) |
025e1fe1 | 93 | -echo -e "d\n2\nw\n\q\n" | fdisk $(DEVICE) |
52ca8220 | 94 | |
c42cbc86 | 95 | kpartx -v -a $(DEVICE) |
52ca8220 AF |
96 | |
97 | # Format them | |
8a5ef45f | 98 | ifeq "$(PART_TYPE)" "c" |
c42cbc86 | 99 | mkfs.vfat $(PART_BOOT) |
185f92e1 | 100 | else |
c42cbc86 | 101 | mkfs.ext2 -F $(PART_BOOT) |
185f92e1 | 102 | endif |
c42cbc86 | 103 | mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT) |
52ca8220 | 104 | |
e9b5c815 AF |
105 | # Most systems that use Flashimages has no RTC at boot |
106 | # so the interval check should disables | |
c42cbc86 MT |
107 | tune2fs -i0 $(PART_ROOT) |
108 | ||
109 | # Mount root partition | |
110 | mount $(PART_ROOT) $(MNThdd) | |
e9b5c815 | 111 | |
c42cbc86 MT |
112 | # Mount boot partition |
113 | mkdir -pv $(MNThdd)/boot | |
114 | mount $(PART_BOOT) $(MNThdd)/boot | |
52ca8220 | 115 | |
56e211f6 | 116 | # Install Pandaboard MLO and uboot first |
a649b645 | 117 | ifeq "$(BUILD_ARCH)" "armv5tel" |
9831c245 | 118 | cp -v /boot/MLO $(MNThdd)/boot/ |
7284262a | 119 | cp -v /boot/u-boot.img $(MNThdd)/boot/ |
9831c245 AF |
120 | sync |
121 | umount $(MNThdd)/boot | |
c42cbc86 | 122 | mount $(PART_BOOT) $(MNThdd)/boot |
9831c245 AF |
123 | endif |
124 | ||
52ca8220 | 125 | # Install IPFire |
dc7d6b20 | 126 | ifneq "$(BUILD_PLATFORM)" "arm" |
c061d66f | 127 | tar -x --xz -C $(MNThdd)/ -f /install/cdrom/distro.img |
9b35b114 AF |
128 | else |
129 | tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img | |
130 | endif | |
6fafd272 AF |
131 | echo "LANGUAGE=en" >> $(MNThdd)/var/ipfire/main/settings |
132 | echo "HOSTNAME=$(SNAME)" >> $(MNThdd)/var/ipfire/main/settings | |
133 | echo "THEME=ipfire" >> $(MNThdd)/var/ipfire/main/settings | |
c42cbc86 | 134 | |
185f92e1 | 135 | -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep |
52ca8220 AF |
136 | mkdir $(MNThdd)/proc |
137 | mount --bind /proc $(MNThdd)/proc | |
138 | mount --bind /dev $(MNThdd)/dev | |
139 | mount --bind /sys $(MNThdd)/sys | |
c42cbc86 | 140 | |
52ca8220 | 141 | chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang" |
c42cbc86 MT |
142 | |
143 | # Create /etc/fstab | |
144 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \ | |
145 | "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab | |
146 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \ | |
147 | "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab | |
edc2be70 | 148 | |
c42cbc86 | 149 | ifeq "$(BOOTLOADER)" "grub" |
6b566244 AF |
150 | # backup defaults file |
151 | cp $(MNThdd)/etc/default/grub $(MNThdd)/etc/default/grub.backup | |
152 | ||
153 | # Enable also serial console on GRUB | |
154 | echo "GRUB_TERMINAL=\"serial console\"" >> $(MNThdd)/etc/default/grub | |
c42cbc86 | 155 | echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub |
6b566244 | 156 | echo "GRUB_TIMEOUT=-1" >> $(MNThdd)/etc/default/grub |
52ca8220 | 157 | |
6b566244 AF |
158 | # Add additional entry for Serial console |
159 | cp $(DIR_SRC)/config/flash-images/grub/11_linux_scon \ | |
160 | $(MNThdd)/etc/grub.d/ | |
dfc4bc56 | 161 | |
c42cbc86 MT |
162 | # Create configuration |
163 | mkdir -pv $(MNThdd)/boot/grub | |
164 | chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg | |
9831c245 | 165 | |
38956241 AF |
166 | # Insert the UUID because grub-mkconfig often fails to |
167 | # detect that correctly | |
c42cbc86 | 168 | sed -i $(MNThdd)/boot/grub/grub.cfg \ |
efd02229 | 169 | -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g" |
52ca8220 | 170 | |
c42cbc86 | 171 | # Install GRUB |
5021ee33 | 172 | grub-install --force --recheck --no-floppy --target=i386-pc \ |
c42cbc86 | 173 | --root-directory=$(MNThdd) $(DEVICE) |
6b566244 AF |
174 | |
175 | # restore orginal defaults | |
176 | mv -f $(MNThdd)/etc/default/grub.backup $(MNThdd)/etc/default/grub | |
177 | rm -f $(MNThdd)/etc/grub.d/11_linux_scon | |
185f92e1 | 178 | endif |
52ca8220 | 179 | |
920f1950 AF |
180 | # Set ramdisk mode to automatic |
181 | echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk | |
182 | ||
a2454679 MT |
183 | # Automatically resize the root partition to its maximum size at first boot |
184 | touch $(MNThdd)/.partresize | |
185 | ||
c42cbc86 MT |
186 | # Unmount |
187 | umount $(MNThdd)/proc | |
188 | umount $(MNThdd)/sys | |
189 | umount $(MNThdd)/dev | |
52ca8220 AF |
190 | umount $(MNThdd)/boot |
191 | umount $(MNThdd) | |
192 | ||
c42cbc86 | 193 | # zerofree the ext2 images to get better compression |
8a5ef45f | 194 | ifneq "$(PART_TYPE)" "c" |
c42cbc86 MT |
195 | zerofree $(PART_BOOT) |
196 | -fsck.ext2 -f -y $(PART_BOOT) | |
197 | fsck.ext2 -f -y $(PART_BOOT) | |
185f92e1 | 198 | endif |
c42cbc86 MT |
199 | zerofree $(PART_ROOT) |
200 | -fsck.ext4 -f -y $(PART_ROOT) | |
201 | fsck.ext4 -f -y $(PART_ROOT) | |
dfc4bc56 | 202 | |
e0b9a600 | 203 | sleep 10 #Ubuntu compiling: allow time to automount/dismount |
c42cbc86 MT |
204 | kpartx -d -v $(DEVICE) |
205 | losetup -d $(DEVICE) | |
52ca8220 | 206 | |
7051d2af MT |
207 | # Add padding at the end of the image (to fix alignment issues if the image is |
208 | # not copied to a block device) | |
209 | dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG) | |
210 | ||
a649b645 | 211 | ifeq "$(BUILD_ARCH)" "armv5tel" |
0a21d63f AF |
212 | # Install u-boot for Orangepi Zero/Nanopi DUO into image 8KB |
213 | dd if=/usr/share/u-boot/orangepi_zero/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc | |
56e211f6 AF |
214 | endif |
215 | ||
52ca8220 | 216 | # Compress Image |
b302b9a6 | 217 | xz $(XZ_OPT) < $(IMG) > $(IMAGE_FILE) |
c42cbc86 | 218 | rm -rf $(IMG) $(MNThdd) |