[lxc-devel] [PATCH] Create busybox commands as symlinks instead of hardlinks

Dwight Engen dwight.engen at oracle.com
Fri Nov 30 16:49:25 UTC 2012


I was getting a "Too many links" error when creating a busybox container on
a btrfs file system. This change has the template create the links as
symlinks instead. It also generates the list of commands to be symlinked from
busybox itself instead of a hardcoded list in the template.

Also set the root password to root, to match what other templates do.

Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
---
 templates/lxc-busybox.in |   49 +++++++++------------------------------------
 1 files changed, 10 insertions(+), 39 deletions(-)

diff --git a/templates/lxc-busybox.in b/templates/lxc-busybox.in
index f38d77e..91095a3 100644
--- a/templates/lxc-busybox.in
+++ b/templates/lxc-busybox.in
@@ -151,40 +151,6 @@ configure_busybox()
 {
     rootfs=$1
 
-    functions="\
-	[ [[ addgroup adduser adjtimex ar arp arping ash awk basename \
-	brctl bunzip2 bzcat bzip2 cal cat catv chattr chgrp chmod \
-	chown chpasswd chpst chroot chrt chvt cksum clear cmp comm \
-	cp cpio crond crontab cryptpw cut date dc dd deallocvt \
-	delgroup deluser df dhcprelay diff dirname dmesg dnsd dos2unix \
-	du dumpkmap dumpleases echo ed egrep eject env envdir envuidgid \
-	ether-wake expand expr fakeidentd false fbset fdformat fdisk \
-	fetchmail fgrep find findfs fold free freeramdisk fsck \
-	fsck.minix ftpget ftpput fuser getopt getty grep gunzip gzip \
-	halt hdparm head hexdump hostid hostname httpd hwclock id \
-	ifconfig ifdown ifenslave ifup inetd init insmod install ip \
-	ipaddr ipcalc ipcrm ipcs iplink iproute iprule iptunnel \
-	kbd_mode kill killall killall5 klogd last length less linux32 \
-	linux64 linuxrc ln loadfont loadkmap logger login logname \
-	logread losetup lpd lpq lpr ls lsattr lsmod lzmacat makedevs \
-	md5sum mdev mesg microcom mkdir mkfifo mkfs.minix mknod mkswap \
-	mktemp modprobe more mount mountpoint msh mt mv nameif nc \
-	netstat nice nmeter nohup nslookup od openvt passwd patch \
-	pgrep pidof ping ping6 pipe_progress pivot_root pkill poweroff \
-	printenv printf ps pscan pwd raidautorun rdate readahead \
-	readlink readprofile realpath reboot renice reset resize rm \
-	rmdir rmmod route rpm rpm2cpio run-parts runlevel runsv \
-	runsvdir rx script sed sendmail seq setarch setconsole \
-	setkeycodes setlogcons setsid setuidgid sh sha1sum slattach \
-	sleep softlimit sort split start-stop-daemon stat strings \
-	stty su sulogin sum sv svlogd swapoff swapon switch_root \
-	sync sysctl syslogd tac tail tar taskset tcpsvd tee telnet \
-	telnetd test tftp tftpd time top touch tr traceroute \
-	true tty ttysize udhcpc udhcpd udpsvd umount uname uncompress \
-	unexpand uniq unix2dos unlzma unzip uptime usleep uudecode \
-	uuencode vconfig vi vlock watch watchdog wc wget which \
-	who whoami xargs yes zcat zcip"
-
     type busybox >/dev/null
 
     if [ $? -ne 0 ]; then
@@ -206,8 +172,14 @@ configure_busybox()
 	return 1
     fi
 
-    # do hardlink to busybox for the different commands
-    for i in $functions; do ln $rootfs/bin/busybox $rootfs/bin/$i; done
+    # symlink busybox for the commands it supports
+    # it would be nice to just use "chroot $rootfs busybox --install -s /bin"
+    # but that only works right in a chroot with busybox >= 1.19.0
+    pushd $rootfs/bin > /dev/null || return 1
+    ./busybox --help | grep 'Currently defined functions:' -A300 | \
+      grep -v 'Currently defined functions:' | tr , '\n' | \
+      xargs -n1 ln -s busybox
+    popd > /dev/null
 
     # relink /sbin/init
     ln $rootfs/bin/busybox $rootfs/sbin/init
@@ -215,9 +187,8 @@ configure_busybox()
     # passwd exec must be setuid
     chmod +s $rootfs/bin/passwd
     touch $rootfs/etc/shadow
-    chroot $rootfs /bin/passwd -d root
-
-    echo "No password for 'root', please change !"
+    echo "setting root passwd to root"
+    echo "root:root" | chroot $rootfs chpasswd
 
     return 0
 }
-- 
1.7.1





More information about the lxc-devel mailing list