Mounting image to check original parameters

Other software discussion
Post Reply
stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Mounting image to check original parameters

Post 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
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

User avatar
Realizator
Site Admin
Posts: 900
Joined: Tue Apr 16, 2019 9:23 am
Contact:

Re: Mounting image to check original parameters

Post 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.
Eugene a.k.a. Realizator

User avatar
stereomii
Posts: 37
Joined: Mon May 13, 2019 3:11 pm
Location: Apeldoorn, The Netherlands
Contact:

Re: Mounting image to check original parameters

Post 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

root@raspi# 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

root@raspi:/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

root@raspi:/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.
Jan a.k.a. stereomii
StereoPi with Waveshare 160deg cams

stereomaton
Posts: 215
Joined: Tue May 21, 2019 12:33 pm
Location: France

Re: Mounting image to check original parameters

Post 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.
Stereophotographer and hacker
Despite my quite active participation in the forum, I am not in the StereoPi team
StereoPi (v1) Standard Edition + CM3Lite module + a few cameras

Post Reply