# mount loopback device fails (kernel 2.6.1)

## arthax

Hi,

I'd like to mount an initrd created by myself. When I try to mount such a file, I got the following error: "ioctl: LOOP_SET_FD: Invalid argument"

These are the commands I typed:

```

# dd if=/dev/zero of=/tmp/my.initrd bs=1k count=10240

# mkfs.ext2 -F -m0 /tmp/my.initrd

# mount -t ext2 -o loop /tmp/my.initrd /mnt/mymount

ioctl: LOOP_SET_FD: Invalid argument

```

My kernel (mm-sources 2.6.1) is compiled with the Loopback device support:

```

# zegrep -i loop /proc/config.gz

CONFIG_BLK_DEV_LOOP=y

# CONFIG_BLK_DEV_CRYPTOLOOP is not set

```

Has anyome had such issues mounting loopback device? What other things should I pay attention to?

I thank you for any suggestion.

PORTAGE config

================

```

Portage 2.0.49-r20 (default-x86-1.4, gcc-3.2.3, glibc-2.3.2-r9, 2.6.1-mm1)

=================================================================

System uname: 2.6.1-mm1 i686 Mobile Intel(R) Pentium(R) 4 - M CPU 2.00GHz

Gentoo Base System version 1.4.3.10

ACCEPT_KEYWORDS="x86"

AUTOCLEAN="yes"

CFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"

CHOST="i686-pc-linux-gnu"

COMPILER="gcc3"

CONFIG_PROTECT="/etc /usr/X11R6/lib/X11/xkb /usr/kde/2/share/config /usr/kde/3.1/share/config /usr/kde/3/share/config /usr/share/config /usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/ /var/qmail/control"

CONFIG_PROTECT_MASK="/etc/gconf /etc/env.d"

CXXFLAGS="-march=pentium4 -O3 -pipe -fomit-frame-pointer"

DISTDIR="/usr/portage/distfiles"

FEATURES="autoaddcvs ccache sandbox"

GENTOO_MIRRORS="http://sunsite.cnlab-switch.ch/ftp/mirror/gentoo http://gentoo.oregonstate.edu http://www.ibiblio.org/pub/Linux/distributions/gentoo"

MAKEOPTS="-j2"

PKGDIR="/usr/portage/packages"

PORTAGE_TMPDIR="/var/tmp"

PORTDIR="/usr/portage"

PORTDIR_OVERLAY=""

SYNC="rsync://rsync.europe.gentoo.org/gentoo-portage"

USE="X aalib apm arts avi berkdb crypt cups encode esd foomaticdb gdbm gif gnome gpm gtk gtk2 imlib java jpeg libg++ libwww mad mikmod motif mozilla mpeg mysql ncurses nls oggvorbis opengl oss pam pdflib perl png python quicktime readline sdl slang spell ssl svga tcltk tcpd tetex truetype x86 xml2 xmms xv zlib"

```

----------

## adaptr

 *arthax wrote:*   

> Hi,
> 
> I'd like to mount an initrd created by myself. When I try to mount such a file, I got the following error: "ioctl: LOOP_SET_FD: Invalid argument"
> 
> These are the commands I typed:
> ...

 

Why don't you use mkinitrd ?

Seems less painful to me, as it will create the file for you.

It gives a filedescriptor error - have you examined the image with file and stat ?

You probably have to give the exact blocksize on mounting it, too.

----------

## arthax

 *adaptr wrote:*   

> 
> 
> Why don't you use mkinitrd ?
> 
> 

 

Cos I got that error after launching:

# pxesconfig

It actually mounts '/tmp/pxes.initrd' as a loop device file. Without that mount, it won't execute successfully and exits! PXES is a Mini Linux Distro (http://pxes.sourceforge.net/) that allow to boot diskless PC through network and 'pxesconfig' allow me to set up the configuration of that packages. I don't really know if 'pxesconfig' uses mkinitrd. But I know the problem is on mount.

And how to write a post in a "standard way", to help people understand my error? I was inspired from /usr/src/linux/Documentation/initrd.txt

