On Sun, Apr 13, 2014 at 02:10:51PM +0200, FRIGN wrote: > Good day, > > sometimes, you depend on an initramfs to do stuff for you before > the rootfs is available. > Busybox has become the standard for "all your initramfs needs", but > tbh, I hate working with it. > Statically linking sbase and ubase and choosing the tools you need for > the job almost solves the problem, but the lack of switch_root, which > almost every initramfs depends on, forces you to use busybox (because > util-linux doesn't link statically). > > Now, I would've already sent in a patch, but I am pretty sure somebody > here already hacked it together before. So, to save my time, I better > ask now. > > Cheers > > FRIGN > > -- > FRIGN <d...@frign.de> >
Why switch_root and not pivot_root? Here's a sh mockup of how to do what you wrote with pivot_root: set -e new_root=$1 put_old=$2 [ -d $put_old ] || made_dir=1 mkdir -p $put_old cd $new_root pivot_root $new_root $put_old chroot $new_root umount ${put_old#$new_root} [ $made_dir ] && rm -rf ${put_old#$new_root} It only depends on the new root being writable, and thus does not require the initramfs to be a RAMFS or TMPFS (I remember being able to boot from USB hard disk only by creating an initramfs, having that loaded by the bootloader and launching linux with root=/dev/ram0, which made my temporary root a SquashFS. In that case, switch_root will just refuse to work)