The officially official Devuan Forum!

You are not logged in.

#1 2018-10-02 02:57:05

0xf4b10
Member
Registered: 2018-05-12
Posts: 30  

mkfs.ext4: invalid blocks offset=X on device device.img

My goal is to create a regular file and within it make a partition and file systems (literally a virtual hard drive) and finally mount it, so I did:

sudo dd if=/dev/zero of=imagem-zero.img count=20480000

To create the file with aprox 20Gb. Then I've partitioned with cfdisk, after that the status of the file was:

$ gdisk -l imagem-zero.img
GPT fdisk (gdisk) version 1.0.1

Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present

Found valid GPT with protective MBR; using GPT.
Disk imagem-zero.img: 40960000 sectors, 19.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 544A9633-7FA3-4BE8-BEE7-612C151A4504
Partition table holds up to 128 entries
First usable sector is 2048, last usable sector is 40959966
Partitions will be aligned on 2048-sector boundaries
Total free space is 0 sectors (0 bytes)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        16779263   8.0 GiB     8304 
   2        16779264        40959966   11.5 GiB    8302


Now I want to make the file system ext4 in both these two sectors but I'm failing with the error message in the title of the question:

$ sudo mkfs.ext4 imagem-zero.img offset=$((2048*512))

mke2fs 1.43.4 (31-Jan-2017)
mkfs.ext4: invalid blocks 'offset=1048576' on device 'imagem-zero.img'

$ sudo mkfs.ext4 imagem-zero.img offset=$((2048))

mke2fs 1.43.4 (31-Jan-2017)
mkfs.ext4: invalid blocks 'offset=2048' on device 'imagem-zero.img'

My question is, how to find the correct offset to make the FS on both of the partitions? Thanks in advance.
Suggestions on how to reach my goal are also welcome smile

Offline

#2 2018-10-02 12:26:11

fsmithred
Administrator
Registered: 2016-11-25
Posts: 928  

Re: mkfs.ext4: invalid blocks offset=X on device device.img

What you tried looks right to me, but the man page for mke2fs doesn't actually say what units to use for offset. Further down the page where it talks about specifying the location of the journal, the wording suggests that you might need to use 'offset=1M'.

One thing you did looks odd - why partition with cfdisk if you want gpt? gdisk is the right tool for that.

Offline

#3 2018-10-02 21:44:04

Plentyn
Member
Registered: 2017-07-14
Posts: 10  

Re: mkfs.ext4: invalid blocks offset=X on device device.img

What about:

loopdev=$(losetup -P -f --show imagem-zero.img)
mkfs.ext4 ${loopdev}p1
losetup -d $loopdev

(Or something along these lines)

Offline

#4 2018-10-04 01:20:15

0xf4b10
Member
Registered: 2018-05-12
Posts: 30  

Re: mkfs.ext4: invalid blocks offset=X on device device.img

fsmithred wrote:

What you tried looks right to me, but the man page for mke2fs doesn't actually say what units to use for offset. Further down the page where it talks about specifying the location of the journal, the wording suggests that you might need to use 'offset=1M'.

One thing you did looks odd - why partition with cfdisk if you want gpt? gdisk is the right tool for that.

Well, it happens that I was just forgetting to pass a -E flag to the mkfs command. After that, it was possible to create the filesystems

Plentyn wrote:

What about:

loopdev=$(losetup -P -f --show imagem-zero.img)
mkfs.ext4 ${loopdev}p1
losetup -d $loopdev

(Or something along these lines)

Nice, losetup did the trick easily

Offline

Board footer