#2555 PR merged: Support loop devices in format_usb_disk

Labels: enhancement, fixed / solved / done

dhoffend opened issue at 2021-01-18 02:46:

Relax-and-Recover (ReaR) Pull Request Template

Pull Request Details:
  • Type: Enhancement

  • Impact: Normal

  • Reference to related issue (URL):

  • How was this pull request tested?

I've created usb disk images using

fallocate -l 8G /var/lib/rear/output/rear-hostname.img
losetup -P /dev/loop0 /var/lib/rear/output/rear-hostname.img
YES=true rear -v format -- --efi /dev/loop0
rear -v -c mkbackup
losetup -d /dev/loop0

With a local.conf


and tested them as usb disk image in libvirt/kvm

  • Brief description of the changes in this pull request:

Support loop devices to create usb disk images without having a physical usb stick plugged in in to the server. The problem is loop devices is that the first partition is names loop0p1 instead of loop01 (like normal disk expands from sda to sda1) which the script assused. This makes creating bootable usbstick backups easier on remote servers. After that you just have to download them and dd'd them to the next stick available.

OliverO2 commented at 2021-01-26 10:29:

ReaR already supports creating an image file via its RAWDISK output method. You don't even need to create a loop device on your own and correct sizing is done automatically.

See the relevant section in default.conf which starts with:

# RAWDISK produces a bootable image file named "rear-$HOSTNAME.raw", which
# - supports UEFI boot if syslinux/EFI or Grub 2/EFI is installed,
# - supports Legacy BIOS boot if syslinux is installed,
# - supports UEFI/Legacy BIOS dual boot if syslinux *and* one of the supported EFI bootloaders are installed.
# A RAWDISK image can be copied onto a disk boot medium (a USB stick will do) with
#   dd if="$uncompressed_image_file.raw" of="$disk_device" bs=1M
# or for the default RAWDISK_IMAGE_COMPRESSION_COMMAND='gzip' below with
#   zcat "$compressed_image_file.raw.gz" | dd of="$disk_device" bs=1M
# Note: Use the entire disk device (like /dev/sdX) to be overwritten, not only a partition (like /dev/sdX12).
# A RAWDISK image is suitable for archiving USB images, works without having to format the USB device
# and can thus be used to replace the USB output method.

dhoffend commented at 2021-01-28 12:57:

That's true, but my problem ist that I want to create an RAWDISK Image that also includes the data backup generated by BACKUP=NETFS

I can't find a BACKUP_URL syntax similar to BACKUP_URL=usb:///dev/disk/by-label/REAR-000 that does the job for me.

Looking at the code, once the rescue stage has been finished the rawdisk image closes the image and compresses the image. After that, including the backup part into the RAWDISK image is no longer possible.

The RAWDISK Image is an option for someone who uses network based backup/restore solutions but not when you want to create a single disk image including rescue and backup part.

OliverO2 commented at 2021-01-28 15:02:

You are right, RAWDISK does not provide the option to integrate backup files into the image file. It's possibly doable, but on first sight ReaR's code structure does not seem to be geared toward this.

gdha commented at 2021-02-12 16:54:

@jsmeix @gozora Could you review the code as well before the merging the code?

dhoffend commented at 2021-02-22 15:46:

Thank you for the review and approval.

jsmeix commented at 2021-02-22 15:52:

thank you for your contribution to improve ReaR!

[Export of Github issue for rear/rear.]