1. Mounting a File System or Partition From a Disk Image

    Sat 23 January 2010

    You cannot just make a disk copy with dd and then just mount it as a regular disk. You must know where the partition starts on the disk. So first, you need to get the partition table with sfdisk:

    sfdisk -l -uS image_file.dd

    The output is something like:

    Disk /mnt/image/image_file.dd: 9729 cylinders, 255 heads, 63 sectors/track
    Warning: The partition table looks like it was made
    for C/H/S=*/240/63 (instead of 9729/255/63).
    
    For this listing I'll assume that geometry.
    
    Units = sectors of 512 bytes, counting from 0
    
    Device Boot Start End #sectors Id System
    
    /mnt/image/simon-besmet.img1 63 8497439 8497377 b W95 FAT32
    /mnt/image/simon-besmet.img2 * 8497440 156280319 147782880 7 HPFS/NTFS
    /mnt/image/simon-besmet.img3 0 - 0 0 Empty
    /mnt/image/simon-besmet.img4 0 - 0 0 Empty
    

    Next, we need to calculate the actual starting point of the partition. The sector number is in sectors, which contain 512 bytes. So in this case, the starting point of the NTFS partition is 8497440 x 512 = 4350689280.

    To mount the image, enter the following command, using the calculated offset:

    mount -o loop,offset=4350689280 /mnt/image/disk_image.dd /mnt/disk
    

    Source:

    http://lists.samba.org/archive/linux/2005-April/013444.html

    Tagged as : Uncategorized
    If you have any comments email me, see the About page for contact details.
  2. Shunit2, Unit Testing for Shell Scripts

    Thu 17 December 2009

    This may be of interest to people who are as stupid as I am and write elaborate shell scripts instead of using a proper scripting language such as Python or Ruby. No I am deliberately not mentioning Perl here.

    Anyway, testing is always an issue. With PPSS, I encountered many times that some change broke something in another place. Testing if some change screwed things up manually is just tedious and a pain.

    As any person who is semi-serious about programming should have done already, I started to write some unit tests. For bash scripts, there is this unit test framework called Sunit2. It takes some effort to write tests. But once you have written some tests and witness how the tests that passed before now fail after you changed some code is priceless. Because often, you would not have found the issue before a long time.

    Tagged as : Uncategorized
    If you have any comments email me, see the About page for contact details.

Page 14 / 34