How to run mkfs on file image partitions without mounting?
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I am creating an empty file...
dd if=/dev/zero of=$SDCARD bs=1 count=0 seek=$(expr 1024 * $SDCARD_SIZE)
...then turning it into an drive image...
parted -s $SDCARD mklabel msdos
...and creating partitions on it
parted -s $SDCARD unit KiB mkpart primary fat32 $IMAGE_ROOTFS_ALIGNMENT $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED)
parted -s $SDCARD unit KiB mkpart primary $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED) $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED + $ROOTFS_SIZE)
How do I use mkfs.ext
and mkfs.vfat
without mounting this image?
linux parted mkfs
add a comment |Â
up vote
5
down vote
favorite
I am creating an empty file...
dd if=/dev/zero of=$SDCARD bs=1 count=0 seek=$(expr 1024 * $SDCARD_SIZE)
...then turning it into an drive image...
parted -s $SDCARD mklabel msdos
...and creating partitions on it
parted -s $SDCARD unit KiB mkpart primary fat32 $IMAGE_ROOTFS_ALIGNMENT $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED)
parted -s $SDCARD unit KiB mkpart primary $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED) $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED + $ROOTFS_SIZE)
How do I use mkfs.ext
and mkfs.vfat
without mounting this image?
linux parted mkfs
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I am creating an empty file...
dd if=/dev/zero of=$SDCARD bs=1 count=0 seek=$(expr 1024 * $SDCARD_SIZE)
...then turning it into an drive image...
parted -s $SDCARD mklabel msdos
...and creating partitions on it
parted -s $SDCARD unit KiB mkpart primary fat32 $IMAGE_ROOTFS_ALIGNMENT $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED)
parted -s $SDCARD unit KiB mkpart primary $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED) $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED + $ROOTFS_SIZE)
How do I use mkfs.ext
and mkfs.vfat
without mounting this image?
linux parted mkfs
I am creating an empty file...
dd if=/dev/zero of=$SDCARD bs=1 count=0 seek=$(expr 1024 * $SDCARD_SIZE)
...then turning it into an drive image...
parted -s $SDCARD mklabel msdos
...and creating partitions on it
parted -s $SDCARD unit KiB mkpart primary fat32 $IMAGE_ROOTFS_ALIGNMENT $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED)
parted -s $SDCARD unit KiB mkpart primary $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED) $(expr $IMAGE_ROOTFS_ALIGNMENT + $BOOT_SPACE_ALIGNED + $ROOTFS_SIZE)
How do I use mkfs.ext
and mkfs.vfat
without mounting this image?
linux parted mkfs
linux parted mkfs
edited 11 mins ago
Ciro Santilli æ°çÂÂæ¹é ä¸Âå¿ å ÂÃ¥ÂÂäºÂ件 æ³Âè½®åÂÂ
4,46123938
4,46123938
asked May 6 '16 at 18:51
Paul Knopf
241310
241310
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
You want to format a partition in a disk-image file, rather than the entire image file. In that case, you need to use losetup
to tell linux to use the image file as a loopback device.
NOTE: losetup
requires root privileges, so must be run as root or with sudo. The /dev/loop*
devices it uses/creates also require root privs to access and use.
e.g (as root)
# losetup /dev/loop0 ./sdcard.img
# fdisk -l /dev/loop0
Disk /dev/loop0: 1 MiB, 1048576 bytes, 2048 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: 0x54c246ab
Device Boot Start End Sectors Size Id Type
/dev/loop0p1 1 1023 1023 511.5K c W95 FAT32 (LBA)
/dev/loop0p2 1024 2047 1024 512K 83 Linux
# file -s /dev/loop0p1
/dev/loop0p1: data
# mkfs.vfat /dev/loop0p1
mkfs.fat 3.0.28 (2015-05-16)
Loop device does not match a floppy size, using default hd params
# file -s /dev/loop0p1
/dev/loop0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, root entries 512, sectors 1023 (volumes <=32 MB) , Media descriptor 0xf8, sectors/FAT 1, sectors/track 32, heads 64, serial number 0xfa9e3726, unlabeled, FAT (12 bit)
and, finally, detach the image from the loopback device:
# losetup -d /dev/loop0
See man losetup
for more details.
add a comment |Â
up vote
4
down vote
To create an image with multiple partitions, a solution that doesn't require any fancy tools or root access is to first create the filesystems, then concatenate them.
truncate -s $IMAGE_ROOTFS_ALIGNMENT disk
truncate -s $BOOT_SPACE_ALIGNED part1
mkfs.fat part1
cat part1 >>disk
truncate -s $ROOTFS_SIZE part2
mkfs.ext4 part2
cat part2 >>disk
Then run parted
or fdisk
to create the partitions.
This approach has the downside that the resulting image won't be sparse.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
You want to format a partition in a disk-image file, rather than the entire image file. In that case, you need to use losetup
to tell linux to use the image file as a loopback device.
NOTE: losetup
requires root privileges, so must be run as root or with sudo. The /dev/loop*
devices it uses/creates also require root privs to access and use.
e.g (as root)
# losetup /dev/loop0 ./sdcard.img
# fdisk -l /dev/loop0
Disk /dev/loop0: 1 MiB, 1048576 bytes, 2048 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: 0x54c246ab
Device Boot Start End Sectors Size Id Type
/dev/loop0p1 1 1023 1023 511.5K c W95 FAT32 (LBA)
/dev/loop0p2 1024 2047 1024 512K 83 Linux
# file -s /dev/loop0p1
/dev/loop0p1: data
# mkfs.vfat /dev/loop0p1
mkfs.fat 3.0.28 (2015-05-16)
Loop device does not match a floppy size, using default hd params
# file -s /dev/loop0p1
/dev/loop0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, root entries 512, sectors 1023 (volumes <=32 MB) , Media descriptor 0xf8, sectors/FAT 1, sectors/track 32, heads 64, serial number 0xfa9e3726, unlabeled, FAT (12 bit)
and, finally, detach the image from the loopback device:
# losetup -d /dev/loop0
See man losetup
for more details.
add a comment |Â
up vote
4
down vote
accepted
You want to format a partition in a disk-image file, rather than the entire image file. In that case, you need to use losetup
to tell linux to use the image file as a loopback device.
NOTE: losetup
requires root privileges, so must be run as root or with sudo. The /dev/loop*
devices it uses/creates also require root privs to access and use.
e.g (as root)
# losetup /dev/loop0 ./sdcard.img
# fdisk -l /dev/loop0
Disk /dev/loop0: 1 MiB, 1048576 bytes, 2048 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: 0x54c246ab
Device Boot Start End Sectors Size Id Type
/dev/loop0p1 1 1023 1023 511.5K c W95 FAT32 (LBA)
/dev/loop0p2 1024 2047 1024 512K 83 Linux
# file -s /dev/loop0p1
/dev/loop0p1: data
# mkfs.vfat /dev/loop0p1
mkfs.fat 3.0.28 (2015-05-16)
Loop device does not match a floppy size, using default hd params
# file -s /dev/loop0p1
/dev/loop0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, root entries 512, sectors 1023 (volumes <=32 MB) , Media descriptor 0xf8, sectors/FAT 1, sectors/track 32, heads 64, serial number 0xfa9e3726, unlabeled, FAT (12 bit)
and, finally, detach the image from the loopback device:
# losetup -d /dev/loop0
See man losetup
for more details.
add a comment |Â
up vote
4
down vote
accepted
up vote
4
down vote
accepted
You want to format a partition in a disk-image file, rather than the entire image file. In that case, you need to use losetup
to tell linux to use the image file as a loopback device.
NOTE: losetup
requires root privileges, so must be run as root or with sudo. The /dev/loop*
devices it uses/creates also require root privs to access and use.
e.g (as root)
# losetup /dev/loop0 ./sdcard.img
# fdisk -l /dev/loop0
Disk /dev/loop0: 1 MiB, 1048576 bytes, 2048 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: 0x54c246ab
Device Boot Start End Sectors Size Id Type
/dev/loop0p1 1 1023 1023 511.5K c W95 FAT32 (LBA)
/dev/loop0p2 1024 2047 1024 512K 83 Linux
# file -s /dev/loop0p1
/dev/loop0p1: data
# mkfs.vfat /dev/loop0p1
mkfs.fat 3.0.28 (2015-05-16)
Loop device does not match a floppy size, using default hd params
# file -s /dev/loop0p1
/dev/loop0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, root entries 512, sectors 1023 (volumes <=32 MB) , Media descriptor 0xf8, sectors/FAT 1, sectors/track 32, heads 64, serial number 0xfa9e3726, unlabeled, FAT (12 bit)
and, finally, detach the image from the loopback device:
# losetup -d /dev/loop0
See man losetup
for more details.
You want to format a partition in a disk-image file, rather than the entire image file. In that case, you need to use losetup
to tell linux to use the image file as a loopback device.
NOTE: losetup
requires root privileges, so must be run as root or with sudo. The /dev/loop*
devices it uses/creates also require root privs to access and use.
e.g (as root)
# losetup /dev/loop0 ./sdcard.img
# fdisk -l /dev/loop0
Disk /dev/loop0: 1 MiB, 1048576 bytes, 2048 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: 0x54c246ab
Device Boot Start End Sectors Size Id Type
/dev/loop0p1 1 1023 1023 511.5K c W95 FAT32 (LBA)
/dev/loop0p2 1024 2047 1024 512K 83 Linux
# file -s /dev/loop0p1
/dev/loop0p1: data
# mkfs.vfat /dev/loop0p1
mkfs.fat 3.0.28 (2015-05-16)
Loop device does not match a floppy size, using default hd params
# file -s /dev/loop0p1
/dev/loop0p1: DOS/MBR boot sector, code offset 0x3c+2, OEM-ID "mkfs.fat", sectors/cluster 4, root entries 512, sectors 1023 (volumes <=32 MB) , Media descriptor 0xf8, sectors/FAT 1, sectors/track 32, heads 64, serial number 0xfa9e3726, unlabeled, FAT (12 bit)
and, finally, detach the image from the loopback device:
# losetup -d /dev/loop0
See man losetup
for more details.
edited May 7 '16 at 2:31
answered May 7 '16 at 2:23
cas
38k44495
38k44495
add a comment |Â
add a comment |Â
up vote
4
down vote
To create an image with multiple partitions, a solution that doesn't require any fancy tools or root access is to first create the filesystems, then concatenate them.
truncate -s $IMAGE_ROOTFS_ALIGNMENT disk
truncate -s $BOOT_SPACE_ALIGNED part1
mkfs.fat part1
cat part1 >>disk
truncate -s $ROOTFS_SIZE part2
mkfs.ext4 part2
cat part2 >>disk
Then run parted
or fdisk
to create the partitions.
This approach has the downside that the resulting image won't be sparse.
add a comment |Â
up vote
4
down vote
To create an image with multiple partitions, a solution that doesn't require any fancy tools or root access is to first create the filesystems, then concatenate them.
truncate -s $IMAGE_ROOTFS_ALIGNMENT disk
truncate -s $BOOT_SPACE_ALIGNED part1
mkfs.fat part1
cat part1 >>disk
truncate -s $ROOTFS_SIZE part2
mkfs.ext4 part2
cat part2 >>disk
Then run parted
or fdisk
to create the partitions.
This approach has the downside that the resulting image won't be sparse.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
To create an image with multiple partitions, a solution that doesn't require any fancy tools or root access is to first create the filesystems, then concatenate them.
truncate -s $IMAGE_ROOTFS_ALIGNMENT disk
truncate -s $BOOT_SPACE_ALIGNED part1
mkfs.fat part1
cat part1 >>disk
truncate -s $ROOTFS_SIZE part2
mkfs.ext4 part2
cat part2 >>disk
Then run parted
or fdisk
to create the partitions.
This approach has the downside that the resulting image won't be sparse.
To create an image with multiple partitions, a solution that doesn't require any fancy tools or root access is to first create the filesystems, then concatenate them.
truncate -s $IMAGE_ROOTFS_ALIGNMENT disk
truncate -s $BOOT_SPACE_ALIGNED part1
mkfs.fat part1
cat part1 >>disk
truncate -s $ROOTFS_SIZE part2
mkfs.ext4 part2
cat part2 >>disk
Then run parted
or fdisk
to create the partitions.
This approach has the downside that the resulting image won't be sparse.
answered May 7 '16 at 19:16
Gilles
514k12110231550
514k12110231550
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f281589%2fhow-to-run-mkfs-on-file-image-partitions-without-mounting%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password