mkfs.xfs /dev/mapper/lvname pwrite failed: Input/output error

Hi everybody,

I am using a luks file under /dev/mapper/luksfile
When I use the mkfs.xfs /dev/mapper/luksfile command, I get an error about pwrite failed: Input/output error
I found some possible solutions online, but nothing seems to work.

Does anyone know what may be causing this problem?

Thank you for any guidance or reference.


It might help if you gave us more information.

Tell us what you did. You probably started with a “cryptsetup” command. Tell us everything you did from that point (no need to tell us the password).

Best would be to start over (reboot), and then give the actual commands and output.

Hi, let me share the steps

I had a disk not partitioned so I did

cfdisk /dev/nvme1
I used gpt then defined two partitions
One with 128G
One with 256G
Both as Linux Filesystems

Next step I created the luks partitions
touch image01.img
touch image02.img
truncate -s 128G image01.img
truncate -s 256G image02.img

I formatted using cryptsetup as (I am going to use only one image from this point)
cryptsetup luksFormat image01.img (provided the passphrase)

cryptsetup luksOpen image01.img image01

dd if=/dev/zero of=/dev/mapper/image01 bs=512M status=progress

After dd was completed, I ran
mkfs.xfs /dev/mapper/image01

Here is where I get the error

meta-data=/dev/mapper/sysfile    isize=512    agcount=4, agsize=8388480 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=0, rmapbt=0
         =                       reflink=0
data     =                       bsize=4096   blocks=33553920, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=16383, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
mkfs.xfs: pwrite failed: Input/output error

I see the permission for the img file is set as rw-r–r–, would that be a problem?

Thank you


Please always show the copy/paste of the complete command and output. Do not tell things like: The command xxxxx gives, because that command should be within the CODE tags. you show that it is all complete and unabridged by including the new prompt line at the end.

Do not

The uname -a command gives

Linux boven 5.3.18-lp152.84-default #1 SMP Tue Jul 20 23:04:11 UTC 2021 (baaeecf) x86_64 x86_64 x86_64 GNU/Linux

but show

henk@boven:~> uname -a
Linux boven 5.3.18-lp152.84-default #1 SMP Tue Jul 20 23:04:11 UTC 2021 (baaeecf) x86_64 x86_64 x86_64 GNU/Linux

Less (miss)typing. Less change for misunderstandings. More information. Much more trustworthy.

Same for: I see the permissions …
We want to see by e.g. an ls -l.

Hello all,

I found the issue. I defined the luk images under a partition with not enough space when I was supposed to use a different disk and partition.
I deleted the old ones and started all commands at the correct location.

Everything is working now and the luk partition was formatted correctly!