Page 1 of 1

Mounting image to check original parameters

Posted: Fri Mar 27, 2020 3:56 pm
by stereomaton
Today, I wanted to get the default parameters of StereoPi.
I downloaded the image file and here is a tip to avoid to burn it, thanks to Linux.

With fdisk, we can get the organisation of the partitions in the image:

Code: Select all

$ fdisk -l stereopi-0-2-3.img 
Disk stereopi-0-2-3.img: 1.9 GiB, 2013265920 bytes, 3932160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb41d5468

Device              Boot Start     End Sectors  Size Id Type
stereopi-0-2-3.img1       8192   98045   89854 43.9M  c W95 FAT32 (LBA)
stereopi-0-2-3.img2      98304 3932159 3833856  1.8G 83 Linux
Here, the first partition starts at sector 8192 and a sector is 512 bytes. Man can compute the offset: 8192*512=4194304

Now, mount the partition as this (after having created an empty /tmp/stereopi_fat/ directory):

Code: Select all

sudo mount -o loop,offset=4194304 stereopi-0-2-3.img /tmp/stereopi_fat/
And voilĂ , you have access to the data written in the image in the specified directory without having to burn it for real.
Linux is fantastic.

You can unmount as usual:

Code: Select all

sudo umount /tmp/stereopi_fat/

By the way, here is the default configuration stereopi.conf I searched for:
video_width=1280
video_mode=3D
video_height=720
video_fps=30
video_bitrate=3000000
video_profile=baseline
rtmp_url=
rtmp_enabled=0
mpegts_clients=192.168.1.10:3001
mpegts_enabled=0
rtsp_enabled=0
usb_enabled=1
audio_enabled=0
video_wb=auto
exposure=auto
contrast=-15
sharpness=0
digitalgain=0.0
wifi_iface=
wifi_ssid=
wifi_psk=
record_enabled=0
record_time=300
dec_enabled=0
up_down=0
udp_clients=192.168.1.10:3000
udp_enabled=0
ws_enabled=0

Re: Mounting image to check original parameters

Posted: Sun Mar 29, 2020 1:19 pm
by Realizator
Hi Stereomaton,
Thank you for your tip! I will add it to our Wiki.
By the way, under MacOS I mount RPi images using Paragon extFS for Mac. It also helps me to avoid recording of the image to the card to access some code and default settings.
UPD> We use "contrast=-15" as a default, but may be "0" is a good option. "-15" comes from our first experiments in a low light conditions.

Re: Mounting image to check original parameters

Posted: Sat Jun 13, 2020 5:26 pm
by stereomii
Stereomaton, you inspired me to a little quest to handle image files.

After "burning" image to a SD card it was up till now rather impossible for me to create a small image for backup from my system. I mostly use 16Gb cards and with W32Imager I get a 16 Gb image, using too much space and too much time for burning.

I found losetup to be very usefull.

Code: Select all

[email protected]# losetup -f -D image.img
will allocate the image to the first free loop device (usually /dev/loop0) and search for a partition table, resulting in f.e.

Code: Select all

[email protected]:/media/pi# ls -l /dev/loop0*

brw-rw---- 1 root disk   7, 0 jun 13 18:45 /dev/loop0
brw-rw---- 1 root disk 259, 0 jun 13 18:45 /dev/loop0p1
brw-rw---- 1 root disk 259, 1 jun 13 18:45 /dev/loop0p2
brw-rw---- 1 root disk 259, 2 jun 13 18:45 /dev/loop0p3
After this you can mount the partitions (/dev/loop0p1 etc.) just like a regular disk, inspect and change files etc.

You can even do a parted or gparted to delete the 3rd FAT32 partition

Code: Select all

gparted /dev/loop0
fdisk -l /dev/loop0 shows the layout

Code: Select all

[email protected]:/media/pi# fdisk -l /dev/loop0
Disk /dev/loop0: 14,5 GiB, 15523119104 bytes, 30318592 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb41d5468

Device       Boot   Start      End  Sectors  Size Id Type
/dev/loop0p1         8192    98045    89854 43,9M  c W95 FAT32 (LBA)
/dev/loop0p2        98304  8484863  8386560    4G 83 Linux
/dev/loop0p3      8484864 30318591 21833728 10,4G  b W95 FAT32
(partition 3 not yet deleted here), you see the last block (8484863) of the (p2) / partiton, if p3 was deleted a

Code: Select all

dd if=image.img of=image-minimal.img bs=512 count=8484863 
(just for sure ;) I take a few more blocks for count), gives me a minimal sized image. All without arithmetic, always nice for a mathematician.

do not forget to umount the partitions and do a

Code: Select all

losetup -D
to disconnect the loop devices.

I used raspbian stretch for this.
Indeed, Linux is fantastic.

Re: Mounting image to check original parameters

Posted: Sat Jun 13, 2020 8:36 pm
by stereomaton
Nice proposition.
I always forget that losetup can do this out of the box now. A few years ago, doing it with a multi-partition image was a nightmare (needed special kernel configuration if I remember well).
Sure it is far easier with your way.