I created a new partition that I would like to encrypt with LUKS. The device is a 1GB partition with ID 83 (Linux). I've changed the owner to root, and chmod to 777. The command I'm using is :

cryptsetup luksFormat /dev/sda2p2

When prompted, I reply the capital YES, then receive this error:

cannot open device /dev/sda2p2 for read-only access

I know this should be simple, but I can't get it to work. Any help would be greatly appreciated.

(currently using CentOS 6)

In response to comment re: parted print

enter image description here

ls -l /dev/sd*:

enter image description here

  • Where is this /dev/sda2p2 coming from? This does not look like a common Linux partition. Can you show the output for # parted /dev/sda print?
    – Spack
    Commented Feb 23, 2015 at 15:10
  • The /dev/sda2p2 partition was created using fdisk.
    – natep
    Commented Feb 23, 2015 at 15:28
  • Can you also do a ls -l /dev/sd*?
    – Spack
    Commented Feb 23, 2015 at 15:35
  • 1
    According to the /dev output, looks like you've done something to generate a file /dev/sda2p2, according to your patition scheme you should only have /dev/sda1 /dev/sda2 and /dev/sda3. One of those is the partition you want to encrypt (sda1 or sda2) and probably sda3 too.
    – YoMismo
    Commented Feb 23, 2015 at 15:47
  • 1
    How did you manage to create that file (/dev/sda2p2)? it shouldn't exist. Creating partitions will create block devices brw-rw---- not files which is what you have. Find why is that file created and act accordingly, if you finally find it its not necessary erase it and format the partition you need to encrypt (which is not sda2p2).
    – YoMismo
    Commented Feb 23, 2015 at 16:06

1 Answer 1


Whatever you did to create /dev/sda2p2, it didn't do what you intended. You created a regular file in memory. In Linux's disk and partition naming convention, /dev/sda is a disk, /dev/sda2 is a partition on that disk.

From the parted output, you currently have three partitions on that disk: a ~300MB partitionwhich is presumably /boot, a partition using most of the disk space which is presumably the system partition, and a swap partition. The sum of their sizes is equal to the disk size (within the tolerance of the reported approximations), so there is no more space to create other partitions. If you want to create a new partition, you'll need to make room by shrinking one of the existing partitions.

Note that with msdos partitions, you can only have 4 primary partitions, or 3 primary partitions plus 1 extended partition that can contain any number of logical partitions. If you want to create more partitions, you may want to switch to LVM which is a lot more flexible.

Once you've created a partition, run cryptsetup luksFormat to set up an encrypted volume on it. This volume will be refered to by a name like /dev/mapper/sda5_crypt. Then, if you want to create a single encrypted filesystem, create a filesystem on the encrypted volume. If you want to partition the encrypted space between multiple filesystems and maybe swap, then make the encrypted volume an LVM physical volume, create a volume group containing this PV, and create as many logical volumes as you like on the VG.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .