Date: Mon, 16 Dec 1996 11:46:19 +0000 () From: "Lenzi, Sergio" <lenzi@bsi.com.br> To: Karl Wagner <karl@host.softronex.com> Cc: questions@FreeBSD.ORG Subject: Re: Bootable Disk Message-ID: <Pine.BSF.3.91.961216113831.493C-100000@sergio> In-Reply-To: <Pine.BSF.3.91.961213142132.9950A-100000@host.softronex.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 13 Dec 1996, Karl Wagner wrote: > > Hi: > > I have a single question. Is is posible to create a 1.44 bootable disk > that holds a compressed ( or regular ) kernel and a small file system so > that FreeBSD could run without a hard disk for very small applications?. > Yes you can build an entire filesystem in memory using the mfs option and a "crunch" feature to put the whole thing in memory like the bootdisk from WC. You need: the system sources (from the cd directory dist/src) -----------config file------------ machine "i386" cpu "I386_CPU" cpu "I486_CPU" cpu "I586_CPU" cpu "I686_CPU" ident GENERIC maxusers 10 options MATH_EMULATE #Support for x87 emulation options INET #Internetworking options FFS #Berkeley Fast Filesystem options MFS options SCSI_DELAY=15 #Be pessimistic about Joe SCSI device options BOUNCE_BUFFERS #include support for DMA bounce buffers options UCONSOLE #Allow users to grab the console options FAILSAFE #Be conservative options MAXCONS=4 options MFS_ROOT=2000 options MFS_AUTOLOAD config kernel root on wd0 controller isa0 controller eisa0 controller pci0 controller fdc0 at isa? port "IO_FD1" bio irq 6 drq 2 vector fdintr disk fd0 at fdc0 drive 0 disk fd1 at fdc0 drive 1 controller wdc0 at isa? port "IO_WD1" bio irq 14 flags 0x80ff80ff vector wdintr disk wd0 at wdc0 drive 0 disk wd1 at wdc0 drive 1 controller ncr0 controller ahc0 controller uha0 at isa? port "IO_UHA0" bio irq ? drq 5 vector uhaintr controller aha0 at isa? port "IO_AHA0" bio irq ? drq 5 vector ahaintr controller aic0 at isa? port 0x340 bio irq 11 vector aicintr controller nca0 at isa? port 0x1f88 bio irq 10 vector ncaintr controller nca1 at isa? port 0x350 bio irq 5 vector ncaintr controller scbus0 device sd0 # syscons is the default console driver, resembling an SCO console device sc0 at isa? port "IO_KBD" tty irq 1 vector scintr # Enable this and PCVT_FREEBSD for pcvt vt220 compatible console driver # Mandatory, don't remove device npx0 at isa? port "IO_NPX" irq 13 vector npxintr pseudo-device loop pseudo-device gzip # Exec gzipped a.out's pseudo-device vn ----------------dofs.sh--------------------------- : #set -ex VNDEVICE=vn0 export BLOCKSIZE=512 MNT=/mnt FSSIZE=2000 FSPROTO=fs FSINODE=4000 FSIMAGE=fs-image rm -f $FSIMAGE if [ ! -b /dev/${VNDEVICE} -o ! -c /dev/r${VNDEVICE} ] ; then ( cd /dev && sh MAKEDEV ${VNDEVICE} ) fi umount /dev/${VNDEVICE} 2>/dev/null || true umount ${MNT} 2>/dev/null || true vnconfig -u /dev/r${VNDEVICE} 2>/dev/null || true dd of=$FSIMAGE if=/dev/zero count=${FSSIZE} bs=1k 2>/dev/null # this suppresses the `invalid primary partition table: no magic' awk 'BEGIN {printf "%c%c", 85, 170}' |\ dd of=$FSIMAGE obs=1 seek=510 conv=notrunc 2>/dev/null vnconfig -s labels -c /dev/r${VNDEVICE} $FSIMAGE sed '/^minimum:/,$d' /etc/disktab > /etc/disktab.tmp cat /etc/disktab.tmp > /etc/disktab rm -f /etc/disktab.tmp ( a=`expr ${FSSIZE} \* 2` echo "minimum:ty=mfs:se#512:nt#1:rm#300:\\" echo " :ns#$a:nc#1:\\" echo " :pa#$a:oa#0:ba#4096:fa#512:\\" echo " :pc#$a:oc#0:bc#4096:fc#512:" ) >> /etc/disktab disklabel -w -r -B \ -b /usr/mdec/fdboot \ -s /usr/mdec/bootfd \ /dev/r${VNDEVICE} minimum newfs -u 0 -t 0 -i ${FSINODE} -m 0 -o space /dev/r${VNDEVICE}a mount /dev/${VNDEVICE}a ${MNT} ( set -e && cd ${FSPROTO} && find . -print | cpio -dump ${MNT} ) set `df -i /mnt | tail -1` umount ${MNT} fsck -p /dev/r${VNDEVICE}a < /dev/null vnconfig -u /dev/r${VNDEVICE} 2>/dev/null || true echo ${FSSIZE} > size echo ">>> Filesystem is ${FSSIZE} K, $4 left" echo ">>> ${FSINODE} bytes/inode, $7 left" echo ">>> `expr ${FSSIZE} \* 1024 / ${FSINODE}`" ----------------config file for the "crunch" command----------- srcdirs /usr/src/sbin/i386 srcdirs /usr/src/sbin srcdirs /usr/src/bin srcdirs /usr/src/gnu/usr.bin srcdirs /usr/src/usr.sbin srcdirs /usr/src/usr.bin progs swapon gzip chroot ln cpio pwd dialog progs expr awk grep tput newfs bc df sync init echo test sh cp progs ls mkdir tar mount umount rm cat progs reboot rmdir env stty sleep fdisk disklabel find special nvi srcdir /usr/src/usr.bin/vi/common ln test [ ln sh -sh ln nvi vi ln reboot halt libs /usr/src/lib/libc/libc.a libs -lipx -lgnuregex -lm libs -lcrypt -lkvm -ll -ledit -lutil -ldialog -lncurses -lmytinfo -------------------write-mfs.c----------- /* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * * $Id: write_mfs_in_kernel.c,v 1.1 1995/04/25 03:45:18 phk Exp $ * * This program patches a filesystem into a kernel made with MFS_ROOT * option. */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/types.h> #include <sys/param.h> #include <sys/stat.h> #include <ufs/ffs/fs.h> main(int argc, char **argv) { unsigned char *buf_kernel, *buf_fs, *p,*q; int fd_kernel, fd_fs; struct stat st_kernel, st_fs; u_long l; if (argc < 3) { fprintf(stderr,"Usage:\n\t%s kernel fs\n",argv[0]); exit(2); } fd_kernel = open(argv[1],O_RDWR); if (fd_kernel < 0) { perror(argv[1]); exit(2); } fstat(fd_kernel,&st_kernel); fd_fs = open(argv[2],O_RDONLY); if (fd_fs < 0) { perror(argv[2]); exit(2); } fstat(fd_fs,&st_fs); buf_kernel = malloc(st_kernel.st_size); if (!buf_kernel) { perror("malloc"); exit(2); } buf_fs = malloc(st_fs.st_size); if (!buf_fs) { perror("malloc"); exit(2); } if (st_kernel.st_size != read(fd_kernel,buf_kernel,st_kernel.st_size)) { perror(argv[1]); exit(2); } if (st_fs.st_size != read(fd_fs,buf_fs,st_fs.st_size)) { perror(argv[2]); exit(2); } for(l=0,p=buf_kernel; l < st_kernel.st_size - st_fs.st_size ; l++,p++ ) if(*p == 'M' && !strcmp(p,"MFS Filesystem goes here")) goto found; fprintf(stderr,"MFS filesystem signature not found in %s\n",argv[1]); exit(1); found: for(l=0,q= p + SBOFF; l < st_fs.st_size - SBOFF ; l++,q++ ) if (*q) goto fail; memcpy(p+SBOFF,buf_fs+SBOFF,st_fs.st_size-SBOFF); lseek(fd_kernel,0L,SEEK_SET); if (st_kernel.st_size != write(fd_kernel,buf_kernel,st_kernel.st_size)) { perror(argv[1]); exit(2); } exit(0); fail: l += SBOFF; fprintf(stderr,"Obstruction in kernel after %ld bytes (%ld Kbyte)\n", l, l/1024); fprintf(stderr,"Filesystem is %ld bytes (%ld Kbyte)\n", (u_long)st_fs.st_size, (u_long)st_fs.st_size/1024); exit(1); } -------------------------------- Hope this can help. Sergio Lenzi. Unix consult.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.961216113831.493C-100000>