livecd-tools icon indicating copy to clipboard operation
livecd-tools copied to clipboard

make livecd-iso-to-disk work for dm linear block device just like loop device

Open hgkamath opened this issue 6 years ago • 1 comments

minor feature request:

Use case: to use livecd-iso-to-disk on a mash-up on a larger block device made by combining other block devices using device-mapper.

  • Goal: to write a live image to a partition, sdd4 but not mess with the efi partition sdd1. ie. user wanting control over the bootloaders and grub2-menu, and not wanting any automatic writing being done there.
  • An alternate feature option might be an option to skip altering efi/grub/mbr sections

livecd-iso-to-disk can write to a loop back image. So i thought to try making an image using dmsetup Device-mapper allows one to combine many non block devices of different peripherals into one larger block device.

$ cat mk_vdisk.tbl 0 2048 linear /dev/loop0 0 2048 258048 linear /dev/loop1 0 260096 8126464 linear /dev/sdd4 0 8386560 4096 linear /dev/loop2 0

dd if=/dev/zero of=/mnt/temp0.img bs=512 count=2048 # for GPT table dd if=/dev/sdd1 of=/mnt/temp1.img bs=512 count=258048 # for dummy efi partition chmod o+r,o+w /dev/sdd4 dd if=/dev/zero of=/mnt/temp2.img bs=512 count=4096 # just padding after the real block device

losetup --find --show /mnt/temp0.img # loop0 losetup --find --show /mnt/temp1.img # loop1 umount /dev/sdd4 losetup --find --show /mnt/temp2.img # loop2

dmsetup create cdsk mk_vdisk.tbl # above command made /dev/dm-6 -> /dev/mapper/cdsk symlink # first use gdisk to make the gpt table delineate partitions correctly. partition start, end, sizes need to be carefully calculated.
# Number Start (sector) End (sector) Size Code Name # 1 2048 260095 126.0 MiB EF00 EFI System # 2 260096 8386559 3.9 GiB 0700 Microsoft basic data partprobe /dev/mapper/cdsk # /dev/dm-6 # above command creates devices for the partitions, cdsk1, cdsk2, and correspondingly /dev/dm-7, /dev/dm-8 chmod o+r,o+w /dev/mapper/cds{k,k1,k2} $ test that cdsk2 is mountable (and is the same as sdd4). csdk1, the dummy efi can also be likewise modified anyhow, may even be set as a dd-copy of the real /dev/sdd1
dmsetup ls dmsetup info /dev/mapper/cdsk dmsetup status /dev/mapper/cdsk

      • Try to use livecd-iso-tools on this

dmsetup remove cdsk2 cdsk1 cdsk losetup -d /dev/loop{0,1,2}

The livecd-iso-to-disk tool has the following section

isdevloop() {
    [[ x${1#/dev/loop} != x$1 ]]
}
...
getdisk() {
...
   if [[ -n $loop ]]; then
        node=${DEV#/dev/loop}
        p=${DEV##*/}
        device=loop${node%p*}

, which I think, have the function of figuring out corresponding symlinks to block names It seemed like the code code be made to intelligently do the same for dm maps. isdmmaps() ... I can't say if that is all that is needed.

Eventually, I decided to give up and try a different way. I used livecd-iso-to-disk directly on /dev/sdd4, but made sure to back up /dev/sdd1 and restored it.

hgkamath avatar Oct 18 '18 17:10 hgkamath

Pull Request #176 enables a Device-mapper target to be the target installation device for livecd-iso-to-disk.

FGrose avatar Feb 19 '21 19:02 FGrose