[klibc] "Destructive" utilities

Alexander E. Patrakov patrakov at ums.usu.ru
Tue Jun 8 13:26:32 PDT 2004


H. Peter Anvin wrote:
(btw no need to CC: me, I am subscribed)

> I just added a "nuke" program, which does the equivalent of "rm -rf".  
> Do we also need unlink/rmdir?

I don't need them anymore, but someone else may need them. Attached.

> The nuke program is in klibc-0.122.

Thanks. One bug though: it deletes the "chroot" binary. I was able to do 
a full cleanup of initramfs using "nuke", but my "init" script 
(attached) relies upon /bin/chroot.static being present on the real root fs.

So what's needed is not "nuke", but a "nuke+chroot" program.

-- 
Alexander E. Patrakov
-------------- next part --------------
#!/bin/sh

mount -t proc proc /proc
mount -t sysfs sysfs /sys

# Kernel is buggy by default
echo >/proc/sys/kernel/hotplug

echo "=================================="
echo "    This kernel uses initramfs    "
echo "=================================="

read cmdline </proc/cmdline
rw=0
init="/sbin/init"

for param in $cmdline
do
	case "$param" in
	root=*)
		root=`echo "$param" | dd bs=1 skip=5 2>/dev/null`
		if [ x"`echo "$root" | dd bs=1 count=5 2>/dev/null`" = x/dev/ ]
		then
			root=`echo "$root" | dd bs=1 skip=5 2>/dev/null`
		fi
		;;
	rootfstype=*|rootflags=*|init=*)
		eval "$param"
		;;
	ro)
		rw=0
		;;
	rw)
		rw=1
		;;
	esac
done

if [ -z "$root" ]
then
	echo "No root parameter specified!"
	exit 1
fi

root="/dev/$root"

udevstart

if [ -z "$rootfstype" ]
then
	eval $( fstype <$root )
	rootfstype="$FSTYPE"
	if [ "$rootfstype" = "unknown" ]
	then
		echo "Unknown root filesystem type!"
		exit 1
	else
		echo "Guessed root filesystem type: $rootfstype"
	fi
fi

if [ ! -z "$rootflags" ]
then
	rootflags="$rootflags,"
fi

if [ "$rw" = 1 ]
then
	rootflags="$rootflags"rw
else
	rootflags="$rootflags"ro
fi

mount -t "$rootfstype" -o "$rootflags" "$root" /root
mount -t ramfs ramfs /root/dev
#mount -o bind / /root/mnt

dd if=/etc/udev/udev.conf.host of=/etc/udev/udev.conf 2>/dev/null

ACTION=add DEVPATH=/class/mem/null udev class
ACTION=add DEVPATH=/class/tty/console udev class

exec </root/dev/console >/root/dev/console 2>&1

umount /sys
umount /proc

cd /root
mount -o move . /
nuke /*
exec bin/chroot.static . "$init" "$@"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: rmdir.c
Type: text/x-csrc
Size: 332 bytes
Desc: not available
Url : http://www.zytor.com/pipermail/klibc/attachments/20040608/94d877ce/rmdir.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unlink.c
Type: text/x-csrc
Size: 254 bytes
Desc: not available
Url : http://www.zytor.com/pipermail/klibc/attachments/20040608/94d877ce/unlink.bin


More information about the klibc mailing list