Jeremy,
In x86_64 and the minimal branch, the "shutdown-helper" and "init.in"
scripts somehow ended up being out of sync. Attached are the versions
that work for me on x86_64 (the reason the shutdown helper initially
didn't work was a missing lib64 symlink). Please commit them, and merge
r1997.
--
Alexander E. Patrakov
#!/bin/sh
EXPECTED_LABEL="[EMAIL PROTECTED]@"
EXPECTED_LABEL="$EXPECTED_LABEL "
EXPECTED_LABEL=${EXPECTED_LABEL:0:32}
PATA=0
NEW_FIREWIRE=0
init=/sbin/init
root=
rootdelay=
rootfstype=auto
ro="ro"
noresume=0
resume=
all_generic_ide=0
toram=0
nodhcp=0
cdtype=
find_cd() {
for SYS in /sys/block/hd* /sys/block/sr* ; do
[ ! -d "$SYS" ] && continue
[ -f "$SYS/media" ] && read MEDIA <"$SYS/media" && [ "$MEDIA"
!= "cdrom" ] && continue
DEV=/dev/${SYS##*/}
LABEL=`dd if=$DEV bs=1 skip=32808 count=32 2>/dev/null`
[ "$LABEL" = "$EXPECTED_LABEL" ] && ln -s "$DEV" /dev/lfs-cd &&
break
done
}
do_resume() {
case "$resume" in
*:*)
echo "$resume" >/sys/power/resume
;;
/dev/*)
if [ -b ${resume} ] ; then
eval echo $( stat -L -c '$(( 0x%t )):$(( 0x%T ))'
${resume} ) >/sys/power/resume
else
echo "Cannot resume from device $resume, which doesn't
exist"
fi
;;
esac
}
copy_cd_to_ram() {
echo "Copying LFS LiveCD to RAM. This will take several minutes..."
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
if [ -d /.tmpfs/.partition ] ; then
/sbin/losetup -d /dev/loop3
umount -n /.tmpfs/.partition && rm -rf /.tmpfs/.partition
fi
ln -sf /dev/loop2 /dev/lfs-cd
}
detect_cd_type() {
mount -n -t iso9660 -o ro /dev/lfs-cd /.tmpfs/.cdrom
if [ -d /.tmpfs/.cdrom/lfs-sources ] ; then
if [ "$toram" = 1 ] ; then
cdtype=toram
else
cdtype=fullcd
fi
else
cdtype=nosrc
fi
umount -n /.tmpfs/.cdrom
}
do_mount_cd() {
i=1
while [ ! -L /dev/lfs-cd ] ; do
find_cd
if [ ! -L /dev/lfs-cd ] ; then
echo "LFS LiveCD not found."
TRIES=5
DELAY=6 # 30 seconds total
for (( ; i<=$TRIES ; i++ )) ; do
[ -L /dev/lfs-cd ] && break
echo -n "Retry attempt $i of $TRIES... "
sleep $DELAY
find_cd
[ -L /dev/lfs-cd ] && echo "success!" || echo
"failed!"
done
fi
if [ ! -L /dev/lfs-cd ] ; then
echo ""
echo "LFS LiveCD could not find its device, perhaps due
to"
echo "unsupported or undetected hardware. Or maybe this
is"
echo "just a slow SCSI or USB controller that needs
more time"
echo "to settle (workaround: add rootdelay=30 to the
kernel"
echo "command line in the boot loader)."
echo ""
echo "Dropping you to a shell."
echo "Please load the needed modules and, optionally,
make"
echo "/dev/lfs-cd a symlink pointing to the correct
device."
echo ""
sh
fi
done
mkdir /.tmpfs/.cdrom
detect_cd_type
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`
OVERHEAD=$(( 0x1000 + $SIZE * 2 ))
OVLSIZE=$(( $SIZE + ( $OVERHEAD + 511 ) / 512 ))
dd if=/dev/null of=/.tmpfs/.overlay bs=512 seek=$OVLSIZE 2>/dev/null
/sbin/losetup /dev/loop1 /.tmpfs/.overlay
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
if [ "$toram" != 1 ] && [ ! -d /.root/dev/shm/.partition ] ; then
cp -a /dev/lfs-cd /.root/dev/lfs-cd
fi
if [ "$toram" != 1 ] ; then
ln -sf /dev/shm/.cdrom/drivers /.root/drivers
fi
cat /etc/modprobe.conf >>/.root/etc/modprobe.conf
ln -sf issue.$cdtype /.root/etc/issue
if [ "$cdtype" = "fullcd" ] ; then
ln -sf /dev/shm/.cdrom/lfs-sources /.root/lfs-sources
fi
if [ "$nodhcp" = "1" ] ; then
rm -f /.root/etc/udev/rules.d/76-network.rules
fi
}
do_mount_iso() {
DEVICE=${root#iso:}
FILE=${DEVICE#*:}
DEVICE=${DEVICE%%:*}
mkdir /.tmpfs/.partition
mount -n -t "$rootfstype" -o "$rootflags" "$DEVICE" /.tmpfs/.partition
/sbin/losetup /dev/loop3 "/.tmpfs/.partition/$FILE"
ln -sf /dev/loop3 /dev/lfs-cd
do_mount_cd
}
do_mount_root() {
mkdir /.root
[ -n "$rootflags" ] && rootflags="$rootflags,"
rootflags="$rootflags$ro"
case "$root" in
iso:*)
mkdir /.tmpfs
mount -n -t tmpfs -o size=90% tmpfs /.tmpfs
do_mount_iso
;;
*:*)
( IFS=":" ; mknod /dev/root b $root )
mount -n -t "$rootfstype" -o "$rootflags" /dev/root /.root
;;
/dev/*)
mount -n -t "$rootfstype" -o "$rootflags" "$root" /.root
;;
"")
mkdir /.tmpfs
mount -n -t tmpfs -o size=90% tmpfs /.tmpfs
do_mount_cd
;;
esac
}
mount -n -t proc proc /proc
mount -n -t sysfs sysfs /sys
read -r cmdline </proc/cmdline
( IFS="," ; for module in $blacklist ; do
echo "blacklist $module" >>/etc/modprobe.conf
done )
for param in $cmdline ; do
case $param in
*.*=*)
module=${param%%.*}
option=${param#*.}
echo "options $module $option" >>/etc/modprobe.conf
;;
ide=*|idebus=*|ide[0123]=*|hd[a-z]=*)
ide_core_opts="$ide_core_opts $param"
;;
pata)
PATA=1
;;
new_firewire)
NEW_FIREWIRE=1
;;
all_generic_ide)
all_generic_ide=1
;;
init=*)
init=${param#init=}
;;
root=*)
root=${param#root=}
;;
rootdelay=*)
rootdelay=${param#rootdelay=}
;;
rootfstype=*)
rootfstype=${param#rootfstype=}
;;
ro)
ro="ro"
;;
rw)
ro="rw"
;;
noresume)
noresume=1
;;
resume=*)
resume=${param#resume=}
;;
toram)
toram=1
;;
nodhcp)
nodhcp=1
;;
esac
done
if [ -n "$ide_core_opts" ] ; then
# remove the extra space from the beginning
ide_core_opts="${ide_core_opts# }"
echo "options ide_core options=\"$ide_core_opts\"" >>/etc/modprobe.conf
fi
case "$PATA" in
0)
for driver in /lib/modules/`uname
-r`/kernel/drivers/ata/pata_*.ko ; do
drv=${driver##*/}
drv=${drv%.ko}
echo "blacklist $drv" >>/etc/modprobe.conf
done
echo "install ata_piix /sbin/modprobe piix ; /sbin/modprobe -i
ata_piix" >>/etc/modprobe.conf
echo "blacklist ata_generic" >>/etc/modprobe.conf
;;
1)
for driver in /lib/modules/`uname
-r`/kernel/drivers/ide/pci/*.ko ; do
drv=${driver##*/}
drv=${drv%.ko}
echo "blacklist $drv" >>/etc/modprobe.conf
done
echo "blacklist ide-cs" >>/etc/modprobe.conf
;;
esac
case "$NEW_FIREWIRE" in
0)
for driver in /lib/modules/`uname
-r`/kernel/drivers/firewire/*.ko ; do
drv=${driver##*/}
drv=${drv%.ko}
echo "blacklist $drv" >>/etc/modprobe.conf
done
;;
1)
for driver in /lib/modules/`uname
-r`/kernel/drivers/ieee1394/*.ko ; do
drv=${driver##*/}
drv=${drv%.ko}
echo "blacklist $drv" >>/etc/modprobe.conf
done
;;
esac
if [ "$all_generic_ide" = 1 ] ; then
echo "options generic all_generic_ide=1" >>/etc/modprobe.conf
echo "options ata-generic all_generic_ide=1" >>/etc/modprobe.conf
else
if [ "$PATA" = 0 ] ; then
echo "blacklist generic" >>/etc/modprobe.conf
else
echo "blacklist ata-generic" >>/etc/modprobe.conf
fi
fi
/sbin/udevd --daemon
( IFS="," ; for module in $load ; do
/sbin/modprobe "$module"
done )
/sbin/udevtrigger
/sbin/udevsettle
if [ -n "$rootdelay" ] ; then sleep "$rootdelay" ; fi
[ "$noresume" = 0 ] && do_resume
do_mount_root
killall -w /sbin/udevd
umount /sys
umount /proc
cd /.root
# Clean up and free some memory
rm -rf /bin /sbin /lib /sys /proc /dev /.tmpfs /init /fakecd.iso.head
./lib/ld-linux-x86-64.so.2 --library-path ./lib ./bin/mount -n --move . /
exec ../lib/ld-linux-x86-64.so.2 --library-path ./lib ./usr/sbin/chroot .
"$init" "$@"
#!/bin/sh
FILES="/lib/libc.so.6
/lib/ld-linux-x86-64.so.2
/lib/libreadline.so.5
/lib/libhistory.so.5
/lib/libncursesw.so.5
/lib/libdl.so.2
/lib/libblkid.so.1
/lib/libuuid.so.1
/bin/sh
/bin/umount
/sbin/losetup
/sbin/halt
/sbin/reboot
/usr/sbin/chroot
/usr/sbin/dmsetup
/usr/lib/libdevmapper.so.1.02
/usr/bin/eject
/bin/sleep
/lib/libm.so.6
/lib/librt.so.1
/lib/libpthread.so.0
/dev/console
/dev/null
/dev/loop0
/dev/loop3
/dev/mapper/control"
case "$RUNLEVEL" in
0)
HALT="/sbin/halt -d -f -i -p"
;;
6)
HALT="/sbin/reboot -d -f -i"
;;
esac
if [ ! -b /dev/lfs-cd ] && [ ! -d /dev/shm/.partition ] ; then
# The CD has been loaded into RAM
$HALT
while true ; do sleep 1 ; done
fi
mkdir /dev/shm/old /dev/shm/proc /dev/shm/etc
ln -s /proc/mounts /dev/shm/etc/mtab
echo "$FILES" | cpio -pLd --quiet /dev/shm
ln -s lib /dev/shm/lib64
ln -s lib /dev/shm/usr/lib64
if [ -b /dev/lfs-cd ] ; then cp -RH /dev/lfs-cd /dev/shm/dev/lfs-cd ; fi
cat >/dev/shm/sbin/init <<EOF
#!/bin/sh
halt() {
$HALT
while true ; do sleep 1 ; done
}
fail() {
echo "Could not unmount the CD, sorry. Please report this as a bug."
sleep 5
halt
}
exec </dev/console >/dev/console 2>/dev/console
TIMEOUT=
while ! umount -n /old 2>/dev/null && [ "\$TIMEOUT" != "....." ] ; do
sleep 1
TIMEOUT=".\$TIMEOUT"
done
[ "\$TIMEOUT" = "....." ] && fail
dmsetup remove_all || fail
losetup -d /dev/loop0 || fail
umount -n /.cdrom || fail
if [ -d /.partition ] ; then
losetup -d /dev/loop3 || fail
umount -n /.partition || fail
fi
if [ -b /dev/lfs-cd ] ; then
eject -r /dev/lfs-cd
echo -n "Take the CD, close the CD-ROM tray and press Enter..."
( sleep 30 ; halt ) &
read ENTER
fi
halt
EOF
chmod 755 /dev/shm/sbin/init
ln -nsf /old/dev/initctl /dev/shm/dev/initctl
# "-t no" because otherwise /dev/pts isn't unmounted.
umount -na -t no
# brltty quirk - it mounts /etc/brltty/usbfs. "not mounted" goes to /dev/null
umount -n /etc/brltty/usbfs 2>/dev/null
cd /dev/shm
mount -n -t proc proc /dev/shm/proc
pivot_root . old
exec chroot . /old/sbin/init u
--
http://linuxfromscratch.org/mailman/listinfo/livecd
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page