Create loop device

delform_17

New Member
Joined
Nov 23, 2022
Messages
10
Reaction score
1
Credits
106
I have a little problems with install software like losetup used to create device loop bacause I must mount img file certanly with RPi version with nographic.
I've tried apt-get update / upgrade command but nothing from this doen't work.

However find some good repository with this tolls isn't so easy despite there is many package contain this tool on the web.
I've tried use this support :
It seems to be asy but ut I'm stuct on losetup tool : https://linuxhandbook.com/create-virtual-block-device/

So now I'm not sure should I mount IMG file using losetup software and make loop driver or choose other point of view and follow this tutorial :
.

I know that here is also second way to fix this issue with fdisk command but I'm not pretty sure. Is it work.

During try to install any package contain losetup I've got this message ,,The folowing package have unmet dependencies ". I've found some info that package called ,,util-linux-ng" have this tool.

Is here a person which have idea how to crush this problem ? I will apreciate and sorry for gramma.
 


If you only want to mount an image file use mount -o loop filename - then you can access it like any other filesystem.

If you want to create a loop device then you create a file of the size you want by using /dev/zero
Code:
dd if=/dev/zero of=my.img bs=1G count=2

This will create a 2GB file, next you give it a filesystem
Code:
sudo mkfs.ext4 my.img

Then you mount it - I just use /mnt
Code:
sudo mount -o loop my.img /mnt

Then you should be able to access it by using /mnt as the directory.

(It has been a while since I have actually used a loop device, but pretty sure the above is right.)
 
This instruction which You've wrote me It was work but when I've tried with raspios version bullseye in img file system gave me error.

So now I don't know is it problem with image file or something else.
 

Attachments

  • raspios_mount_bad_fs_type_error.jpg
    raspios_mount_bad_fs_type_error.jpg
    41.5 KB · Views: 129
i was able to mount the root partition (but not esp for some reason) of a 2023-05-03-raspios-bullseye-arm64-lite.img using the method described on this page using fdisk and adding an offset option: https://www.linuxquestions.org/questions/linux-general-1/how-to-mount-img-file-882386/

similar info here, but a little more recent: https://unix.stackexchange.com/a/82315

Code:
$ fdisk -l /path/to/2023-05-03-raspios-bullseye-arm64-lite.img
Disk /path/to/2023-05-03-raspios-bullseye-arm64-lite.img: 1.96 GiB, 2101346304 bytes, 4104192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x544c6228

Device                                                Boot  Start     End Sectors  Size Id Type
Downloads/2023-05-03-raspios-bullseye-arm64-lite.img1        8192  532479  524288  256M  c W95 FAT32
Downloads/2023-05-03-raspios-bullseye-arm64-lite.img2      532480 4104191 3571712  1.7G 83 Linux
# mount -t auto -o loop,offset=272629760 /path/to/2023-05-03-raspios-bullseye-arm64-lite.img /mnt/dir/
$ cat /mnt/dir/etc/rpi-issue
Raspberry Pi reference 2023-05-03
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 7c750947a959fb626a70c09fd17c65815df192ac, stage2
 
@ delform_17

Aha, you didn't mention it was a RPi image file, that is a complete operating system that gets image copied to a disk, it has 2
partitions, one for the boot, & one for the system itself. ;)
 
On this moment I mounted second part from that Image where should be the system but still have a problem because He told me that he doesn't see any disc or image on a black screen. I have no typical RPI begining screen with raspberry. I've found some help on one tutorial but there autor make this through create a new partition by fdisk, mount this partition and then emulate system.
I don't know is this a good idea.
 

Members online


Top