Last active
March 17, 2025 23:10
-
-
Save Dids/c6fa12602ae812e873db539f71c52a3a to your computer and use it in GitHub Desktop.
Revisions
-
Dids revised this gist
Jan 29, 2025 . 1 changed file with 18 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,20 +18,20 @@ dd if=/dev/zero of=image.img iflag=fullblock bs=1M count=100 && sync ##### Mount the image ```sh # Mount the image on the first available loop device losetup -f image.img # List currently mounted loop devices # (this is just to confirm it was mounted) losetup ``` ##### Create the EFI partition on the image ```sh # Get the loop device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'` # Partition the loop device # (enter the commands/characters and press enter) gdisk $LOOP_DEV_PATH o @@ -42,17 +42,17 @@ n w y # Trigger partition discovery for the newly partitioned loop device partprobe $LOOP_DEV_PATH # List the partitions of the loop device # (this is only for confirming that the partitions are visible) ls $LOOP_DEV_PATH* ``` ##### Format the EFI partition ```sh # Get the loop device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'`p1 # Format the EFI partition as FAT32 @@ -61,7 +61,7 @@ mkfs.fat -F32 $LOOP_DEV_PATH ##### Mount the EFI partition ```sh # Get the loop device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'`p1 # Make sure the target mounting directory exists @@ -74,7 +74,7 @@ mount $LOOP_DEV_PATH /mnt/image ##### Working with files on the EFI partition At this point you should be able to freely create, edit and remove files mounted under the `/mnt/image` path. Once you're done, simply continue to the next step, where we will safely and cleanly unmount the partition and image/loop device. ##### Unmount the EFI partition ```sh @@ -86,12 +86,12 @@ umount /mnt/image rm -rf /mnt/image ``` ##### Unmount the image/loop device ```sh # Get the loop device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'` # Unmount the loop device losetup -d $LOOP_DEV_PATH # Verify that the image is no longer mounted @@ -104,12 +104,12 @@ This section assumes that you no longer have the image mounted in any way. It al ##### Mount the image ```sh # Mount the image as a loop device first # -f searches for the next free loop device (no need to manually select one) # -P triggers a scan for any available partitions in the image losetup -f -P image.img # Get the loop device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'`p1 # Mount the EFI partition to a local path (create path first if necessary) @@ -125,7 +125,7 @@ ls -lah /mnt/image ##### Working with files on the image At this point you should be able to freely create, edit and remove files mounted under the `/mnt/image` path. Once you're done, simply continue to the next step, where we will safely and cleanly unmount the partition and image/loop device. ##### Unmount the image ```sh @@ -136,9 +136,9 @@ umount /mnt/image # DISCLAIMER: Be careful with this, as you could potentially lose data if unmounting was unsuccessful etc. rm -rf /mnt/image # Get the loop device path LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'` # Remove the loop device losetup -d $LOOP_DEV_PATH ``` -
Dids revised this gist
Jul 15, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -71,7 +71,7 @@ mkdir -p /mnt/image mount $LOOP_DEV_PATH /mnt/image ``` ##### Working with files on the EFI partition At this point you should be able to freely create, edit and remove files mounted under the `/mnt/image` path. Once you're done, simply continue to the next step, where we will safely and cleanly unmount the partition and image/loopback device. -
Dids revised this gist
Jul 15, 2021 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -73,6 +73,9 @@ mount $LOOP_DEV_PATH /mnt/image ##### Copy files to /mnt/image etc. At this point you should be able to freely create, edit and remove files mounted under the `/mnt/image` path. Once you're done, simply continue to the next step, where we will safely and cleanly unmount the partition and image/loopback device. ##### Unmount the EFI partition ```sh # Unmount the EFI partition -
Dids revised this gist
Jul 15, 2021 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,8 @@ For example, you might use it as temporary or even portable storage, mountable a **DISCLAIMER:** Be _very_ careful with the commands listed below, as you could potentially not only cause data loss, but even prevent your operating system from booting, no matter how unlikely either of those may be. Pay attention to the commands, comments and differences between the guide and your local environment. --- ### Creating the disk image ##### Create a blank disk image @@ -115,6 +117,8 @@ mount $LOOP_DEV_PATH /mnt/image ls -lah /mnt/image ``` --- ##### Working with files on the image At this point you should be able to freely create, edit and remove files mounted under the `/mnt/image` path. -
Dids revised this gist
Jul 15, 2021 . 1 changed file with 15 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ For example, you might use it as temporary or even portable storage, mountable a **DISCLAIMER:** Be _very_ careful with the commands listed below, as you could potentially not only cause data loss, but even prevent your operating system from booting, no matter how unlikely either of those may be. Pay attention to the commands, comments and differences between the guide and your local environment. ### Creating the disk image ##### Create a blank disk image ```sh @@ -24,7 +24,7 @@ losetup -f image.img losetup ``` ##### Create the EFI partition on the image ```sh # Get the loopback device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'` @@ -48,7 +48,7 @@ partprobe $LOOP_DEV_PATH ls $LOOP_DEV_PATH* ``` ##### Format the EFI partition ```sh # Get the loopback device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'`p1 @@ -57,7 +57,7 @@ LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'`p1 mkfs.fat -F32 $LOOP_DEV_PATH ``` ##### Mount the EFI partition ```sh # Get the loopback device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'`p1 @@ -69,9 +69,9 @@ mkdir -p /mnt/image mount $LOOP_DEV_PATH /mnt/image ``` ##### Copy files to /mnt/image etc. ##### Unmount the EFI partition ```sh # Unmount the EFI partition umount /mnt/image @@ -81,7 +81,7 @@ umount /mnt/image rm -rf /mnt/image ``` ##### Unmount the image/loopback device ```sh # Get the loopback device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'` @@ -93,11 +93,11 @@ losetup -d $LOOP_DEV_PATH losetup -l ``` ### Working with the disk image This section assumes that you no longer have the image mounted in any way. It also assumes your image is properly formatted and you're familiar with its partition layout. ##### Mount the image ```sh # Mount the image as a loopback device first # -f searches for the next free loop device (no need to manually select one) @@ -115,7 +115,12 @@ mount $LOOP_DEV_PATH /mnt/image ls -lah /mnt/image ``` ##### Working with files on the image At this point you should be able to freely create, edit and remove files mounted under the `/mnt/image` path. Once you're done, simply continue to the next step, where we will safely and cleanly unmount the partition and image/loopback device. ##### Unmount the image ```sh # Unmount the EFI partition umount /mnt/image -
Dids revised this gist
Jul 15, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ For example, you might use it as temporary or even portable storage, mountable a ## Creating the disk image ##### Create a blank disk image ```sh dd if=/dev/zero of=image.img iflag=fullblock bs=1M count=100 && sync ``` -
Dids revised this gist
Jul 15, 2021 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,12 +9,12 @@ For example, you might use it as temporary or even portable storage, mountable a ## Creating the disk image #### Create a blank disk image ```sh dd if=/dev/zero of=image.img iflag=fullblock bs=1M count=100 && sync ``` ##### Mount the image ```sh # Mount the image on the first available loopback device losetup -f image.img -
Dids revised this gist
Jul 15, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,8 @@ I originally wanted to create bootable disks for UEFI (i)PXE booting, meaning I While this guide serves my purpose well, it's also generic enough to be extended to almost any use case. For example, you might use it as temporary or even portable storage, mountable across different operating systems, or you might use it as a disk image for a virtual machine. **DISCLAIMER:** Be _very_ careful with the commands listed below, as you could potentially not only cause data loss, but even prevent your operating system from booting, no matter how unlikely either of those may be. Pay attention to the commands, comments and differences between the guide and your local environment. ## Creating the disk image ### Create a blank disk image -
Dids revised this gist
Jul 15, 2021 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,11 @@ # What is the purpose of this guide? I originally wanted to create bootable disks for UEFI (i)PXE booting, meaning I could directly boot premade disk images over the network, no matter what they may contain. While this guide serves my purpose well, it's also generic enough to be extended to almost any use case. For example, you might use it as temporary or even portable storage, mountable across different operating systems, or you might use it as a disk image for a virtual machine. ## Creating the disk image ### Create a blank disk image ```sh @@ -84,7 +91,7 @@ losetup -d $LOOP_DEV_PATH losetup -l ``` ## Working with the disk image This section assumes that you no longer have the image mounted in any way. It also assumes your image is properly formatted and you're familiar with its partition layout. -
Dids revised this gist
Jul 15, 2021 . 1 changed file with 52 additions and 19 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,56 +6,87 @@ dd if=/dev/zero of=image.img iflag=fullblock bs=1M count=100 && sync ``` ### Mount the image ```sh # Mount the image on the first available loopback device losetup -f image.img # List currently mounted loopback devices # (this is just to confirm it was mounted) losetup ``` ### Create the EFI partition on the image ```sh # Get the loopback device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'` # Partition the loopback device # (enter the commands/characters and press enter) gdisk $LOOP_DEV_PATH o y n # <keep clicking enter until it asks for a hex code> 0xEF00 w y # Trigger partition discovery for the newly partitioned loopback device partprobe $LOOP_DEV_PATH # List the partitions of the loopback device # (this is only for confirming that the partitions are visible) ls $LOOP_DEV_PATH* ``` ### Format the EFI partition ```sh # Get the loopback device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'`p1 # Format the EFI partition as FAT32 mkfs.fat -F32 $LOOP_DEV_PATH ``` ### Mount the EFI partition ```sh # Get the loopback device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'`p1 # Make sure the target mounting directory exists mkdir -p /mnt/image # Mount the EFI partition to a local path mount $LOOP_DEV_PATH /mnt/image ``` ### Copy files to /mnt/image etc. ### Unmount the EFI partition ```sh # Unmount the EFI partition umount /mnt/image # Remove the mount point # DISCLAIMER: Be careful with this, as you could potentially lose data if unmounting was unsuccessful etc. rm -rf /mnt/image ``` ### Unmount the image/loopback device ```sh # Get the loopback device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'` # Unmount the loopback device losetup -d $LOOP_DEV_PATH # Verify that the image is no longer mounted losetup -l ``` # Working with the disk image This section assumes that you no longer have the image mounted in any way. It also assumes your image is properly formatted and you're familiar with its partition layout. ### Mount the image ```sh @@ -70,20 +101,22 @@ LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'`p1 # Mount the EFI partition to a local path (create path first if necessary) mkdir -p /mnt/image mount $LOOP_DEV_PATH /mnt/image # List the image contents to verify that it is mounted correctly ls -lah /mnt/image ``` ### Unmount the image ```sh # Unmount the EFI partition umount /mnt/image # Remove the mount point # DISCLAIMER: Be careful with this, as you could potentially lose data if unmounting was unsuccessful etc. rm -rf /mnt/image # Get the loopback device path LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'` # Remove the loopback device losetup -d $LOOP_DEV_PATH -
Dids revised this gist
Jul 15, 2021 . 1 changed file with 40 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # Creating the disk image ### Create a blank disk image ```sh dd if=/dev/zero of=image.img iflag=fullblock bs=1M count=100 && sync @@ -7,6 +9,7 @@ dd if=/dev/zero of=image.img iflag=fullblock bs=1M count=100 && sync (losetup will list all used loopback devices) (losetup loop4 will mount it on the next available loopback devices, eg n+1) ```sh # NOTE: For experienced users, you can use "losetup -f image.img" to automatically use the next available loop device losetup losetup loop4 image.img losetup @@ -48,4 +51,40 @@ umount /mnt/image ```sh losetup -d /dev/loop4 losetup ``` # Working with the disk image This section assumes that you no longer have the image mounted in any way. ### Mount the image ```sh # Mount the image as a loopback device first # -f searches for the next free loop device (no need to manually select one) # -P triggers a scan for any available partitions in the image losetup -f -P image.img # Get the loopback device for the mounted image LOOP_DEV_PATH=`losetup -a | grep image.img | awk -F: '{print $1;}'`p1 # Mount the EFI partition to a local path (create path first if necessary) mkdir -p /mnt/image mount $LOOP_DEV_PATH /mnt/image ls -lah /mnt/image ``` ### Unmount the image ```sh # Unmount the EFI partition umount /mnt/opencore # Remove the mount point # DISCLAIMER: Be careful with this, as you could potentially lose data if unmounting was unsuccessful etc. rm -rf /mnt/opencore # Get the loopback device path LOOP_DEV_PATH=`losetup -a | grep opencore.img | awk -F: '{print $1;}'` # Remove the loopback device losetup -d $LOOP_DEV_PATH ``` -
Dids revised this gist
Jul 14, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,7 @@ ### Create a blank disk image ```sh dd if=/dev/zero of=image.img iflag=fullblock bs=1M count=100 && sync ``` ### Mount the image (losetup will list all used loopback devices) -
Dids revised this gist
Jul 14, 2021 . 1 changed file with 22 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,17 @@ ### Create a blank disk image dd if=/dev/zero of=image.img iflag=fullblock bs=1M count=100 && sync ### Mount the image (losetup will list all used loopback devices) (losetup loop4 will mount it on the next available loopback devices, eg n+1) ```sh losetup losetup loop4 image.img losetup ``` ### Create the EFI partition on the image ```sh gdisk /dev/loop4 o y @@ -19,19 +22,28 @@ w y partprobe /dev/loop4 ls /dev/loop4* ``` ### Format the EFI partition ```sh mkfs.fat -F32 /dev/loop4p1 ``` ### Mount the EFI partition ```sh mkdir /mnt/image mount /dev/loop4p1 /mnt/image ``` ### Copy files to /mnt/image etc. ### Unmount the EFI partition ```sh umount /mnt/image ``` ### Unmount the image ```sh losetup -d /dev/loop4 losetup ``` -
Dids created this gist
Jul 14, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ # Create a blank disk image dd if=/dev/zero of=image.img iflag=fullblock bs=1M count=100 && sync # Mount the image # (losetup will list all used loopback devices) # (losetup loop4 will mount it on the next available loopback devices, eg n+1) losetup losetup loop4 image.img losetup # Create the EFI partition on the image gdisk /dev/loop4 o y n <enter until hex code> 0xEF00 w y partprobe /dev/loop4 ls /dev/loop4* # Format the EFI partition mkfs.fat -F32 /dev/loop4p1 # Mount the EFI partition mkdir /mnt/image mount /dev/loop4p1 /mnt/image # Copy files to /mnt/image etc. # Unmount the EFI partition umount /mnt/image # Unmount the image losetup -d /dev/loop4 losetup