Booting an EXT4 image file from GRUB2Is there a Linux equivalent for VHD from which it can boot?Is it...

How can I improve my fireworks photography?

How to acknowledge an embarrassing job interview, now that I work directly with the interviewer?

Rear brake cable temporary fix possible?

Why do neural networks need so many training examples to perform?

Do authors have to be politically correct in article-writing?

How can I deal with a significant flaw I found in my previous supervisor’s paper?

What makes the Forgotten Realms "forgotten"?

Dilemma of explaining to interviewer that he is the reason for declining second interview

Unwarranted claim of higher degree of accuracy in zircon geochronology

Number of FLOP (Floating Point Operations) for exponentiation

If I delete my router's history can my ISP still provide it to my parents?

What to do when being responsible for data protection in your lab, yet advice is ignored?

What kind of hardware implements Fourier transform?

What is better: yes / no radio, or simple checkbox?

1 0 1 0 1 0 1 0 1 0 1

I am on the US no-fly list. What can I do in order to be allowed on flights which go through US airspace?

Eww, those bytes are gross

Issues with new Macs: Hardware makes them difficult for me to use. What options might be available in the future?

How do you funnel food off a cutting board?

Compound Interest... with Wizard Money

En Passant For Beginners

Closed form for these polynomials?

What to do if authors don't respond to my serious concerns about their paper?

Why is button three on trumpet almost never used alone?



Booting an EXT4 image file from GRUB2


Is there a Linux equivalent for VHD from which it can boot?Is it possible to fake a Windows install for grub to add to boot menu?Dualboot Linux Mint & Windows 8.1 (GRUB Problems)Grub2 on msdos table partition won't loadRepairing bootloader for kali linux 2.0Boot from btrfs RAID5/6?Install Linux to a single partitionGrub2 cannot detect SSD but fdisk canWindows 10 booting old installation after SSD cloneDual booting configurationGrub installing in wrong drive













0















My friend needed a fast HDD so I gave her my small 64GB SDD. This SSD had my Linux install on it. I used dd to make an image of the partition (boot, root and home on one partition).



This partition is now sitting on a traditional 500GB EXT4 formatted drive.



Is there any way I can get GRUB to just boot using this .img file I have? I'm not getting my SSD back and I can't be bothered to go through the hassle of setting up my Linux install from scratch. I have come across loopback support in GRUB for ISO images. Does this support EXT4 also? I don't seem to be able to find anything specific and don't want to trash anything.



Cheers.










share|improve this question














bumped to the homepage by Community 23 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






migrated from stackoverflow.com Apr 13 '12 at 11:24


This question came from our site for professional and enthusiast programmers.



















  • I highly doubt you have an *ISO*(9660) image. Also note that even if you can boot the kernel with grub, the initrd has no idea about your new (and nested) layout. The shortest solution is to replay the disk image file back onto a (raw) disk, i.e. resolving the loop indirection.

    – jørgensen
    Apr 13 '12 at 14:01











  • Yeah I thought as much. I expect booting from the image would cause all kinds of problems with GRUB and kernel updates anyway. Thanks for replying.

    – sjjg
    Apr 14 '12 at 12:01
















0















My friend needed a fast HDD so I gave her my small 64GB SDD. This SSD had my Linux install on it. I used dd to make an image of the partition (boot, root and home on one partition).



This partition is now sitting on a traditional 500GB EXT4 formatted drive.



Is there any way I can get GRUB to just boot using this .img file I have? I'm not getting my SSD back and I can't be bothered to go through the hassle of setting up my Linux install from scratch. I have come across loopback support in GRUB for ISO images. Does this support EXT4 also? I don't seem to be able to find anything specific and don't want to trash anything.



Cheers.










share|improve this question














bumped to the homepage by Community 23 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






migrated from stackoverflow.com Apr 13 '12 at 11:24


This question came from our site for professional and enthusiast programmers.



















  • I highly doubt you have an *ISO*(9660) image. Also note that even if you can boot the kernel with grub, the initrd has no idea about your new (and nested) layout. The shortest solution is to replay the disk image file back onto a (raw) disk, i.e. resolving the loop indirection.

    – jørgensen
    Apr 13 '12 at 14:01











  • Yeah I thought as much. I expect booting from the image would cause all kinds of problems with GRUB and kernel updates anyway. Thanks for replying.

    – sjjg
    Apr 14 '12 at 12:01














0












0








0








My friend needed a fast HDD so I gave her my small 64GB SDD. This SSD had my Linux install on it. I used dd to make an image of the partition (boot, root and home on one partition).



This partition is now sitting on a traditional 500GB EXT4 formatted drive.



Is there any way I can get GRUB to just boot using this .img file I have? I'm not getting my SSD back and I can't be bothered to go through the hassle of setting up my Linux install from scratch. I have come across loopback support in GRUB for ISO images. Does this support EXT4 also? I don't seem to be able to find anything specific and don't want to trash anything.



Cheers.










share|improve this question














My friend needed a fast HDD so I gave her my small 64GB SDD. This SSD had my Linux install on it. I used dd to make an image of the partition (boot, root and home on one partition).



This partition is now sitting on a traditional 500GB EXT4 formatted drive.



Is there any way I can get GRUB to just boot using this .img file I have? I'm not getting my SSD back and I can't be bothered to go through the hassle of setting up my Linux install from scratch. I have come across loopback support in GRUB for ISO images. Does this support EXT4 also? I don't seem to be able to find anything specific and don't want to trash anything.



Cheers.







linux grub ext4






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 13 '12 at 10:41









sjjgsjjg

11




11





bumped to the homepage by Community 23 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 23 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.






migrated from stackoverflow.com Apr 13 '12 at 11:24


This question came from our site for professional and enthusiast programmers.









migrated from stackoverflow.com Apr 13 '12 at 11:24


This question came from our site for professional and enthusiast programmers.















  • I highly doubt you have an *ISO*(9660) image. Also note that even if you can boot the kernel with grub, the initrd has no idea about your new (and nested) layout. The shortest solution is to replay the disk image file back onto a (raw) disk, i.e. resolving the loop indirection.

    – jørgensen
    Apr 13 '12 at 14:01











  • Yeah I thought as much. I expect booting from the image would cause all kinds of problems with GRUB and kernel updates anyway. Thanks for replying.

    – sjjg
    Apr 14 '12 at 12:01



















  • I highly doubt you have an *ISO*(9660) image. Also note that even if you can boot the kernel with grub, the initrd has no idea about your new (and nested) layout. The shortest solution is to replay the disk image file back onto a (raw) disk, i.e. resolving the loop indirection.

    – jørgensen
    Apr 13 '12 at 14:01











  • Yeah I thought as much. I expect booting from the image would cause all kinds of problems with GRUB and kernel updates anyway. Thanks for replying.

    – sjjg
    Apr 14 '12 at 12:01

















I highly doubt you have an *ISO*(9660) image. Also note that even if you can boot the kernel with grub, the initrd has no idea about your new (and nested) layout. The shortest solution is to replay the disk image file back onto a (raw) disk, i.e. resolving the loop indirection.

– jørgensen
Apr 13 '12 at 14:01





I highly doubt you have an *ISO*(9660) image. Also note that even if you can boot the kernel with grub, the initrd has no idea about your new (and nested) layout. The shortest solution is to replay the disk image file back onto a (raw) disk, i.e. resolving the loop indirection.

– jørgensen
Apr 13 '12 at 14:01













Yeah I thought as much. I expect booting from the image would cause all kinds of problems with GRUB and kernel updates anyway. Thanks for replying.

– sjjg
Apr 14 '12 at 12:01





Yeah I thought as much. I expect booting from the image would cause all kinds of problems with GRUB and kernel updates anyway. Thanks for replying.

– sjjg
Apr 14 '12 at 12:01










1 Answer
1






active

oldest

votes


















0














even if file contains partition table grub2 can meanwhile boot from, where (hd0,1) is the location of file and (loop,1) is partition within file. however, this will only boot the initramfs, the file is not really mounted.



/etc/grub.d/40_custom



menuentry "My bootable disk image" {
set isofile="hdd_ext4.img"
loopback loop (hd0,1)/${isofile}
linux (loop,1)/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda1 loop=/${isofile} ro
initrd (loop,1)/boot/initrd.img-3.16.0-4-amd64
}


write your own mount script, chmod a+x and copy into local-premount folder. use initramfs-tools to create your own "initrd.img-3.16.0-4-amd64" and copy it inside the image file. no need to hard code just use the vars from grub entry ${ROOT} and ${loop} inside the script.



/etc/initramfs-tools/scripts/local-premount



#!/bin/sh

modprobe loop
modprobe ext4

# mount /dev/sda1 (file location)
mkdir /host
mount -n -t ext4 -o rw,data=ordered ${ROOT} /host

# kpartx add partition devmappings for hdd_ext4.img
loop_pt=$(kpartx -av /host${loop} 2>&1 | grep loop | cut -f3 -d" ")

# mount hdd_ext4.img (image file)
mount -n -t ext4 -o loop,rw,data=ordered /dev/mapper/${loop_pt} ${rootmnt}


Note: this will only work if kpartx is installed in initramfs






share|improve this answer
























  • grep loop0p1 from output is not always working, this is more exactly... replace: grep loop | cut -f3 -d" " with: grep -owE '(loop[0-9]+p[0-9]+)' | head -n1

    – alecxs
    Mar 8 '18 at 19:56











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f412028%2fbooting-an-ext4-image-file-from-grub2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














even if file contains partition table grub2 can meanwhile boot from, where (hd0,1) is the location of file and (loop,1) is partition within file. however, this will only boot the initramfs, the file is not really mounted.



/etc/grub.d/40_custom



menuentry "My bootable disk image" {
set isofile="hdd_ext4.img"
loopback loop (hd0,1)/${isofile}
linux (loop,1)/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda1 loop=/${isofile} ro
initrd (loop,1)/boot/initrd.img-3.16.0-4-amd64
}


write your own mount script, chmod a+x and copy into local-premount folder. use initramfs-tools to create your own "initrd.img-3.16.0-4-amd64" and copy it inside the image file. no need to hard code just use the vars from grub entry ${ROOT} and ${loop} inside the script.



/etc/initramfs-tools/scripts/local-premount



#!/bin/sh

modprobe loop
modprobe ext4

# mount /dev/sda1 (file location)
mkdir /host
mount -n -t ext4 -o rw,data=ordered ${ROOT} /host

# kpartx add partition devmappings for hdd_ext4.img
loop_pt=$(kpartx -av /host${loop} 2>&1 | grep loop | cut -f3 -d" ")

# mount hdd_ext4.img (image file)
mount -n -t ext4 -o loop,rw,data=ordered /dev/mapper/${loop_pt} ${rootmnt}


Note: this will only work if kpartx is installed in initramfs






share|improve this answer
























  • grep loop0p1 from output is not always working, this is more exactly... replace: grep loop | cut -f3 -d" " with: grep -owE '(loop[0-9]+p[0-9]+)' | head -n1

    – alecxs
    Mar 8 '18 at 19:56
















0














even if file contains partition table grub2 can meanwhile boot from, where (hd0,1) is the location of file and (loop,1) is partition within file. however, this will only boot the initramfs, the file is not really mounted.



/etc/grub.d/40_custom



menuentry "My bootable disk image" {
set isofile="hdd_ext4.img"
loopback loop (hd0,1)/${isofile}
linux (loop,1)/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda1 loop=/${isofile} ro
initrd (loop,1)/boot/initrd.img-3.16.0-4-amd64
}


write your own mount script, chmod a+x and copy into local-premount folder. use initramfs-tools to create your own "initrd.img-3.16.0-4-amd64" and copy it inside the image file. no need to hard code just use the vars from grub entry ${ROOT} and ${loop} inside the script.



/etc/initramfs-tools/scripts/local-premount



#!/bin/sh

modprobe loop
modprobe ext4

# mount /dev/sda1 (file location)
mkdir /host
mount -n -t ext4 -o rw,data=ordered ${ROOT} /host

# kpartx add partition devmappings for hdd_ext4.img
loop_pt=$(kpartx -av /host${loop} 2>&1 | grep loop | cut -f3 -d" ")

# mount hdd_ext4.img (image file)
mount -n -t ext4 -o loop,rw,data=ordered /dev/mapper/${loop_pt} ${rootmnt}


Note: this will only work if kpartx is installed in initramfs






