]> git.ipfire.org Git - ipfire-2.x.git/blame - lfs/flash-images
Revert "core123: Ship updated usbutils"
[ipfire-2.x.git] / lfs / flash-images
CommitLineData
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
25include Config
26
27VER = ipfire
28
29THISAPP = flash-image
30TARGET = $(DIR_INFO)/$(THISAPP)
31
c42cbc86
MT
32DEVICE = $(shell losetup -f)
33PART_BOOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p1
05656571 34PART_ROOT = /dev/mapper/$(patsubst /dev/%,%,$(DEVICE))p3
c42cbc86 35
b302b9a6 36IMAGE_FILE = /install/images/$(SNAME)-$(VERSION).2gb-ext4.$(BUILD_ARCH)-full-core$(CORE).img.xz
c42cbc86
MT
37
38FSTAB_FMT = UUID=%s %-8s %-4s %-10s %d %d\n
39
52ca8220
AF
40###############################################################################
41# Top-level Rules
42###############################################################################
43
44install : $(TARGET)
45
46check :
47
48download :
49
50md5 :
51
52###############################################################################
53# Installation Details
54###############################################################################
52ca8220 55MNThdd := /install/harddisk
c42cbc86 56IMG := /install/images/image.img
8a5ef45f
SS
57
58# All sizes in blocks
dc7d6b20 59ifeq "$(BUILD_PLATFORM)" "arm"
c42cbc86 60 BOOTLOADER =
8a5ef45f
SS
61 S_OFFSET = 8192
62
63 # FAT32
64 PART_TYPE = c
65else
c42cbc86
MT
66 BOOTLOADER = grub
67 S_OFFSET = 8192
8a5ef45f
SS
68
69 # Logical
70 PART_TYPE = L
71endif
72
779706b5 73# /boot: 128MB - OFFSET
02c36af4 74# / : 1200 MB
779706b5 75S_BOOT := $(shell echo $$(( 262144 - $(S_OFFSET) )))
02c36af4 76S_ROOT := 2477600
52ca8220 77
7051d2af
MT
78PADDING = 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 98ifeq "$(PART_TYPE)" "c"
c42cbc86 99 mkfs.vfat $(PART_BOOT)
185f92e1 100else
c42cbc86 101 mkfs.ext2 -F $(PART_BOOT)
185f92e1 102endif
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 117ifeq "$(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
123endif
124
52ca8220 125 # Install IPFire
dc7d6b20 126ifneq "$(BUILD_PLATFORM)" "arm"
c061d66f 127 tar -x --xz -C $(MNThdd)/ -f /install/cdrom/distro.img
9b35b114
AF
128else
129 tar -x -C $(MNThdd)/ -f /install/cdrom/distro.img
130endif
185f92e1 131 -touch $(MNThdd)/lib/modules/$(KVER)-ipfire/modules.dep
52ca8220
AF
132 mkdir $(MNThdd)/proc
133 mount --bind /proc $(MNThdd)/proc
134 mount --bind /dev $(MNThdd)/dev
135 mount --bind /sys $(MNThdd)/sys
c42cbc86 136
52ca8220 137 chroot $(MNThdd) /usr/bin/perl -e "require '/var/ipfire/lang.pl'; &Lang::BuildCacheLang"
c42cbc86
MT
138
139 # Create /etc/fstab
140 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_BOOT))" "/boot" \
141 "auto" "defaults" 1 2 > $(MNThdd)/etc/fstab
142 printf "$(FSTAB_FMT)" "$$(blkid -o value -s UUID $(PART_ROOT))" "/" \
143 "auto" "defaults" 1 1 >> $(MNThdd)/etc/fstab
edc2be70 144
c42cbc86 145ifeq "$(BOOTLOADER)" "grub"
6b566244
AF
146 # backup defaults file
147 cp $(MNThdd)/etc/default/grub $(MNThdd)/etc/default/grub.backup
148
149 # Enable also serial console on GRUB
150 echo "GRUB_TERMINAL=\"serial console\"" >> $(MNThdd)/etc/default/grub
c42cbc86 151 echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> $(MNThdd)/etc/default/grub
52ca8220 152
6b566244
AF
153 # Add additional entry for Serial console
154 cp $(DIR_SRC)/config/flash-images/grub/11_linux_scon \
155 $(MNThdd)/etc/grub.d/
dfc4bc56 156
c42cbc86
MT
157 # Create configuration
158 mkdir -pv $(MNThdd)/boot/grub
159 chroot $(MNThdd) grub-mkconfig -o /boot/grub/grub.cfg
9831c245 160
1f2a90b5
MT
161 # Boot the first kernel by default
162 chroot $(MNThdd) grub-set-default 0
163
38956241
AF
164 # Insert the UUID because grub-mkconfig often fails to
165 # detect that correctly
c42cbc86 166 sed -i $(MNThdd)/boot/grub/grub.cfg \
efd02229 167 -e "s/root=[A-Za-z0-9\/=-]*/root=UUID=$$(blkid -o value -s UUID $(PART_ROOT))/g"
52ca8220 168
c42cbc86 169 # Install GRUB
5021ee33 170 grub-install --force --recheck --no-floppy --target=i386-pc \
c42cbc86 171 --root-directory=$(MNThdd) $(DEVICE)
6b566244
AF
172
173 # restore orginal defaults
174 mv -f $(MNThdd)/etc/default/grub.backup $(MNThdd)/etc/default/grub
175 rm -f $(MNThdd)/etc/grub.d/11_linux_scon
185f92e1 176endif
52ca8220 177
920f1950
AF
178 # Set ramdisk mode to automatic
179 echo RAMDISK_MODE=2 > $(MNThdd)/etc/sysconfig/ramdisk
180
a2454679
MT
181 # Automatically resize the root partition to its maximum size at first boot
182 touch $(MNThdd)/.partresize
183
c42cbc86
MT
184 # Unmount
185 umount $(MNThdd)/proc
186 umount $(MNThdd)/sys
187 umount $(MNThdd)/dev
52ca8220
AF
188 umount $(MNThdd)/boot
189 umount $(MNThdd)
190
c42cbc86 191 # zerofree the ext2 images to get better compression
8a5ef45f 192ifneq "$(PART_TYPE)" "c"
c42cbc86
MT
193 zerofree $(PART_BOOT)
194 -fsck.ext2 -f -y $(PART_BOOT)
195 fsck.ext2 -f -y $(PART_BOOT)
185f92e1 196endif
c42cbc86
MT
197 zerofree $(PART_ROOT)
198 -fsck.ext4 -f -y $(PART_ROOT)
199 fsck.ext4 -f -y $(PART_ROOT)
dfc4bc56 200
e0b9a600 201 sleep 10 #Ubuntu compiling: allow time to automount/dismount
c42cbc86
MT
202 kpartx -d -v $(DEVICE)
203 losetup -d $(DEVICE)
52ca8220 204
7051d2af
MT
205 # Add padding at the end of the image (to fix alignment issues if the image is
206 # not copied to a block device)
207 dd if=/dev/zero bs=1M count=$(PADDING) >> $(IMG)
208
a649b645 209ifeq "$(BUILD_ARCH)" "armv5tel"
0a21d63f
AF
210 # Install u-boot for Orangepi Zero/Nanopi DUO into image 8KB
211 dd if=/usr/share/u-boot/orangepi_zero/u-boot-sunxi-with-spl.bin of=$(IMG) bs=1K seek=8 conv=notrunc
56e211f6
AF
212endif
213
52ca8220 214 # Compress Image
b302b9a6 215 xz $(XZ_OPT) < $(IMG) > $(IMAGE_FILE)
c42cbc86 216 rm -rf $(IMG) $(MNThdd)