```

We'll describe the loopback device method:

 

 1) make sure loopback block devices are configured into the kernel

 2) create an empty file system of the appropriate size, e.g.

    # dd if=/dev/zero of=initrd bs=300k count=1

    # mke2fs -F -m0 initrd

    (if space is critical, you may want to use the Minix FS instead of Ext2)

 3) mount the file system, e.g.

    # mount -t ext2 -o loop initrd /mnt

 4) create the console device (not necessary if using devfs, but it can't

    hurt to do it anyway):

    # mkdir /mnt/dev

    # mknod /mnt/dev/console c 5 1

 5) copy all the files that are needed to properly use the initrd

    environment. Don't forget the most important file, /linuxrc

    Note that /linuxrc's permissions must include "x" (execute).

 6) correct operation the initrd environment can frequently be tested

    even without rebooting with the command

    # chroot /mnt /linuxrc

    This is of course limited to initrds that do not interfere with the

    general system state (e.g. by reconfiguring network interfaces,

    overwriting mounted devices, trying to start already running demons,

    etc. Note however that it is usually possible to use pivot_root in

    such a chroot'ed initrd environment.)

 7) unmount the file system

    # umount /mnt

 8) the initrd is now in the file "initrd". Optionally, it can now be

    compressed

    # gzip -9 initrd

```

It doesn't sound me too starnge to simply test this kernel feature. It should work!

These commands are executed correctly from your box?

Which kernel version d'you have?

What file system d'u use?

I use reiserfs:

```

# cat /proc/mounts

rootfs / rootfs rw 0 0

/dev/root / reiserfs rw,noatime 0 0

none /dev devfs rw 0 0

none /proc proc rw 0 0

none /sys sysfs rw 0 0

none /dev/pts devpts rw 0 0

tmpfs /var/tmp tmpfs rw 0 0

none /dev/shm tmpfs rw 0 0

none /proc/bus/usb usbfs rw 0 0

/dev/hda7 /boot ext2 rw,noatime 0 0

```

----------

## MikeyPants

I, too, am having the same problem, but with loading up an ISO to take a peek inside.

```

# mount -t iso9660 -o loop myfile.iso /mnt/myfiletest

ioctl: LOOP_SET_FD: Invalid argument

# mount -o loop myfile.iso /mnt/myfiletest

ioctl: LOOP_SET_FD: Invalid argument

```

I'm running kernel 2.6.1 in an ext3 filesystem.  I've also checked my .config to make sure loopback was compiled in, and it was..

```

Device Drivers --->

    Block Devices --->

    <*> Loopback device support

      <> Cryptoloop support

```

I never had this problem in 2.4.22.  The filesystem and everything are still the same, just a different kernel.

Any ideas?

----------

## arthax

 *MikeyPants wrote:*   

> I, too, am having the same problem, but with loading up an ISO to take a peek inside.
> 
> 

 

I found this: http://lkml.org/lkml/2004/1/8/43

So I compiled and installed (as usually) the mm-sources-2.6.1-r5 and all his modules. But, when I rebooted, after init, the boot process hangs on and an "Oops" failure is printed. I'm trying to report it more accurately.... Did happen the same also to you?

----------

## MikeyPants

No, I didn't get any error like that yet.  However, I haven't patched anything.  And I'm running a vanilla 2.6.1 kernel with only the bootsplash patch added.

I do notice that the patch from the mailing list entry you pointed me at is in the Changelog for version 2.6.2_rc1, so, as I'm not completely in a rush for this (I just wanted to open an ISO so I can take a look and then burn it to CD to get it off of my hard drive), I'll just wait a bit for 2.6.2 final to come out.  I would hope at that point that your booting issue gets cleared up as well.

Good luck!

----------

## Ian Goldby

I've got this problem too. I got a clue from this message.

My main filing system is Reiser 3. When I copied the .iso to my boot partition (which is ext2), it worked fine (except my boot partition is too small to hold the entire iso file). i.e. 

```
# mount -o loop image.iso /mnt/loopback
```

I'd like to know how to get this to work with a Reiser 3 file system.

----------

## wimac

I think you need to set up your loop device try 

```

losetup  /dev/loop0 image.iso 

```

then try your mount

----------

## Ian Goldby

```
/home/ian

(502) # losetup /dev/loop0 image.iso

ioctl: LOOP_SET_FD: Invalid argument
```

Same problem. Why should that make a difference when it works with ext2 but not Reiser?

----------

## Ian Goldby

Another fun fact:

mount -o loop doesn't work on multisession CD images. This is probably due to a bug in mount. (It gives an error about something not being a directory.)

----------

## ghost5316

I was having the same problem, I was trying to mount an ISO from my /mnt/d folder (Fat File system).

Since I had supermount setup, I decided to unmount the /mnt/d and mount it again manually, this allowed me to mount the iso.

```
none      /mnt/d      supermount   fs=auto,dev=/dev/hda5         0 0
```

----------

