loop number

Non release banter
raja
Shogun
Shogun
Posts: 434
Joined: 02 May 2017, 09:51
Distribution: v3.2.2-32 and Porteus-Artix-64
Location: Chennai,India

loop number

Post#1 by raja » 05 Jun 2019, 08:48

How do we identify the module activated with reference to loop number in /sys/block/? Thanks.
Linux Kernel-4.4.272 -32 bit; Linux Kernel-5.4.185 - 64 bit

jssouza
Legendary
Legendary
Posts: 1165
Joined: 09 Jul 2015, 14:17
Distribution: Porteus x86 arm

loop number

Post#2 by jssouza » 05 Jun 2019, 13:59

For every loop[0-n] directories in loop there is a loop/backing_file that shows the activated module.

Eg:
guest@porteus:~$ cat /sys/block/
loop0/ loop1/ loop2/ loop3/ loop4/ loop5/ loop6/ loop7/ sda/ sdb/

Code: Select all

guest@porteus:~$ cat /sys/block/loop0/loop/backing_file 
/mnt/sda3/test/porteus/base/000-kernel.xzm

guest@porteus:~$ cat /sys/block/loop1/loop/backing_file 
/mnt/sda3/test/porteus/base/001-core.xzm
and so on.

This can be used in a script, say a python script to retrieve the module:

Code: Select all

def get_backing_files(self):
        os.chdir('/sys/block/')
        loop_devices = glob.glob('loop*')
        for loop_device in loop_devices:
            if os.path.exists('/sys/block/' + loop_device + '/loop/'):
                with open('/sys/block/' + loop_device + '/loop/backing_file', encoding = 'utf-8') as fd:
                    fline = fd.read()
                    if fline[:-1].endswith(".xzm"):
                        self.backing_files.append(fline[:-1])
        return len(self.backing_files)

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

loop number

Post#3 by brokenman » 05 Jun 2019, 14:03

Here is one way.

Code: Select all

guest@porteus:~$ file /sys/block/loop5
/sys/block/loop5: symbolic link to ../devices/virtual/block/loop5

guest@porteus:~$ cat /sys/devices/virtual/block/loop5/loop/backing_file 
/mnt/sda2/porteus/modules/fire fox.xzm
Added in 2 minutes 27 seconds:
Nice tip above with the python script!

Added in 3 minutes 13 seconds:
In a bash script you could do it like so:

To find which module is loaded on loop5

Code: Select all

cat /sys/devices/virtual/block/$1/loop/backing_file
To find which loop device contains a module with the string "fox"

Code: Select all

find /sys/devices/virtual/block/ -type f -name "backing_file" | xargs -n1 -i grep fox {}
How do i become super user?
Wear your underpants on the outside and put on a cape.

raja
Shogun
Shogun
Posts: 434
Joined: 02 May 2017, 09:51
Distribution: v3.2.2-32 and Porteus-Artix-64
Location: Chennai,India

loop number

Post#4 by raja » 05 Jun 2019, 17:58

Thanks jssouza and brokenman.

May be when you are free, you can educate me a little.

When you activate a module, it is mounted and shows up in /mnt/live/memory/images/.

Why does OS need to create loop devices for them to read/write, Can´t mount option alone do that?

What expects a block device and hence a RaiserFS and all these remapping?

How errors crop up in these loop block devices?
Linux Kernel-4.4.272 -32 bit; Linux Kernel-5.4.185 - 64 bit

raja
Shogun
Shogun
Posts: 434
Joined: 02 May 2017, 09:51
Distribution: v3.2.2-32 and Porteus-Artix-64
Location: Chennai,India

loop number

Post#5 by raja » 09 Jun 2019, 09:07

Two lines from DMESG file. - 6 seconds work out

Code: Select all

[    2.526660] sd 2:0:0:0: [sdb] Attached SCSI removable disk
[    8.619084] udevd[599]: starting eudev-3.2.5
I was interested in these ¨loop devices¨ stuff since ,I assume 6 seconds were consumed, during boot , building loop devices . Obviously, more modules you load more will be the delay.

Lines from /etc/udev/rules.d/10-porteus-fstab-update.rules:

Code: Select all

# we don't care about loop* and ram* devices
KERNEL=="[!lr]*", SUBSYSTEM=="block", RUN+="/sbin/udev-fstab-update %r/%k"
KERNEL=="loop*",ENV{UDISKS_IGNORE}="1"
so no need for loop devices in fstab.

But, lsblk, lists them along with HDD and other storage devices.

Is there a way in future, when live systems do away with loop devices, and drastically reduce boot time?.
Linux Kernel-4.4.272 -32 bit; Linux Kernel-5.4.185 - 64 bit

Post Reply