Score:0

How to search block device for text?

ec flag

Strangely to me google had not returned any relevant (IMO) links in top results.

I want to edit iso9660.

Here How is it easier to make a persistent live drive with Ubuntu 19.10? I've read

sed 's/quiet splash/persistent  /' lubuntu-19.10-desktop-amd64.iso > persistent-lubuntu-19.10-desktop-amd64.iso  # yes, sed works with binary files

Then I thought, I have already made USB stick, why not try to edit it. dd works, but sed: couldn't edit /dev/sdb: not a regular file, so short of dumping all partition to file I better seek position of text to replace.

Any utilities to search within block file/device?

guiverc avatar
cn flag
Why don't you just `mount` the ISO? https://askubuntu.com/questions/164227/how-to-mount-an-iso-file
Score:0
sy flag

I expand Martian's answer to make it automatic. I'm using /dev/mapper/vgmint-root which is the root volume of my Linux Mint's LVM volume group with Ext4 filesystem):

sudo grep --only-matching --byte-offset --max-count=1 --text 'unique\.str \
    /dev/mapper/vgmint-root | cut -d: -f1 | xargs -I{} -- sh -xc \
    'sudo dd count=1 skip=$(echo "{} / 512" | bc) if=/dev/mapper/vgmint-root \
        | xxd -c 32'

This is actually a useful undelete command, at least for small plain text files. You can increase --max-count=1 if you want to see more matches, and count=1 if you expect a file longer than 512 bytes.

If you found what you're looking for, copy the xxd output into a file and run, and voila!

xxd -c 32 -r the_xxd_output_to_reverse
Score:0
cn flag

I think what you are trying to accomplish two seperate things,

The First is scanning an entire partition for a specific string.

You shouldn't try to edit/read block devices, rather try mounting them first! with

sudo mkdir /media/iso
sudo mount -o loop path/to/iso/file/YOUR_ISO_FILE.ISO /media/iso 

in your case. Source

Then you can use the mentioned sed command.

Now the actual thing you're trying to accomplish (as far as I understand) is making a persistant live Installation. This can be done two ways: Installing Ubuntu to the USB drive itself OR Iso-booting with persistant storage.

You are probably trying to boot the ISO with persistant storage so your changes dont get lost upon reboot!

Now This article is a little old and in german, though it has worked for me and you are probably able to follow the command snippets of it after using google translate on the site :)

My Grub-script for persistant live boot is as follows, you can install it like seen here.

insmod part_gpt
insmod ext2
set root='(hd0,2)'
set isofile='/iso/ubuntu-21.10-desktop-amd64.iso'

if [ x$feature_platform_search_hint = xy ]; then
  search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos2 --hint-efi=hd0,gpt2 --hint-baremetal=ahci0,msdos2  4e3de29b-008c-4063-9376-c52f34c87225
else
  search --no-floppy --fs-uuid --set=root 4e3de29b-008c-4063-9376-c52f34c87225
fi

loopback loop $isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile persistent quiet splash noeject
initrd (loop)/casper/initrd

The cryptic Text 4e3de29b-008c-4063-9376-c52f34c87225 is the UUID of the partition, the ISO is on. You can find yours using gnome-disks, g-parted or blkid /dev/sdX I hope I could help you!

Martian2020 avatar
ec flag
Thank you, but I do not have iso file on USB, it is already ISO 9660 device (I mean I want to edit USB stick, not original iso ;-). I've found now I can use `grep`.
Score:0
ec flag
$ sudo grep --only-matching --byte-offset --max-count=1 --text "quiet splash" /dev/sdb
1927125977:quiet splash

So this outputs offset in bytes, then divide by 512 (default dd block size) and then

sudo dd count=1 skip=3763917 if=/dev/sdb | hd


000001c0  69 6e 69 74 72 64 3d 2f  63 61 73 70 65 72 2f 69  |initrd=/casper/i|
000001d0  6e 69 74 72 64 2e 6c 7a  20 71 75 69 65 74 20 73  |nitrd.lz quiet s|
000001e0  70 6c 61 73 68 20 2d 2d  0a 6d 65 6e 75 20 64 65  |plash --.menu de|
000001f0  66 61 75 6c 74 0a 6c 61  62 65 6c 20 78 66 6f 72  |fault.label xfor|

Pattern located.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.