As identified by richard, the filesystem starts on the very first sector of the disk: you have no partitions. To create an encrypted partition, you will need to create a partition table first. And you do need to have two partitions if you want to have an encrypted partition, because you need some non-encrypted space for the bootloader.
You can create a partition table without losing your data. It's a delicate task, so double-check that your backups are up-to-date, but it can be done.
The ext4 filesystem leaves the first 512 bytes unused, and an MBR partition table fits within the first 512 bytes of the disk, so you have room for an MBR partition table. (Note that it has to be MBR, not GPT.)
First, boot some rescue media. Do not attempt to do any of this while the filesystem is mounted. SystemRescueCd is good for this kind of things.
If more than half the disk space is free, then you can create a partition in the second half of the disk as follows:
- Determine the path to the disk device. Note that a rescue system might name the disks differently from your normal system. Here I'll assume that the path is
/dev/sda
.
resize2fs /dev/sda
to shrink the filesystem about as much as it'll go. You can see how much space is free with tune2fs -l /dev/sda
.
- Run
fdisk /dev/sda
. Fdisk will create a “dos disklabel”, i.e. an MBR partition table, in memory. Enter n
and create a new primary partition that starts after the end of the filesystem. Enter w
to write the new partition table and exit fdisk.
- Copy the filesystem to the new partition with
head -c SIZE /dev/sda1
where SIZE
is the size of the filesystem after shrinking.
- Verify that the data new partition is safe.
- You can now create partitions to span the first half of the disk, where the old copy of the filesystem is located.
If more than half the disk is in use then you're in for quite some pain. I think you can do it by first converting the data to an LVM volume with blocks, then shrinking the filesystem, the logical volume and the physical volume, and using gparted to move the start of the physical volume. But I've never done anything like this, so triple-check your backups.
sudo file -kLs /dev/sda
?/dev/sda: Linux rev 1.0 ext4 filesystem data, UUID=4a48b072-5b30-49f4-b4a7-f8b4ad4e5a37 (needs journal recovery) (extents) (large files) (huge files)\012- data
@richard (edit: fixed formatting)sudo file -kLs /dev/sda
shows a file-system andsda
is the raw device, therefore you do not have a partition-table on this device. Note also please ignoreneeds journal recovery
, they usually say that when mounted.