Hot answers tagged

21

loop device is a pseudo ("fake") device (actually just a file) that acts as a block-based device. You want to mount a file (disk1.iso) that will act as entire filesystem, so you use loop. The -o comes from the -options. And the last thing, if you want to search for "-o" you need to escape the '-'. Try: man mount | grep "\-o"


13

Traditionally, UNIX systems have had various types of nodes in their filesystems: directory file symlink block device character device FIFO UNIX domain socket While there are now exceptions, generally block devices containing filesystems are mounted on directories. Since you want to mount a file, you must first create a loop block device that is backed ...


13

Technically a loop device is a block device that writes to a file, rather than a piece of hardware. So you always use/need to use the loop back device when mounting a file. So much for a direct answer. Maybe this serves as an explanation: The kernel implements several layers of abstraction so that it can treat different hardware the same way. Imagine if ...


12

You can do that with the device mapper and its snapshot target. Basically, you'd do the same as what LVM does when you create a writable snapshot. dev=/dev/read-only-device ovl=/path/to/overlay.file newdevname=newdevice size=$(blockdev --getsize -- "$dev") loop=$(losetup -f --show -- "$ovl") printf '%s\n' "0 $size snapshot $dev $loop P 8" | dmsetup ...


12

If on Linux, when loading the loop module, make sure you pass a max_part option to the module so that the loop devices are partitionable. Check the current value: cat /sys/module/loop/parameters/max_part If it's 0: modprobe -r loop # unload the module modprobe loop max_part=31 To make this setting persistent, add the following line to /etc/modprobe....


11

This is a classic problem in concurrency: when allocating a resource, you need to atomically determine that the resource is free and reserve it, otherwise another process could reserve the resource between the time you check that it's free and the time you reserve it. Do use losetup's automatic allocation mode (-f), and pass the --show option to make it ...


10

Make sure you are running mknod -m 660 /dev/loop10 b 7 10. The format is mknod -m 660 /dev/loop<ID> b 7 <ID> where ID is the same. Update [07/10/2014] I also found a good blog post to always have more at boot. See https://yeri.be/xen-failed-to-find-an-unused-loop-device Update [05/25/2016] I run a CentOS server, and I found that this post was ...


9

Create a sparse-file device, using dd. df -hm # to show where we started dd of=sparse-file bs=1k seek=102400 count=0 # creates a 100Meg sparsefile mkfs.ext4 sparse-file mkdir blah mount sparse-file blah cp somefile blah ls -lahts sparse-file # The 's' option will report the actual space taken in the first column ls -lahts blah df -hm # doublecheck my work ...


8

I don't think you can do it in place but if you have enough space this should work: # Create the files that will hold your data dd if=/dev/zero of=part-00 bs=1M count=4k dd if=/dev/zero of=part-01 bs=1M count=4k # Create the loop devices losetup /dev/loop0 part-00 losetup /dev/loop1 part-01 # Create a RAID array mdadm --create /dev/md0 --level=linear --...


8

losetup /dev/loop0 produces something like: /dev/loop0: [000f]:8070558 (/path/to/file.iso) losetup comes with the util-linux package.


6

Parted should be able to read disk image from file and interpret the partition table. So use parted -s disk.img unit s print For my (testing) disk image it gives: # parted -s /root/sdd.img unit s print Model: (file) Disk /root/sdd.img: 16384s Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End Size Type File ...


5

That's just grub2's loop device feature. grub is able to read a number of filesystems and in addition to that to nest them, in that it is able to read files (an initrd and linux kernel above) inside a filesystem inside a file inside another file system. I has nothing to do with linux loop devices. Grub uses it just to load those kernel and initrd files in ...


5

This should be a comment to mrb's answer. But I am not allowed to add comments, so adding this as another answer. We can use the following dd command for the 100GB image creation to save some time. dd if=/dev/zero of=/mnt/hetzner_backup/backup-fs.image bs=1024 count=0 seek=$[1024*1024*100] This finishes in a fraction of a second, while the one in mrb's ...


5

Mount your network location with whichever protocol you're using: # smbfs example: mount -o username=your_hetzner_username //server.or.ip.addr/sharename /mnt/server-mountpoint Create an ext2fs image (or another filesystem, if you prefer) inside a file on that share. Do this only the first time, as it wipes the data in backup-fs.image: # create a 1000 MB ...


5

I think this is obvious, but typeset -i M=1 while [ $M -le 102 ] do mount mysourcedevice$M targetdir$M & let M++ done wait Should do the job. The wait will wait until all sub-processess are finished, before executing the next command.


5

You have to create device nodes into /dev with mknod. The device nodes in dev have a type (block, character and so on), a major number and a minor number. You can find out the type and the major number by doing ls -l /dev/loop0: user@foo:/sys# ls -l /dev/loop0 brw-rw---- 1 root disk 7, 0 Oct 8 08:12 /dev/loop0 This means loop device nodes should have the ...


5

losetup (the command normally used to set them up) will tell you: $ /sbin/losetup --list NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE /dev/loop0 0 0 0 0 /var/tmp/jigdo/debian-7.6.0-amd64-CD-1.iso Note that with older versions you may hat to use use -a instead of --list, and this outputs in a different and now deprecated format....


5

I figured it out. While I am not sure how the issue with the permission thing is, I can instead shoot first and ask later like this: sudo losetup -f myfile.img ld=$(losetup -j myfile.img | grep -o "/dev/loop[0-9]*") dostuffwith $ld


5

echo "how many times would you like to run your loop ?" read max i=0 while [ "$((i+=1))" -le "$max" ] do # whatever you want to do here done


5

That's not how you define arrays in bash. a="foo bar" defines a string/scalar variable. And using it as $a (unquoted) performs the split+glob operator which only makes sense for strings representing a $IFS separated list of file patterns. In bash, arrays are defined as: a=(foo bar) So here, you'd want: array1=(name1 name2) name1=(one two) name2=(red ...


4

With recent kernels (≥ 2.6.37), see Petr Uzel's answer. With older kernels, this length limit is inherent. Strace shows that losetup -a obtains the name through the LOOP_GET_STATUS ioctl, which calls loop_get_status_old, which gets its data from a struct loop_info. The name field in that kernel data structure is limited to LO_NAME_SIZE = 64 bytes. (There's ...


4

If you don't have to use the loop option to mount a regular file, it is because mount is detecting this and activating it for you automatically. You used to have to specify it manually.


4

Splitting a string at a particular character is built into the shell at a very deep level: if you write $var without any surrounding quotes, then it is expanded as follows: Take the value of the var variable. Split this value into a list of fields. The field separator is any character in the value of the IFS variable. If IFS contains whitespace characters, ...


4

Maybe a threaded version could be a bit faster, you've to adjust the mount() parameters yourself. #include <stdio.h> #include <pthread.h> #include <sys/mount.h> #include <string.h> #include <errno.h> #define DEVS 100 static void *mountt(void *d) { int i = (int)d; char loop[48], mp[48]; snprintf(loop, 47, "/dev/...


4

The thing here is that /dev/sr0 is linked to a kernel device driver. That device driver will allow access to a physical CDROM if available through that node; VMWare and VirtualBox emulate hardware as you mention and hence the kernel and device driver think they're communicating with hardware. The /dev/sr0 doesn't point to a certain buffer directly, it ...


4

push(){ shuttle push note Chrome \ "Aurora: $1" \ "Battery is at $percent percent" } full=0 while percent=$(acpi | awk '{ print $4}' | sed 's/[,%]//g') do case $percent:$full in (100:1) ;; (100:0) full=1 push 'Battery charged';; (?:*|1?:*|20:*) full=0 ...


4

A loop device is a particular type of block device, managed by the loop device driver. A loop device is a block device whose content is stored in a file, similar to the way a SCSI disk device is a block device whose content is stored on a SCSI disk, a USB storage device is a block device whose content is stored on a USB storage peripheral, etc. Linux has a ...


3

If you're sure that the fields between the commas do not contain any whitespaces than you could do something like this: for job in $(echo $all_jobs | tr "," " "); do sendevent -verbose -S NYT -E JOB_OFF_HOLD -J "$job" --owner me done If you need something more robust, take a look at the tools needed to deal with CSV files under Unix.


3

It's possible to do with fuse, but would probably be cleaner with custom tools. Solution With apt-get-able tools the following kludge is possible: mkdir mnt xmount --in dd --out vdi disk.img mnt mkdir mnt2 vdfuse -f mnt/disk.vdi mkdir mnt3 fuseext2 -o "rw" mnt2/Partition1 mnt3 Explanation The basic idea is that fuse can be used to separate a full ...


3

GRUB 2 is able to mount ISOs in loopback. This is not relevant to to-be-loaded OS.



Only top voted, non community-wiki answers of a minimum length are eligible