Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
####### # # E-scripts on using the loop devices. # # Note 1: use the eev command (defined in eev.el) and the # ee alias (in my .zshrc) to execute parts of this file. # Executing this file as a whole makes no sense. # An introduction to eev can be found here: # # (find-eev-quick-intro) # http://angg.twu.net/eev-intros/find-eev-quick-intro.html # # Note 2: be VERY careful and make sure you understand what # you're doing. # # Note 3: If you use a shell other than zsh things like |& # and the for loops may not work. # # Note 4: I always run as root. # # Note 5: some parts are too old and don't work anymore. Some # never worked. # # Note 6: the definitions for the find-xxxfile commands are on my # .emacs. # # Note 7: if you see a strange command check my .zshrc -- it may # be defined there as a function or an alias. # # Note 8: the sections without dates are always older than the # sections with dates. # # This file is at <http://angg.twu.net/e/loop.e> # or at <http://angg.twu.net/e/loop.e.html>. # See also <http://angg.twu.net/emacs.html>, # <http://angg.twu.net/.emacs[.html]>, # <http://angg.twu.net/.zshrc[.html]>, # <http://angg.twu.net/escripts.html>, # and <http://angg.twu.net/>. # ####### # «.blkid» (to "blkid") # «.losetup» (to "losetup") # «.partx» (to "partx") # «.two-partitions» (to "two-partitions") * (eepitch-shell) * (eepitch-kill) * (eepitch-shell) # This takes 20 seconds or more... time cp -v $S/http/mirror.fsf.org/trisquel-images/trisquel-mini_8.0_amd64.iso /tmp/trisquel.iso # https://en.wikipedia.org/wiki/Loop_device # (find-esgrep "grep -nH -e loop *.e") # (find-esgrep "grep -nH -e loop *.e | grep -v loops") # (find-esgrep "grep -nH -e losetup *.e") # (find-man "1 man" "man -k printf") # (find-sh "man -k printf") # (find-sh "man -k loop") # (find-es "trisquel" "pen-drive-2018") # (find-es "qemu" "qemu-2018") partitions /tmp/trisquel.iso ##### # # blkid # 2018mai08 # ##### # «blkid» (to ".blkid") # (find-man "8 blkid") # (find-sh "blkid -h") # (find-sh "blkid -k") # (find-fline "/etc/blkid.conf") # (find-fline "/etc/" "blkid.tab") blkid sudo blkid -p /dev/sda sudo blkid -p /dev/sda1 sudo blkid -p /dev/sda1 | tr ' ' '\n' sudo blkid -p /dev/sda2 | tr ' ' '\n' sudo blkid -p /dev/sda3 | tr ' ' '\n' sudo blkid -p /dev/sda4 | tr ' ' '\n' sudo blkid -p /dev/sda5 | tr ' ' '\n' sudo blkid -p /dev/sda6 | tr ' ' '\n' sudo blkid -p /dev/sda7 | tr ' ' '\n' sudo blkid -p /dev/sda8 | tr ' ' '\n' ##### # # losetup # 2018mai08 # ##### # «losetup» (to ".losetup") # (find-man "8 losetup") # (find-man "8 losetup" "-a, --all") # (find-man "8 losetup" "-f, --find") # (find-man "8 losetup" "-o, --offset offset") # (find-man "8 losetup" "-j, --associated file") # (find-man "8 mount") # (find-man "8 mount" "THE LOOP DEVICE") # (find-man "8 mount" "THE LOOP DEVICE" "offset") # (find-fline "/dev/" "loop") laf /dev/loop* sudo losetup --show /dev/loop0 sudo losetup -f /tmp/trisquel.iso sudo losetup --find /tmp/trisquel.iso sudo losetup --find /tmp/trisquel.iso sudo losetup --associated /tmp/trisquel.iso sudo losetup --show /dev/loop0 sudo losetup /dev/loop0 sudo losetup /dev/loop1 sudo losetup --detach /dev/loop0 sudo losetup --detach /dev/loop1 sudo losetup --associated /tmp/trisquel.iso sudo losetup /dev/loop4 /tmp/trisquel.iso sudo losetup --associated /tmp/trisquel.iso sudo losetup /dev/loop4 sudo losetup --detach /dev/loop4 sudo losetup --associated /tmp/trisquel.iso ##### # # partx # 2018mai08 # ##### # «partx» (to ".partx") # https://dustymabe.com/2012/12/15/mounting-a-partition-within-a-disk-image/ # https://www.suse.com/c/accessing-file-systems-disk-block-image-files/ # (find-man "8 partx") # (find-man "8 partx" "-a, --add") # (find-man "8 partx" "-d, --delete") # (find-man "8 partx" "-s, --show") # (find-fline "/dev/" "loop") # This works: # partx --show - /tmp/trisquel.iso # sudo losetup /dev/loop4 /tmp/trisquel.iso sudo partx --show - /dev/loop4 sudo partx --add /dev/loop4 laf /dev/loop* # mkdir /tmp/tris1 sudo mount -o ro /dev/loop4p1 /tmp/tris1 # (find-fline "/tmp/tris1/") sudo umount /tmp/tris1 sudo partx --delete /dev/loop4 # sudo losetup /dev/loop4 sudo losetup --detach /dev/loop4 sudo losetup /dev/loop4 # This works: # sudo losetup /dev/loop4 /tmp/trisquel.iso sudo partx --show - /dev/loop4 sudo partx --add /dev/loop4 sudo partx --delete /dev/loop4 sudo losetup --detach /dev/loop4 # This works: # sudo losetup /dev/loop4 /tmp/trisquel.iso sudo partx --show - /dev/loop4 sudo partx --add /dev/loop4 mkdir /tmp/tris1 sudo mount -o ro /dev/loop4p1 /tmp/tris1 sudo umount /tmp/tris1 sudo partx --delete /dev/loop4 sudo losetup --detach /dev/loop4 sudo losetup /dev/loop4 # This works: # sudo losetup /dev/loop4 /tmp/trisquel.iso sudo partx --show - /dev/loop4 sudo partx --add /dev/loop4 mkdir -p /tmp/tris1 sudo mount -o ro /dev/loop4p1 /tmp/tris1 laf /tmp/tris1/casper/filesystem.squashfs sudo losetup /dev/loop5 /tmp/tris1/casper/filesystem.squashfs mkdir -p /tmp/tris1s sudo mount -o ro /dev/loop5 /tmp/tris1s # (find-fline "/tmp/tris1s/") sudo umount /tmp/tris1s sudo losetup --detach /dev/loop5 sudo umount /tmp/tris1 sudo losetup --detach /dev/loop4 sudo partx --delete /dev/loop4 ##### # # Creating two partitions in a loop device # 2018mai21 # ##### # «two-partitions» (to ".two-partitions") # (find-es "grub" "grub-pen-drive-2018") # (find-es "grub" "ext2-embedding-not-possible") * (eepitch-shell) * (eepitch-kill) * (eepitch-shell) # (find-man "dd") mount # Clean up from a previous run # sudo umount /tmp/pengrub1 sudo umount /tmp/pengrub2 sudo losetup --detach /dev/loop4 rm -v /tmp/pengrub1/ rm -v /tmp/pengrub2/ rm -v /tmp/pengrub.img # Create /tmp/pengrub.img and point /dev/loop4 to it # dd bs=1M count=100 if=/dev/zero of=/tmp/pengrub.img ls -lAFh /tmp/pengrub.img sudo losetup /dev/loop4 /tmp/pengrub.img # Create two partitions in /dev/loop4 # (find-man "8 fdisk") # sudo fdisk /dev/loop4 n p 1 +50M p n p 2 p m w sudo fdisk -l /dev/loop4 # Format the partitions # (find-man "8 partprobe") # (find-man "8 partx" "are in 512-byte sectors") # sudo partx --show /dev/loop4 sudo partprobe /dev/loop4 sudo mke2fs /dev/loop4p1 sudo mke2fs /dev/loop4p2 # sudo losetup --detach /dev/loop4 # Mount the partitions # mkdir /tmp/pengrub1/ mkdir /tmp/pengrub2/ sudo losetup /dev/loop4 /tmp/pengrub.img sudo mount -o loop /dev/loop4p1 /tmp/pengrub1 sudo mount -o loop /dev/loop4p2 /tmp/pengrub2 # (find-fline "/tmp/pengrub1/") # (find-fline "/tmp/pengrub2/") # Umount the partitions # sudo umount /tmp/pengrub1 sudo umount /tmp/pengrub2 sudo losetup --detach /dev/loop4 # (find-grubnode "Invoking grub-install") # sudo grub-install /dev/loop4 # sudo grub-install /dev/pengrub1 # Local Variables: # coding: utf-8-unix # End: