Loopback mounts are cool as heck. You can take a file containing an image of a partition and mount on top of your regular filesystem. But what if you have a file containing an entire disk image rather than just an image of a single partition? It’s common to deal with such files when dealing with User Mode Linux (UML) root filesystems.
Well, you can still do it. It turns out that
losetup and hence
mount which uses
losetup to do loopback mounting, allow you to specify an
offset option to specify the starting offset into the file from which to read. Now the only trick is to use
fdisk to figure out where the partitions are:
$ fdisk -l -u -C 592 FedoraCore6-x86-root_fs
Disk FedoraCore6-x86-root_fs: 0 MB, 0 bytes
255 heads, 63 sectors/track, 592 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
FedoraCore6-x86-root_fs1 * 63 208844 104391 83 Linux
FedoraCore6-x86-root_fs2 208845 6281414 3036285 8e Linux LVM
$ echo $((63 * 512))
$ sudo mount FedoraCore6-x86-root_fs fc6-loop -o loop,offset=32256
In this case, I was wanting to mount the first partition, which according to
fdisk, starts at sector 63. In order to convert that to a byte offset, I simply multiplied 63 by 512 (the number of bytes per sector) to get a byte offset of 32256. Note that the second partition can’t be mounted this way, because it’s an LVM partition.
Whatever you’re celebrating, I hope it’s a good one.
Merry Christmas & Happy Holidays!
What *is* a yule?
OK, looks like it’s my turn:
- When I was thirteen years old, I wrote two programs for my Atari 800XL that were published in Antic Magazine. One was a clone of Tetris, which I got hooked on when I visited my Dad at work and played it on his IBM PC, only to find out that it was not available for the Atari (at least at the time).
- The longest I’ve dated anyone is 7 months, with the exception of one girlfriend, who is now my wife.
- My college roommate and I once flew to Seattle and spent a couple of days with two sisters that we met in an AOL chat room.
- My fourth grade teacher, Mr. Rubcich, told us that he could guarantee that we would always remember the three rivers in Pittsburgh, Pennsylvania. We of course didn’t believe him. Oh yeah, they’re the Ohio, the Allegheny, and the Monongahela, and yes I did remember them off the top of my head (I’m going to check the names and spelling at Wikipedia). I’ve never been to Pittsburgh, except for the airport, when I was interviewing at Lucent in Allentown.
- As a teenager, I played guitar in a heavy metal band called Aftershock. I have a VHS tape of us playing at a place in Staten Island called The Rock Palace. At one point we got an awesome gig, opening up for a local band whose name escapes me, which was a big deal because it was a band with Bobby Gustafson, who had been the guitar player for a very popular thrash metal band called Overkill. We even were mentioned on some radio commercials on the local college metal station. At the last minute, we had to pull out of the gig, because our singer contracted food poisoning from some mushrooms that he ate. I recently discovered that two of my former bandmates, Chris and Emmett, are on MySpace.
OK, now how about Chris, Hsin, and Phil.