r1883 - trunk/packages/initramfs

alexander at linuxfromscratch.org alexander at linuxfromscratch.org
Tue May 8 09:05:11 PDT 2007


Author: alexander
Date: 2007-05-08 10:05:11 -0600 (Tue, 08 May 2007)
New Revision: 1883

Modified:
   trunk/packages/initramfs/Makefile
   trunk/packages/initramfs/init.in
Log:
Initial support for copying the whole CD to RAM.
Shutdown is currently unclean in this situation.


Modified: trunk/packages/initramfs/Makefile
===================================================================
--- trunk/packages/initramfs/Makefile	2007-05-08 13:26:58 UTC (rev 1882)
+++ trunk/packages/initramfs/Makefile	2007-05-08 16:05:11 UTC (rev 1883)
@@ -25,6 +25,7 @@
 	sed -i 's/, *GROUP="[^"]*"//' $(WDIR)/etc/udev/rules.d/*
 	sed s/@VERSION@/$(VERSION)/ init.in >$(WDIR)/init
 	chmod 755 $(WDIR)/init
+	cp fakecd.iso.head $(WDIR)
 	mknod -m 640 $(WDIR)/dev/console c 5 1
 	mknod -m 664 $(WDIR)/dev/null c 1 3
 	cp /bin/{sh,dd,cat,cp,mkdir,mount,umount,sed,sleep,ln,rm,uname} $(WDIR)/bin

Modified: trunk/packages/initramfs/init.in
===================================================================
--- trunk/packages/initramfs/init.in	2007-05-08 13:26:58 UTC (rev 1882)
+++ trunk/packages/initramfs/init.in	2007-05-08 16:05:11 UTC (rev 1883)
@@ -13,6 +13,7 @@
 noresume=0
 resume=
 all_generic_ide=0
+toram=0
 
 find_cd() {
 	for SYS in /sys/block/hd* /sys/block/sr* ; do
@@ -39,6 +40,46 @@
 	esac
 }
 
+copy_cd_to_ram() {
+	mount -n -t iso9660 -o ro,norock /dev/lfs-cd /.tmpfs/.cdrom
+	cat /fakecd.iso.head >/.tmpfs/.fakecd.iso
+	dd if=/.tmpfs/.cdrom/root.ext2 bs=2048 conv=sync >>/.tmpfs/.fakecd.iso
+	# Update volume size
+	vsize=`stat -c '%s' /.tmpfs/.fakecd.iso`
+	vsize=$(( $vsize >> 11 ))
+	printf $(printf '\\x%x\\x%x\\x%x\\x%x\\x%x\\x%x\\x%x\\x%x\n' \
+		$(( vsize & 0xff )) $(( ( vsize >> 8 ) & 0xff )) \
+		$(( ( vsize >> 16 ) & 0xff )) $(( ( vsize >> 24 ) & 0xff )) \
+		$(( ( vsize >> 24 ) & 0xff )) $(( ( vsize >> 16 ) & 0xff )) \
+		$(( ( vsize >> 8 ) & 0xff )) $(( vsize & 0xff )) \
+	) | dd of=/.tmpfs/.fakecd.iso bs=1 seek=32848 conv=notrunc 2>/dev/null
+	# Update compressed size
+	csize=`stat -c '%s' /.tmpfs/.cdrom/root.ext2`
+	printf $(printf '\\x%x\\x%x\\x%x\\x%x\\x%x\\x%x\\x%x\\x%x\n' \
+		$(( csize & 0xff )) $(( ( csize >> 8 ) & 0xff )) \
+		$(( ( csize >> 16 ) & 0xff )) $(( ( csize >> 24 ) & 0xff )) \
+		$(( ( csize >> 24 ) & 0xff )) $(( ( csize >> 16 ) & 0xff )) \
+		$(( ( csize >> 8 ) & 0xff )) $(( csize & 0xff )) \
+	) | dd of=/.tmpfs/.fakecd.iso bs=1 seek=47352 conv=notrunc 2>/dev/null
+	# Update compression parameters
+	dd if=/.tmpfs/.cdrom/root.ext2 of=of=/.tmpfs/.fakecd.iso \
+		bs=1 count=2 skip=12 seek=47473 conv=notrunc 2>/dev/null
+	# Update uncompressed size
+	dd if=/.tmpfs/.cdrom/root.ext2 of=of=/.tmpfs/.fakecd.iso \
+		bs=1 count=4 skip=8 seek=47475 conv=notrunc 2>/dev/null
+	dd if=/.tmpfs/.cdrom/root.ext2 of=of=/.tmpfs/.fakecd.iso \
+		bs=1 count=1 skip=11 seek=47479 conv=notrunc 2>/dev/null
+	dd if=/.tmpfs/.cdrom/root.ext2 of=of=/.tmpfs/.fakecd.iso \
+		bs=1 count=1 skip=10 seek=47480 conv=notrunc 2>/dev/null
+	dd if=/.tmpfs/.cdrom/root.ext2 of=of=/.tmpfs/.fakecd.iso \
+		bs=1 count=1 skip=9 seek=47481 conv=notrunc 2>/dev/null
+	dd if=/.tmpfs/.cdrom/root.ext2 of=of=/.tmpfs/.fakecd.iso \
+		bs=1 count=1 skip=8 seek=47482 conv=notrunc 2>/dev/null
+	umount -n /.tmpfs/.cdrom
+	/sbin/losetup /dev/loop2 /.tmpfs/.fakecd.iso
+	ln -sf /dev/loop2 /dev/lfs-cd
+}
+
 do_mount_cd() {
 	while [ ! -L /dev/lfs-cd ] ; do
 		find_cd
@@ -60,6 +101,7 @@
 	mkdir /.tmpfs
 	mount -n -t tmpfs -o size=90% tmpfs /.tmpfs
 	mkdir /.tmpfs/.cdrom
+	if [ "$toram" = 1 ] ; then copy_cd_to_ram ; fi
 	mount -n -t iso9660 -o ro /dev/lfs-cd /.tmpfs/.cdrom
 	/sbin/losetup /dev/loop0 /.tmpfs/.cdrom/root.ext2
 	SIZE=`/sbin/blockdev --getsize /dev/loop0`
@@ -70,7 +112,7 @@
 	echo "0 $SIZE snapshot /dev/loop0 /dev/loop1 p 8" | /sbin/dmsetup create lfs-cd
 	mount -n -t ext2 /dev/mapper/lfs-cd /.root
 	mount -n --move /.tmpfs /.root/dev/shm
-	cp -a /dev/lfs-cd /.root/dev/lfs-cd
+	if [ "$toram" != 1 ] ; then cp -a /dev/lfs-cd /.root/dev/lfs-cd ; fi
 	cat /etc/modprobe.conf >>/.root/etc/modprobe.conf
 }
 
@@ -138,6 +180,9 @@
 	resume=*)
 		resume=${param#resume=}
 		;;
+	toram)
+		toram=1
+		;;
 	esac
 done
 
@@ -185,6 +230,6 @@
 umount /proc
 cd /.root
 # Clean up and free some memory
-rm -rf /bin /sbin /lib /sys /proc /dev /.tmpfs /init
+rm -rf /bin /sbin /lib /sys /proc /dev /.tmpfs /init /fakecd.iso.head
 ./lib/ld-linux.so.2 --library-path ./lib ./bin/mount -n --move . /
 exec ../lib/ld-linux.so.2 --library-path ./lib ./usr/sbin/chroot . /sbin/init "$@"




More information about the livecd mailing list