Author: alexander
Date: 2005-11-01 08:04:20 -0700 (Tue, 01 Nov 2005)
New Revision: 1023

Added:
   branches/dm/packages/zisofs-tools/
   branches/dm/packages/zisofs-tools/Makefile
Modified:
   branches/dm/Makefile
   branches/dm/initramfs/Makefile
   branches/dm/initramfs/init.c
   branches/dm/initramfs/init.h
   branches/dm/packages/cdrtools/Makefile
Log:
Adjusted /init in initramfs for device-mapper
Installed cdrtools in /tools because mkisofs should be available with root.ext2 
unmounted
Added zisofstools

The CD now boots, but doesn't shut down, and some bugs still have to be fixed.


Modified: branches/dm/Makefile
===================================================================
--- branches/dm/Makefile        2005-11-01 11:10:50 UTC (rev 1022)
+++ branches/dm/Makefile        2005-11-01 15:04:20 UTC (rev 1023)
@@ -242,8 +242,6 @@
         make x86_64-blfs $(chbash-post-bash)'
 endif
 endif
-       @make unmount
-       @touch $@
 
 lfsuser:
        @-groupadd lfs
@@ -320,7 +318,7 @@
        ch-curl ch-zip ch-unzip ch-docbook-xml ch-libxslt ch-docbook-xsl \
        ch-html_tidy ch-LFS-BOOK \
        ch-dhcpcd ch-cpio ch-eject ch-nALFS ch-dialog ch-device-mapper \
-       ch-linux stop-here ch-cdrtools ch-zisofs-tools ch-initramfs \
+       ch-linux ch-cdrtools ch-zisofs-tools ch-initramfs \
        ch-syslinux ch-nALFS-profile
 
 blfs: ch-openssl ch-wget ch-reiserfsprogs ch-xfsprogs ch-nano ch-joe \
@@ -486,7 +484,7 @@
 # Targets to create the iso
 #==============================================================================
 
-prepiso: unmount
+prepiso: $(MP)$(ROOT)
        @-rm $(MP)/etc/rc.d/rc{2,3,5}.d/{K,S}21xprint
        @-rm $(MP)/root/.bash_history
        @>$(MP)/var/log/btmp
@@ -507,8 +505,8 @@
        @install -m600 root/.bashrc $(MP)/root/.bashrc
 ifneq ($(LFS-ARCH),x86_64)
 ifneq ($(LFS-ARCH),sparc64)
-       @install -m644 etc/X11/app-defaults/XTerm 
$(MP)/etc/X11/app-defaults/XTerm
-       @install -m644 etc/X11/twm/system.twmrc $(MP)/etc/X11/twm/system.twmrc
+#      @install -m644 etc/X11/app-defaults/XTerm 
$(MP)/etc/X11/app-defaults/XTerm
+#      @install -m644 etc/X11/twm/system.twmrc $(MP)/etc/X11/twm/system.twmrc
 else
        @sed -i "s/Version:.*/Version: $(VERSION)/" $(MP)/boot/boot.msg
 endif
@@ -518,30 +516,27 @@
 ifndef CROSS
        @-mv $(MP)/bin/uname.real $(MP)/bin/uname
 endif
-       @-mkdir $(MP)/iso
-       @cp -rav $(MP)/lfs-sources $(MP)/iso
-       @cp -rav $(MP)/boot $(MP)/iso
-       @touch $@
 
-$(MP)/iso/.root.sqfs:
-       @$(WD)/bin/mksquashfs $(MP) .root.sqfs -info -e \
-        boot cross-tools sources lfs-sources tools iso lfs-livecd lost+found 
tmp proc >sqfs.log 2>&1 && \
-        mv .root.sqfs $@
+$(MPBASE)/iso/root.ext2: root.ext2
+       @make unmount
+       @$(WD)/bin/mkzftree -F root.ext2 $(MPBASE)/iso/root.ext2
 
-iso: prepiso $(MP)/iso/.root.sqfs
+iso: prepiso $(MPBASE)/iso/root.ext2
 ifeq ($(LFS-ARCH),x86)
-       @cd $(MP)/iso ; $(MP)/usr/bin/mkisofs -R -l --allow-leading-dots -D -o \
-       $(MKTREE)/lfslivecd-$(VERSION).iso -b boot/isolinux/isolinux.bin \
+       @cd $(MPBASE)/iso ; $(WD)/bin/mkisofs -z -R -l --allow-leading-dots -D 
-o \
+       $(MPBASE)$(ROOT)/lfslivecd-$(VERSION).iso -b boot/isolinux/isolinux.bin 
\
        -c boot/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
        -V "lfslivecd-$(VERSION)" ./
 endif
 ifeq ($(LFS-ARCH),x86_64)
-       @cd $(MP)/iso ; $(MP)/usr/bin/mkisofs -R -l --allow-leading-dots -D -o \
-       $(MKTREE)/lfslivecd-$(VERSION).iso -b boot/isolinux/isolinux.bin \
+       @cd $(MPBASE)/iso ; $(WD)/bin/mkisofs -z -R -l --allow-leading-dots -D 
-o \
+       $(MPBASE)$(ROOT)/lfslivecd-$(VERSION).iso -b boot/isolinux/isolinux.bin 
\
        -c boot/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table \
        -V "lfslivecd-$(VERSION)" ./
 endif
 ifeq ($(LFS-ARCH),ppc)
+       # Commands below are known wrong
+       exit 1
        @cd $(MP) ; ./usr/bin/mkisofs -hfs -part --allow-leading-dots \
        -map $(MKTREE)/$(PKG)/yaboot/map.hfs -no-desktop \
        -hfs-volid "lfslivecd-$(VERSION)" -V "lfslivecd-$(VERSION)" \
@@ -551,7 +546,9 @@
         echo "Iso incorrectly made! Boot directory not blessed." ; fi
 endif
 ifeq ($(LFS-ARCH),sparc64)
-       @cd $(MP) ; ./usr/bin/mkisofs -v -R -l -D --allow-leading-dots \
+       # Commands below are known wrong
+       exit 1
+       @cd $(MP) ; ./usr/bin/mkisofs -z -v -R -l -D --allow-leading-dots \
         -G iso/boot/isofs.b -B ... -r -V "lfslivecd-$(VERSION)" \
         -o $(MKTREE)/lfslivecd-$(VERSION).iso iso >$(MKTREE)/iso.log 2>&1
 endif
@@ -602,8 +599,9 @@
        @-umount $(MP)$(SRC)
        @-umount $(MP)$(WD)
        @-umount $(MP)$(ROOT)
-       @-umount $(MP)
        @-rmdir $(MP)$(SRC) $(MP)$(WD) $(MP)$(ROOT)
+       @-umount $(MP)
+       @touch root.ext2
 
 
 .PHONY: unmount clean_sources scrub clean iso chroot-gvim update-fontsdir \

Modified: branches/dm/initramfs/Makefile
===================================================================
--- branches/dm/initramfs/Makefile      2005-11-01 11:10:50 UTC (rev 1022)
+++ branches/dm/initramfs/Makefile      2005-11-01 15:04:20 UTC (rev 1023)
@@ -21,7 +21,7 @@
        @touch $@
 
 compile-stage2: init
-       mkdir -p $(WDIR)/{dev,bin,.tmpfs,.union}
+       mkdir -p $(WDIR)/{dev/mapper,bin,.tmpfs,.lfs-cd}
        $(CP) init $(WDIR)/
        $(MK) -m 640 $(WDIR)/dev/console c 5 1
        $(MK) -m 660 $(WDIR)/dev/hda b 3 0
@@ -41,7 +41,10 @@
        $(MK) -m 660 $(WDIR)/dev/sr5 b 11 5
        $(MK) -m 660 $(WDIR)/dev/sr6 b 11 6
        $(MK) -m 660 $(WDIR)/dev/sr7 b 11 7
+       $(MK) -m 660 $(WDIR)/dev/mapper/control c 10 63
+       $(MK) -m 660 $(WDIR)/dev/mapper/lfs-cd b 254 0
        $(MK) -m 660 $(WDIR)/dev/loop0 b 7 0
+       $(MK) -m 660 $(WDIR)/dev/loop1 b 7 1
        cd $(WDIR); find . | cpio -o -H newc | gzip -9 > 
../initramfs_data.cpio.gz
 ifeq ($(LFS-ARCH),x86)
        $(CP) initramfs_data.cpio.gz /boot/isolinux/initramfs_data_cpio.gz
@@ -58,7 +61,7 @@
        rm -rf temp
 
 init:
-       gcc [EMAIL PROTECTED] -o $@ -static -Os -s -Wall 
-DVOLUME_ID=\"lfslivecd-$(VERSION)\"
+       gcc [EMAIL PROTECTED] -o $@ -static -ldevmapper -Os -s -Wall 
-DVOLUME_ID=\"lfslivecd-$(VERSION)\"
 
 clean:
        -rm -rf temp

Modified: branches/dm/initramfs/init.c
===================================================================
--- branches/dm/initramfs/init.c        2005-11-01 11:10:50 UTC (rev 1022)
+++ branches/dm/initramfs/init.c        2005-11-01 15:04:20 UTC (rev 1023)
@@ -23,70 +23,26 @@
 
 int mountlfscd(void);
 
-int main(int argc, char * argv[], char * envp[])
+int losetup(char * loop, char * file, int flags)
 {
-       int i, fd, ffd;
        struct loop_info loopinfo;
+       int fd, ffd;
        
-       umask(0);
-       
-       printf("Initramfs activated\n");
+       memset(&loopinfo, 0, sizeof(loopinfo));
 
-       printf("Mounting tmpfs...\n");
-       i = mount("tmpfs", TMPFS, "tmpfs", 0, "size=90%"); /* Mount a tmpfs */
-       if (i<0) {
-               printf("Failed to mount tmpfs: %s\n", strerror(errno));
-               return (0);
-       }
-       mkdir(OVERLAY, 0755);                        /* Create a .overlay 
directory */
-       mkdir(DEV, 0755);                            /* Create a /dev directory 
*/
-       mkdir(SHM, 0755);                            /* Create a /dev/shm 
directory */
-       mkdir(PROC, 0755);                           /* Create a /proc 
directory */
-       mkdir(TMP, 01777);                           /* Create a /tmp directory 
*/
-       mkdir(CDROM_MOUNT, 0755);                    /* Create a .cdrom 
directory */
-       mkdir(SQFS, 0755);                           /* Create a .sqfs 
directory */
-       mkdir("/.tmpfs/.tmp",01777);                 /* Create a .tmp directory 
*/
-
-       printf("Searching for the CD named %s...\n", VOLUME_ID);
-
-       for (i=0;i<MAX_RETRIES;i++)
-       {
-               if (mountlfscd())
-                       break;
-
-               /* Failed to find any device with an LFS LiveCD */
-               printf("I couldn't find an LFS LiveCD in any drive!!\n");
-               printf("I'm going to wait 10 seconds and try again (Try 
%d/%d)\n", i, MAX_RETRIES);
-               sleep(10);
-       }
-
-       if (i>=MAX_RETRIES)
-       {
-               printf("I couldn't find an LFS LiveCD in any drive after %d 
retries!\n", MAX_RETRIES);
-               reboot(RB_POWER_OFF);
-               return(0);
-       }
-
-       /* If we're here, we have the LiveCD mounted and verifieid */
-       
-       /* Now, attempt to attach the squashfs root file to /dev/loop0 */
-
-       printf("Setting up the loopback device...\n");
-
-       ffd = open(SQFS_FILE, O_RDONLY);
+       ffd = open(file, flags);
        if (ffd<0) {
-               printf("Failed to open the squashfs file: %s\n", 
strerror(errno));
+               printf("Failed to open the %s file: %s\n", file, 
strerror(errno));
                return(0);
        }
        
-       fd = open(LOOP, O_RDONLY);
+       fd = open(loop, flags);
        if (fd<0) {
                printf("Failed to open the loop device: %s\n", strerror(errno));
                return(0);
        }
 
-       memset(&loopinfo, 0, sizeof(loopinfo));
-       snprintf(loopinfo.lo_name, LO_NAME_SIZE, "%s", SQFS_FILE);
+       snprintf(loopinfo.lo_name, LO_NAME_SIZE, "%s", file);
 
        loopinfo.lo_offset = 0;
        loopinfo.lo_encrypt_key_size = 0;
@@ -105,48 +61,113 @@
                 return(0);
         }
         close(fd);
+       return(1);
+}
 
