1

I need some help figuring out how to mount partition 1 (xfs, boot) of the /dev/sda device from CentOS-7-x86_64-Minimal-1511.iso on a CentOS Linux release 7.2.1511 (Core) VM. There are multiple devices in the image. This partition is in the second device. The first device is the ISO image itself.

Some system info

$ cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
$ uname -a
Linux localhost.localdomain 3.10.0-327.3.1.el7.x86_64 #1 SMP Wed Dec 9 14:09:15 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ whoami
root

This is what I have done so far.

Step 1. Download and verify the ISO

$ wget http://ftp.riken.jp/Linux/centos/7.2.1511/isos/x86_64/CentOS-7-x86_64-Minimal-1511.iso
<output snipped>
$ ls -l CentOS-7-x86_64-Minimal-1511.iso 
-rw-rw-r--. 1 jlinoff jlinoff 632291328 Dec  9 15:03 CentOS-7-x86_64-Minimal-1511.iso
$ md5sum CentOS-7-x86_64-Minimal-1511.iso 
88c0437f0a14c6e2c94426df9d43cd67  CentOS-7-x86_64-Minimal-1511.iso
$ # matches 88c0437f0a14c6e2c94426df9d43cd67 from http://ftp.riken.jp/Linux/centos/7.2.1511/isos/x86_64/md5sum.txt

Step 2. View the available devices using parted

$ parted CentOS-7-x86_64-Minimal-1511.iso print devices
/home/jlinoff/work/iso/CentOS-7-x86_64-Minimal-1511.iso (632MB)
/dev/sda (21.5GB)
/dev/mapper/centos-swap (2147MB)
/dev/mapper/centos-root (18.8GB)
/dev/sr0 (59.0MB)

Step 3. View the partitions

$ parted CentOS-7-x86_64-Minimal-1511.iso select /dev/sda unit B print
Using /dev/sda
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21474836480B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start       End           Size          Type     File system  Flags
 1      1048576B    525336575B    524288000B    primary  xfs          boot
 2      525336576B  21474836479B  20949499904B  primary               lvm

Step 4. Mount partition 1 based on the offset

$ mkdir -m 0777 /tmp/foo
$ mount -t xfs -o loop,ro,offset=1048576 CentOS-7-x86_64-Minimal-1511.iso /tmp/mnt
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.

Step 5. Try to figure out the correct offset

It seemed obvious that the offset was wrong so I tried to figure it out based on the preceding filesystem by incorporating the endpoint from the previous device:

$ parted CentOS-7-x86_64-Minimal-1511.img select /home/jlinoff/work/iso/CentOS-7-x86_64-Minimal-1511.img unit B print
Using /home/jlinoff/work/iso/CentOS-7-x86_64-Minimal-1511.img
Model:  (file)
Disk /home/jlinoff/work/iso/CentOS-7-x86_64-Minimal-1511.img: 632291328B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start    End       Size      Type     File system  Flags
 2      196608B  6615039B  6418432B  primary

$ bc
1048576 + 6615039
7663615

I tried offset=7663615 and offset=6615039. Same error.

This is the full list of all devices.

$ parted CentOS-7-x86_64-Minimal-1511.iso unit B print all
Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0
has been opened read-only.
Error: /dev/sr0: unrecognised disk label
Model:  (file)
Disk /home/jlinoff/work/iso/CentOS-7-x86_64-Minimal-1511.iso: 632291328B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start    End       Size      Type     File system  Flags
 2      196608B  6615039B  6418432B  primary


Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 21474836480B
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start       End           Size          Type     File system  Flags
 1      1048576B    525336575B    524288000B    primary  xfs          boot
 2      525336576B  21474836479B  20949499904B  primary               lvm


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 2147483648B
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End          Size         File system     Flags
 1      0B     2147483647B  2147483648B  linux-swap(v1)


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 18756927488B
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End           Size          File system  Flags
 1      0B     18756927487B  18756927488B  xfs

What am I doing wrong?

  • The iso is not formatted as XFS... I'm sure it wouldn't be. – Braiam Dec 24 '15 at 23:03
  • Right, that makes sense but I was hoping that the /dev/sda device was just the raw bytes which might be formatted as XFS and that I could access it by using the appropriate offset. Can you think of another way to extract that data without mounting the ISO and installing the OS? – Joe Linoff Dec 24 '15 at 23:29
1

losetup(8) has an option (-P or --partscan) that can scan for partitions inside an image file and then actually map them to virtual block devices, so that instead of this:

$ losetup -a
/dev/loop0: []: yourisoimage.iso

...you will be able to see additional loop devices referring to partitions:

$ ls /dev/loop*
/dev/loop0
/dev/loop0p1
/dev/loop0p2
/dev/loop-control

Use the following command to automatically allocate a new loopX device and scan for additional partitions:

$ losetup -f -P yourisoimage.iso

Then just mount the corresponding loop device without the -o loop mount option.


EDIT: after reading your comment below, I think some clarifications are in order.


What I think is going on here is you're looking for a rabbit in the hen-house.

What you are seeing in the second step above is the list of all devices in the system, not just a list of partitions on the ISO file. Your command includes a bogus parameter (the name of the ISO file) and parted is just listing every partition it sees on any device.

What you are probably actually trying to do is to mount /dev/sda2 off the physical disk /dev/sda which has absolutely nothing to do with that CentOS ISO file.

Furthermore, since that partition is not a filesystem partition but rather a physical volume (of LVM fame), there is no filesystem present directly on it.

To be able to access its contents, you should use pvscan to discover all physical volumes in the system, vgchange -ay to activate all volume groups, and then vgs and lvs to see the list of volume groups and logical volumes.

The contents are accessed under a special name which reads /dev/<vgname>/<lvname>, so for a volume group named foo, and a logical volume named bar, the name would be /dev/foo/bar.

What you mount is hence /dev/foo/bar and not /dev/sda2.

  • That is a great idea but it doesn't work for devices other than the first one (home/jlinoff/work/iso/CentOS-7-x86_64-Minimal-1511.iso) in this case. You can see what losetup will create by running fdisk -l. – Joe Linoff Dec 24 '15 at 17:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.