Experience with initrd and loop devices (script included)
I started building an initrd image for use with loadlin and md (I
wanto to put everything under raid-0). As first step, I needed the
image of an ext2 (or whatever) file system to mount via loopback
device, in order to put into it all the necessary modules and so on.
First, I realised that, if any docs exist on how to use the loopback
device, they are well hidden. Hints are found in the mount man page
and in the Bootdisk-HOWTO, but nothing general enough.
Indeed, everyone assumes that you have an image and want to mount it,
but nothing is said about what to do to *create* an image from
scratch. Well, the Bootdisk-HOWTO says how to do, but it does not
work... It says that you just need to do
dd if=/dev/zero of=/tmp/fsfile bs=1k count=nnn
mount -o loop -t ext2 /tmp/fsfile /mnt
and voila`. But mount refuses to mount, because it does not find a
superblock. So I tried to mkfs.ext2 on the file, but to no avail:
apparently mkfs is not able to work on loop devices. Moreover, the
mkfs.ext2 man page is missing (I filed a bug report).
Well, if you cannot suggest a better way, here is a small script that
creates an ext2 file systrem image from scratch. One caveat: it uses
a ram disk, so you must have enough free memory to hold all of it.
Improvements welcome.
-------------------------------------------------------------------
#!/bin/sh
# Create file IMG of size SIZE KB, which is the image of an ext2
# file system, using ramdisk device RAM, and mount it at MNT
IMG=/boot/initrd.img
SIZE=200
RAM=/dev/ramdisk
MNT=/mnt/initrd
LABEL='initrd image'
set -ex # exit on all errors
mkfs.ext2 -L "$LABEL" -m 0 -v -b 1024 $RAM $SIZE
mount $RAM $MNT
mount $RAM $MNT -o remount,ro
dd if=$RAM of=$IMG bs=1024 count=$SIZE
umount $MNT
mount -t ext2 -o loop $IMG $MNT
--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word "unsubscribe" to
debian-user-request@lists.debian.org .
Trouble? e-mail to templin@bucknell.edu .
Reply to: