# mount -o loop



## balanga (Nov 15, 2017)

Is there something equivalent in FreeBSD to:-

```
mount -o loop initrd-noheader <mount point>
```

as in https://archlinuxarm.org/forum/viewtopic.php?f=53&t=4334 ?


----------



## SirDice (Nov 15, 2017)

mdconfig(8)


----------



## PacketMan (Nov 15, 2017)

SirDice said:


> mdconfig(8)



Can I use that to create ram disk? Is it the same thing / for same or similar purpose(s)? Thanks again.


----------



## tobik@ (Nov 15, 2017)

Yes.


----------



## SirDice (Nov 15, 2017)

Look at the vnode option. That will allow you to create a virtual device from a file. You can then mount that device.


----------



## balanga (Nov 15, 2017)

SirDice said:


> mdconfig(8)



After a couple of hours trying, I can't get mdconfig(8) to do what `loop` does....


----------



## Maxnix (Nov 15, 2017)

balanga said:


> After a couple of hours trying, I can't get mdconfig(8) to do what `loop` does....




```
mdconfig -f <your_file> -u 0
mount -t <fs_type> /dev/md0 <your_mountpoint>
```


----------



## balanga (Nov 15, 2017)

I get 

```
mount: /dev/md0: Invalid argument
```

My file is not an ISO.


----------



## Maxnix (Nov 16, 2017)

It's up to you figuring out what filesystem is that (`file -s <file>`).


----------



## aragats (Nov 17, 2017)

balanga said:


> I get
> 
> ```
> mount: /dev/md0: Invalid argument
> ...


If your file is an image of an *entire* disk, you should find /dev/md0s1 or /dev/md0p1 device nodes for partition(s) to mount.


----------



## balanga (Nov 18, 2017)

This is some code I've managed to cobble together which works on Linux. I would like to do the same on FreeBSD but I can't get the `mount -o loop` to work. Not sure that `mdconfig` can be used... initrd-noheader just seems to be an archive file of some description which Linux knows how to decompress...


```
mkdir /mnt/gfh
mkdir /tmp/gfh
cd /tmp/gfh
wget http://support.goflexhome.hipserv.com/en/reflash/goflex_2_7_2_firmware.zip
unzip goflex_2_7_2_firmware.zip
dd if=initrd of=initrd-noheader.gz skip=64 bs=1
gunzip initrd-noheader.gz
mount -o loop initrd-noheader /mnt/gfh
cd /mnt/gfh
ls -al >~/loop.lst
cp etc/init.d/rcs ~
```

What I'm eventually hoping to do is be able to install FreeBSD on my GoFlexHome unit - it may take some time ...


----------



## Beastie (Nov 18, 2017)

So you still haven't identified the file using the file(1) utility as previously advised?!

There's no Linux-specific voodoo in the decompression. A gzip is a gzip.


----------



## balanga (Nov 19, 2017)

Maxnix said:


> It's up to you figuring out what filesystem is that (`file -s <file>`).


`file -s initrd-noheader`

```
initrd-noheader: Linux rev 1.0 ext2 filesystem data (mounted or unclean), UUID=e015a6c3-09ee-47f2-9cdb-18ed0f3c94dc
```


----------



## aragats (Nov 19, 2017)

```
kldload ext2fs
mount -t ext2fs /dev/md0 <mount_point>
```


----------



## Beastie (Nov 19, 2017)

See? That wasn't so difficult after all. It's just like FreeBSD setup images: the CD/DVD images are ISOs and the ones for pendrives are IMG raw filesystem images. In the case of FreeBSD these IMGs are UFS2-based and in this Linux-specific case they're ext2-based.


----------



## balanga (Nov 20, 2017)

Many thanks to everyone who helped point me in the right direction. I eventually came up with a script to create a USB disk which would provide
root Access to GoFlex Home without Registering Device

This should work on FreeBSD:-

```
TMPFILE=`mktemp XXXX`
echo $TMPFILE
mkdir /mnt/$TMPFILE
mkdir /tmp/gfh
cd /tmp/gfh
wget http://support.goflexhome.hipserv.com/en/reflash/goflex_2_7_2_firmware.zip
unzip goflex_2_7_2_firmware.zip
dd if=initrd of=initrd-noheader.gz skip=64 bs=1
gunzip initrd-noheader.gz
mount -t ext2fs /dev/`mdconfig -f initrd-noheader` /mnt/$TMPFILE
cd /mnt/$TMPFILE/etc/init.d/
#ls -al >~/loop.lst
cp rcS ~
cat <<EOF >sed.txt
/umount/a\
\\
# Attach the root file system and update /etc/passwd\\
echo "**** Attaching UBI file system"\\
ubiattach /dev/ubi_ctrl -m 2 -O 2048\\
if [ $? != 0 ]; then\\
        echo "**** ERROR - Could not attach UBIFS"\\
fi\\
mdev -s\\
mkdir -p /mnt/ubifs\\
\\
# sleep a while to allow devices to settle\\
sleep 5\\
\\
echo "**** Mounting root file system"\\
mount -t ubifs ubi0 /mnt/ubifs\\
\\
echo "**** Updating system password file"\\
sed -i 's/root:\*:/root:\$1\$3h5WisJ4\$JbJ\/AJORbUw8Mf.LtNVtp\/:/' /mnt/ubifs/etc/shadow
EOF

sed -f sed.txt rcS >newrcS
mv newrcS rcS
rm sed.txt
cd /tmp/gfh

gzip initrd-noheader

mkimage -A arm -O linux -C gzip -T ramdisk -n initramfs -d initrd-noheader.gz initrd

rm $TMPFILE
umount /mnt/$TMPFILE
rmdir /mnt/$TMPFILE
```

I don't think the standard FreeBSD installation contains `unzip` or `mkimage` so they may need to be added (not sure about `wget`).

I'd appreciate any comments or suggestions on how the change this script.


----------



## scottro (Nov 20, 2017)

You can install wget with pkg install wget.  It doesn't come with  the base install, but the base does provide fetch, which is similar.


----------

