public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Chris Friesen <cfriesen@nortelnetworks.com>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: linux-kernel@vger.kernel.org, kai@tp1.ruhr-uni-bochum.de
Subject: Re: Kernel setup() and initrd problems
Date: Fri, 14 Mar 2003 14:27:45 -0500	[thread overview]
Message-ID: <3E722D31.6050702@nortelnetworks.com> (raw)
In-Reply-To: b4t9i6$eon$1@cesium.transmeta.com

H. Peter Anvin wrote:
> Followup to:  <Pine.LNX.4.44.0303131051160.7342-100000@chaos.physics.uiowa.edu>
> By author:    Kai Germaschewski <kai@tp1.ruhr-uni-bochum.de>

>>I think whoever came up with that just got the idea of pivot_root wrong. 
>>The idea was to get rid of the initrd special case. It should be possible 
>>to do the following, though I didn't work out the details: 
>>
>>Tell the kernel that our root dev is /dev/ram and give it an initrd which 
>>isn't really a classical initrd (with /linuxrc on it), but instead has a 
>>/sbin/init which is similar to the linuxrc above.

> It *is* possible, but you need to pass "root=/dev/ram0" to the kernel,
> for backwards compatibility reasons.  That will incidentally make it
> run /sbin/init, not /linuxrc, unless you pass init=/linuxrc as well.


Below is the script that I used to pivot from a standard ramdisk (for with
the infrastructure is already in place in our build environment) to a tmpfs
filesystem.  This requires no changes to the boot args.

This script runs as /sbin/init, sets up the tmpfs filesystem, pivots, and
hands off control to the real init program.

One interesting bit is the rework of fstab so that mount and df show the
root filesystem as tmpfs.  freeramdisk simply tells the kernel that its
okay to give up the space used by the ramdisk.

This seems to work fine, though it isn't actually in production yet, just
a private prototype.

Chris






#!/bin/bash
# Set up tmpfs filesystem as root and pivot into it.

echo "Setting up tmpfs..."

#mount the tmpfs filesystem
mount -t tmpfs tmpfs mnt -o size=37M

#copy the initrd into the tmpfs filesystem
cp -a `ls -1 | grep -v mnt | grep -v proc | grep -v lost+found` mnt

#change dirs and make some directories
cd mnt
mkdir proc mnt

#pivot the filesystems
/sbin/pivot_root . mnt

#set up the /etc/fstab file to have / listed as tmpfs
#this will be used instead of the ramdisk line
echo "tmpfs             /               tmpfs   rw,size=37M     0 0" > etc/fstab.new

#grab the rest of /etc/fstab after the first entry since we want to keep the info
tail -n +2 etc/fstab >> etc/fstab.new
mv etc/fstab.new etc/fstab

# remove this script, move the real init to the right place, and run it
mv /sbin/init.orig /sbin/init

#unmount the original ramdisk, free the memory, and run the real init
exec /sbin/chroot . sh -c 'umount /mnt; /sbin/freeramdisk; exec /sbin/init' <dev/console >dev/console 2>&1


-- 
Chris Friesen                    | MailStop: 043/33/F10
Nortel Networks                  | work: (613) 765-0557
3500 Carling Avenue              | fax:  (613) 765-2986
Nepean, ON K2H 8E9 Canada        | email: cfriesen@nortelnetworks.com


  reply	other threads:[~2003-03-14 19:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-13  8:42 Kernel setup() and initrd problems Oliver Tennert
2003-03-13 17:16 ` Kai Germaschewski
2003-03-13 18:05   ` Kevin P. Fleming
2003-03-14 19:12   ` H. Peter Anvin
2003-03-14 19:27     ` Chris Friesen [this message]
2003-03-14 19:43       ` H. Peter Anvin
2003-03-14 20:04         ` Chris Friesen
2003-03-14 20:42           ` H. Peter Anvin
2003-03-14 20:53             ` Chris Friesen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3E722D31.6050702@nortelnetworks.com \
    --to=cfriesen@nortelnetworks.com \
    --cc=hpa@zytor.com \
    --cc=kai@tp1.ruhr-uni-bochum.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox