-1

I want to join (concatenate) two files in Linux without using space in the filesystem. Can I do this?

A + B = AB

The file AB use sectors or fragments of A and B from the filesystem. Is it possible to do this?

Could I use gparted to recognize AB as a new file without copying two files (which is a slow process)?

AdminBee
  • 22,803
ArtEze
  • 55

2 Answers2

1

I'm supposing you have a very large disk image split into large files f1, f2 and f3 and want to modify the partitions in that disk image. Then assuming the size of all files are multiple of 512, you could do (as root)

offset=0
for f in f1 f2 f3; do
   loop=$(losetup -f --show -- "$f")
   size=$(blockdev --getsz "$loop")
   printf '%s\n' "$offset $size linear $loop 0"
   offset=$(( offset + size ))
done | dmsetup create myimg

Then you can do a gparted /dev/mapper/myimg, and even format and mount the partitions it creates afterwards.

To tear down that device:

  • make sure all filesystems and other resources on it are unmounted / freed
  • dmsetup remove myimg
  • run losetup -d on each loop device.
0

Process substitution can be used to concatenate two or more files so that they appear to be one file for a process e.g. some_program <(cat A B).

However, that wouldn't make any sense to use with gparted or any other program that's meant to modify the input file - it's not a real file, it's a fifo, an anonymous pipe, and it's ephemeral. The "file" created by <() is also read-only and non-seekable (i.e. it can only be read sequentially).

Process substitution also includes >() for redirecting stdout to a process, but that still wouldn't be of any use with gparted, which expects to be working with a real block device or disk image file.

cas
  • 78,579