-       /* Mount the squashfs root file system */
+int main(int argc, char * argv[], char * envp[])
+{
+       int i, overhead;
+       int fd;
+       struct dm_task * dmt;
+       struct stat stat_buf;
+       char buf[65536];
+       
+       printf("Initramfs activated\n");
 
-       printf("Mounting squashfs file...\n");
-       i = mount(LOOP, SQFS, "squashfs", MS_RDONLY, NULL);
-       if (i<0) {
-               printf("Failed to mount squashfs: %s\n", strerror(errno));
+       mkdir("/proc", 0755);
+       mount("proc", "/proc", "proc", 0, 0);
+       
+       mkdir(TMPFS, 0755);
+       if (mount("tmpfs", TMPFS, "tmpfs", 0, "size=90%") < 0) {
+               printf("Failed to mount tmpfs: %s\n", strerror(errno));
+               return (0);
+       }
+       
+       mkdir(CDROM_MOUNT, 0755);
+
+       printf("Searching for the CD named %s...\n", VOLUME_ID);
+
+       for (i=0;i<MAX_RETRIES;i++)
+       {
+               if (mountlfscd())
+                       break;
+
+               /* Failed to find any device with an LFS LiveCD */
+               printf("I couldn't find an LFS LiveCD in any drive!!\n");
+               printf("I'm going to wait 10 seconds and try again (Try 
%d/%d)\n", i, MAX_RETRIES);
+               sleep(10);
+       }
+
+       if (i>=MAX_RETRIES)
+       {
+               printf("I couldn't find an LFS LiveCD in any drive after %d 
retries!\n", MAX_RETRIES);
+               reboot(RB_POWER_OFF);
                return(0);
        }
 
-       /* Activate unionfs */
+       /* If we're here, we have the LiveCD mounted and verifieid */
+       
+       /* Now, attempt to attach the root file to /dev/loop0 */
 
-       printf("Mounting unionfs...\n");
-       i = mount("unionfs", "/.union", "unionfs", 0, 
"dirs=/.tmpfs/.overlay=rw:/.tmpfs/.cdrom=ro:/.tmpfs/.sqfs=ro");
+       printf("Setting up the loopback devices...\n");
+       
+       losetup("/dev/loop0", ROOT_FILE, O_RDONLY);
+       
+       /* Create a sparse file for the second loop */
+       
+       stat(ROOT_FILE, &stat_buf);
+       overhead = 0x1000 + stat_buf.st_size / 0x100;
+       
+       fd = open(OVERLAY, O_CREAT | O_WRONLY, 0600);
+       ftruncate(fd, stat_buf.st_size + overhead);
+       close(fd);
+       
+       losetup("/dev/loop1", OVERLAY, O_RDWR);
+       
+       /* Set up device-mapper */
+        dmt = dm_task_create(DM_DEVICE_CREATE);
+        dm_task_set_name(dmt, "lfs-cd");
+        dm_task_set_major(dmt, 254);
+        dm_task_set_minor(dmt, 0);
+        dm_task_add_target(dmt, 0, stat_buf.st_size / 0x200,
+           "snapshot", "/dev/loop0 /dev/loop1 p 8");
+        dm_task_run(dmt);
+        dm_task_destroy(dmt);
+                                                       
+       printf("Mounting root filesystem...\n");
+       mkdir(ROOT, 0755);
+       i = mount("/dev/mapper/lfs-cd", ROOT, "ext2", 0, 0);
        if (i<0) {
-               printf("Failed to mount unionfs: %s\n", strerror(errno));
+               printf("Failed to mount root fs: %s\n", strerror(errno));
                return(0);
        }
 
-       /* Move the tmpfs to /dev/shm in the unionfs */
+       /* Move the tmpfs to /dev/shm in the root fs */
 
-       mount(TMPFS, "/.union/dev/shm", NULL, MS_MOVE, NULL);
+       mount("/.tmpfs", ROOT "/dev/shm", NULL, MS_MOVE, NULL);
 
        /* Create a symlink for the CD drive to /dev/lfs-cd */
 
        symlink(lfscd, "/.union/dev/lfs-cd");
 
-       mount("/.union/dev/shm/.tmp", "/.union/tmp", NULL, MS_BIND, NULL);
 
-       /* Chroot into the unionfs */
+       /* Remove the "/init" binary to free some RAM */
+       unlink ("/init");
+       umount2("/proc", 0);
+       
+       /* Chroot into the root fs */
 
-       chdir("/.union");
-
+       chdir(ROOT);
        mount(".", "/", NULL, MS_MOVE, NULL);
 
        if ( chroot(".") || chdir("/") )
                return(0);
        
-       
        /* We're done! Pass control to sysvinit. */
 
        printf("Starting init...\n");
+       
+       /* FIXME: file descriptors still point to initramfs */
        i = execve("/sbin/init", argv, envp);
        if (i<0)
                printf("Failed to start init: %s :(\n", strerror(errno));

Modified: branches/dm/initramfs/init.h
===================================================================
--- branches/dm/initramfs/init.h        2005-11-01 11:10:50 UTC (rev 1022)
+++ branches/dm/initramfs/init.h        2005-11-01 15:04:20 UTC (rev 1023)
@@ -13,18 +13,14 @@
 #include <linux/cdrom.h>
 #include <linux/fs.h>
 #include <sys/reboot.h>
+#include <libdevmapper.h>
 #include "iso9660.h"
 
 #define TMPFS          "/.tmpfs"                       /* Mount point for 
tmpfs */
 #define CDROM_MOUNT    "/.tmpfs/.cdrom"                /* Mount point for CD */
-#define SQFS           "/.tmpfs/.sqfs"                 /* Mount point for 
squashfs */
-#define SQFS_FILE      "/.tmpfs/.cdrom/.root.sqfs"     /* Squashfs file, root 
system */
+#define ROOT_FILE      "/.tmpfs/.cdrom/root.ext2"      /* Origin file for the 
root fs */
+#define ROOT           "/.root"                        /* Mount point for the 
root fs */
 #define OVERLAY                "/.tmpfs/.overlay"              /* Full path to 
overlay */
-#define SHM            "/.tmpfs/.overlay/dev/shm"      /* Full path to dev/shm 
*/
-#define PROC           "/.tmpfs/.overlay/proc"         /* Full path to proc */
-#define DEV            "/.tmpfs/.overlay/dev"          /* Full path to dev */
-#define TMP            "/.tmpfs/.overlay/tmp"          /* Full path to tmp */
-#define LOOP           "/dev/loop0"                    /* Loopback device */
 
 #define        ISO_BLOCK_SIZE  2048
 #define        ISO_PD_BLOCK    0x10

Modified: branches/dm/packages/cdrtools/Makefile
===================================================================
--- branches/dm/packages/cdrtools/Makefile      2005-11-01 11:10:50 UTC (rev 
1022)
+++ branches/dm/packages/cdrtools/Makefile      2005-11-01 15:04:20 UTC (rev 
1023)
@@ -20,8 +20,8 @@
        $(std_build)
 
 compile-stage2:
-       make $(PM) INS_BASE=/usr DEFINSUSR=root DEFINSGRP=root
-       make INS_BASE=/usr DEFINSUSR=root DEFINSGRP=root install
+       make $(PM) INS_BASE=/tools DEFINSUSR=root DEFINSGRP=root
+       make INS_BASE=/tools DEFINSUSR=root DEFINSGRP=root install
 
 clean:
        -rm -rf $(DIR)

Added: branches/dm/packages/zisofs-tools/Makefile
===================================================================
--- branches/dm/packages/zisofs-tools/Makefile  2005-11-01 11:10:50 UTC (rev 
1022)
+++ branches/dm/packages/zisofs-tools/Makefile  2005-11-01 15:04:20 UTC (rev 
1023)
@@ -0,0 +1,30 @@
+# zisofs-tools Makefile
+
+NM= zisofs-tools
+VRS= 1.0.6
+DIR= $(NM)-$(VRS)
+
+FILE= $(DIR).tar.bz2
+URL-$(FILE)= http://www.kernel.org/pub/linux/utils/fs/zisofs/$(FILE)
+SHA-$(FILE)= a95dc42c6e03bdce68acdb803861c9957cb0b8de
+
+# Targets
+
+include $(ROOT)/scripts/functions
+
+chroot:
+       chroot "$(MP)" $(chenv-blfs) \
+       'cd $(ROOT) && make ch-$(NM) $(chbash-post-bash)'
+
+stage2: Makefile $(FILE)
+       $(std_build)
+
+compile-stage2:
+       ./configure --prefix=/tools
+       make $(PM)
+       make install
+
+clean:
+       -rm -rf $(DIR)
+
+.PHONY: clean chroot compile-stage2

-- 
http://linuxfromscratch.org/mailman/listinfo/livecd
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to