Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Sunday, 14 August 2016

Mounting an ISO/IMG on Linux / Raspberry PI

To mount an ISO/IMG file in Linux (or your Raspberry PI), first information on the contents of the image must be found using the fdisk command:

pi@pi_horizon_emb:~ $ fdisk  -lu /media/pi/41AB-0764/2016-03-18-raspbian-jessie-lite.img
 
Disk /media/pi/41AB-0764/2016-03-18-raspbian-jessie-lite.img: 1.3 GiB, 1361051648 bytes, 2658304 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: 0x6f92008e
 
Device                                                   Boot  Start     End Sectors  Size Id Type
/media/pi/41AB-0764/2016-03-18-raspbian-jessie-lite.img1        8192  131071  122880   60M  c W95 FAT32 (LBA)
/media/pi/41AB-0764/2016-03-18-raspbian-jessie-lite.img2      131072 2658303 2527232  1.2G 83 Linux 

Note the block size and start location of the partition you wish to mount.
Then mount the partition within the image to a location of your choice on your local disk. Note you need to specify the offset, which is the start location * the block size.


pi@pi_horizon_emb:/ $ sudo mount -t auto -o loop,offset=$((131072*512))  /media/pi/41AB-0764/2016-03-18-raspbian-jessie-lite.img ~/iso_mount/
pi@pi_horizon_emb:/ $ ls ~/iso_mount/
bin  boot  dev  etc  home  lib  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
pi@pi_horizon_emb:/ $

You can then modify the contents of the image partition. Note the partition size is restricted (it won't just expand as you add to it):


pi@pi_horizon_emb:/ $ df /home/pi/iso_mount
Filesystem     1K-blocks   Used Available Use% Mounted on
/dev/loop0       1210960 732164    399232  65% /home/pi/iso_mount

Monitoring Linux Disk Usage Using iotop

iotop

iotop needs to be run as root. Once running hit ‘a’, then ‘o’ - a will display accumulated I/O instead of bandwidth, and o will only display processes or threads actually doing I/O.
I’d recommend running it as ‘sudo iotop -d0.5’, this should get it refreshing its data at a reasonable rate.
E.g.
image2016-4-13 9:58:54.png

The only drawback of this mode, is that you won’t easily see results for processes which are periodically spawned and killed – you might catch them if you are continuously monitoring the output.
If you think you have processes which are periodically spawned and killed, you could try using it in batch mode: ‘sudo iotop -boat -qqq’, and pipe to grep to catch particular processes.

image2016-4-13 9:58:59.png