[6991] in linux-scsi channel archive

home help back first fref pref prev next nref lref last post

Re: Kernels > 1M - RFC: Makefile for Bootdisk creation

daemon@ATHENA.MIT.EDU (Ph. Marek)
Fri Aug 13 12:21:33 1999

Date:   Thu, 12 Aug 1999 06:10:28 +0200
To: linux-scsi@vger.rutgers.edu
From: "Ph. Marek" <marek@bmlv.gv.at>

Hi,

I've attached a Makefile for bootdisk creation. Works very nice, except re_creating the filesystem image if files have changed - see the commented line.

Works as follows:
You've got a directory with Makefile.include and a subdirectory for each (type of) bootdisk you create.
In each subdir is 
- another subdir fs/ with all the files on it
- a kernel (default name zImage)
- a Makefile (see example).

A subdir obj will be created for intermediary files.


The Makefile can specify type=INITRD, in which case a initrd-style-bootdisk will be created (with lilo on it).


Completely automated bootdisks - seems like your birthday, doesn't it?


>>Makefile.include start
ifneq "$(TYPE)" "initrd"

TYPE	:= normal

else

ifndef BOOTB
BOOTB	:= /boot/boot.b 
endif
ifndef LILOCONF
LILOCONF:= /tmp/make.lilo.conf
MKLILO	:= 1
endif
ifndef DISKLC
DISKLC	:= /etc/lilo.conf
endif

endif


ifndef DESTDIR 
DESTDIR := obj
endif

ifndef FS
FS := $(DESTDIR)/fs.image
endif

ifndef SIZE
SIZE := 4096
endif


ifndef SRC
SRC := fs
endif

ifndef KERNEL
KERNEL := zImage
endif

ifndef DISKIMAGE
DISKIMAGE := $(DESTDIR)/disk.image
endif

ifndef DEVICE
DEVICE := /dev/fd0
endif



ifndef FSZ
FSZ := $(FS).gz
endif

ifndef DIR
DIR := /tmp/bootdisk.tmpdir
endif


.PHONY:	clean all initrd_fs

override KS := $(shell perl -e "print int((1023 + -s shift)/1024); " $(KERNEL))


clean:
	@rm $(DISKIMAGE) $(FSZ) $(FS) 2>/dev/null || true
	@echo ""

$(FS):	
#$(shell find $(SRC) -type f -print) # funkt nicht ...
	@echo "Creating new $(FS) ($(SIZE) kB) ..."
	@dd if=/dev/zero of=$(FS) bs=1024 count=$(SIZE)
	@mke2fs -q -i 8192 -m 0 -F $(FS)
	@mkdir $(DIR) || true
	@mount -o loop $(FS) $(DIR)
	@cp -a $(SRC)/* $(DIR)/
	@umount $(FS)
	@rmdir $(DIR)
	@echo ""

$(FSZ):	$(FS)
	@ls -la $(FSZ) 2>/dev/null || true
	@echo zipping $(FS) to $(FSZ) ...
	@gzip -9 -v < $(FS) > $(FSZ)
	@ls -la $(FSZ)
	@echo ""


override FSS = $(shell perl -e "print int((1023 + -s shift)/1024); " "$(FSZ)")


ifeq "$(TYPE)" "initrd"


initrd_fs:
	@echo 'Making initrd-"root" fs ...'
	@mkfs.minix -n14 -i 16 $(DEVICE) # -v
	@echo ""
	

# initrd bootdisk
disk: $(FSZ) initrd_fs
	@echo 'Making bootable ...'
	@mkdir $(DIR) || true
	@mount $(DEVICE) $(DIR)
	@mkdir $(DIR)/dev $(DIR)/boot $(DIR)/bin $(DIR)/etc
	@cp $(KERNEL) $(DIR)/bin/zImage
	@cp $(FSZ) $(DIR)/bin/fs.gz
	@cp $(BOOTB) $(DIR)/boot/boot.b
	@cp -a $(DEVICE) $(DIR)/dev/boot
	
	@mknod $(DIR)/dev/initrd b 1 250
	@chmod 400 $(DIR)/dev/initrd

ifdef MKLILO
	@echo "boot=/dev/boot" > $(LILOCONF)
	@echo "read-only" >> $(LILOCONF)
	@echo "prompt" >> $(LILOCONF)
	@echo "timeout=100" >> $(LILOCONF)
	@echo "#vga = 4" >> $(LILOCONF)
	@echo "image = /bin/zImage" >> $(LILOCONF)
	@echo "#map = /etc/lilo.map" >> $(LILOCONF)
	@echo "initrd = /bin/fs.gz" >> $(LILOCONF)
	@echo "label = linux" >> $(LILOCONF)
	@mv $(LILOCONF) $(DIR)/$(DISKLC)
else
	@cp $(LILOCONF) $(DIR)/$(DISKLC)
endif
	@lilo -v -v -C $(DISKLC) -r $(DIR)
	
	@df $(DEVICE)
	 
	@umount $(DEVICE)
	@rmdir $(DIR)
	@echo ""

else

# "Normal" bootdisk
$(DISKIMAGE): $(FSZ)
	@printf "Kernel: %5d kB\n" $(KS)
	@printf "FS    : %5d kB\n" $(FSS)
	@printf "------:---------\n"
	@printf "Summe : %5d kB\n" $(shell echo $(FSS) + $(KS) | bc)

	@dd if=$(KERNEL) of=$(DISKIMAGE) bs=1024 count=$(KS)		2> /dev/null
	@dd if=$(FSZ) of=$(DISKIMAGE) bs=1024 count=$(FSS) seek=$(KS)	2> /dev/null

	@rdev $(DISKIMAGE) $(DEVICE)
	@rdev -R $(DISKIMAGE) 0
	@rdev -r $(DISKIMAGE) $(shell perl -e 'print 0x4000 | shift' $(KS))
	@echo Image $(DISKIMAGE) created
	@echo ""
	
disk: $(DISKIMAGE) 
	@echo Writing image to $(DEVICE) ...
	@dd if=$(DISKIMAGE) of=$(DEVICE) bs=1024
	@echo ""
endif
>>Makefile.include ends


>>Makefile start
include ../Makefile.include

all:	
	@rm $(FS) || true 
	$(MAKE) $(DISKIMAGE) 
>>Makefile ends



Ph.




-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majordomo@vger.rutgers.edu

home help back first fref pref prev next nref lref last post