LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-10-2017, 07:59 PM   #1
JRHeisey
LQ Newbie
 
Registered: Mar 2017
Location: Sunnyvale, CA
Posts: 3

Rep: Reputation: Disabled
kpartx fails to mount partition from an image file


  • I am using CentOS 7 as a guest in VirtualBox under Windows 7 host.
  • I am trying to create a bootable SD card by creating its image as file to be used in an embedded system.
  • Used dd to create the sdcard.img file and filled with zeros from /dev/zero
  • Used fdisk to create two partitions in the sdcard.img file
  • When I use kpartx with -av only the second 'root' partition is mounted. The first 'boot' partition does not mount.

I have been researching this all day and have not found any references to this type of issue.

Any suggestions?

If not I'll have to just create the partitions directly on the SD card. I've done this before.

- J.R.
 
Old 07-10-2017, 11:44 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,771

Rep: Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571
You did something wrong - or at least not what you expected. A zeroed partition will not mount - be careful of your terminology. Very careful.
Run it all again and post a screenshot or cut-and-paste - include everything from the initial "dd". Maybe then we can help.
 
Old 07-11-2017, 12:17 PM   #3
JRHeisey
LQ Newbie
 
Registered: Mar 2017
Location: Sunnyvale, CA
Posts: 3

Original Poster
Rep: Reputation: Disabled
I initially was blindly following instructions from a DornerWorks document. DornerWorks provide support services for the Xen hypervisor.

As I become more familiar with the tools used I am beginning to understand what each tool does.

Here are the steps from the document from DornerWorks.
Quote:
1. Create a new clean two partition image.
$ dd if=/dev/zero of=$RELEASE_DIR/dist/images/sdcard.img bs=1G count=7
$ echo -e "n\np\n1\n\n+256M\nt\nc\nn\np\n2\n\n\nt\n2\n83\nw\n" | fdisk
$RELEASE_DIR/dist/images/sdcard.img
2. Install kpartx if it is not already.
$ sudo apt-get install kpartx
3. Mount both partitions of the image using kpartx.
sudo kpartx -av $RELEASE_DIR/dist/images/sdcard.img
sudo mkfs.vfat /dev/mapper/loop1p1
sudo mkfs.ext4 /dev/mapper/loop1p2
I have a couple of issues.
- For dd I changed the count=7 to count=15 for my larger SD card.
- The string piped to fdisk did not work out-of-the-box. I needed to manually run fdisk to create the two partitions.
- The string shows the first partition set to the system ID of 'c' which is 'W95 FAT32 (LBA)'.
- I tried leaving it at the default of '83' for 'Linux' but it did not change the behavior of kpartx.
- Result of kpartx
$ sudo kpartx -av $RELEASE_DIR/dist/images/sdcard.img
[sudo] password for username:
add map loop0p2 (253:2): 0 14680001 linear /dev/loop0 63
- mkfs.*: loop1 part of loop1p1 reference is not appropriate for my system because it is mounting as loop0. Easy to compensate.
- In the two mkfs.vfat command loop0p1 is not mounted at all just loop0p2.

Results from fdisk -l
Code:
Disk /media/sf_projects/RDP3/XZD_20161231/dist/images/sdcard.img: 16.1 GB, 16106127360 bytes, 31457280 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
Disk label type: dos
Disk identifier: 0x322d1bed

                                                      Device Boot      Start         End      Blocks   Id  System
/media/sf_projects/RDP3/XZD_20161231/dist/images/sdcard.img1            2048     2099199     1048576   83  Linux
/media/sf_projects/RDP3/XZD_20161231/dist/images/sdcard.img2         2099200    31457279    14679040   83  Linux

Last edited by JRHeisey; 07-11-2017 at 12:33 PM. Reason: formatting
 
Old 07-11-2017, 06:55 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 19,771

Rep: Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571Reputation: 3571
My apologies, all that looks ok.
Been too many years since I looked at XEN, so I can't offer any advice - they are doing something under the covers with the loop device(s).
If you have mkfs.vfat, I would expect (in a normal world) you to also be able mount vfat.

This is what I get (and expect to get) from my small test - non-virtualised. Both mount (manually) as expected.
Code:
Disk /dev/loop0: 10 MiB, 10485760 bytes, 20480 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: 0x0eaf30f8

Device       Boot Start   End Sectors Size Id Type
/dev/loop0p1       2048  6143    4096   2M  c W95 FAT32 (LBA)
/dev/loop0p2       6144 20479   14336   7M 83 Linux
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Mount image file of a partition ViniciusBorges Linux - Hardware 2 09-18-2014 07:09 PM
partimage fails to restore image of partition which has soft-link of other LV Kaustuv Linux - Enterprise 0 02-25-2012 10:36 AM
android fails to mount nand yaffs2 system image barr16 Linux - Mobile 11 04-25-2011 09:08 AM
How to mount an image of a partition on a DVD? jnriopel Linux - Newbie 1 11-26-2008 08:51 AM
Fails to mount NTFS partition preeth45 Linux - Software 3 06-20-2008 05:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration