]>
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 | |
784cd5cb MT |
34 | ifeq "$(EFI)" "1" |
35 | PART_EFI = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p2 | |
36 | endif | |
05656571 | 37 | PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3 |
c42cbc86 | 38 | |
b302b9a6 | 39 | IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).2gb-ext4.$(BUILD_ARCH)-full-core$(CORE).img.xz |
c42cbc86 MT |
40 | |
41 | FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n | |
42 | ||
52ca8220 AF |
43 | ############################################################################### |
44 | # Top-level Rules | |
45 | ############################################################################### | |
46 | ||
47 | install : $(TARGET) | |
48 | ||
49 | check : | |
50 | ||
51 | download : | |
52 | ||
53 | md5 : | |
54 | ||
55 | ############################################################################### | |
56 | # Installation Details | |
57 | ############################################################################### | |
52ca8220 | 58 | MNThdd := /install/harddisk |
c42cbc86 | 59 | IMG := /install/images/image.img |
8a5ef45f SS |
60 | |
61 | # All sizes in blocks | |
f096a2ea | 62 | ifeq "$(BUILD_ARCH)" "armv5tel" |
c42cbc86 | 63 | BOOTLOADER = |
8a5ef45f SS |
64 | S_OFFSET = 8192 |
65 | ||
66 | # FAT32 | |
67 | PART_TYPE = c | |
68 | else | |
c42cbc86 MT |
69 | BOOTLOADER = grub |
70 | S_OFFSET = 8192 | |
8a5ef45f | 71 | |
89e79c50 | 72 | # Linux |
8a5ef45f SS |
73 | PART_TYPE = L |
74 | endif | |
75 | ||
89e79c50 MT |
76 | # /boot: 128MB - OFFSET |
77 | # / : 1200 MB | |
78 | S_BOOT := $(shell echo $$(( 262144 - $(S_OFFSET) ))) | |
79 | S_ROOT := 2477600 | |
80 | ||
784cd5cb | 81 | ifeq "$(EFI)" "1" |
b89c7379 | 82 | S_EFI = 65536 # 32 MB |
784cd5cb MT |
83 | else |
84 | S_EFI = 0 | |
85 | endif | |
86 | ||
7051d2af MT |
87 | PADDING = 100 # MB |
88 | ||
784cd5cb | 89 | ifeq "$(EFI)" "1" |
784cd5cb MT |
90 | SFDISK = $(SFDISK_BOOT)$(SFDISK_EFI)$(SFDISK_ROOT) |
91 | else | |
89e79c50 | 92 | SFDISK = $(SFDISK_BOOT)$(SFDISK_ROOT) |
784cd5cb MT |
93 | endif |
94 | ||
89e79c50 MT |
95 | SFDISK_BOOT = $(S_OFFSET),$(S_BOOT),$(PART_TYPE),*\n |
96 | SFDISK_EFI = $(shell echo $$(( $(S_OFFSET) + $(S_BOOT) ))),$(S_EFI),U\n | |
97 | SFDISK_ROOT = $(shell echo $$(( $(S_OFFSET) + $(S_BOOT) + $(S_EFI) ))),$(S_ROOT),L\n | |
784cd5cb | 98 | |
52ca8220 | 99 | $(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects)) |
c42cbc86 MT |
100 | # Stop if $(MNThdd) is still mounted |
101 | mountpoint $(MNThdd) && exit 1 || exit 0 | |
102 | ||
103 | rm -rf $(IMG) $(MNThdd) && mkdir -p $(MNThdd) | |
104 | ||
105 | # Allocate image on disk | |
784cd5cb | 106 | dd if=/dev/zero of=$(IMG) bs=512 count=$$(( $(S_OFFSET) + $(S_BOOT) + $(S_EFI) + $(S_ROOT) )) |
c42cbc86 | 107 | losetup $(DEVICE) $(IMG) |
52ca8220 | 108 | |
c42cbc86 | 109 | # Write Partition table |
784cd5cb MT |
110 | echo -e "$(SFDISK)" | sfdisk -uS $(DEVICE) |
111 | ||
c42cbc86 | 112 | kpartx -v -a $(DEVICE) |
52ca8220 AF |
113 | |
114 | # Format them | |
8a5ef45f | 115 | ifeq "$(PART_TYPE)" "c" |
c42cbc86 | 116 | mkfs.vfat $(PART_BOOT) |
185f92e1 | 117 | else |
c42cbc86 | 118 | mkfs.ext2 -F $(PART_BOOT) |
784cd5cb MT |
119 | endif |
120 | ifeq "$(EFI)" "1" | |
121 | mkfs.vfat $(PART_EFI) | |
185f92e1 | 122 | endif |
c42cbc86 | 123 | mkfs.ext4 -O ^has_journal,extent -F $(PART_ROOT) |
52ca8220 | 124 | |
e9b5c815 AF |
125 | # Most systems that use Flashimages has no RTC at boot |
126 | # so the interval check should disables | |
c42cbc86 MT |
127 | tune2fs -i0 $(PART_ROOT) |
128 | ||
129 | # Mount root partition | |
130 | mount $(PART_ROOT) $(MNThdd) | |
e9b5c815 | 131 | |
c42cbc86 MT |
132 | # Mount boot partition |
133 | mkdir -pv $(MNThdd)/boot | |
134 | mount $(PART_BOOT) $(MNThdd)/boot | |
52ca8220 | 135 | |
784cd5cb MT |
136 | ifeq "$(EFI)" "1" |
137 | mkdir -pv $(MNThdd)/boot/efi | |
138 | mount $(PART_EFI) $(MNThdd)/boot/efi | |
139 | endif | |
140 | ||
56e211f6 | 141 | # Install Pandaboard MLO and uboot first |
a649b645 | 142 | ifeq "$(BUILD_ARCH)" "armv5tel" |
9831c245 | 143 | cp -v /boot/MLO $(MNThdd)/boot/ |
7284262a | 144 | cp -v /boot/u-boot.img $(MNThdd)/boot/ |
9831c245 AF |
145 | sync |
146 | umount $(MNThdd)/boot | |
c42cbc86 | 147 | mount $(PART_BOOT) $(MNThdd)/boot |
9831c245 AF |
148 | endif |
149 | ||
52ca8220 | 150 | # Install IPFire |
dc7d6b20 | 151 | ifneq "$(BUILD_PLATFORM)" "arm" |
c061d66f | 152 | tar -x --xz -C $(MNThdd)/ -f /install/cdrom/distro.img |
9b35b114 AF |
153 | else |
154 | tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img | |
155 | endif | |
185f92e1 | 156 | -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep |
52ca8220 AF |
157 | mkdir $(MNThdd)/proc |
158 | mount --bind /proc $(MNThdd)/proc | |
159 | mount --bind /dev $(MNThdd)/dev | |
160 | mount --bind /sys $(MNThdd)/sys | |
c42cbc86 | 161 | |
52ca8220 | 162 | chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang" |
c42cbc86 MT |
163 | |
164 | # Create /etc/fstab | |
165 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \ | |
166 | "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab | |
784cd5cb MT |
167 | ifeq "$(EFI)" "1" |
168 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_EFI))" "/boot/efi" \ | |
169 | "auto" "defaults" 1 2 >> $(MNThdd)/etc/fstab | |
170 | endif | |
c42cbc86 MT |
171 | printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \ |
172 | "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab | |
edc2be70 | 173 | |
c42cbc86 | 174 | ifeq "$(BOOTLOADER)" "grub" |
6b566244 AF |
175 | # backup defaults file |
176 | cp $(MNThdd)/etc/default/grub $(MNThdd)/etc/default/grub.backup | |
177 | ||
178 | # Enable also serial console on GRUB | |
179 | echo "GRUB_TERMINAL=\"serial console\"" >> $(MNThdd)/etc/default/grub | |
c42cbc86 | 180 | echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub |
52ca8220 | 181 | |
6b566244 AF |
182 | # Add additional entry for Serial console |
183 | cp $(DIR_SRC)/config/flash-images/grub/11_linux_scon \ | |
184 | $(MNThdd)/etc/grub.d/ | |
dfc4bc56 | 185 | |
c42cbc86 | 186 | # Create configuration |
dfb0084e MT |
187 | mkdir -pv $(MNThdd)/boot/grub |
188 | chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg | |
9831c245 | 189 | |
1f2a90b5 MT |
190 | # Boot the first kernel by default |
191 | chroot $(MNThdd) grub-set-default 0 | |
192 | ||
38956241 AF |
193 | # Insert the UUID because grub-mkconfig often fails to |
194 | # detect that correctly | |
c42cbc86 | 195 | sed -i $(MNThdd)/boot/grub/grub.cfg \ |
efd02229 | 196 | -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g" |
52ca8220 | 197 | |
c42cbc86 | 198 | # Install GRUB |
5021ee33 | 199 | grub-install --force --recheck --no-floppy --target=i386-pc \ |
c42cbc86 | 200 | --root-directory=$(MNThdd) $(DEVICE) |
6b566244 | 201 | |
7d456c39 MT |
202 | ifeq "$(EFI)" "1" |
203 | # Install GRUB for EFI | |
204 | grub-install --target=$(BUILD_ARCH)-efi --removable --no-nvram \ | |
205 | --boot-directory=$(MNThdd)/boot --efi-directory=$(MNThdd)/boot/efi | |
206 | endif | |
207 | ||
6b566244 AF |
208 | # restore orginal defaults |
209 | mv -f $(MNThdd)/etc/default/grub.backup $(MNThdd)/etc/default/grub | |
210 | rm -f $(MNThdd)/etc/grub.d/11_linux_scon | |
185f92e1 | 211 | endif |
52ca8220 | 212 | |
920f1950 AF |
213 | # Set ramdisk mode to automatic |
214 | echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk | |
215 | ||
a2454679 MT |
216 | # Automatically resize the root partition to its maximum size at first boot |
217 | touch $(MNThdd)/.partresize | |
218 | ||
c42cbc86 MT |
219 | # Unmount |
220 | umount $(MNThdd)/proc | |
221 | umount $(MNThdd)/sys | |
222 | umount $(MNThdd)/dev | |
784cd5cb MT |
223 | ifeq "$(EFI)" "1" |
224 | umount $(MNThdd)/boot/efi | |
225 | endif | |
52ca8220 AF |
226 | umount $(MNThdd)/boot |
227 | umount $(MNThdd) | |
228 | ||
c42cbc86 | 229 | # zerofree the ext2 images to get better compression |
8a5ef45f | 230 | ifneq "$(PART_TYPE)" "c" |
c42cbc86 MT |
231 | zerofree $(PART_BOOT) |
232 | -fsck.ext2 -f -y $(PART_BOOT) | |
233 | fsck.ext2 -f -y $(PART_BOOT) | |
185f92e1 | 234 | endif |
c42cbc86 MT |
235 | zerofree $(PART_ROOT) |
236 | -fsck.ext4 -f -y $(PART_ROOT) | |
237 | fsck.ext4 -f -y $(PART_ROOT) | |
dfc4bc56 | 238 | |
e0b9a600 | 239 | sleep 10 #Ubuntu compiling: allow time to automount/dismount |
c42cbc86 MT |
240 | kpartx -d -v $(DEVICE) |
241 | losetup -d $(DEVICE) | |
52ca8220 | 242 | |
7051d2af MT |
243 | # Add padding at the end of the image (to fix alignment issues if the image is |
244 | # not copied to a block device) | |
245 | dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG) | |
246 | ||
a649b645 | 247 | ifeq "$(BUILD_ARCH)" "armv5tel" |
0a21d63f AF |
248 | # Install u-boot for Orangepi Zero/Nanopi DUO into image 8KB |
249 | dd if=/usr/share/u-boot/orangepi_zero/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc | |
56e211f6 AF |
250 | endif |
251 | ||
52ca8220 | 252 | # Compress Image |
b302b9a6 | 253 | xz $(XZ_OPT) < $(IMG) > $(IMAGE_FILE) |
c42cbc86 | 254 | rm -rf $(IMG) $(MNThdd) |