share|improve this answer
























  • grep loop0p1 from output is not always working, this is more exactly... replace: grep loop | cut -f3 -d" " with: grep -owE '(loop[0-9]+p[0-9]+)' | head -n1

    – alecxs
    Mar 8 '18 at 19:56














0












0








0







even if file contains partition table grub2 can meanwhile boot from, where (hd0,1) is the location of file and (loop,1) is partition within file. however, this will only boot the initramfs, the file is not really mounted.



/etc/grub.d/40_custom



menuentry "My bootable disk image" {
set isofile="hdd_ext4.img"
loopback loop (hd0,1)/${isofile}
linux (loop,1)/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda1 loop=/${isofile} ro
initrd (loop,1)/boot/initrd.img-3.16.0-4-amd64
}


write your own mount script, chmod a+x and copy into local-premount folder. use initramfs-tools to create your own "initrd.img-3.16.0-4-amd64" and copy it inside the image file. no need to hard code just use the vars from grub entry ${ROOT} and ${loop} inside the script.



/etc/initramfs-tools/scripts/local-premount



#!/bin/sh

modprobe loop
modprobe ext4

# mount /dev/sda1 (file location)
mkdir /host
mount -n -t ext4 -o rw,data=ordered ${ROOT} /host

# kpartx add partition devmappings for hdd_ext4.img
loop_pt=$(kpartx -av /host${loop} 2>&1 | grep loop | cut -f3 -d" ")

# mount hdd_ext4.img (image file)
mount -n -t ext4 -o loop,rw,data=ordered /dev/mapper/${loop_pt} ${rootmnt}


Note: this will only work if kpartx is installed in initramfs






share|improve this answer













even if file contains partition table grub2 can meanwhile boot from, where (hd0,1) is the location of file and (loop,1) is partition within file. however, this will only boot the initramfs, the file is not really mounted.



/etc/grub.d/40_custom



menuentry "My bootable disk image" {
set isofile="hdd_ext4.img"
loopback loop (hd0,1)/${isofile}
linux (loop,1)/boot/vmlinuz-3.16.0-4-amd64 root=/dev/sda1 loop=/${isofile} ro
initrd (loop,1)/boot/initrd.img-3.16.0-4-amd64
}


write your own mount script, chmod a+x and copy into local-premount folder. use initramfs-tools to create your own "initrd.img-3.16.0-4-amd64" and copy it inside the image file. no need to hard code just use the vars from grub entry ${ROOT} and ${loop} inside the script.



/etc/initramfs-tools/scripts/local-premount



#!/bin/sh

modprobe loop
modprobe ext4

# mount /dev/sda1 (file location)
mkdir /host
mount -n -t ext4 -o rw,data=ordered ${ROOT} /host

# kpartx add partition devmappings for hdd_ext4.img
loop_pt=$(kpartx -av /host${loop} 2>&1 | grep loop | cut -f3 -d" ")

# mount hdd_ext4.img (image file)
mount -n -t ext4 -o loop,rw,data=ordered /dev/mapper/${loop_pt} ${rootmnt}


Note: this will only work if kpartx is installed in initramfs







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 3 '18 at 20:36









alecxsalecxs

1




1













  • grep loop0p1 from output is not always working, this is more exactly... replace: grep loop | cut -f3 -d" " with: grep -owE '(loop[0-9]+p[0-9]+)' | head -n1

    – alecxs
    Mar 8 '18 at 19:56



















  • grep loop0p1 from output is not always working, this is more exactly... replace: grep loop | cut -f3 -d" " with: grep -owE '(loop[0-9]+p[0-9]+)' | head -n1

    – alecxs
    Mar 8 '18 at 19:56

















grep loop0p1 from output is not always working, this is more exactly... replace: grep loop | cut -f3 -d" " with: grep -owE '(loop[0-9]+p[0-9]+)' | head -n1

– alecxs
Mar 8 '18 at 19:56





grep loop0p1 from output is not always working, this is more exactly... replace: grep loop | cut -f3 -d" " with: grep -owE '(loop[0-9]+p[0-9]+)' | head -n1

– alecxs
Mar 8 '18 at 19:56


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f412028%2fbooting-an-ext4-image-file-from-grub2%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...

Tribunal Administrativo e Fiscal de Mirandela Referências Menu de...

looking for continuous Screen Capture for retroactivly reproducing errors, timeback machineRolling desktop...