date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,532,142,916,000 |
If I do an mv command from the command line in OneFS (Isilon, FreeBSD based), what exactly happens in the background and on the disks?
Will the data be physically moved from sectors to other sectors on the disks, or is it just a change to the links to those files in the files system? Does the data on the physical disk stay where they are? How are inodes involved here?
I am asking because I have a huge directory which contains over 50 TB of data, and it is shared on the network. I need to mv this directory under another directory within the same file system. I wanted to stop sharing and mv it and then share it again. I am not sure if this will be as simple as I thought.
Any inputs?
|
No, there are no copy of the whole file. Each file is described by a structure (on most UNIX file system, it is called an inode). This structure contains the informations about the file (length, date, where to find its blocks, right permission...), excepted the name.
The name of a file is in a directory which does the mapping between file names and inodes. If you move a file, you are just suppressing a mapping on a directory and create on other on a different directory.
Some filesystems may have some differences (on FAT file systems, the file informations are in the directory, but the system will transfer all the informations - a few bytes - from one directory to an other). But you have the whole scheme.
On typical UNIX filesystems, the file structure is separated from the directory, and this allow you to use multiple names (eventually from different directories) for a single file (using the ln command).
| What exactly happens in the OneFS (FreeBSD) files system if I move files from one directory to another? |
1,532,142,916,000 |
When I do a directory listing of a python installation the include directory appears twice and each one has a different inode.
╰─○ ls -i1
2282047 bin
2641630 include
2642559 include
2282048 lib
2641850 share
I assume that their contents may be different as the inodes are different.
Is there away to use the ls command to use the inode not the directory name so I can check them individually?
When I execute ls include I have no idea which directory is listed.
|
It is not possible to have directories or files with duplicate names in Unix and so there would be no reason for ls to have an option to handle that use case.
The reason you are seeing what appears to be duplicates is because one directory actually has a trailing space (inode 2642559).
BusyBox's ls, unlike GNU's ls, doesn't quote names of directories and files that have spaces so it can be easy to misinterpret them.
| How can you list a directory using the inode not the directory name? I have the same directory name appearing twice with different inodes |
1,532,142,916,000 |
we notices about some of our RHEL machines that inode information show 100%
the following for example show that /dev/sdb is 100%
df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sdc 2621440 231603 2389837 9% /data/sdc
/dev/sdd 2621440 2616856 4584 100% /data/sdd
/dev/sde 2621440 2613251 8189 100% /data/sde
/dev/sdb 2621440 2621440 0 100% /data/sdb
but from df -h /dev/sdb is only 65% used
/dev/sdb 40G 26G 14G 65% /data/sdb
what are the options that we have in order to decrease the used of /dev/sdb ?
|
As per the man page for mkfs.ext4:
Be warned that it is not possible to expand the number of inodes on a
filesystem after it is created, so be careful deciding the correct
value for this parameter.
You have a couple choices.
Reduce inodes in use (remove files or directories)
Back up the data and recreate the filesystem with more inodes. (See -i and -I options in man page)
Use XFS which has dynamic inode allocation, if you have a lot of small files.
| linux + list inode information show 100% used |
1,532,142,916,000 |
I'm studying the Ext4 filesystem and am confused by the 128 byte inode size because it appears to conflict with the last metatdata value it stores which is supposed to be offset at byte 156.
In this documentation it states that inodes are 128 bytes in length. I called dumpe2fs on an unmounted /dev/sdb1. The dumpe2fs result corroborates the inode size is 128.
But I'm confused because this documentation delineates the metadata stored in the inode. For each entry of metadata there is a corresponding physical offset. The last entry is the project id. It's offset is in 0x9c (which is 156 as an integer).
It appears the metadata offsets exceed the allocated size of the inode. What am I misunderstanding here?
|
it states that inodes are 128 bytes in length
No. It states that [emphasis mine]:
[…] each inode had a disk record size of 128 bytes. Starting with ext4, it is possible to allocate a larger on-disk inode at format time for all inodes in the filesystem to provide space beyond the end of the original ext2 inode. The on-disk inode record size is recorded in the superblock as s_inode_size. The number of bytes actually used by struct ext4_inode beyond the original 128-byte ext2 inode is recorded in the i_extra_isize field for each inode […] By default, ext4 inode records are 256 bytes, and (as of August 2019) the inode structure is 160 bytes (i_extra_isize = 32).
Your doubt:
The last entry is the project id. Its offset is in 0x9c (which is 156 as an integer). It appears the metadata offsets exceed the allocated size of the inode.
The last entry starts at 156 and takes 4 bytes (__le32). It's within the default 160 bytes.
If dumpe2fs says the inode size is 128 for your filesystem, this means the filesystem uses the original 128-byte ext2 inode. There is no i_extra_isize (it would be at the offset 0x80, decimal 128) or anything specified beyond.
| Why do inode offset values appear to exceed inode size? |
1,532,142,916,000 |
This page on inodes has been exceptional help in grasping the surface-level concept of file systems. On the same page, the author has inserted this snippet demonstrating that each file or directory has at least 2 names (and hard links):
/tmp/junk$ ls -id ..
327681 ..
/tmp/junk$ cd ..
/tmp$ ls -id .
327681 .
We can see that /tmp has 3 hard links:
Presumably, an inode for the filename “tmp”
The same inode for the name “..”
The same inode for the name “.”
My question: can the “junk” file in the /tmp directory also have 3 names (and hard links) if it is given a child directory? For example, /tmp/junk/paper_balls.
My hypothesis: If the “junk” file becomes a parent, it can be invoked with .. but relatively, meaning the current working directory (from which .. is typed) would have to be within the directory path /tmp/. The answer to my question is probably too advanced.
|
The initial number of hard links is 1 for a file and 2 for a directory (the first link is its name in the parent folder, and the second hard link is .). The link count for a directory goes up by one each time a subdirectory is created in it (due to .. in each subdirectory).
This count can be easily viewed with ls -l. It is the second value. Take a look:
~/x$ ls -la
total 16
drwxr-xr-x 2 tomasz tomasz 4096 Sep 24 00:08 .
drwxr-xr-x 54 tomasz tomasz 4096 Sep 24 00:11 ..
-rw-r--r-- 1 tomasz tomasz 19 Sep 23 18:45 1
-rw-r--r-- 1 tomasz tomasz 19 Sep 23 18:45 2
~/x$ mkdir d
~/x$ ls -la
total 20
drwxr-xr-x 3 tomasz tomasz 4096 Sep 24 00:11 .
drwxr-xr-x 54 tomasz tomasz 4096 Sep 24 00:11 ..
-rw-r--r-- 1 tomasz tomasz 19 Sep 23 18:45 1
-rw-r--r-- 1 tomasz tomasz 19 Sep 23 18:45 2
drwxr-xr-x 2 tomasz tomasz 4096 Sep 24 00:11 d
~/x$ mkdir d/dd
~/x$ ls -la
total 20
drwxr-xr-x 3 tomasz tomasz 4096 Sep 24 00:11 .
drwxr-xr-x 54 tomasz tomasz 4096 Sep 24 00:11 ..
-rw-r--r-- 1 tomasz tomasz 19 Sep 23 18:45 1
-rw-r--r-- 1 tomasz tomasz 19 Sep 23 18:45 2
drwxr-xr-x 3 tomasz tomasz 4096 Sep 24 00:11 d
The second value for d went up from 2 to 3 after creating d/dd within it.
See mosvy's comments below for a wider view.
| Can every file really own at least 2 names (and thus 2 hard links)? |
1,532,142,916,000 |
I read a couple of articles about Linux inode and understand that each file created always have a corresponding inode number. Since one of our servers is using ext4 there is no way to increase the inode to an already running production server.
There are two solutions we can do one is to delete older files and the other is to transfer older files to another server and archive it.
My question now is if I archive and compress the files and then move it to another server. On the archive server how many inode number will be assigned to the compressed file I just transferred?
|
Collecting multiple files in a single archive file reduces inode consumption to that required to handle that file. The number of blocks used is not correspondingly guaranteed to be reduced (but it usually will be regardless).
| Does archiving files reduces number of inode |
1,532,142,916,000 |
I am currently studying device drivers in an operating systems course and am getting confused regarding the difference between the "inode" structs and "cdev" structs. Could someone clarify the differences between these two structures and what they're meant to achieve?
|
Your question doesn’t mention any specific context; this answer describes struct cdev and struct inode.
The two are fundamentally different.
struct cdev represents a character device, giving access to a driver; it points to the implementations of the various operations supported by a character device.
struct inode represents an inode, along with all the information the kernel needs to use it and keep track of it. An inode gives access to a file, and contains the file’s metadata: its ownership, permissions, ACLs, timestamps, size etc. The kernel needs to know which file system it’s tied to, where the implementations of the operations it supports are, what its state is, etc.
An instance of a struct inode can contain a pointer to a struct cdev, if the inode itself corresponds to a character device (e.g. the inode corresponding to /dev/null, once it’s instantiated in the kernel, is represented by a struct inode with i_cdev pointing to the relevant character device).
| What's the difference between structures "cdev" and "inode" in the context of device driver programming? |
1,532,142,916,000 |
We are using Logstash to ingest our logs and we are facing some issues due inodes being reused. We tried all possible options on Logstash side so we are exploring the OS side.
As far as I can see, if I create a file, drop it and later on I create a new one, most of the time it will get the same inode
[root@XXXX~]# touch a.txt
[root@XXXX~]# stat -c%i a.txt
671092802
[root@XXXX~]# rm a.txt
rm: remove regular empty file ‘a.txt’? y
[root@XXXX~]# touch a.txt
[root@XXXX~]# stat -c%i a.txt
671092802
[root@XXXX~]# rm a.txt
rm: remove regular empty file ‘a.txt’? y
[root@XXXX~]# touch b.txt
[root@XXXX~]# stat -c%i b.txt
671092802
How can I prevent OS with XFS to reuse recently used inodes for new files?
Ideally, we would like to define a period of time between the file is deleted until the inode is being reused. The disk is big so we don't expect issue reaching inode limits.
Thanks
|
The only way to prevent the creation of a file with a given inode number is if there is already one (or if the inode value is one that the filesystem won't use, of course). You can't reserve an inode value. This is true through generic interfaces (i.e. through interfaces that aren't specific to a particular filesystem type), this is true of most filesystems (i.e. most don't have a proprietary means of reserving an inode number), and as far as I can tell this is, unsurprisingly, true of XFS in particular.
If you create a new file immediately after deleting one, on many filesystems, most of the time, the new file will have the same inode as the just-deleted file. But this is never guaranteed.
If you want the inode to remain in use, don't delete the file. You can truncate it (e.g. truncate -s0 /path/to/file or : >|/path/to/file) to save disk space if you want. You can move it to another directory on the same filesystem if some tool is exploring a directory and you don't want that tool to see the file anymore.
| prevent inode reuse |
1,532,142,916,000 |
I synchronize data with rsync --delete --backup --backup-dir=[some directory] -avz [source] [destination].
On the machine where rsync is executed, both [source] and [destination] directories are NFS exports mounted locally (i.e. the machine running rsync is a NFS client).
after a succesfull rsync + some checks, the backup is deleted.
Another machine of my LAN is an application server and has this same [destination] NFS export mounted locally.
Due to some intricacies on the application side I have NO CONTROL on, it looks like the application refers to files by their inodes rather than using their names. Which brings difficulties when a file was changed from [source] :
let's say that on [destination], this file has the inode 123
the application "points to" the file having the inode 123
rsync detects a difference between the [source] and [destination] versions of
this file and has to transfer it
before transferring it, it creates a backup by "moving" it : the backup file now has the inode 123
the updated version of the file is transferred by rsync, and gets a new inode (456)
after a successfull rsync + checks, the backup is deleted : no file has the inode 123 anymore
the application, still pointing to inode 123, is broken
Do you confirm I got it clear about how rsync --backup works and inodes ?
How does the --inplace rsync option work with --backup :
will rsync create a backup file having its own inode ?
will the file keep its current inode ?
|
It's almost impossible to refer to a file by its inode. To open a file, it is necessary to open a reference to a file name in a directory. Then you have a file handle which is now independent of the file name (which is why a file can be removed from the filesystem but still be open and active). So, let's assume the file is being kept open throughout the life of the application. You now need to replace the content of this file using rsync.
Normally, rsync will create a temporary copy of the target file alongside any existing instance, and then at the last moment it will delete (or backup) the original and switch in the replacement. This behaviour can be modified with the --inplace option, such that instead of creating a new copy rsync will write to the actual target.
Now, you've also specified --backup, so rsync does the right thing and creates a copy for the backup before allowing --inplace to update the original instance. You can see this with a short example:
# Prepare scenario
mkdir /tmp/624404
cd /tmp/624404
date >src
cp -p src dst
# Initial files, with inodes
ls -li src dst
149172 -rw-r--r-- 1 roaima 29 Dec 14 11:49 dst
137559 -rw-r--r-- 1 roaima 29 Dec 14 11:49 src
# Update, copy, and list
date >src
rsync --times --inplace --backup src dst
ls -li
total 12
149172 -rw-r--r-- 1 roaima 29 Dec 14 11:50 dst
149194 -rw-r--r-- 1 roaima 29 Dec 14 11:49 dst~
137559 -rw-r--r-- 1 roaima 29 Dec 14 11:50 src
# Update again, copy, and list
date >src
rsync --times --inplace --backup src dst
ls -li
total 12
149172 -rw-r--r-- 1 roaima 29 Dec 14 11:50 dst
149194 -rw-r--r-- 1 roaima 29 Dec 14 11:50 dst~
137559 -rw-r--r-- 1 roaima 29 Dec 14 11:50 src
You can see that the destination (dst) file still has its original inode but that the backup has been given a new one. The second update shows that inodes are retained thereafter.
In your instance it does sound like --inplace --backup is what you need. However, please note that the man page warns,
WARNING: you should not use this option to update files that are being accessed by others, so be careful when choosing to use this for a copy.
The reason that --inplace is not a default is that an interrupted partial copy could leave the target file in an inconsistent state, and the author(s) decided that it would be better to have an internally consistent out-of-date file than a corrupted out-of-date file. Such behaviour can be modified with flags such as --inplace and --partial (and even --append with rsync versions 3.0.0 onwards).
| How does rsync's --inplace option work with --backup? |
1,532,142,916,000 |
The following output (from a Vagrant VM running CentOS 6.6) mostly speaks for itself:
[root@localhost ~]# echo 131072 > /proc/sys/fs/inode-max
-bash: /proc/sys/fs/inode-max: No such file or directory
[root@localhost ~]# sysctl -q -p
[root@localhost ~]# echo 'fs.inode-max = 131072' >> /etc/sysctl.conf
[root@localhost ~]# sysctl -q -p
error: "fs.inode-max" is an unknown key
[root@localhost ~]# man proc | col -b | grep -A6 '/proc/sys/fs/inode-max$'
/proc/sys/fs/inode-max
This file contains the maximum number of in-memory inodes. On
some (2.4) systems, it may not be present. This value should be
3-4 times larger than the value in file-max, since stdin, stdout
and network sockets also need an inode to handle them. When you
regularly run out of inodes, you need to increase this value.
[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]#
How to reconcile the man page statement that implies this won't exist on 2.4 kernels, with the fact that it doesn't exist on this 2.6 kernel?
|
The man page in man7.org and in Debian has a more useful description:
/proc/sys/fs/inode-max (only present until Linux 2.2)
This file contains the maximum number of in-memory inodes. This value should be 3-4 times larger than the value in file-max, since stdin, stdout and network sockets also need an inode to handle them. When you regularly run out of inodes, you need to increase this value.
Starting with Linux 2.4, there is no longer a static limit on the number of inodes, and this file is removed.
Based on the last sentence, it's not there since it's not needed.
| Why does the fs.inode-max kernel tunable not exist on version 2.6 of the Linux kernel? |
1,532,142,916,000 |
My question deals with the relationship between the read and execute bits on a directory. I'm going to give my assumptions, first, all according to my current knowledge, then ask my question in bold in the context of those assumptions. Please feel free to correct any incorrect assumptions:
Files and directories both are stored using inodes.
Files and directories both have permissions (let's just focus on the rwx bits, forgetting the sticky, setuid, setguid (unless they're relevant)).
The contents of a directory's inode's data blocks store a mapping of file names to inode numbers.
Read permission on a directory allows a user to obtain a list of the names of all files in that directory.
The user must know a file's inode number in order to access its contents. UPDATE: The meaning of the original statement here doesn't reflect what I meant to express. What I meant is more along the lines of: The user doesn't need to know a file's inode number, but the user must have permission to get an inode for a given filename in order to get the contents of the file.
Execute permission on a directory allows a user to "use" that directory, and I understand that specifically to mean obtaining the directory's inode number (I would like confirmation of my understanding of this). This will allow the user to do things like cd into that directory, which is the prototypical example given of what a user needs the execute permission for.
Given that a user must be able to obtain the "contents" of a directory (really the contents of the directory's inode's data blocks) in order to gain access to the directory listing, and that the user must know the directory's inode number to gain access to its contents, why is it that a user can still obtain a directory listing while not having execute permission on the directory? It seems that obtaining a listing of the contents of a directory D requires temporarily looking up its inode number in order to read the contents of the inode's data blocks. Furthermore, it would seem necessary that read permission would imply execute permission on a directory.
|
I had a slight misunderstanding, which invalidates my point 6 above. The execute (aka "search") bit on a directory is required in order to obtain the inode numbers of the files it contains, but not its own inode number.
Quote:
You can think of read and execute on directories this way: directories are data files that hold two pieces of information for each file within, the file's name and it's inode number. Read permission is needed to access the names of files in a directory. Execute (a.k.a. search) permission is needed to access the inodes of files in a directory, if you already know the file's name.
References:
https://askubuntu.com/questions/83788/accessing-files-in-a-directory-without-x-permission
https://wpollock.com/AUnix1/FilePermissions.htm
https://superuser.com/questions/442581/why-do-you-need-execute-permission-on-the-parent-directory-to-rename-a-file
| The relationship between execute permission on a directory and its inode structure |
1,532,142,916,000 |
Let's assume I was very unlucky and ran out of inodes in my ext4 filesystem but left with enough free space.
Inode usage is 100%, but it has 50% disk free space.
How can I resolve it?
|
One option is to recreate your filesystem specifying bytes-to-inode ratio with -i option.
Backup all of your data to another disk.
List your filesystems and find the one you want to modify:
$ df -h
assuming that filesystem is /dev/sdX and is mounted on /mnt/mountpoint.
Unmount that filesystem:
$ umount /mnt/mountpoint
Create that filesystem using mkfs.ext4 command specifying -i byte-to-inode ratio:
$ mkfs.ext4 -i 4096 /dev/sdX
This command will create ext4 filesystem with 4 KB per inode ratio (which will create four times more inodes than the default value - 16 KB per inode).
Mount that filesystem:
$ mount /dev/sdX /mnt/mountpoint
| Inode limit reached with free space available |
1,532,142,916,000 |
According to this SO question, when we open a file to read it we only check permissions once when we open it. And if we change the permissions of the file and say the user is no longer allowed to read from the file, the user will still be able to read the file. This raises a few questions:
Don't we need to keep checking permissions, since if for example we open a file to read it, and then try to use write, shouldn't we get an error? This means that we check what we're allowed to do with the file. (perhaps we save locally with the fd the operations we are allowed to do with it and check them each time?)
When we update permissions, do we update the single copy of the inode in the inode table or do we directly update the copy on the disk? Since if we update the permissions directly on the copy on the disk, other processes looking at the inode table will not see the updated version, so it makes more sense to update the inode table and from there let the OS write the changes back to the disk.
|
Don't we need to keep checking permissions, since if for example we open a file to read it, and then try to use write, shouldn't we get an error?
No, we shouldn't! This is intended. The permissions at the point of opening the file matter, not later. That's the API.
When we update permissions, do we update the single copy of the inode in the inode table or do we directly update the copy on the disk?
That is totally an implementation detail of the file system layer. We don't know – and also, we mustn't care. All we know is that this should be consistent across multiple processes, and where the change is made doesn't matter.
| Changing file permissions in inodes while a user has the file open |
1,532,142,916,000 |
I see there are two ways to create quotas, there is xfs_quota and then this suite of utilities like edquota and repquota. It seems all of these utilities can provide inode quotas. How does that tools relate to each other?
|
The XFS User Guide mentions that the generic quota tools work with XFS, but are unable to set project quotas on XFS.
8.11. Generic Quota Tools:
In addition to xfs_quota, xfs also works with generic quota tools
provided on Linux. These tools include quota, repquota, quotactl, edquota, quotacheck, setquota, quotaon/quotaoff (enforcement only), quotawarn.
The generic tools do not understand XFS project quotas.
The RHEL 7 storage documentation pretty much states the same thing:
Generic quota configuration tools (quota, repquota, and edquota for
example) may also be used to manipulate XFS quotas. However, these
tools cannot be used with XFS project quotas.
| Are XFS quotas and linux quotas part of the same thing? |
1,532,142,916,000 |
mkdir test
echo "hi" > test/file1
tar -c -f archive.0.tar -g test.snar test
touch -a test/file1 # changes atime and ctime, doesn't change mtime
tar -c -f archive.1.tar -g test.snar test
tar -t -G -vv -f archive.1.tar # lists Y for file1
So did GNU tar store the entire file again, even though only access time (atime) and metadata change time (ctime) were changed? This seems horribly inefficient to me, as we can reasonably expect many files to be read but not changed.
|
Using gtar for incremental backups is unreliable, but this is not a result of handling time stamps incorrectly.
Any backuptool that works in userland and thus cannot check internal filesystem structures as done by e.g. zfs send needs to handle time stamps the same way or it cannot grant a correct incremental backup.
atime is irrelevant for backups since it is only a hint that the file has been read, but not whether the file has been modified.
mtime may look interesting from the first view, but is irrelevant as well. This is because the mtime of a file can be set to any value by user space programs.
ctime is the only important time stamp for incremental backups as this is the only time stamp that cannot be manipulated.
As ctime cannot bemanipulated and as ctime is updated for both, content and meta data change, a backup tool needs to archive the file content and the file meta data whenever ctime has been updated.
As a result, a file that apparently did not change mtime could still have a modified content and thus needs to be in the backup
Finally: GNU tar does not implement a method, you asked for. The behavior is hard coded.
star however offers the option -dumpmeta that has been created in 2004 in order to experiment with inremental backups. star however clearly warns to use this option, see the man page:
-dumpmeta
changes the behavior of star in incremental dump mode. If
-dumpmeta is used and only the inode change time (st_ctime) of a
file has been updated since the last incremental dump, star will
archive only the meta data of the file (e.g. uid, permissions,
...) but not the file content. Using -dumpmeta will result in
smaller incremental dumps, but files that have been created
between two incrementals and set to an old date in st_mtime (e.g. as a
result from a tar extract) will not be archived with
full content. Using -dumpmeta thus may result in incomplete
incremental dumps, use with extreme care.
The method used by star by default is used by ufsdump and ufsrestore from around 1981 and this is the method used by star since February 2005 and there has never been a problem with restoring incremental backups using these programs.
| Does GNU tar incremental backup save an entire file again, even if only atime or mtime is different? |
1,532,142,916,000 |
As per my understanding kernel maintains 4 tables.
Per process FD table.
System wide open file table struct file
Inode (in-memory) table struct vnode
Inode (on-disk) table.
struct file have one field named struct file_operations f_ops; which contains FS specific operations like ext2_read(), ext2_write();
struct vnode also have one field struct vnodeops v_op; which contains FS specific operations too.
My question is why we have similar functionalities inside both? Or am I getting something wrong?
Are things different in Unix and Linux? Because I did not find struct vnode inside Linux's fs.h
Reference: https://www.usna.edu/Users/cs/wcbrown/courses/IC221/classes/L09/Class.html
Diagram (from "Unix internals new frontiers" book)
|
Okay, I have found the answer.
In previous versions of Unix like SVR4, struct file does not contain file_operations field and all operations e.g. read, write etc. contained by vnode->v_op.
However, in case of Linux struct file will contain file_operations field which will have functions like open, read, write etc. and struct inode (similar to vnode) will contain inode_operations field which will have operations like lookup, link, unlink, symlink, rmdir, mkdir, rename, etc.
| struct file_operations vs struct vnodeops |
1,532,142,916,000 |
On my server, the root partition is 73GB, but the disk says, it is full, although there are only about 6GB used on that device:
# df -h
Filesystem Size Used Avail Use% Mounted on
udev 997M 0 997M 0% /dev
tmpfs 202M 41M 162M 20% /run
/dev/mapper/p22server-root 73G 68G 655M 100% /
(I use LVM on the server: /dev/mapper/p22server-root -> ../dm-0)
If I check with
ncdu -x /
I find out that the total usage is just 5.9GB.
My guess is, that there must be files still open, that are not visible in the file-tree.
How can I debug this? I guess, that a reboot will restore the lost space, but rebooting is not possible right now.
|
There are two possibilities:
1. There are deleted files still open by some procesces
You can see all open files with lsof. For example those are the TYPEs shown in lsof and how often they appear in the output:
# lsof|cut -c50-54|sort|uniq -c
375 CHR
610 DIR
211 FIFO
32 IPv4
17 IPv6
40 link
419 node
152 nown
6008 REG
9 sock
598 unix
This shows only the File Descriptor column (FD):
# lsof|awk -v field="FD" 'NR==1 {c = index($0,field)} {print substr($0,c-1,length(field)+4)}'|sort|uniq -c|sort -n|tail
look for files with the value DEL in the output of lsof to get a hint.
2. Files are hidden behinid a mount point
But more probably, the files are just "hidden" due to a mount point, that was not used while large amount of files was stored in the mount-folder and now they are invisible to ncdu.
mount the root directory in another location and analyze this:
mkdir /temp-root
mount --bind / /temp-root
ncdu -x /temp_root
| Find out which process has data open on the hard drive that is no longer visible in the directory tree [duplicate] |
1,532,142,916,000 |
I have an image that I know was ok. (image.jpg)
A few days later when I open, image.jpg was corrupt. (not displaying properly)
How to check if bit in hard disk drive where image is located is failing?
I am ok with permanent destruction of image.
Can I dd over file with all ones wait a few days and check if any of the bits have flipped?
If it matters, I am on standard Ubuntu installation.
|
Try badblocks, which seems to work on regular files provided the files aren't open:
badblocks -b 512 -vn image.jpg
Example on a real 13K file:
sudo badblocks -b 512 -vn \
/usr/share/texlive/texmf-dist/tex/latex/mwe/example-image.jpg
Output:
Checking for bad blocks in non-destructive read-write mode
From block 0 to 25
Testing with random pattern: Pass completed, 0 bad blocks found. (0/0/0 errors)
| Bad bit in file |
1,532,142,916,000 |
Are there any files created and or broadened by the system besides mail and logs?
AFAIK, the only files that are created and/or broadened by the system in default are /var/mail/ files and /var/log/ files (broadened by means of file size).
To cope with that I've redirected `/dev/null on files in these directories.
But are there more files besides mail and logs that I should worry that they'll be created and broadened by the Linux system itself, throughout time?
|
I'd recommend reading up on the Unix filesystem.
The /var/ directory holds frequently changing files. The /etc/ directory holds configurations that don't typically grow too much. the /usr/ directory holds OS files that don't change too much outside of system upgrades. If you have third-party applications running off of /srv/ or /opt/, those directories may grow.
| Are there any files created and or broadened by the system besides mail and logs? |
1,478,232,523,000 |
I recently upgraded my disk from a 128GB SSD to 512GB SSD. The / partition is encrypted with LUKS. I'm looking for help extending the partition to use all the free space on the new disk. I've already dd'd the old drive onto the new one:
[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 477 GiB, 512110190592 bytes, 1000215216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x00009f33
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 1026047 1024000 500M 83 Linux
/dev/sda2 1026048 250064895 249038848 118.8G 83 Linux
There's about 380GB of unused space after sda2.
More relevant info:
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
fedora_chocbar 1 3 0 wz--n- 118.75g 4.00m
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home fedora_chocbar -wi-a----- 85.55g
root fedora_chocbar -wi-a----- 29.30g
swap fedora_chocbar -wi-a----- 3.89g
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/mapper/encrypted fedora_chocbar lvm2 a-- 118.75g 4.00m
There seems to be a lot of info regarding how to do this, but very little explanation. I appreciate any help on this.
|
OK! The definitive answer finally. My steps to expand a LUKS encrypted volume...
cryptsetup luksOpen /dev/sda2 crypt-volume to open the encrypted volume.
parted /dev/sda to extend the partition. resizepart NUMBER END.
vgchange -a n fedora_chocbar. Stop using the VG so you can do the next step.
cryptsetup luksClose crypt-volume. Close the encrypted volume for the next steps.
cryptsetup luksOpen /dev/sda2 crypt-volume. Open it again.
cryptsetup resize crypt-volume. Will automatically resize the LUKS volume to the available space.
vgchange -a y fedora_chocbar. Activate the VG.
pvresize /dev/mapper/crypt-volume. Resize the PV.
lvresize -l+100%FREE /dev/fedora_chocbar/home. Resize the LV for /home to 100% of the free space.
e2fsck -f /dev/mapper/fedora_chocbar-home. Throw some fsck magic at the resized fs.
resize2fs /dev/mapper/fedora_chocbar-home. Resize the filesystem in /home (automatically uses 100% free space)
I hope someone else finds this useful. I now have 300+GB for my test VMs on my laptop!
| Extend a LUKS encrypted partition to fill disk |
1,478,232,523,000 |
I have a luks-encrypted partition that was protected by a passphrase and a key file. The key file was for routine access and the passphrase was in a sealed envelope for emergencies. May months went by and I accidentally shredded the key file, so I recovered by using the passphrase from the envelope. Now I want to know, I have two active key slots but I don't know which contains the useless key file pass phrase and which has my emergency passphrase in it. Obviously if I remove the wrong one I'll lose all the data on the drive.
#cryptsetup luksDump /dev/sda2
LUKS header information for /dev/sda2
Version: 1
Cipher name: aes
Cipher mode: xts-plain64
Hash spec: sha256
Payload offset: 4096
MK bits: 256
MK digest: xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
MK salt: xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
MK iterations: 371000
UUID: 28c39f66-dcc3-4488-bd54-11ba239f7e68
Key Slot 0: ENABLED
Iterations: 2968115
Salt: xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
Key material offset: 8
AF stripes: 4000
Key Slot 1: ENABLED
Iterations: 2968115
Salt: xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx
Key material offset: 264
AF stripes: 4000
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED
|
As you've discovered, you can use cryptsetup luksDump to see which key slots have keys.
You can check the passphrase for a particular slot with
cryptsetup luksOpen --test-passphrase --key-slot 0 /dev/sda2 && echo correct
This succeeds if you enter the correct passphrase for key slot 0 and fails otherwise (including if the passphrase is correct for some other key slot).
If you've forgotten one of the passphrases then you can only find which slot it's in by elimination, and if you've forgotten two of the passphrases then there's no way to tell which is which (otherwise the passphrase hash would be broken).
To remove the passphrase you've forgotten, you can safely run cryptsetup luksKillSlot /dev/sda2 0 and enter the passphrase you remember. To wipe a key slot, cryptsetup requires the passphrase for a different key slot, at least when it isn't running in batch mode (i.e. no --batch-mode, --key-file=- or equivalent option).
| Detemine which luks slot a passphrase is in |
1,478,232,523,000 |
I would like to change a LUKS password. I want to remove my old password, but I would like to try out my new password before removing the original. I obviously know the old password. I would like to use the terminal not GUI.
I have sensitive data on the drive and would rather not have to use my backup so I need the method to be safe.
|
In LUKS scheme, you have 8 "slots" for passwords or key files. First, check, which of them are used:
cryptsetup luksDump /dev/<device> |grep BLED
Then you can add, change or delete chosen keys:
cryptsetup luksAddKey /dev/<device> [/path/to/<additionalkeyfile>, optional]
cryptsetup luksChangeKey /dev/<device> -S 6
As for deleting keys, you have 2 options:
a) delete any key that matches your entered password:
cryptsetup luksRemoveKey /dev/<device>
b) delete a key in specified slot:
cryptsetup luksKillSlot /dev/<device> 6
| How do I change a LUKS password? |
1,478,232,523,000 |
I have a Debian Wheezy server that's been running for a while with an encrypted drive. The password for the encrypted drive (/dev/sda5) was lost when my encrypted password file was corrupted.
I'd like to be able to reboot this server, but that will of course require that password. Since the drive is clearly in a decrypted state, is there a way to change the password without knowing the old one?
cryptsetup luksChangeKey /dev/sda5 requires the password of the volume.
I could of course rsync everything off and rebuild, but I'd like to avoid that. I looked through memory (#cat /dev/mem | less), but was unable to find it (which is a very good thing!).
|
Yes, you can do this by accessing the master key while the volume is decrypted.
The quick and dirty to add a new passphrase:
device=/dev/sda5
volume_name=foo
cryptsetup luksAddKey $device --master-key-file <(dmsetup table --showkeys $volume_name | awk '{ print $5 }' | xxd -r -p)
device and volume_name should be set appropriately.
volume_name is the name of the decrypted volume, the one you see in /dev/mapper.
Explanation:
LUKS volumes encrypt their data with a master key. Each passphrase you add simply stores a copy of this master key encrypted with that passphrase. So if you have the master key, you simply need to use it in a new key slot.
Lets tear apart the command above.
$ dmsetup table --showkeys $volume_name
This dumps a bunch of information about the actively decrypted volume. The output looks like this:
0 200704 crypt aes-xts-plain64 53bb7da1f26e2a032cc9e70d6162980440bd69bb31cb64d2a4012362eeaad0ac 0 7:2 4096
Field #5 is the master key.
$ dmsetup table --showkeys $volume_name | awk '{ print $5 }' | xxd -r -p
Not going to show the output of this as it's binary data, but what this does is grab the master key for the volume, and then convert it into raw binary data which is needed later.
$ cryptsetup luksAddKey $device --master-key-file <(...)
This is telling cryptsetup to add a new key to the volume. Normally this action requires an existing key, however we use --master-key-file to tell it we want to use the master key instead.
The <(...) is shell command substitution & redirection. It basically executes everything inside, sends the output to a pipe, and then substitutes the <(...) with a path to that pipe.
So the whole command is just a one-liner to condense several operations.
| Change password on a LUKS filesystem without knowing the password |
1,478,232,523,000 |
If I mount a simple loop device,
losetup -a
give me the devices opened.
Is something similar possible with cryptsetup?
|
dmsetup is useful for anything device mapper related. For Example:
[root@localhost]~# dmsetup ls --target crypt
luks-90dc732d-e183-4948-951e-c32f3f11b305 (253, 0)
[root@localhost]~#
| List open dm-crypt LUKS volumes |
1,478,232,523,000 |
I tried removing LUKS encryption on my home directory using the following command:
cryptsetup luksRemoveKey /dev/mapper/luks-3fd5-235-26-2625-2456f-4353fgdgd
But it gives me an error saying:
Device /dev/mapper/luks-3fd5-235-26-2625-2456f-4353fgdgd is not a
valid LUKS device.
Puzzled, I tried the following:
cryptsetup status luks-3fd5-235-26-2625-2456f-4353fgdgd
And it says:
/dev/mapper/luks-3fd5-235-26-2625-2456f-4353fgdgd is active and is in use.
type: LUKS1
cipher: ...
It seems the encrypted device is active, but not valid. What could be wrong here?
|
ANSWER FROM 2013 - See other answers for happy times
Backup
Reformat
Restore
cryptsetup luksRemoveKey would only remove an encryption key if you had more than one. The encryption would still be there.
The Fedora Installation_Guide Section C.5.3 explains how luksRemoveKey works.
That it's "impossible" to remove the encryption while keeping the contents is just an educated guess. I base that on two things:
Because the LUKS container has a filesystem or LVM or whatever on top of it, just removing the encryption layer would require knowledge of the meaning of the data stored on top of it, which simply is not available. Also, a requirement would be that overwriting a part of the LUKS volume with its decrypted counterpart, would not break the rest of the LUKS content, and I'm not sure if that can be done.
Implementing it would solve a problem that is about as far away from the purpose of LUKS as you can get, and I find it very unlikely that someone would take the time to do that instead of something more "meaningful".
| How to remove LUKS encryption? |
1,478,232,523,000 |
I just received a new USB flash drive, and set up 2 encrypted partitions on it. I used dm-crypt (LUKS mode) through cryptsetup. With an additional non-encrypted partition, the drive has the following structure:
/dev/sdb1, encrypted, hiding an ext4 filesystem labelled "Partition 1".
/dev/sdb2, encrypted, hiding another ext4 filesystem, labelled "Partition 2".
/dev/sdb3, clear, visible ext4 filesystem labelled "Partition 3".
Because the labels are attached to the ext4 filesystems, the first two remain completely invisible as long as the partitions haven't been decrypted. This means that, in the meantime, the LUKS containers have no labels. This is particularly annoying when using GNOME (automount), in which case the partitions appear as "x GB Encrypted" and "y GB Encrypted" until I decide to unlock them.
This isn't really a blocking problem, but it's quite annoying, since I really like my labels and would love to see them appear even when my partitions are still encrypted.
Therefore, is there a way to attach labels to dm-crypt+LUKS containers, just like we attach labels to ext4 filesystems? Does the dm-crypt+LUKS header have some room for that, and if so, how may I set a label?
Note that I don't want to expose my ext4 labels before decryption, that would be silly. I'd like to add other labels to the containers, which could appear while the ext4 labels are hidden.
|
For a permanent solution to change the label of the container, use:
sudo cryptsetup config /dev/sdb1 --label YOURLABEL
Edit: Notice that labeling only works with Luks2 headers. In any case, it is possible to convert a Luks1 header into Luks2 with:
sudo cryptsetup convert /dev/sdb1 --type luks2
OBS: Please notice that Luks2 header occupy more space, which can reduce the total number of key slots. Converting Luks2 back to Luks1 is also possible, but there are reports of people who have had problems or difficulties in converting back.
| How can I set a label on a dm-crypt+LUKS container? |
1,478,232,523,000 |
What's the fastest method to backup and restore a luks encrypted device (e.g. a full encrypted usb-device to a image-file).
The usb-device can be decrypted/accessed. I'm looking for a solution to mount the backup image as a file (encryped). Can it be possible?
Keep it simple, stupid.
|
cryptsetup handles image files just as well as block devices, if that was your question. So if you make a dd image (which will be freaking huge) it will work. And if it didn't, you could just create the loop device yourself.
Best practice (if you want to keep the backup encrypted) is to encrypt the backup disk also, then open both containers, then run any backup solution of your choice as you would with unencrypted filesystems. It won't be the fastest method as it'd decrypt data from the source disk and then re-encrypt it for the backup disk. On the other hand it allows for incremental backup solutions, so it should still beat the dd-image-creation on average.
If you want to stick to dd, the only way to make something faster than dd would be a partimage of sorts which takes LUKS header and offset into account, so it would only store the encrypted data that is actually in use by the filesystem.
If the source disk is a SSD and you allow TRIM inside LUKS, and the SSD shows trimmed regions as zeroes, you get this behaviour for free with dd conv=sparse. It's still not something I'd recommend, though.
| Best practice to backup a LUKS encrypted device |
1,478,232,523,000 |
What command can be used to determine the used encryption on a LUKS partition (all the relevant information, initialization vector, generation scheme, mode of operation and block cipher primitive)?
|
If the decrypted volume is /dev/mapper/crypto then you can get the information with
dmsetup table crypto
0 104853504 crypt aes-cbc-essiv:sha256 000[...]000 0 254:2 4096
If the encrypted volume is /dev/storage2/crypto then you get the information with
cryptsetup luksDump /dev/storage2/crypto
LUKS header information for /dev/storage2/crypto
Version: 1
Cipher name: aes
Cipher mode: cbc-essiv:sha256
Hash spec: sha256
[...]
| How to determine what encryption is being used a LUKS partition? |
1,478,232,523,000 |
I am investigating a problem where encrypting a block device imposes a huge performance penalty when writing to it. Hours of Internet reading and experiments did not provide me with a proper understanding, let alone a solution.
The question in short: Why do I get perfectly fast write speeds when putting a btrfs onto a block device (~170MB/s), while the write speed plummets (~20MB/s) when putting a dm-crypt/LUKS in between the file system and the block device, although the system is more than capable of sustaining a sufficiently high encryption throughput?
Scenario
/home/schlimmchen/random is a 4.0GB file filled with data from /dev/urandom earlier.
dd if=/dev/urandom of=/home/schlimmchen/Documents/random bs=1M count=4096
Reading it is super fast:
$ dd if=/home/schlimmchen/Documents/random of=/dev/null bs=1M
4265841146 bytes (4.3 GB) copied, 6.58036 s, 648 MB/s
$ dd if=/home/schlimmchen/Documents/random of=/dev/null bs=1M
4265841146 bytes (4.3 GB) copied, 0.786102 s, 5.4 GB/s
(the second time, the file was obviously read from cache).
Unencrypted btrfs
The device is directly formatted with btrfs (no partition table on the block device).
$ sudo mkfs.btrfs /dev/sdf
$ sudo mount /dev/sdf /mnt
$ sudo chmod 777 /mnt
Write speed gets as high as ~170MB/s:
$ dd if=/home/schlimmchen/Documents/random of=/mnt/dd-test1 bs=1M conv=fsync
4265841146 bytes (4.3 GB) copied, 27.1564 s, 157 MB/s
$ dd if=/home/schlimmchen/Documents/random of=/mnt/dd-test2 bs=1M conv=fsync
4265841146 bytes (4.3 GB) copied, 25.1882 s, 169 MB/s
$ dd if=/home/schlimmchen/Documents/random of=/mnt/dd-test3 bs=1M conv=fsync
4265841146 bytes (4.3 GB) copied, 29.8419 s, 143 MB/s
Read speed is well above 200MB/s.
$ dd if=/mnt/dd-test1 of=/dev/null bs=1M
4265841146 bytes (4.3 GB) copied, 19.8265 s, 215 MB/s
$ dd if=/mnt/dd-test2 of=/dev/null bs=1M
4265841146 bytes (4.3 GB) copied, 19.9821 s, 213 MB/s
$ dd if=/mnt/dd-test3 of=/dev/null bs=1M
4265841146 bytes (4.3 GB) copied, 19.8561 s, 215 MB/s
Encrypted btrfs on block device
The device is formatted with LUKS, and the resultant device is formatted with btrfs:
$ sudo cryptsetup luksFormat /dev/sdf
$ sudo cryptsetup luksOpen /dev/sdf crypt
$ sudo mkfs.btrfs /dev/mapper/crypt
$ sudo mount /dev/mapper/crypt /mnt
$ sudo chmod 777 /mnt
$ dd if=/home/schlimmchen/Documents/random of=/mnt/dd-test1 bs=1M conv=fsync
4265841146 bytes (4.3 GB) copied, 210.42 s, 20.3 MB/s
$ dd if=/home/schlimmchen/Documents/random of=/mnt/dd-test2 bs=1M
4265841146 bytes (4.3 GB) copied, 207.402 s, 20.6 MB/s
Read speed suffers only marginally (why does it at all?):
$ dd if=/mnt/dd-test1 of=/dev/null bs=1M
4265841146 bytes (4.3 GB) copied, 22.2002 s, 192 MB/s
$ dd if=/mnt/dd-test2 of=/dev/null bs=1M
4265841146 bytes (4.3 GB) copied, 22.0794 s, 193 MB/s
luksDump: http://pastebin.com/i9VYRR0p
Encrypted btrfs in file on btrfs on block device
The write speed "skyrockets" to over 150MB/s when writing into an encrypted file. I put a btrfs onto the block device, allocated a 16GB file, which I lukfsFormat'ed and mounted.
$ sudo mkfs.btrfs /dev/sdf -f
$ sudo mount /dev/sdf /mnt
$ sudo chmod 777 /mnt
$ dd if=/dev/zero of=/mnt/crypted-file bs=1M count=16384 conv=fsync
17179869184 bytes (17 GB) copied, 100.534 s, 171 MB/s
$ sudo cryptsetup luksFormat /mnt/crypted-file
$ sudo cryptsetup luksOpen /mnt/crypted-file crypt
$ sudo mkfs.btrfs /dev/mapper/crypt
$ sudo mount /dev/mapper/crypt /tmp/nested/
$ dd if=/home/schlimmchen/Documents/random of=/tmp/nested/dd-test1 bs=1M conv=fsync
4265841146 bytes (4.3 GB) copied, 26.4524 s, 161 MB/s
$ dd if=/home/schlimmchen/Documents/random of=/tmp/nested/dd-test2 bs=1M conv=fsync
4265841146 bytes (4.3 GB) copied, 27.5601 s, 155 MB/s
Why is the write performance increasing like this? What does this particular nesting of filesystems and block devices achieve to aid in high write speeds?
Setup
The problem is reproducible on two systems running the same distro and kernel. However, I also observed the low write speeds with kernel 3.19.0 on System2.
Device: SanDisk Extreme 64GB USB3.0 USB Stick
System1: Intel NUC 5i5RYH, i5-5250U (Broadwell), 8GB RAM, Samsung 840 EVO 250GB SSD
System2: Lenovo T440p, i5-4300M (Haswell), 16GB RAM, Samsung 850 PRO 256GB SSD
Distro/Kernel: Debian Jessie, 3.16.7
cryptsetup: 1.6.6
/proc/crypto for System1: http://pastebin.com/QUSGMfiS
cryptsetup benchmark for System1: http://pastebin.com/4RxzPFeT
btrfs(-tools) is version 3.17
lsblk -t /dev/sdf: http://pastebin.com/nv49tYWc
Thoughts
Alignment is not the cause as far as I can see. Even if the stick's page size is 16KiB, the cryptsetup payload start is aligned to 2MiB anyway.
--allow-discards (for cryptsetup's luksOpen) did not help, as I was expecting.
While doing a lot less experiments with it, I observed very similar behavior with an external hard drive, connected through a USB3.0 adapter.
It seems to me that the system is writing 64KiB blocks. A systemtrap script I tried indicates that at least. /sys/block/sdf/stat backs this hypothesis up since a lot of writes are merged. So my guess is that writing in too small blocks is not the cause.
No luck with changing the block device queue scheduler to NOOP.
Putting the crypt into an LVM volume did not help.
|
The answer (as I now know): concurrency.
In short: My sequential write, either using dd or when copying a file (like... in daily use), becomes a pseudo-random write (bad) because four threads are working concurrently on writing the encrypted data to the block device after concurrent encryption (good).
Mitigation (for "older" kernels)
The negative effect can be mitigated by increasing the amount of queued requests in the IO scheduler queue like this:
echo 4096 | sudo tee /sys/block/sdc/queue/nr_requests
In my case this nearly triples (~56MB/s) the throughput for the 4GB random data test explained in my question. Of course, the performance still falls short 100MB/s compared to unencrypted IO.
Investigation
Multicore blktrace
I further investigated the problematic scenario in which a btrfs is placed on a top of a LUKS encrypted block device. To show me what write instructions are issued to the actual block device, I used blktrace like this:
sudo blktrace -a write -d /dev/sdc -o - | blkparse -b 1 -i - | grep -w D
What this does is (as far as I was able to comprehend) trace IO request to /dev/sdc which are of type "write", then parse this to human readable output but further restrict the output to action "D", which is (according to man blkparse) "IO issued to driver".
The result was something like this (see about 5000 lines of output of the multicore log):
8,32 0 32732 127.148240056 3 D W 38036976 + 240 [ksoftirqd/0]
8,32 0 32734 127.149958221 3 D W 38038176 + 240 [ksoftirqd/0]
8,32 0 32736 127.160257521 3 D W 38038416 + 240 [ksoftirqd/0]
8,32 1 30264 127.186905632 13 D W 35712032 + 240 [ksoftirqd/1]
8,32 1 30266 127.196561599 13 D W 35712272 + 240 [ksoftirqd/1]
8,32 1 30268 127.209431760 13 D W 35713872 + 240 [ksoftirqd/1]
Column 1: major,minor of the block device
Column 2: CPU ID
Column 3: sequence number
Column 4: time stamp
Column 5: process ID
Column 6: action
Column 7: RWBS data (type, sector, length)
This is a snipped of the output produced while dd'ing the 4GB random data onto the mounted filesystem. It is clear that at least two processes are involved. The remaining log shows that all four processors are actually working on it. Sadly, the write requests are not ordered anymore. While CPU0 is writing somewhere around the 38038416th sector, CPU1, which is scheduled afterwards, is writing somewhere around the 35713872nd sector. That's bad.
Singlecore blktrace
I did the same experiment after disabling multi-threading and disabling the second core of my CPU. Of course, only one processor is involved in writing to the stick. But more importantly, the write request are properly sequential, which is why the full write performance of ~170MB/s is achieved in the otherwise same setup.
Have a look at about 5000 lines of output in the singlecore log.
Discussion
Now that I know the cause and the proper google search terms, the information about this problem is bubbling up to the surface. As it turns out, I am not the first one to notice.
Four years ago, a patch brought multi-threaded dm-crypt to the kernel. That commit pretty much matches my findings exactly.
Two years ago, patches were discussed improving dm-crypt performance, including re-ordering of write requests.
One year ago, the topic was still discussed.
Recently, a patch enabling sorting for dm-crypt was finally commited to the kernel.
There is an interesting email with performance tests (which I did not read very much of) concerning this phenomenon.
Fixed in current kernels (>=4.0.2)
Because I (later) found the kernel commit obviously targeted at this exact problem, I wanted to try an updated kernel. [After compiling it myself and then finding out it's already in debian/sid] It turns out that the problem is indeed fixed. I don't know the exact kernel release in which the fix appeared, but the original commit will give clues to anyone interested.
For the record:
$ uname -a
Linux t440p 4.0.0-1-amd64 #1 SMP Debian 4.0.2-1 (2015-05-11) x86_64 GNU/Linux
$ dd if=/home/schlimmchen/Documents/random of=/mnt/dd-test bs=1M conv=fsync
4294967296 bytes (4.3 GB) copied, 29.7559 s, 144 MB/s
A hat tip to Mikulas Patocka, who authored the commit.
| Abysmal general dm-crypt (LUKS) write performance |
1,478,232,523,000 |
I am in progress of resizing a LUKS encrypted partition that contains a single ext4 filesystem (no LVM or something). The cryptsetup FAQ recommends to remove the old partition and recreate it, but that sounds like wasting a lot time. Therefore I want to proceeed by manually, carefully resizing the partition.
So far, I think that I need to do:
Create an (encrypted) backup of the filesystem. Important! You won't be the first to lose your data while performing the following tasks.
Unmount the existing ext4 filesystem (e.g. by booting into a Live CD). If booting from a Live CD, mount the encrypted partition using cryptsetup luksOpen /dev/sdXY ExistingExt4
Resize the existing ext4 filesystem.
cryptsetup resize /dev/mapper/ExistingExt4 -b $SECTORS
Close/ "unmount" the LUKS partition using cryptsetup luksClose ExistingExt4
Shrink the partition size.
Are the above steps correct?
In step 4, what should I choose for $SECTORS? Is this step even necessary? The cryptsetup manual page is not really descriptive on the resize option:
resize <name>
resizes an active mapping <name>.
If --size (in sectors) is not specified, the size of the underlying
block device is used.
Finally, if I shrink the ext4 partition by 15 GiB, can I safely assume that 15 GiB can be removed from the existing partition using parted? If yes, how to do so? My disk is GPT partitioned, if that matters.
|
After backing up (step 1) and unmounting (between 2 and 3), run fsck to ensure that the filesystem is healthy:
e2fsck -f /dev/mapper/ExistingExt4
Other than that, the steps are OK.
Purpose of the cryptsetup resize command
what should I choose for $SECTORS? Is this step even necessary?
This step is necessary, otherwise the partition would still show up at the old side. This is confirmed with Nautilus, even after resizing with resize2fs, the LUKS partition showed up as the old size. After running cryptsetup resize, the correct number is shown. This step is not necessary. It only affects the current size status as shown in the file browser. After changing the size and closing/opening the partition again, the number is restored. So, when closing the LUKS partition as shown later will make this obsolete.
$SECTORS can be determined by looking at the output of cryptsetup status ExistingExt4:
/dev/mapper/ExistingExt4 is active.
type: LUKS1
cipher: aes-cbc-essiv:sha256
keysize: 256 bits
device: /dev/sda2
sector size: 512
offset: 2056 sectors
size: 156049348 sectors
mode: read/write
(As of cryptsetup 2.0.0 (December 2017), the sector size may be larger than 512 bytes: see the cryptsetup(8) manpage and the --sector-size option.)
Thus, to subtract 15 GiB, use a sector size of 156049348 - 15 * 1024 * 1024 * 2 = 124592068:
cryptsetup resize ExistingExt4 -b 124592068
Resizing the partition with parted
As for resizing the partition, parted works fine with GPT partitions. The resize command does not work however, as a workaround (or solution), remove the partition information and create a new partition as inspired by http://ubuntuforums.org/showthread.php?p=8721017#post8721017:
# cryptsetup luksClose ExistingExt4
# parted /dev/sda2
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) unit s
(parted) p
Model: ATA INTEL SSDSA2CW08 (scsi)
Disk /dev/sda: 156301488s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 34s 2082s 2049s Boot bios_grub
3 2083s 250034s 247952s ext2 RootBoot
2 250035s 156301438s 156051404s Everything
As 15 GiB has to be shaved off, the new end becomes 156301438 - 15 * 1024 * 1024 * 2 = 124844158. Since I want to change partition 2, I first have to remove it and then recreate it with the label "Everything" (this could be changed if you like). Note: this disk has a GPT layout. For MBR, you should replace Everything by primary or extended (untested, resizing a partition on MBR has not been tested and is not recommended because it is untested).
WARNING: the following commands has destroyed data. Do not copy it without understanding what is happening. The sector dimensions must be changed, otherwise you WILL destroy your partition(s). I am in no way responsible for your stupidness, BACKUP BACKUP BACKUP your data to a second storage medium before risking your data.
(parted) rm 2
(parted) mkpart Everything 250035s 124844158s
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? ignore
(parted) p
Model: ATA INTEL SSDSA2CW08 (scsi)
Disk /dev/sda: 156301488s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name Flags
1 34s 2082s 2049s Boot bios_grub
3 2083s 250034s 247952s ext2 RootBoot
2 250035s 124844158s 124594124s Everything
(parted) quit
In the above parted example, my sectors are not aligned which is a mistake from an earlier installation, do not pay too much attention to it.
That is it! You can use cryptsetup status and file -Ls /dev/... to verify that everything is OK and then reboot.
| How can I shrink a LUKS partition, what does `cryptsetup resize` do? |
1,478,232,523,000 |
I accidentally created a new physical volume over my LUKS partition; nothing else happened. The LUKS partition contains a LVM setup and the root partition (this setup was initially created by the debian installer).
I can see that the LUKS partition is mostly intact:
00000200: 4c41 4245 4c4f 4e45 0100 0000 0000 0000 LABELONE........
00000210: 0ccb b873 2000 0000 4c56 4d32 2030 3031 ...s ...LVM2 001
00000220: 4b48 5047 5667 6465 477a 7831 306a 6649 KHPGVgdeGzx10jfI
00000230: 7635 4432 4637 6966 446a 7172 3339 4863 v5D2F7ifDjqr39Hc
00000240: 0000 40a2 e800 0000 0000 1000 0000 0000 ..@.............
....
00005000: 7b22 6b65 7973 6c6f 7473 223a 7b22 3022 {"keyslots":{"0"
00005010: 3a7b 2274 7970 6522 3a22 6c75 6b73 3222 :{"type":"luks2"
00005020: 2c22 6b65 795f 7369 7a65 223a 3634 2c22 ,"key_size":64,"
00005030: 6166 223a 7b22 7479 7065 223a 226c 756b af":{"type":"luk
00005040: 7331 222c 2273 7472 6970 6573 223a 3430 s1","stripes":40
00005050: 3030 2c22 6861 7368 223a 2273 6861 3235 00,"hash":"sha25
00005060: 3622 7d2c 2261 7265 6122 3a7b 2274 7970 6"},"area":{"typ
00005070: 6522 3a22 7261 7722 2c22 6f66 6673 6574 e":"raw","offset
00005080: 223a 2233 3237 3638 222c 2273 697a 6522 ":"32768","size"
00005090: 3a22 3235 3830 3438 222c 2265 6e63 7279 :"258048","encry
000050a0: 7074 696f 6e22 3a22 6165 732d 7874 732d ption":"aes-xts-
000050b0: 706c 6169 6e36 3422 2c22 6b65 795f 7369 plain64","key_si
000050c0: 7a65 223a 3634 7d2c 226b 6466 223a 7b22 ze":64},"kdf":{"
000050d0: 7479 7065 223a 2261 7267 6f6e 3269 222c type":"argon2i",
However, the characteristic "LUKS" is missing.
Is there any way to access the LUKS partition to retrieve the data? I tried testdisk, but without success.
Update, since I did not include this originally: Here is the LUKS header backup @ 0x4000:
00004000: 0000 0000 0000 0002 0000 0000 0000 4000 ..............@.
00004010: 0000 0000 0000 0005 0000 0000 0000 0000 ................
00004020: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004030: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004040: 0000 0000 0000 0000 7368 6132 3536 0000 ........sha256..
00004050: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004060: 0000 0000 0000 0000 735b 6f53 2466 e2bb ........s[oS$f..
00004070: abcf fb4a d5ea d395 70ab f4e8 1f99 a173 ...J....p......s
00004080: 2303 93a0 7582 eb4a 77fe 28f8 3e01 b246 #...u..Jw.(.>..F
00004090: e9eb cd58 8a7a afd5 4e45 319a c007 906b ...X.z..NE1....k
000040a0: b22a c393 1918 981c 6636 6333 6461 3534 .*......f6c3da54
000040b0: 2d63 6435 362d 3433 3036 2d38 6330 312d -cd56-4306-8c01-
000040c0: 3534 3334 3366 6265 6564 3236 0000 0000 54343fbeed26....
000040d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000040f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004100: 0000 0000 0000 4000 0000 0000 0000 0000 ......@.........
00004110: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004120: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004130: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004140: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004150: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004160: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00004170: 0000 0000 0000 0000 0000 0000 0000 0000 ................
|
cryptsetup repair, Part One — Magic Bytes Recovery
See also: cryptsetup repair, Part Two — Full Header Recovery
This looks like a LUKS 2 header that was directly overwritten with LVM metadata. So the LUKS device became a LVM Physical Volume. So this is a damaged LUKS header recovery problem. Depending on the damage, it might be irrecoverable.
For LUKS1, it's usually game over, but LUKS2 has a secondary header at offset 0x4000. You inconveniently did not include that offset range in your output, but the LUKS2 JSON data at offset 0x5000 is still there.
So you can try the following experiment:
Copy the first 16 MiB of the device (the LUKS 2 header):
# head -c 16M /dev/yourdevice > luksheaderdamage.img
Restore LUKS 2 header magic byte signatures (wiped by LVM):
--- Primary: 0x0000 » LUKS\xba\xbe\x00\x02 ---
# printf 'LUKS\272\276\0\2' |
dd bs=1 count=8 conv=notrunc of=luksheaderdamage.img
--- Secondary: 0x4000 » SKUL\xba\xbe\x00\x02 ---
# printf 'SKUL\272\276\0\2' |
dd bs=1 count=8 seek="$((0x4000))" conv=notrunc of=luksheaderdamage.img
Try to repair the LUKS 2 header:
# cryptsetup repair luksheaderdamage.img
WARNING: Device luksheaderdamage.img already contains a 'LVM2_member' superblock signature.
WARNING!
========
Really try to repair LUKS device header?
Are you sure? (Type 'yes' in capital letters): YES
Check the result:
# cryptsetup luksDump luksheaderdamage.img
If successful, open the device:
# cryptsetup open --readonly --header=luksheaderdamage.img /dev/yourdevice cryptyourdevice
Then see what can be found...
# file -s /dev/mapper/cryptyourdevice
If any of these steps fail, you might not have much hope left...
(The hoop jumping with all these commands is only necessary because cryptsetup repair is not flexible and refuses to repair LUKS 2 headers even if the damage is limited to the magic bytes. Hence the restoring of the magic byte signature is a manual process.)
| Restore a LUKS partition that was overwritten by pvcreate |
1,478,232,523,000 |
How can I change the hash-spec and iter-time of an existing dm-crypt LUKS device?
Clearly I can pass the options if I create a new device, for example something like this:
sudo cryptsetup luksFormat --cipher aes-cbc-essiv:sha256 --key-size 256 --iter-time 2100 --hash sha512 /dev/loop0
But if the device already exists, how can I change for example sha256 to sha1 or change the iteration time without "destroying" the device. (Clearly you would have to retype your password since a new hash will be generated.)
|
Each key slot has its own iteration time. If you want to change the number of iterations, create a new slot with the same passphrase and a new number of iterations, then remove the old slot.
cryptsetup -i 100000 --key-slot 2 luksAddKey $device
cryptsetup luksKillSlot $device 1
I think the hash algorithm cannot be configured per slot, it's always PBKDF2 with a globally-chosen hash function.
Recent versions of cryptsetup include a tool cryptsetup-reencrypt, which can change the main encryption key and all the parameters, but it is considered experimental (and it reencrypts the whole device even though this would not be necessary to merely change the password-based key derivation function).
| How to change the hash-spec and iter-time of an existing dm-crypt LUKS device? |
1,478,232,523,000 |
The LUKS / dm-crypt / cryptsetup FAQ page says:
2.15 Can I resize a dm-crypt or LUKS partition?
Yes, you can, as neither dm-crypt nor LUKS stores partition size.
I'm befuzzled:
What is "resized" if no size information is stored?
How does a "resize" get remembered across open / closes of a encrypted volume?
|
It's about online resize.
For example if you use LVM, create a LV of 1G size, and put LUKS on that, it's like this:
# lvcreate -L1G -n test VG
# cryptsetup luksFormat /dev/mapper/VG-test
# cryptsetup luksOpen /dev/mapper/VG-test lukstest
# blockdev --getsize64 /dev/mapper/VG-test
1073741824
# blockdev --getsize64 /dev/mapper/lukstest
1071644672
So the LUKS device is about the same size as the VG-test device (1G minus 2MiB used by the LUKS header).
Now what happens when you make the LV larger?
# lvresize -L+1G /dev/mapper/VG-test
Size of logical volume VG/test changed from 1.00 GiB (16 extents) to 2.00 GiB (32 extents).
Logical volume test successfully resized.
# blockdev --getsize64 /dev/mapper/VG-test
2147483648
# blockdev --getsize64 /dev/mapper/lukstest
1071644672
The LV is 2G large now, but the LUKS device is still stuck at 1G, as that was the size it was originally opened with.
Once you luksClose and luksOpen, it would also be 2G — because LUKS does not store a size, it defaults to the device size at the time you open it. So close and open (or simply rebooting) would update the crypt mapping to the new device size. However, since you can only close a container after umounting/stopping everything inside of it, this is basically an offline resize.
But maybe you have a mounted filesystem on the LUKS, it's in use, and you don't want to umount it for the resize, and that's where cryptsetup resize comes in as an online resize operation.
# cryptsetup resize /dev/mapper/lukstest
# blockdev --getsize64 /dev/mapper/lukstest
2145386496
cryptsetup resize updates the active crypt mapping to the new device size, no umount required, and then you can follow it up with resize2fs or whatever to also grow the mounted filesystem itself online.
If you don't mind rebooting or remounting, you'll never need cryptsetup resize as it happens automatically offline. But if you want to do it online, that's the only way.
When shrinking (cryptsetup resize --size x), the resize is temporary. LUKS does not store device size, so next time you luksOpen, it will simply use the device size again. So shrinking sticks only if the backing device was also shrunk accordingly.
For a successful shrink you have to work backwards... growing is grow partition first, then LUKS, then filesystem... shrinking is shrink filesystem first, and partition last.
If the resize doesn't work, it's most likely due to the backing device not being resized, for example the kernel may refuse changes to the partition table while the drive is in use. Check with blockdev that all device layers have the sizes you expect them to have.
| What does `cryptsetup resize` do if LUKS doesn't store partition size? |
1,478,232,523,000 |
I recently installed Fedora 20. I don't recall what exact options I chose for encrypting the disk/LVM during installation. It installed fine and I can log in etc. Here is the situation I have:
I booted up with LiveCD and tried the following: (I have installed Fedora20 to /dev/sda3' partition).
If I run cryptsetup open /dev/sda3 fedo I get an error saying it is not a LUKS device.
I I run cryptsetup luksDump /dev/sda3 I get an error saying it is not a LUKS device
If I run cryptsetup open --type plain /dev/sda3 fedo, it prompts for password and it opens the device fine.
So, obviously, that is a plain-text encrypted (without LUKS header) partition.
Now, when I try to run mount /dev/mapper/fedo /mnt/fedora, it says unknown crypto_LUKS filesystem.
I do have LVM on top of it, so, I can run pvdisplay, vgdisplay, lvdisplay and it shows information. I have a VG called fedora and two LVs, viz 00 for swap partition and 01 for / partition.
Now, if I do a cryptsetup luksDump /dev/fedora/01 I can see LUKS headers etc. And, I can mount by running mount /dev/fedora/00 /mnt/fedora, no password prompt.
So, do I have a LUKS-over-LVM-over-(plain-text)-encrypted partition?
Here is my output of lsblk:
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 37.3G 0 disk
|-sda3 8:3 0 17.4G 0 part
|-fedora-00 253:0 0 2.5G 0 lvm
| |-luks-XXXXX 253:3 0 2.5G 0 crypt [SWAP]
|-fedora-01 253:1 0 15G 0 lvm
|-luks-XXXXX 253:2 0 15G 0 crypt /
So, the question is, how to figure out whether I have LVM-over-LUKS or LUKS-over-LVM, or some other combination thereof (LUKS over LVM over LUKS etc)? To make my question clear, I know I have LVM and LUKS, I want to figure out the order of them.
|
cryptsetup luksDump /dev/fedora/01 shows the LVM logical volume to be a LUKS encrypted volume. The output of pvs or pvdisplay would show the partition /dev/sda3 to be a physical volume. Thus you have LUKS over LVM. At a lower level, you have LVM over PC partition.
The output of lsblk confirms this: sda is a disk, sda3 is a partition (which contains an LVM physical volume), fedora-00 and fedora-01 are logical volumes, and each logical volume contains a LUKS encrypted volume.
| How to identify LVM-over-LUKS or LUKS-over-LVM |
1,478,232,523,000 |
Context
Encrypting whole new external hard drive with Luks.
I.e. it is not a system drive (will be used only to store data, not to boot the OS), and it is completely blank.
Observation
All descriptions that I found about how to achieve this go along the lines of:
create a new partition, which is the same size as the whole disk
encrypt that partition
Some examples:
From here:
Creating a new encrypted partition:
[...]
Encrypting an existing partition
Or here.
Question
Is it possible to encrypt the whole disk, instead of having one big encrypted partition?
Probably the answer will be no, so the real question is why not?
In other words
What would happen if instead of typing
sudo cryptsetup -v -y luksFormat /dev/sda1
I would type
sudo cryptsetup -v -y luksFormat /dev/sda
(without having created sda1)?
|
The cryptsetup FAQ mentions whole-disk encryption using LUKS. Basically, cryptsetup doesn’t care what the LUKS device is, partition, disk, or loop device, so you can use whichever is appropriate.
sudo cryptsetup -v -y luksFormat /dev/sda
will create a LUKS container using all of /dev/sda.
Section 2.2 of the FAQ recommends this for external disks:
Fully encrypted raw block device: For this, put LUKS on the raw
device (e.g. /dev/sdb) and put a filesystem into the LUKS container,
no partitioning whatsoever involved. This is very suitable for
things like external USB disks used for backups or offline
data-storage.
Note that cryptsetup doesn’t need /etc/crypttab.
| Encrypting whole disk with Luks (instead of one big encrypted partition) |
1,478,232,523,000 |
How does bit rot affect a LUKS container and the filesystem inside?
Suppose you have a filesystem that is well suited to deal with bit rot. Now put it inside a LUKS container. In case bit rot corrupted the container, I assume the decrypted filesystem will suffer huge amounts of corrupted raw bytes / blocks.
How does LUKS protect against this?
|
Bitrot in the LUKS header (key and otherwise critical material): it's *poof* gone.
(There is a bit of redundancy and checksum for the LUKS2 header but it doesn't cover much, so chances are... it's still gone).
Bitrot in encrypted data: it depends on the encryption mode, but in general, a single bit flip will result in 16 wrong bytes.
Set up encryption:
# truncate -s 32M bitrottest.img
# cryptsetup luksFormat bitrottest.img
# cryptsetup luksOpen bitrottest.img bitrottest
Make it all zero:
# shred -n 0 -z /dev/mapper/bitrottest
# hexdump -C /dev/mapper/bitrottest
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
01000000
Flip a bit:
# losetup
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop0 0 0 1 0 bitrottest.img 0 4096
# dd bs=1 count=1 skip=30M if=/dev/loop0 | hexdump -C
00000000 a2 |.|
00000001
# printf "\xa3" | dd bs=1 count=1 seek=30M of=/dev/loop0
# dd bs=1 count=1 skip=30M if=/dev/loop0 | hexdump -C
00000000 a3 |.|
00000001
Result:
# hexdump -C /dev/mapper/bitrottest
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00e00000 eb d1 bd b0 2a f5 77 73 35 df 82 40 1e a7 27 11 |....*.ws5..@..'.|
00e00010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
01000000
One flipped bit, 16 whacky bytes.
Protection? None whatsoever. For that, you'd have to add integrity (just to report errors, redundancy is still a separate issue from that).
You are not supposed to deliberately write corrupt data to your storage.
Storage is supposed to report read errors instead of returning bogus data. In that case your data is still gone, but at least, it's not silent bitrot.
| Bit Rot within LUKS Encryption |
1,478,232,523,000 |
Following the Kali Linux documentation for "Adding USB Persistence with LUKS Encryption", I created a persistent partition and encrypted the volume with:
cryptsetup --verbose --verify-passphrase luksFormat /dev/sdb2
cryptsetup luksOpen /dev/sdb2 my_usb
mkfs.ext3 -L persistence /dev/mapper/my_usb
e2label /dev/mapper/my_usb persistence
mkdir -p /mnt/my_usb
mount /dev/mapper/my_usb /mnt/my_usb
echo "/ union" > /mnt/my_usb/persistence.conf
umount /dev/mapper/my_usb
(substituting a volume name for "my_usb")
However, I forgot to close the volume (the following line was ophaned on the next page in the documentation, so I didn't see it):
cryptsetup luksClose /dev/mapper/my_usb
Is this a problem? If so, how and is there any way to repair it?
This article suggests it is but doesn't say why and the instructions don't work for me.
The disk appears to work fine.
|
Forgetting the luksClose doesn't harm the data on the disk, after the umount, everything is flushed to the disk, so you are safe at this point.
What the article you linked is talking about is that without the luksClose, the device mapper mapping for the crypt device is still lingering around, which blocks the name my_usb for any future luksOpen (of the same or another crypt disk) until the machine is rebooted or the manual removal procedure from the article is done. This doesn't affect any data on the disk even if you reconnect it, it is just a nuisance.
| forgot to luksClose usb persistent partition, is this a problem? |
1,478,232,523,000 |
My system is full of very sensitive data, so I need to encrypt as much of it as possible.
I have an encrypted Debian installation which asks for a long password every time during boot.
Is there a simple way to set it up so that I can input that password remotely?
If some other distribution can do it, I don't mind installing something else instead of Debian.
|
You can enable this by installing dropbear-initramfs and following the instructions to configure your SSH keys. This will start an SSH server from the initramfs, allowing you to connect remotely and enter your encryption passphrase.
| Turning encrypted system on remotely |
1,478,232,523,000 |
I want to create a new encrypted LUKS-partition in GParted.
I've searched the UI and the help, but the only thing I can find is how to open and close an existing LUKS partition and how to to copy and paste an existing one.
However, I can find no way to create a new one. I can create a new partition e.g. for btrfs, but it is never encrypted.
So it seems for that only task of creating a new partition I have to resort to other tools like GNOME Disks (GNOME Disk Utility), which easily allows this when creating a new partition, or fallback to the commandline, which I'd like to avoid.
Or is there any way to create a new encrypted partition?
Broader use case
Actually, i want to do what is described in the GParted help: Copy an encrypted partition and „maintaining an encrypted” partition on a new disk. However, to do so (i.e. to not decrypt the data while copying), I have to paste it „into an existing open LUKS encrypted partition”, i.e. I need to have an encrypted partition first.
So, finally, is there any way to create a new encrypted partition in GParted?
|
GParted doesn't support creating of encrypted partitions, you'll need to use either GNOME Disks or blivet-gui (shameless plug for my project) or you can just use cryptsetup directly if you are ok with using command line tools.
See GParted Features page for details about supported features, LUKS is listed as not supported in the Create column.
| How to create a new encrypted LUKS-partition in GParted? |
1,478,232,523,000 |
I have a fully encrypted server running Debian 7 and have set up dropbear and busybox to unlock the LUKS container via SSH (as described in this tutorial and in this U&L answer).
Unfortunately, whenever I try and SSH to the server (over the LAN) at reboot, I get a "Connection refused" error. I have tried telnet and nmap to the default port (22) and both say the port is closed.
The server has a ufw rule to accept all traffic from the LAN:
Anywhere ALLOW 192.168.1.0/24
I have tried changing the port that dropbear listens on in /etc/defaults/dropbear but ssh and telnet are still refused connections1.
How can I ensure that a port is open at that stage in the boot process so that I can connect to unlock the LUKS container?
Disabling the firewall makes no difference: nmap shows all ports still closed.
Update 2/14
I added break=premount to the kernel line and had a poke around in the initramfs. dropbear has started, but the network is not up at that point. After exiting, the network comes up and boot continues until the prompt to unlock the LUKS device.
At this point, the network is up, and the host has been assigned the correct IP address, but port 22 is still closed.
The IP line in /etc/initramfs-tools/intiramfs.conf I am using is:
export IP=192.168.1.200::192.168.1.1:255.255.255.0::eth0:off
Consistent with the directions in /usr/share/doc/cryptsetup/README.remote.gz I have tried just adding the device option, but that is not sufficient to bring the network up and obtain a dhcp lease.
Update 11/10/14
Karl's answer was what was required: setting up /etc/initramfs-tools/conf.d/cryptroot was the key:
target=md1_crypt,source=UUID=8570d12k-ccha-4985-s09f-e43dhed9fa2a
This guide also proved more up-to-date and relevant (and successful).
|
I got this same problem a few weeks ago (Debian Wheezy 7.6) and after some days of troubleshooting I found out that there was a config file missing which was preventing to the cryptroot script on init-top to run correctly, hence it was not stopping to ask the password via ssh, killing the dropbear at the end of the sequence (init-bottom).
The config file is called cryptroot and should be under /etc/initramfs-tools/conf.d/
If I am not mistaken that config file should have been created automatically during install (I have read just one tutorial talking about that config file) but somehow it did not (tested in a physical server and in a VM, same OS and versions)
It took me a couple of tries to configure it properly, since I could not find the proper syntax at that time. My cryptroot config file is as follows:
target=crypt-root,source=/dev/vg0/root,lvm=root
Once created the config file just update the initramfs and try again:
update-initramfs -u
| How to open a port early in boot process to unlock LUKS via SSH |
1,478,232,523,000 |
When using LUKS full disk encryption, how would you go about protecting against evil maids ?
The evil maid attack is when someone gets physical access to your computer while you're away and compromises the unencrypted /boot partition to capture your FDE password the next time you start your computer
One of the solutions is to leave your /boot partition on an USB stick that's always with you (the maid can't get to it), but which filesystem should I use on it, and how do I configure my system to gracefully handle removal of the USB stick (and thus the /boot partition itself) ?
I'm using CentOS, but generic, distro-agnostic answers are of course welcome. Thanks.
|
Finally figured it out. This still feels really hacky and dirty because the system is never aware that /boot may not be mounted and you'll have to manually mount it before doing anything that might write to it (think system updates, etc), but other than that it works perfectly.
prepare your flash drive with a single partition with the boot flag set on it. You may run shred -n 1 -v /dev/sdX on it to erase it completely, including any previous boot sectors; once that's done run fdisk to create a partition and mkfs your filesystem of choice on it.
mount your flash drive somewhere, /mnt/boot or even /newboot will do just fine.
move over everything from /boot to the flash drive with mv /boot/* /newboot.
edit your /etc/fstab and change the original boot partition's UUID (or create an entry if there isn't any) to match the one of your flash drive. You can get the UUID with lsblk -o name,uuid. Also add the noauto option so that the drive won't be mounted automatically to be able to remove it as soon as the system starts booting (once the kernel is loaded) without risking corrupting the FS on it.
unmount the original boot partition and the flash drive (umount /boot && umount /newboot) and mount the flash drive; if your fstab entry is correct you can just run mount /boot and it'll automatically mount it based on the UUID specified in the fstab.
regenerate your bootloader's configuration to reflect the new partition's UUIDs and "physical" position, for GRUB the flash drive will actually appear as the first hard drive in the computer (hd0). If you're okay with using the default GRUB configuration scripts supplied by most distros, you can run grub-mkconfig -o /path/to/grub.cfg and it'll generate the file according to the currently mounted partitions and/or fstab. Note that for CentOS 7, the correct grub.cfg is actually located in /boot/grub2/grub.cfg.
When doing any operation that may access the boot partition, connect your USB stick and run mount /boot. Once done, you may run umount /boot. Note that the latter command can take moments to complete because it's flushing the buffers to the disk (the disk itself is slow so the kernel buffers some write operations to speed things up).
| Defending against the evil maid, how to handle removal of the /boot partition |
1,478,232,523,000 |
I'm having problems unlocking a luks-encrypted disk with KDE dolphin, in a system with manjaro.
The issue is not critical. It can be solved by rebooting, but sometimes it is not convenient to do so, and I find that it might be useful to understand why this problem appears in the first place.
So the first time I unlock the device after a reboot everything is fine. If I unmount the system, next times will also be ok. The problem is that sometimes, I connect the device, and after entering the password I get the following error:
An error occurred while accessing 'Home', the system responded: The requested operation has failed: Error unlocking /dev/sdxy: Failed to activate device: File exists
But this file cannot be seen with df -h, and it is not mounted via /etc/fstab, it is always mounted and unlocked when connected. The command fuser won't show anything relevant, and lsof only returns:
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
Output information may be incomplete.
lsof: WARNING: can't stat() fuse file system /run/user/1000/doc
Output information may be incomplete.
In fact, I see some processes using this folder (ps aux | grep 1000), but do not know whether this actually helps to solve the problem.
1779 ? Sl 0:03 /usr/lib/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
1847 ? S 0:03 file.so [kdeinit5] file local:/run/user/1000/klaunchermRxLKs.1.slave-socket local:/run/user/1000/kded5IKggHu.1.slave-socket
23434 ? S 0:00 file.so [kdeinit5] file local:/run/user/1000/klauncherDwiyfV.1.slave-socket local:/run/user/1000/dolphinaVwzoi.58.slave-socket
I suspect killing these processes might help, but do not know if it's safe (cannot risk to do so right know, not without knowing). Any ideas?
EDIT: Output for dmsetup info and dmsetup table:
dmsetup info
Name: luks-92bde790-5ca6-441b-bad3-5c3163292c8b
State: ACTIVE
Read Ahead: 256
Tables present: LIVE
Open count: 0
Event number: 0
Major, minor: 254, 1
Number of targets: 1
UUID: CRYPT-LUKS1-92bde7905ca6441bbad35c3163292c8b-luks-92bde790-5ca6-441b-bad3-5c3163292c8b
Name: luks-1f919383-2d4a-44e2-b28e-21bffd11dd6c
State: ACTIVE
Read Ahead: 256
Tables present: LIVE
Open count: 1
Event number: 0
Major, minor: 254, 0
Number of targets: 1
UUID: CRYPT-LUKS1-1f9193832d4a44e2b28e21bffd11dd6c-luks-1f919383-2d4a-44e2-b28e-21bffd11dd6c
dmsetup table
luks-92bde790-5ca6-441b-bad3-5c3163292c8b: 0 4294963200 crypt aes-xts-plain64 0000000000000000000000000000000000000000000000000000000000000000 0 8:33 4096
luks-1f919383-2d4a-44e2-b28e-21bffd11dd6c: 0 3906401473 crypt aes-xts-plain64 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0 8:2 4096
|
If, after looking at the output of dmsetup ls you find that you have stale devices you can remove them with dmsetup remove – ideally after carefully verifying that the device is indeed not in use.
I had the same problem and after doing so I was able to unlock and mount my encrypted USB hard disk again:
# dmsetup ls --tree
luks-f53274db-3ede-4a27-9aa6-2525d9305f94 (254:5)
`- (8:34)
# ls -l /dev/mapper/
total 0
crw------- 1 root root 10, 236 Nov 24 15:22 control
lrwxrwxrwx 1 root root 7 Nov 27 09:42 luks-f53274db-3ede-4a27-9aa6-2525d9305f94 -> ../dm-5
# dmsetup remove /dev/dm-5
| Error unlocking a LUKS partition (failed to activate device:file exists) |
1,478,232,523,000 |
In what I now know feel was a stupid decision, I attempted to dual boot Windows and linux by using the windows installer, After booting into the windows installer I chose one of a 2 cloned hard drives about 500GB in size to erase, as they were cloned it wouldn't matter if I picked one over the other.
After doing so, the installer said it changed the partition table for one of the 500GB hard drives and then failed to install windows. Crashing with an error without copying files, or so it says, I am unsure if I can trust it when it says it failed to even begin installing.
So I booted into my linux install to check which drive it had overwritten and manually install it. What greeted me instead was one of my other drives, a 6TB dm-luks and btrfs drive, missing. Not only were both 500GB drives untouched, but the 6TB drive had seemingly a mess of partitions added to it. 6 partitions in the order of 499M, 99M, 499M, 100M, 499M, 100M.
As my drive is quite large and additionally slow, running hexdump -C /dev/sda |grep LUKS has so far produced this much, I will update when it finishes:
8d411ce0 e1 ad 4c 55 4b 53 c0 85 22 3d de 49 dd 44 fd 08 |..LUKS.."=.I.D..|
e6449610 d5 cf 4a 86 9f cc 4c 55 4b 53 a9 a9 16 cc ba 1d |..J...LUKS......|
446ea9a70 b3 db a9 bf 8b 2e 41 4c 55 4b 53 ef f0 75 b0 18 |......ALUKS..u..|
4732c6040 e0 b3 bb ff 4c 55 4b 53 4c c2 5b 12 c6 41 fc d6 |....LUKSL.[..A..|
So far the only thing that has even touched the disk since this has happened is hexdump, I am hesitant to run testdisk as I have heard it overwrites data on the drive and it does not list luks as something it can search for.
I can see others have used hexdump to check for intact headers, however, I do not know what exactly I am looking for.
What can I do at this point to see if I can recover any bit of the header. Is there a way to run testdisk or another tool to look for luks headers in order to tell if they've been overwritten? Any way that allows me to know whether everything is FUBAR or not is equally as welcome as a way to recover my data.
EDIT
Running hexdump on the first bit of the drive without grep shows that there's at least some intact JSON, from 00005000 to 00005310 shows as much, I am even less sure what I am specifically looking for now to know if its still intact. It seems it overwrote data up until this exact string.
00005000 7b 22 6b 65 79 73 6c 6f 74 73 22 3a 7b 22 30 22 |{"keyslots":{"0"|
00005010 3a 7b 22 74 79 70 65 22 3a 22 6c 75 6b 73 32 22 |:{"type":"luks2"|
Cutting out the data in-between because it includes the salt, but the block ends in:
000052f0 22 2c 22 6b 65 79 73 6c 6f 74 73 5f 73 69 7a 65 |","keyslots_size|
00005300 22 3a 22 31 36 37 34 34 34 34 38 22 7d 7d 00 00 |":"16744448"}}..|
00005310 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
It it intact enough?
|
cryptsetup repair, Part Two — Full Header Recovery
See also: cryptsetup repair, Part One — Magic Bytes Recovery
In order to recover a partially overwritten LUKS2 header, you need at minimum two things: One, the key material of at least one of your keyslots. Two, the metadata describing how that key material is to be used (algorithm, iteration counts, salts, etc.).
The key material is roughly 256KB of random data, usually found at offset 32768 (0x8000) and beyond, however the exact offset and size has to be determined from metadata.
The metadata is a JSON string, usually found at offsets 4096 (0x1000) and 20480 (0x5000). LUKS2 maintains two identical copies of it (primary and secondary header). The key material itself exists only once.
If the partition table itself is also lost, you'll also have to determine the correct partition offset.
Setup:
# truncate -s 128M disk.img
# losetup --find --show --partscan disk.img
/dev/loop0
# parted /dev/loop0 -- mklabel gpt
# parted /dev/loop0 -- mkpart luks $((RANDOM%100))MiB 100%
# cryptsetup luksFormat --type luks2 /dev/loop0p1
WARNING!
========
This will overwrite data on /dev/loop0p1 irrevocably.
Are you sure? (Type 'yes' in capital letters): YES
Enter passphrase for /dev/loop0p1:
Verify passphrase:
# cryptsetup open /dev/loop0p1 luks
Enter passphrase for /dev/loop0p1:
# mkfs.ext2 -L encrypted /dev/mapper/luks
# blkid /dev/mapper/luks
/dev/mapper/luks: LABEL="encrypted" […] TYPE="ext2"
A shiny new encrypted filesystem!
Damage:
# cryptsetup close luks
# wipefs -a /dev/loop0p1
/dev/loop0p1: 6 bytes were erased at offset 0x00000000 (crypto_LUKS): 4c 55 4b 53 ba be
/dev/loop0p1: 6 bytes were erased at offset 0x00004000 (crypto_LUKS): 53 4b 55 4c ba be
# dd count=32 if=/dev/urandom of=/dev/loop0p1
32+0 records in
32+0 records out
16384 bytes (16 kB, 16 KiB) copied, 0.000334077 s, 49.0 MB/s
# wipefs -a /dev/loop0
/dev/loop0: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/loop0: 8 bytes were erased at offset 0x063ffe00 (gpt): 45 46 49 20 50 41 52 54
/dev/loop0: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
/dev/loop0: calling ioctl to re-read partition table: Success
# losetup -d /dev/loop0
So this is a disk.img with a LUKS2 partition at an unknown offset, with a damaged header on it (magic bytes erased, partially overwritten, partition table wiped).
Metadata recovery:
Since the LUKS2 JSON string is plain ASCII, it can be found with strings, which will also show the offset:
# stdbuf -oL strings -n 64 -t d disk.img | grep '"keyslots":'
60837888 {"keyslots":{"0":{"type":"luks2","key_size":64,"af":{"type":"luks1","stripes":4000,"hash":"sha256"},"area":{"type":"raw","offset":"32768","size":"258048","encryption":"aes-xts-plain64","key_size":64},"kdf":{"type":"argon2id","time":13,"memory":1048576,"cpus":4,"salt":"R1z3arzSCjRb3STaCAnstIygkHCXf0CHf6kXl5yQj/E="}}},"tokens":{},"segments":{"0":{"type":"crypt","offset":"16777216","size":"dynamic","iv_tweak":"0","encryption":"aes-xts-plain64","sector_size":512}},"digests":{"0":{"type":"pbkdf2","keyslots":["0"],"segments":["0"],"hash":"sha256","iterations":324435,"salt":"0nSkpvmDJlvfkDaQteVVo6JdD/Oqt3vnndkZt1Qnd84=","digest":"lefQ21EaiuSdHFhSIFW3wDfMcRqG0HLCAO1bGI3SfvM="}},"config":{"json_size":"12288","keyslots_size":"16744448"}}
So here we have an intact JSON string at offset 60837888. Copy&Paste it into a header.json file. The file should start with { and end with }. You can use jq to make sure it's indeed a valid JSON string, and also to show it in a more human-readable form:
# jq < header.json
{
"keyslots": {
"0": {
"type": "luks2",
[…]
}
}
Partition recovery:
The offset of the JSON metadata within the LUKS2 header is usually either 4096 or 20480, depending on whether it's the primary or secondary header. You have to substract these values from the offset that strings found earlier.
Thus, the correct partition offset in this case could be either 60837888 - 4096 = 60833792 = 58.02MiB or 60837888 - 20480 = 60817408 = 58 MiB. Since the latter is MiB aligned, it's the more likely candidate for the correct partition offset.
If in doubt, try both.
Key material recovery:
According to the JSON metadata, this LUKS2 header has a single keyslot and its key material is to be found at "offset":"32768","size":"258048". Let's grab it with dd:
# partition=60817408
# offset=32768
# size=258048
# dd bs=1 skip=$((partition+offset)) count=$((size)) if=disk.img of=header.$((offset))
If there are multiple keyslots, repeat this process for each of them.
The key material is supposed to look like random data. To verify this, you could look at the whole thing with hexdump -C.
# hexdump -C header.32768
00000000 f1 3b 23 73 98 d7 8f e3 22 24 9a 9d 5a 2c a9 ae |.;#s...."$..Z,..|
00000010 95 82 3e c6 df e7 0e a0 f4 ba 54 6c 7f e9 fa f6 |..>.......Tl....|
00000020 b7 12 64 8d 7d a5 ca 4b c8 89 89 08 3e de 59 0d |..d.}..K....>.Y.|
[…]
0003efe0 b2 b3 bc cd de 60 17 a7 57 bb 1a 84 5a 15 68 95 |.....`..W...Z.h.|
0003eff0 7f 1f 07 ee ee d1 e8 a2 6c cf 5f 40 0b 73 00 0b |[email protected]..|
0003f000
Or you could try to compress it and see if the compressed result is any smaller:
# gzip < header.32768 > header.32768.gz
# stat -c %s header.*
258048
258106
Random data usually can't be compressed at all, so if the gzipped version isn't any smaller (or even a few bytes larger), there's a good chance that the whole thing is random data.
True verification is only possible at the very end — when it accepts your passphrase, or not.
Full Header Recovery:
After you've collected the necessary ingredients above, you can attempt rebuilding a full header from them:
# truncate -s 16M luks.recovery
# cryptsetup luksFormat --type luks2 luks.recovery
# cryptsetup luksErase luks.recovery
Use cryptsetup produce a valid, albeit unusable header without keyslots. The purpose here is to obtain a file that is set up with all the correct magic bytes, UUIDs, etc. — unrelated to encryption, but it's what makes a LUKS header a LUKS header.
Now transplant your metadata onto it:
# printf "%s\0" "$(jq -c < header.json)" |
dd conv=notrunc bs=1 seek=4096 of=luks.recovery
# printf "%s\0" "$(jq -c < header.json)" |
dd conv=notrunc bs=1 seek=20480 of=luks.recovery
As well as the key material:
# dd conv=notrunc bs=1 seek=32768 if=header.32768 of=luks.recovery
At this point, we'd finally be done, except:
# cryptsetup luksDump luks.recovery
Device luks.recovery is not a valid LUKS device.
# cryptsetup repair luks.recovery
Device luks.recovery is not a valid LUKS device.
Checksum recovery:
Ehhh, what's wrong now? Add --debug to find out:
# cryptsetup luksDump --debug luks.recovery
[…]
# LUKS2 header version 2 of size 16384 bytes, checksum sha256.
# Checksum:5babf58f0f788911897989ff3d9a580de1c22db8869b3b08cd0d6d56906005cb (on-disk)
# Checksum:b2ff5dd7b53978723402103ba914ed87ef2c5b5d9a9062d68363e4df38aebf6f (in-memory)
[…]
LUKS2 has a checksum for its primary and secondary headers. Since we modified the JSON metadata without updating the checksum, it's a mismatch. Thankfully, cryptsetup shows the expected value so we don't have to calculate it manually.
This checksum is part of the binary header, so you have to use xxd -r -p to convert it to binary:
# echo 5babf58f0f788911897989ff3d9a580de1c22db8869b3b08cd0d6d56906005cb | xxd -r -p | hexdump -C
00000000 5b ab f5 8f 0f 78 89 11 89 79 89 ff 3d 9a 58 0d |[....x...y..=.X.|
00000010 e1 c2 2d b8 86 9b 3b 08 cd 0d 6d 56 90 60 05 cb |..-...;...mV.`..|
00000020
# echo b2ff5dd7b53978723402103ba914ed87ef2c5b5d9a9062d68363e4df38aebf6f | xxd -r -p | hexdump -C
00000000 b2 ff 5d d7 b5 39 78 72 34 02 10 3b a9 14 ed 87 |..]..9xr4..;....|
00000010 ef 2c 5b 5d 9a 90 62 d6 83 63 e4 df 38 ae bf 6f |.,[]..b..c..8..o|
00000020
Replace the wrong on-disk checksum with the correct in-memory checksum:
# hexdump -C luks.recovery | grep '5b ab f5 8f 0f 78 89 11'
000001c0 5b ab f5 8f 0f 78 89 11 89 79 89 ff 3d 9a 58 0d |[....x...y..=.X.|
# echo b2ff5dd7b53978723402103ba914ed87ef2c5b5d9a9062d68363e4df38aebf6f |
xxd -r -p |
dd conv=notrunc bs=1 seek=$((0x000001c0)) of=luks.recovery
And that should allow things to proceed.
# cryptsetup repair luks.recovery
# cryptsetup luksDump luks.recovery
LUKS header information
Version: 2
[…]
Wrapping things up:
# losetup --find --show --read-only --offset 60817408 disk.img
/dev/loop0
# cryptsetup open --read-only --header luks.recovery /dev/loop0 luksrecovery
Enter passphrase for /dev/loop0:
# blkid /dev/mapper/luksrecovery
/dev/mapper/luksrecovery: LABEL="encrypted" […] TYPE="ext2"
Done. Finally.
| Overwritten LUKS with a partition table |
1,478,232,523,000 |
I have read:
Resize LUKS Volume(s)
Increase the size of a LUKS encrypted partition
Resizing LVM-on-LUKS
And others.
I'm trying to resize from 250 GB to 500 GB. Previously, the partition /dev/sda2, was 250 GB, I've now resized the partition to 500 GB.
However, what about the LUKS device, which resides at /dev/sda2? How do I resize that?
Well, the manual (for cryptsetup) provides us with "resize". However, when I check with cryptsetup status, my device is already 500 GB.
Furthermore, when I check in parted, it (the encrypted device /dev/dm-0 or /dev/mapper/cryptdevice which is a symlink) also shows up as 500 GB.
It appears my encrypted device is already the correct size!
Why then, when I actually mount the encrypted device (/dev/mapper/cryptdevice), does it show up as 250 GB?
Did I miss a step? What else do I need to do?
I've obviously rebooted many times between doing this. I've started from a bootable USB device, executed cryptsetup, rebooted, etc. It still shows up as 250 GB, when I would expect it to be 500 GB.
Note that I never actually resized anything beyond the partition itself. After resizing the partition, cryptsetup and parted started reporting the encrypted volume as also being resized -- but again, when I mount it, it is still only 250 GB.
I don't have LVM on top of this, I just have:
/dev/sda2, which contains a LUKS encrypted file system. I open this with cryptsetup luksOpen /dev/sda2 cryptdevice, etc.
|
You still have to resize the filesystem using the resized block device. The precise method and possible limitations depend on each filesystem.
Here are two examples to resize the filesystems to the whole available size for EXT4 and XFS. An other filesystem will require an other specific command.
An EXT4 filesystem can be enlarged online or offline (and can also be shrunk, but only offline).
resize2fs /dev/mapper/cryptdevice
An XFS filesystem can only be enlarged, and online (can't be shrunk back once done).
The filesystem must be mounted to be grown. The command requires the mountpoint rather than the block device.
mount -t xfs /dev/mapper/cryptdevice /mnt
xfs_growfs /mnt
You actually missed this step twice from the links:
Resize LUKS Volume(s)
in the question:
# Step 5: Resize encrypted volume (Trying to give it some space)
> resize2fs -p /dev/CryptVolumeGroup/root 101G
but in the answer:
Enlarge the rootfs logical volume. No need to un-mount since ext4 and
be enlarged while mounted: lvresize -r -L +100G archvg/home
lvresize -r resizes automatically the underlying filesystem, hence no specific command in the answer. Resizing the filesystem for your specific case not using LVM wasn't present in this answer.
Increase the size of a LUKS encrypted partition
As a final step, the file-system needs to be expanded to the new size.
With the resize2fs(8) command the file-system is extended to the new
size of the LUKS volume.
$ sudo resize2fs /dev/mapper/sdb1_crypt
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/sdb1_crypt is mounted on /media/gerhard/Daten; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/mapper/sdb1_crypt is now 14647925 (4k) blocks long.
Resizing LVM-on-LUKS
Resizing the encrypted volume
Now we are going to resize the encrypted volume itself. By taking in
account the total size of the logical volume minus some safety space:
# resize2fs -p /dev/CryptVolumeGroup/Home 208G
| How to resize a LUKS device, revisited |
1,478,232,523,000 |
I'm debugging a weird behavior of cryptsetup:
Assume the correct password is stored in the file pw. I expected now that --test-passphrase would always succeed (i.e. printing no output) if it is passed in as stdin. But it turns out that it randomly fails:
# cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2 < pw
# cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2 < pw
No key available with this passphrase.
# cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2 < pw
# cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2 < pw
No key available with this passphrase.
# cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2 < pw
# cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2 < pw
No key available with this passphrase.
# cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2 < pw
# cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2 < pw
# cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2 < pw
No key available with this passphrase.
I noticed it, since I constantly fail multiple times to unlock my partition at boot (in GRUB). First, I thought I'm mistyping it, but now I get the impression that it might be a bug in cryptsetup. I also fail to unlock it consistently later (not in GRUB), even if I'm copy-pasting the correct password.
Note that it also differs when I pass it through this (mostly equivalent) way:
# cat pw | cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2
No key available with this passphrase.
# cat pw | cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2
No key available with this passphrase.
# cat pw | cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2
# cat pw | cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2
No key available with this passphrase.
# cat pw | cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2
No key available with this passphrase.
# cat pw | cryptsetup luksOpen --test-passphrase /dev/nvme0n1p2
No key available with this passphrase.
Here all but one attempt failed. While the other approach succeeds more often. That behavior is reproducible for me: it always fails more often.
# cryptsetup --version
cryptsetup 2.6.1 flags: UDEV BLKID KEYRING KERNEL_CAPI
# cryptsetup luksDump /dev/nvme0n1p2
LUKS header information
Version: 2
Epoch: 5
Metadata area: 16384 [bytes]
Keyslots area: 16744448 [bytes]
UUID: 2372e472-ef96-428f-b971-f68fb0c35b63
Label: (no label)
Subsystem: (no subsystem)
Flags: (no flags)
Data segments:
0: crypt
offset: 16777216 [bytes]
length: (whole device)
cipher: aes-xts-plain64
sector: 512 [bytes]
Keyslots:
0: luks2
Key: 512 bits
Priority: normal
Cipher: aes-xts-plain64
Cipher key: 512 bits
PBKDF: argon2id
Time cost: 13
Memory: 1048576
Threads: 4
Salt: ea b0 88 ...
f3 f9 72 ...
AF stripes: 4000
AF hash: sha256
Area offset:32768 [bytes]
Area length:258048 [bytes]
Digest ID: 0
Tokens:
Digests:
0: pbkdf2
Hash: sha256
Iterations: 334367
Salt: f0 ac 44 ...
f3 6f d5 ...
Digest: cd a8 ...
23 2a ...
$ uname -a
Linux amd12 6.3.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 11 May 2023 16:40:42 +0000 x86_64 GNU/Linux
(OS: Arch Linux)
Eventually, I can always unlock, but I need many attempts, which is annoying. Looks like the verification code or the mechanism to read the input is flaky.
I wonder if it is a known problem (though I haven't found anything about it)? If not, is there a way to debug? Unfortunately, I saw no option to get any visual feedback (I think, it is considered a security flaw to reveal the password length).
Update: Just realized that there is a --debug option. Though the output of a successful and failing run are identical till the point where the computation happens. All headers and checksums in the debug log are the same.
Also, it shows the same behavior with cryptsetup 2.4.3 on a Linux Mint Live CD.
|
@frostschutz was correct. It turns out that the memory on my machine shows errors in a Memtest86+ run.
The most likely explanation is that the computation works or fails depending on what part of the RAM is being used. And Argon2 - now the default for key derivation - uses a lot of memory during the computation.
But it is not the fault of cryptsetup. Now, I tested again with only one memory block that passed at least one run of Memtest86+. It is no longer reproducible. Both versions (< pwand cat pw |) are now always passing.
Update: I did more testing with removing RAM slots. Interestingly, it works with individual slots, but in combination it becomes unreliable. The machine itself is new, but I saw that XMP (Extreme Memory Profile) was enabled. From what I read, it is a reasonable safe default on new hardware, but on my machine it seems to cause the issues. After disabling it, it works now.
Perhaps they should include Argon2 in memtest86+. On my system, it is great to detect memory issues.
| cryptsetup: verification in luksOpen is non-deterministic when reading the password from a file |
1,478,232,523,000 |
Is it possible to convert LUKS2 to LUKS version 1, and by extension, change the use of features that would block such a conversion?
Fedora 30 uses LUKS2 by default, however I ran into a situation where I need to stick with LUKS version 1. Specifically, Relax-and-Recover (rear) does not support LUKS2 at the moment.
Documentation mentions that converting between LUKS2 and LUKS1 is possible under certain conditions:
In-place conversion form LUKS1
To allow easy testing and transition to the new LUKS2 format, there
is a new convert command that allows in-place conversion from the
LUKS1 format and, if there are no incompatible options, also
conversion back from LUKS2 to LUKS1 format.
Note this command can be used only on some LUKS1 devices (some
device header sizes are not supported). This command is dangerous,
never run it without header backup! If something fails in the middle
of conversion (IO error), the header is destroyed. (Note that
conversion requires move of keyslot data area to a different
offset.)
To convert header in-place to LUKS2 format, use
$ cryptsetup convert --type luks2
To convert it back to LUKS1 format, use
$ cryptsetup convert --type luks1
You can verify LUKS version with luksDump command.
$ cryptsetup luksDump
Note that some LUKS2 features will make header incompatible with
LUKS1 and conversion will be rejected (for example using new
Argon2 PBKDF or integrity extensions). Some minor attributes can
be lost in conversion.
That last point is a problem as it seems that feature is used by default at least on Fedora.
$ sudo cryptsetup convert /dev/sda3 --type luks1
WARNING!
========
This operation will convert /dev/sda3 to LUKS1 format.
Are you sure? (Type uppercase yes): YES
Cannot convert to LUKS1 format - keyslot 0 is not LUKS1 compatible.
$ sudo cryptsetup luksDump /dev/sda3
LUKS header information
Version: 2
Epoch: 3
Metadata area: 16384 [bytes]
Keyslots area: 16744448 [bytes]
UUID: 974b19f8-021a-46b6-a089-a46e06e6e746
Label: (no label)
Subsystem: (no subsystem)
Flags: (no flags)
Data segments:
0: crypt
offset: 16777216 [bytes]
length: (whole device)
cipher: aes-xts-plain64
sector: 512 [bytes]
Keyslots:
0: luks2
Key: 512 bits
Priority: normal
Cipher: aes-xts-plain64
Cipher key: 512 bits
PBKDF: argon2i
Time cost: 4
Memory: 973984
Threads: 4
Salt: af 33 7e 3b 6c bb 55 dc e3 dc 2b 07 c5 9e c3 6d
f2 c9 08 be 2f 1d 8b 78 8a 33 65 90 41 e3 05 10
AF stripes: 4000
AF hash: sha256
Area offset:32768 [bytes]
Area length:258048 [bytes]
Digest ID: 0
Tokens:
Digests:
0: pbkdf2
Hash: sha256
Iterations: 100361
Salt: d9 30 b6 7f 60 d0 e0 19 39 f6 a2 38 ae 22 88 43
1e 5c 74 75 e6 b5 dd db a9 e7 29 1a 74 64 9c 0f
Digest: ae 06 29 5f 71 49 bd c8 75 de 53 e8 95 94 d3 38
57 43 5f 0e 1e ac 6d 59 fb 34 a3 97 e4 5a 94 0c
|
Converting LUKS1 to LUKS2, then back to LUKS1 works just fine. It's starting out with LUKS2 then converting to LUKS1 that causes problems. Apparently, cryptsetup convert is unable to convert between LUKS2 argon2i keys and LUKS1 pbkdf2 keys.
Setup:
# truncate -s 100M luks1.img
# truncate -s 100M luks2.img
# cryptsetup luksFormat --type luks1 luks1.img
# cryptsetup luksFormat --type luks2 luks2.img
Test with originally luks1:
# cryptsetup convert luks1.img --type luks2
WARNING!
========
This operation will convert luks1.img to LUKS2 format.
Are you sure? (Type uppercase yes): YES
# cryptsetup convert luks1.img --type luks1
WARNING!
========
This operation will convert luks1.img to LUKS1 format.
Are you sure? (Type uppercase yes): YES
We've got LUKS1 -> LUKS2 -> LUKS1 working.
Test with originally luks2:
# cryptsetup convert luks2.img --type luks1
WARNING!
========
This operation will convert luks2.img to LUKS1 format.
Are you sure? (Type uppercase yes): YES
Cannot convert to LUKS1 format - keyslot 0 is not LUKS1 compatible.
Same story for the originally luks1.img, if you add another key while in LUKS2 format.
But since we're able to add argon2i keys to originally luks1, perhaps we can add pbkdf key to originally luks2? There were some weird issues with that, too, but after some trial and error, I ended up with:
# cryptsetup luksConvertKey --pbkdf=pbkdf2 luks2.img
Enter passphrase for keyslot to be converted: I have a sudden craving for butternut biscuits.
And then it works (provided that was the only key).
# cryptsetup convert luks2.img --type luks1
WARNING!
========
This operation will convert luks2.img to LUKS1 format.
Are you sure? (Type uppercase yes): YES
But it's not quite the same as the originally LUKS1 header (in particular, Payload offset: 32768 stands out). Now, LUKS1 changed their data offset before (originally it was not MiB aligned) so third-party software should be able to handle unusual offsets, but you never know.
LUKS2 also has other features that make conversions impossible (without oldfashioned re-encrypting) so the method described here only covers the most simple case.
| Convert LUKS2 back to LUKS version 1 |
1,478,232,523,000 |
I want to extend my LUKS-encrypted lvm (volume group) with a new physical volume.
In my previous question I was told - in respect to my actual setup - that I need to encrypt the new physical volume prior to add it to my existing volume group.
I would like to know what steps I have to respect, to successfully add that physical volume to my existing volume group.
My actual stacking looks like this:
nvme0n1p8 -> luks -> physical volume -> volume group -> lv
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
├─nvme0n1p8 259:8 0 86,5G 0 part
│ └─nvme0n1p8_crypt 253:0 0 86,5G 0 crypt
│ ├─lvm--crypt-wurzel 253:1 0 30,7G 0 lvm /
│ ├─lvm--crypt-home 253:2 0 80G 0 lvm /home
My crypttab file looks like this:
cat /etc/crypttab
nvme0n1p8_crypt UUID=1697ec4a-b30b-4642-b4f3-6ba94afc40ec none luks,discard
Now I want to add a new physical volume to that volume group.
How do I add a new physical volume to that volume group without losing encryption?
What modifications to which configuration file might I need to do?
|
You’ll need to set up encryption on the new physical device:
sudo cryptsetup luksFormat /dev/newdevice
(replacing newdevice as appropriate).
Then open it:
sudo cryptsetup luksOpen /dev/newdevice newdevice_crypt
You’ll need to add a matching line to /etc/crypttab so that it’s opened at boot, and update your initramfs using the appropriate command for your distribution (e.g. sudo update-initramfs -c -k all on Debian derivatives).
Once you have newdevice_crypt, you can create a physical volume on it:
sudo pvcreate /dev/newdevice_crypt
or
sudo pvcreate /dev/mapper/newdevice_crypt
and add it to your volume group:
sudo vgextend lvm /dev/mapper/newdevice_crypt
(replacing lvm with the name of the volume group).
You can share the passphrase for several encrypted devices; see Using a single passphrase to unlock multiple encrypted disks at boot.
| How can I add a new physical volume to extend an existing LUKS-encrypted lvm (volume group) and maintain encryption? |
1,478,232,523,000 |
I am working on my yocto distribution including cryptsetup in the 2.3.2 version
I am running such distribution on a board with 1 GB RAM and I am incurring in an "out of memory" error trying to open an encrypted partition that I am not able to properly debug. Any ideas?
My distro runs from an mSD with 3 partitions; the third one (30 MB) is the encrypted one.
I used the steps described on the ArchLinux guide to encrypt that partition, with ext3 instead of ext4
# cryptsetup -y -v luksFormat /dev/sda2
# cryptsetup open /dev/sda2 cryptroot
# mkfs.ext3 /dev/mapper/cryptroot
But trying to open that partition on my board raises an error:
cryptsetup --debug open /dev/mmcblk0p3 cryptroot
# cryptsetup 2.3.2 processing "cryptsetup --debug open /dev/mmcblk0p3 cryptroot"
# Running command open.
# Locking memory.
# Installing SIGINT/SIGTERM handler.
# Unblocking interruption on signal.
# Allocating context for crypt device /dev/mmcblk0p3.
# Trying to open and read device /dev/mmcblk0p3 with direct-io.
# Initialising device-mapper backend library.
# Trying to load any crypt type from device /dev/mmcblk0p3.
# Crypto backend (OpenSSL 1.1.1k 25 Mar 2021) initialized in cryptsetup library version 2.3.2.
# Detected kernel Linux 4.1.35-rt41 ppc.
# Loading LUKS2 header (repair disabled).
# Acquiring read lock for device /dev/mmcblk0p3.
# Opening lock resource file /run/cryptsetup/L_179:3
# Verifying lock handle for /dev/mmcblk0p3.
# Device /dev/mmcblk0p3 READ lock taken.
# Trying to read primary LUKS2 header at offset 0x0.
# Opening locked device /dev/mmcblk0p3
# Veryfing locked device handle (bdev)
# LUKS2 header version 2 of size 16384 bytes, checksum sha256.
# Checksum:43e122216ab19330fdfb6d2f9d7b586c4e5189884aef24be884e7159228e9ee5 (on-disk)
# Checksum:43e122216ab19330fdfb6d2f9d7b586c4e5189884aef24be884e7159228e9ee5 (in-memory)
# Trying to read secondary LUKS2 header at offset 0x4000.
# Reusing open ro fd on device /dev/mmcblk0p3
# LUKS2 header version 2 of size 16384 bytes, checksum sha256.
# Checksum:4ed9a44c22fde04c4b59a638c20eba6da3a13e591a6a1cfe7e0fec4437dc14cc (on-disk)
# Checksum:4ed9a44c22fde04c4b59a638c20eba6da3a13e591a6a1cfe7e0fec4437dc14cc (in-memory)
# Device size 32505856, offset 16777216.
# Device /dev/mmcblk0p3 READ lock released.
# Only 1 active CPUs detected, PBKDF threads decreased from 4 to 1.
# Not enough physical memory detected, PBKDF max memory decreased from 1048576kB to 255596kB.
# PBKDF argon2i, time_ms 2000 (iterations 0), max_memory_kb 255596, parallel_threads 1.
# Activating volume cryptroot using token -1.
# Interactive passphrase entry requested.
Enter passphrase for /dev/mmcblk0p3:
# Activating volume cryptroot [keyslot -1] using passphrase.
device-mapper: ioctl: 4.31.0-ioctl (2015-3-12) initialised: [email protected]
# dm version [ opencount flush ] [16384] (*1)
# dm versions [ opencount flush ] [16384] (*1)
# Detected dm-ioctl version 4.31.0.
# Device-mapper backend running with UDEV support enabled.
# dm status cryptroot [ opencount noflush ] [16384] (*1)
# Keyslot 0 priority 1 != 2 (required), skipped.
# Trying to open LUKS2 keyslot 0.
# Keyslot 0 (luks2) open failed with -12.
Not enough available memory to open a keyslot.
# Releasing crypt device /dev/mmcblk0p3 context.
# Releasing device-mapper backend.
# Closing read only fd for /dev/mmcblk0p3.
# Unlocking memory.
Command failed with code -3 (out of memory).
|
LUKS2 uses Argon2i key derivation function which is memory-hard -- meaning it requires a lot of memory to open the device to prevent (or at least make it harder) brute force attacks using GPUs. You can check how much memory you need to open your device using cryptsetup luksDump /dev/sda2, look for the line Memory: 755294 under Keyslots.
When creating the device, cryptsetup checks how much memory is available and adjusts the amount required for opening it accordingly, but if you did create the LUKS device from a different computer (for example when formatting the SD card on a desktop) or even on the same machine with more memory available, it's possible you simply don't have enough memory now. And we are talking only about RAM, swap is not used in this case.
I recommend re-creating the LUKS device with --pbkdf pbkdf2 to switch to the "old" (used to be default in LUKS1) key derivation function PBKDF2 which doesn't use extra memory. Alternatively you can also use --pbkdf-memory <num> to force lower amount of memory for the default Argon2i.
| Open: cryptsetup out of memory ("Not enough available memory to open a keyslot.") |
1,478,232,523,000 |
I have used GRUB_ENABLE_CRYPTODISK=y in /etc/default/grub to allow LUKS encryption of everything except my EFI partition, which I mount to /boot/efi. This works fine. The only admittedly small problem is that, if I happen to mistype my password, I don't get a second chance. Instead, after 10 seconds or so, I'm left on a GRUB rescue> prompt. Is there anything I can type at this prompt to try again, or must I power off and on?
|
The simplest way is to just hit ctrl+alt+del to soft reset, but you do have to go through the POST again.
Another way to go, from the rescue prompt:
replace hd0,gpt2 with the appropriate value for your machine - on my system it is shown as part of the password prompt. I'm using btrfs without any lvm (and no separate /boot partition), so your cryptomount and prefix parameters may differ somewhat from mine:
cryptomount hd0,gpt2
set prefix=(crypto0)/__active/boot/grub
insmod normal
normal
| Odd wrong password behaviour with GRUB cryptodisk |
1,478,232,523,000 |
I've an image backup file of my harddisk, which consists of three partitions (sudo fdisk -l /mnt/hdd/19_02.img):
Device Start End Sectors Size Type
/mnt/hdd/19_02.img1 2048 1050623 1048576 512M EFI System
/mnt/hdd/19_02.img2 1050624 34686975 33636352 16G Linux swap
/mnt/hdd/19_02.img3 34686976 976773134 942086159 449.2G Linux filesystem
The third partition ist of type crypto_LUKS. If it wouldn't be encrypted I could mount it with sudo mount -o loop,offset=$(expr 512 \* 34686976) /mnt/hdd/19_02.img /mnt/img, which results in mount: /mnt/img: unknown filesystem type 'crypto_LUKS'.
What I've tried
sudo cryptsetup luksOpen /mnt/hdd/19_02.img3 img results in Device /mnt/hdd/19_02.img3 doesn't exist or access denied.
sudo cryptsetup plainOpen --offset=$(expr 512 \* 34686976) /mnt/hdd/19_02.img img asks for my passphrase which also gets accepted, but returns with Requested offset is beyond real size of device /mnt/hdd/19_02.img.
Alright, maybe cryptsetup does multiply the offset value with the block size by itself.
sudo cryptsetup plainOpen --offset=34686976 /mnt/hdd/19_02.img img asks for my passphrase which also gets accepted and returns fine. But sudo mount /dev/mapper/img /mnt/img complains mount: /mnt/img: wrong fs type, bad option, bad superblock on /dev/mapper/img. Analysing with sudo lsblk -f /dev/mapper/img shows there is no filesystem recognized.
NAME FSTYPE LABEL UUID FSAVAIL FSUSE% MOUNTPOINT
img
The encrypted device was created by LUKS mode, so it properly makes not much sense opening it with plainOpen. But luksOpen doesn't offer an --offset option.
Doing sudo cryptsetup luksOpen --offset=34686976 /mnt/hdd/19_02.img img results in cryptsetup: Option --offset is supported only for open of plain and loopaes devices and for luksFormat. (Didn't tried luksFormat, but it sets up the LUKS device header and encrypts the master-key.)
The question after all
How to do cryptsetup luksOpen with offset on an image file?
|
fdisk is being a bit stupid here: when displaying device names for the partitions, it just takes the name of the whole-disk device given to it, and appends the partition number (prefixed with p if the last character of the whole-disk device name is also a number). It does this without checking if a device by that name actually exists or not.
In other words, if your image file is named /mnt/hdd/19_02.img and you're using fdisk to examine it directly, then partition names like /mnt/hdd/19_02.img3 are completely fictional and unusable.
Instead of trying to calculate offsets manually, you could simply attach the image file into a loop device and have it automatically detect the partitions for you:
sudo losetup -P /dev/loop0 /mnt/hdd/19_02.img
If your system is new enough to support the -P option for losetup, you should now have partition devices like /dev/loop0p1, /dev/loop0p2 and /dev/loop0p3 appearing automatically.
For older distributions with no partitioned loop device support, you can use the kpartx command (may come with the device-mapper-multipath tools if not packaged separately) for the same purpose. In that case, you'll have to perform two steps and the device names will be slightly different:
sudo losetup /dev/loop0 /mnt/hdd/19_02.img
sudo kpartx -a /dev/loop0
When using kpartx like this, the partition devices will appear under /dev/mapper, e.g. /dev/mapper/loop0p1 and so on.
Now you should be able to do either
sudo cryptsetup luksOpen /dev/loop0p3 img
or
sudo cryptsetup luksOpen /dev/mapper/loop0p3 img
depending on whether you used losetup -P or kpartx to handle the partition devices.
After you're done accessing the image, unmount any mounted filesystems on the partition devices, sudo cryptsetup luksClose the encrypted image, then undo the loop device binding:
If you used kpartx, first run sudo kpartx -d /dev/loop0 to release the partition devices. If you used losetup -P, this step is not needed.
Then, release the loop device: sudo losetup -d /dev/loop0.
| Mount encrypted partition of an image file |
1,478,232,523,000 |
I created an encrypted container via
#!/bin/bash
dd if=/dev/zero of=$1 bs=1 count=0 seek=$2
MAPPER=$(mktemp -up /dev/mapper)
LOOPDEV=$(losetup --find --show $1)
cryptsetup luksFormat $LOOPDEV
cryptsetup luksOpen $LOOPDEV $(basename $MAPPER)
mkfs.ext3 $MAPPER
cryptsetup luksClose $MAPPER
losetup -d $LOOPDEV
i.e. a file e.g. container specified to this script will contain a ext3 filesystem encrypted via cryptsetup luksFormat.
To mount it, I currently use another script, say dm.mount container /mnt/decrypted:
#!/bin/bash
set -e
MAPPER=$(mktemp -up /dev/mapper)
LOOPDEV=$(losetup --find --show $1)
cryptsetup luksOpen $LOOPDEV $(basename $MAPPER) || losetup -d $LOOPDEV
mount $MAPPER $2 || (
cryptsetup luksClose $MAPPER
losetup -d $LOOPDEV
)
and to unmount it dm.umount /mnt/decrypted:
#!/bin/bash
set -e
MAPPER=$(basename $(mount | grep $1 | gawk ' { print $1 } '))
LOOPDEV=$(cryptsetup status $MAPPER | grep device | gawk ' { print $2 } ')
umount $1
cryptsetup luksClose $MAPPER
losetup -d $LOOPDEV
There's a lot of redundancy and manually grabbing a loop device and mapper both of which could remain anonymous. Is there a way to simply do something like mount -o luks ~/container /mnt/decrypted (prompting for the passphrase) and umount /mnt/decrypted the easy way instead?
edit Basically I am happy with my scripts above (although the error checking could be improved...), so
How can a mount option -o luks=~/container be implemented similar to -o loop ~/loopfile using the scripts I wrote?
Can this be achieved without rewriting mount? Or alternatively, could -t luks -o loop ~/container be implemented?
|
In fact, modifying mount is possible, as I learned from the existence of mount.ntfs-3g. I'm doing only guesswork, but I suspect mount -t sometype results in a call to mount.sometype $DEV $MOUNTPOINT $OPTIONS, feel free to correct me here or quote some actual documentation. Especially the option -o loop is already treated so there's no need for lopsetup anymore...
Symlink/create the mount script as /sbin/mount.crypto_LUKS. Remove the loopdevice part and instead just use the -o loop switch. Here's my /sbin/mount.crypto_LUKS:
#!/bin/bash
set -e
if [[ $(mount | grep ${2%%/} | wc -l) -gt 0 ]]; then
echo "Path $2 is already mounted!" >&2
exit 9
else
MAPPER=$(mktemp -up /dev/mapper)
cryptsetup luksOpen $1 $(basename $MAPPER)
shift
mount $MAPPER $* || cryptsetup luksClose $(basename $MAPPER)
fi
Now I just have to run mount -o loop ~/container /mnt/decrypted, and mount will prompt me for the password and then mount the container, automatically releasing the loopdevice once the container is closed. If the decrypted filesystem fails to mount, the container will be closed again, but you can modify that of course. Or implement some option parsing instead of passing everything on to mount.
I was hoping the same could be achieved via /sbin/umount.luks, but umount /mnt/decrypted (even with -t crypto_LUKS) still only does the usual unmount, leaving the container open. If you find a way to have umount call my dm.umount script instead, please let me know... At the moment, directly calling umount is discouraged since you will have to figure out the /dev/mapper name to manually cryptsetup luksClose $MAPPER. At least the loop device will be release automatically if mount -o loop was used before...
| How to mount a cryptsetup container just with `mount`? |
1,478,232,523,000 |
When you run luksDump on a LUKS device, I get this:
$ sudo cryptsetup luksDump /dev/sda1
LUKS header information
Version: 2
Epoch: 3
Metadata area: 16384 [bytes]
Keyslots area: 16744448 [bytes]
UUID: 4640c6e4-[…]
Label: (no label)
Subsystem: (no subsystem)
Flags: (no flags)
[…]
I’s quite obvious what “version” refers to (the current best is v2, so this is what you should aim for) and I’ve seen values for Epoch from 3 to 5.
However, what does Epoch refer to, actually?
And what value should I aim at? Does it matter (security-wise) what number is stated there?
Is it bad if it is still Epoch 3 e.g.? Can one upgrade that Epoch?
I’ve searched the web and the FAQ for information, but the word epoch is not mentioned there.
|
The Epoch increases every time you change anything in your LUKS header (like when adding or removing keys, etc.).
The LUKS2 header specification states:
uint64_t seqid; // sequence ID, increased on update
seqid is a counter (sequential number) that is always increased when
a new update of the header is written. The header with a higher seqid
is more recent and is used for recovery (if there are primary and secondary
headers with different seqid, the more recent one is automatically used).
Why this is called a "sequence ID" in code and technical documentation, but uses the term "Epoch" when shown to the end user, remains a mystery.
That it is in fact the same thing, can be seen if you read the fine source, which prints seqid as Epoch:
log_std(cd, "Epoch: \t%" PRIu64 "\n", hdr->seqid);
tl;dr You can safely ignore the Epoch, it is a harmless counter with no specific meaning.
| What is the epoch of LUKS that is shown when running luksDump? |
1,478,232,523,000 |
I am struggling with setting up an encrypted NAS for some days now. The basic plan is to have btrfs on lvm on luks on raid1 with lvmcache in writeback mode thrown in for the root partition to reduce disk access.
TL;DR:
After setting up the partitions and filesystems GRUB fails to install with:
grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels. This is not supported yet..
grub-install: error: embedding is not possible, but this is required for RAID and LVM install.
Partitions
Following the Arch Wiki I start by setting up the partitions:
gdisk output for /dev/sda and /dev/sdb:
Disk /dev/sda: 976773168 sectors, 465.8 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 9EFA6587-E34F-4AC1-8B56-5262480A6C6A
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 976773134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4095 1024.0 KiB EF02 BIOS boot partition
2 4096 976773134 465.8 GiB 8300 Linux filesystem
Note the BIOS boot partition that is apparently required by GRUB when installing in BIOS/GPT mode.
MDADM
As I have two disk I want them in a RAID1 array:
mdadm --create --level=1 --raid-devices=2 /dev/md0 /dev/sda2 /dev/sdb2
root@archiso ~ # mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 name=archiso:0 UUID=bdfc3fea:f4a0ee6d:6ac08012:59ea384b
root@archiso ~ # cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb2[1] sda2[0]
488253440 blocks super 1.2 [2/2] [UU]
[>....................] resync = 2.0% (9832384/488253440) finish=96.6min speed=82460K/sec
bitmap: 4/4 pages [16KB], 65536KB chunk
unused devices: <none>
LUKS
Next I setup a LUKS volume on top of the RAID:
root@archiso ~ # cryptsetup luksFormat /dev/md0
WARNING!
========
This will overwrite data on /dev/md0 irrevocably.
Are you sure? (Type uppercase yes): YES
Enter passphrase:
Verify passphrase:
root@archiso ~ # cryptsetup luksOpen /dev/md0 md0-crypt
Enter passphrase for /dev/md0:
LVM
Btrfs snapshots could be used instead of LVM, but as of writing this there is no way to add a SSD caching device to Btrfs. So I opted to use LVM and add the SSD via lvmcache later:
(Creating the volume group in one step:)
root@archiso ~ # vgcreate vg0 /dev/mapper/md0-crypt
Physical volume "/dev/mapper/md0-crypt" successfully created
Volume group "vg0" successfully created
root@archiso ~ # lvcreate -L 100M -C y vg0 -n boot
Logical volume "boot" created.
root@archiso ~ # lvcreate -L 20G vg0 -n root
Logical volume "root" created.
root@archiso ~ # lvcreate -L 10G vg0 -n var
Logical volume "var" created.
root@archiso ~ # lvcreate -L 6G -C y vg0 -n swap
Logical volume "swap" created.
root@archiso ~ # lvcreate -l +100%FREE vg0 -n home
Logical volume "home" created
Resulting in the following layout:
root@archiso ~ # lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
boot vg0 -wc-a----- 100.00m
home vg0 -wi-a----- 429.53g
root vg0 -wi-a----- 20.00g
swap vg0 -wc-a----- 6.00g
var vg0 -wi-a----- 10.00g
Btrfs/Filesystems
Creating the filesystems:
root@archiso ~ # mkfs.ext4 /dev/vg0/boot
root@archiso ~ # mkfs.btrfs /dev/vg0/home
root@archiso ~ # mkfs.btrfs /dev/vg0/root
root@archiso ~ # mkfs.btrfs /dev/vg0/var
(ext4 was chosen for boot because btrfs complains about the small partition size.)
Mounting the filesystems:
root@archiso ~ # swapon /dev/vg0/swap
root@archiso ~ # mount /dev/vg0/root /mnt/arch -o compress=lzo
root@archiso ~ # mount /dev/vg0/home /mnt/arch/home -o compress=lzo
root@archiso ~ # mount /dev/vg0/var /mnt/arch/var -o compress=lzo
root@archiso ~ # mount /dev/vg0/boot /mnt/arch/boot
Installing Arch
Actually I just copy the system from a previous backup:
root@archiso ~ # rsync -Pa /mnt/bkp/sda/* /mnt/arch
(coffee break)
Setting up mdadm.conf and fstab
root@archiso ~ # genfstab -U /mnt/arch > /mnt/arch/etc/fstab
root@archiso ~ # cat /mnt/arch/etc/fstab
# /dev/mapper/vg0-root
UUID=62ebf0c9-bb37-4b4e-87dd-eb8a4ace6a69 / btrfs rw,relatime,compress=lzo,space_cache 0 0
# /dev/mapper/vg0-home
UUID=53113e11-b663-452f-b4da-1443e470b065 /home btrfs rw,relatime,compress=lzo,space_cache 0 0
# /dev/mapper/vg0-var
UUID=869ffe10-7a1c-4254-9612-25633c7ae619 /var btrfs rw,relatime,compress=lzo,space_cache 0 0
# /dev/mapper/vg0-boot
UUID=d121a9df-8c03-4ad9-a6e0-b68739b1a358 /boot ext4 rw,relatime,data=ordered 0 2
# /dev/mapper/vg0-swap
UUID=29035eeb-540d-4437-861b-c30597bb7c16 none swap defaults 0 0
root@archiso ~ # mdadm --detail --scan >> /mnt/arch/etc/mdadm.conf
root@archiso ~ # cat /mnt/arch/etc/mdadm.conf
[...]
ARRAY /dev/md0 metadata=1.2 name=archiso:0 UUID=bdfc3fea:f4a0ee6d:6ac08012:59ea384b
Chrooting into the system
root@archiso ~ # arch-chroot /mnt/arch /bin/bash
[root@archiso /]#
mkinitcpio.conf
These hooks were added: mdadm_udev encrypt lvm2 btrfs
[root@archiso /]# mkinitcpio -p linux
Configuring GRUB
Now for the interesting (and failing) part, I chose GRUB as my bootloader as it should support all of the contraptions that I use.
References:
https://wiki.archlinux.org/index.php/Dm-crypt/Encrypting_an_entire_system#LVM_on_LUKS
http://www.pavelkogan.com/2014/05/23/luks-full-disk-encryption/
Changed parts in /etc/default/grub:
GRUB_CMDLINE_LINUX="cryptdevice=/dev/md0:vg0"
GRUB_ENABLE_CRYPTODISK=y
Installing grub:
[root@archiso /]# grub-install --target=i386-pc --recheck /dev/sda
Installing for i386-pc platform.
/run/lvm/lvmetad.socket: connect failed: No such file or directory
WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
/run/lvm/lvmetad.socket: connect failed: No such file or directory
WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
/run/lvm/lvmetad.socket: connect failed: No such file or directory
WARNING: Failed to connect to lvmetad. Falling back to internal scanning.
grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels. This is not supported yet..
grub-install: error: embedding is not possible, but this is required for RAID and LVM install.
(--debug output available here)
Frankly ... I have no idea what's the problem here. In BIOS/GPT mode GRUB should embed it's core.img into the ef02/BIOS boot partition shouldn't it?
Edit
https://bbs.archlinux.org/viewtopic.php?id=144254 doesn't apply here:
[root@archiso /]# btrfs fi show --all-devices
Label: none uuid: 62ebf0c9-bb37-4b4e-87dd-eb8a4ace6a69
Total devices 1 FS bytes used 965.77MiB
devid 1 size 20.00GiB used 3.04GiB path /dev/mapper/vg0-root
Label: none uuid: 869ffe10-7a1c-4254-9612-25633c7ae619
Total devices 1 FS bytes used 339.15MiB
devid 1 size 10.00GiB used 3.04GiB path /dev/mapper/vg0-var
Label: none uuid: 53113e11-b663-452f-b4da-1443e470b065
Total devices 1 FS bytes used 384.00KiB
devid 1 size 429.53GiB used 2.04GiB path /dev/mapper/vg0-home
Btrfs v3.17.3
|
Hmm ... apparently this line was the clue:
grub-install: warning: Attempting to install GRUB to a disk with multiple partition labels. This is not supported yet..
Previously I had installed btrfs directly on /dev/sda and /dev/sdb. That's why both of them had a FSTYPE and LABEL attached (as shown in lsblk).
Solution: I have now wiped both /dev/sda and /dev/sdb with hdparm (Secure Erase). There is probably a better way to unset those flags ... but this worked for me.
| Grub-install: embedding is not possible in Bios/GPT |
1,478,232,523,000 |
I'm trying to use cryptdisks_start to open a LUKS device that is defined in my /etc/crypttab. Unfortunately, the command fails with the following error message:
martin ~ # cryptdisks_start luks-01a2e5d8-9211-40ce-b160-d3f973d1a155
* Starting crypto disk...
* luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 (starting)..
* luks-01a2e5d8-9211-40ce-b160-d3f973d1a155: the precheck for '/dev/disk/by-uuid/01a2e5d8-9211-40ce-b160-d3f973d1a155' failed: - The device /dev/disk/by-uuid/01a2e5d8-9211-40ce-b160-d3f973d1a155 contains a filesystem type crypto_LUKS.
* luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 (failed)...
...fail!
A rather strange error, because of course that device has to contain a crypto_LUKS filesystem!
The relevant line from /etc/crypttab, as set up by GNOME Disks:
luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 UUID=01a2e5d8-9211-40ce-b160-d3f973d1a155 /etc/luks-keys/luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 nofail
|
It doesn't work because the /etc/crypttab line is missing the option keyword luks. Changing the line to this resolved the issue:
luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 UUID=01a2e5d8-9211-40ce-b160-d3f973d1a155 /etc/luks-keys/luks-01a2e5d8-9211-40ce-b160-d3f973d1a155 luks,nofail
This is due to the fact that cryptdisks_start uses the options to determine what kind of encryption is being used so that it will use the correct command to open the device. Without the luks option, cryptdisks_start will try to open the device as a plain dm-crypt device with cryptsetup create. Luckily a sanity check prevents this, although it causes a confusing error message.
Apparently the Disks tool of GNOME3 writes this incorrect line to /etc/crypttab when using the unlock icon and saving the passphrase.
| cryptdisks_start: precheck failed: the device contains a filesystem type crypto_LUKS |
1,478,232,523,000 |
I wiped the disk using
wipefs -a /dev/sda.
I happily formatted the disk, and it seems that when I'm about to mount /dev/sda3 it says "unknown file system type crypto_LUKS".
I did no encryption on this partition, so it's like the previous configuration is saved somehow.
If I apparently wiped or reset the disk, how can this be possible?
Do I have to open and decrypt and remove encryption on that drive first?
|
wipefs -a /dev/sdx only wipes magic signatures on that device, not on its partitions. So at best, it only wipes your partition table, but if you then proceed to re-create the partitions at the same offsets at before, the old data is still there. You'd have to wipe the partitions as well.
wipefs -a /dev/sdx[1-9]* # wipe old partitions
wipefs -a /dev/sdx # wipe the disk itself
parted /dev/sdx # create new partitions
wipefs -a /dev/sdx[1-9]* # wipe the new partitions, just in case
# create filesystems or whatever
That aside it's also entirely possible for wipefs to not wipe something if it doesn't know the signature. Or for another program to still recognize the data on the partition despite the signature being damaged. wipefs only overwrites a few magic bytes, which is reversible in most cases.
| Partition still encrypted with luks after wipefs |
1,478,232,523,000 |
I'm working on a script to create a fully encrypted washable system from debootstrap. It's doing some good, but the initramfs image that comes out does not pick up the cryptroot properly. After booting the image with qemu, I'm dropped to a busybox shell and I have to unlock the luks encryption manually with cryptsetup:
cryptsetup luksOpen /dev/sda1 system
/scripts/local-premount/flashback
exit
(flashback does some btrfs snapshoting magic to forget changes made on every boot)
After this, boot in qemu continues normally and I am then able to generate a good initramfs image. I copy this to the btrfs @root.base subvolume and all is well from then on.
I need help with figuring out why the cryptsetup/cryptroot part is not being picked up in the chroot environment by update-initramfs:
echo "CRYPTSETUP=y" >> /usr/share/initramfs-tools/conf-hooks.d/cryptsetup
echo "export CRYPTSETUP=y" >> /usr/share/initramfs-tools/conf-hooks.d/cryptsetup
update-initramfs -ut
I have tried many things, I write a good fstab and crypttab and even tried to explicitly set cryptdevice in grub.cfg. Refer to the specific version of the script.
Here's how I create the fstab and crypttab:
export partuuid=$(blkid $partition | sed -re 's/.*: UUID="([^"]+)".*/\1/')
export decruuid=$(blkid /dev/mapper/$decrypted | sed -re 's/.*: UUID="([^"]+)".*/\1/')
echo "Adding flashback with uuid $partuuid"
echo "system UUID=$partuuid none luks" >> "$rootmount/etc/crypttab"
echo "UUID=$decruuid / btrfs [email protected] 0 0" >> "$rootmount/etc/fstab"
echo "UUID=$decruuid /home btrfs subvol=@home 0 0" >> "$rootmount/etc/fstab"
The question in principle is: How do you generate a functioning initramfs image in an encrypted chroot of a debootstrapped debian?
Thanks a bunch
|
Using /etc/initramfs-tools/conf.d/cryptsetup is deprecated in stretch.
The new preferred method is to set "CRYPTSETUP=y" in /etc/cryptsetup-initramfs/conf-hook.
In buster and later, this configuration parameter appears to be redundant, as the default behaviour seems to be to configure cryptsetup in initramfs IFF the initramfs-cryptsetup package is installed.
| Initramfs in debootstrap chroot of fully encrypted system |
1,419,471,821,000 |
I'm trying to open a LUKS drive through SSH directly.
ssh root@XX "cryptsetup luksOpen /dev/sdb3 secure
But, no password prompt and it stuck.
debug1: Sending command: cryptsetup luksOpen /dev/sdb3 secure
debug2: channel 1: request exec confirm 1
debug2: callback done
debug2: channel 1: open confirm rwindow 0 rmax 32768
debug2: channel 1: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 1
debug2: exec request accepted on channel 1
Is that something impossible?
|
For the prompt to work, you need to add -t.
ssh -t root@host cryptsetup luksOpen /dev/thing luksthing
(It also works if you just type out your password when it's "stuck" waiting for input, but it will echo in your local terminal.)
Alternatively, piping the passphrase works well enough:
echo -n 'password' | ssh root@host cryptsetup luksOpen /dev/thing luksthing
And to prevent it leaking to the process list and command history, better put it in a file.
ssh root@host cryptsetup luksOpen /dev/thing luksthing < passwordfile
At which point you might just as well use a truly random keyfile rather than just a simple passphrase.
| Cannot run cryptsetup throught SSH? |
1,419,471,821,000 |
I've created a encrypted volume with LUKS at home and was looking to use it at work too. Unfortunately, that's not possible. Whyever, I'm unable to access the encrypted data on any other computer than my workstation at home.
After entering the passphrase, I do recieve this error message:
No key available with this passphrase.
Strangely enough, I've no WTF complications to access the encrypted data on my home workstation. How can I encrypt the volume ?
|
LUKS sometimes gives the No key available error message when the cipher isn't supported. Which cipher did you use? For supported ciphers, check /proc/crypto.
Also, passphrase may depend on keyboard layout and (if it has non-ascii characters) charset encoding. The keyboard layout problem can be worked around by adding another passphrase that would match the same keysequence typed in the other layout. So for example if you have one box with a QWERTZ keyboard and another with QWERTY, you could just switch Z and Y for the second passphrase.
Also check dmesg if there are any kernel messages related to opening the encrypted container, it may point you to other errors.
If you're looking for a simpler solution and don't mind redoing it from scratch, how about encrypting the disk at your work computer and then see if you can open that at home.
| luksOpen: No key available with this passphrase |
1,419,471,821,000 |
I already asked once about LUKS unlocking of multiple HDDs in Linux: LUKS and multiple hard drives.
Now I would like to know how to secure store the keyfile used for the automatic unlock of the associated partitions.
My plan is (if possible):
Encrypt a small USB drive with LUKS that requires a passphrase
Unlock it at boot as the first drive by using the passphrase
Mount it to a given mount point, for instance /test (is this possible ?)
Now the keyfile can be safely read: /test/keyfile
Use the keyfile to unlock other drives without needing to ask password for them
LuksClose the USB drive in order to assure a certain degree of safety as soon as other drives have been unlocked
Automount /, /usr, /var and other mount-points as usual
Can this work? Basically I store the LUKS keyfile on a password-encrypted LUKS USB drive that only asks for passphrase once, while all other drives can be unlocked without further action. I'm not sure if there is some way to make the USB drive be unlocked first, then be mounted and only then the other drives try to access the keyfile. Furthermore in what concerns automation I suppose /etc/fstab and /etc/crypttab should be accessible BEFORE the other drives can be mounted, but this is not possible if the whole / file system is LUKS encrypted.
Unless there is the possibility of fully manually configure how LUKS works:
LuksOpen /dev/sdc1 usb_keyfile
mount /dev/mapper/usb_keyfile /keyfile (is this possible ?)
LuksOpen --keyfile /keyfile/key /dev/sda1 disk1
LuksOpen --keyfile /keyfile/key /dev/sdb1 disk2
LuksClose /dev/sdc1
Basically being able to run a shell script just after the required modules have been loaded and disable automatic LUKS password prompt.
Additionnal details
Distribution used: Gentoo GNU/Linux (amd64) or Debian GNU/Linux (amd64) because I'd like to apply this procedure to multiple installations
|
Your approach looks good. Some remarks though:
If you want to encrypt rootfs, you'll need to use initrd (to have some minimal unencrypted system that will process the encrypted partitions).
If the USB device is removable, both initrd and kernel can be stored on the USB to heighten tamper resistance (supposing you make sure the USB won't get into unauthorized hands) - which is usually why one encrypts rootfs. Once both kernel and initrd are on a removable media, you can ensure that nobody changes the kernel (or initrd) from the running system by simply removing the media.
This is of course not an option if you want to have it inside of a server, but then again the question stands whether it makes sense to have such a device at all and not to use a small partition on one of the hard-drives. If for example all drives in the machine are in RAID, one would probably want to put rootfs on the USB as well. An interesting alternative to an internally connected USB flash device could be a CompactFlash card attached to ATA interface through an adapter, by the way.
Some distributions offer prepared solutions for encrypted root, some don't - but mostly it's question of putting a couple of lines into initrd script before it tries to mount the "real" root (see for example man pages for pivot_root, usually in sections 2 (syscall) and 8 (bonary), if you're not familiar with the process).
remember to backup the keys and passphrases in case your USB drive dies. LUKS follows rather one-sided approach when it comes to damaging its header - once a single sector of its header (key-slot to be more precise) dies, you are unable to mount it. This is to make sure that erasing the header isn't effectively thwarted by block reallocation performed by the device itself (because that's what flash-memory based devices do a lot) - the key is spread over the whole key slot and one needs all of the data to reconstruct it - there is no redundancy. See Clemens Fruwirth's website for deeper discussion.
That said, maybe a simple encrypted device on the USB would be enough (check section PLAIN MODE in man cryptsetup). Or a file encrypted with e.g. openssl enc. The former might actually be an option even for the encrypted partitions themselves.
| LUKS storing keyfile in encrypted usb drive |
1,419,471,821,000 |
I am using manjaro with full disk encrypt, however, the wait time at boot for decrypt is very long ( i assume because of a high difficulty setting) . How can I change encryption difficulty/ wait time of the encryption setup during install?
|
Too much passphrase hashing?
If it's only slow because you're waiting for a lot of passphrase hashing iterations, you could add a new passphrase with a quicker --iter-time, but that could reduce security & allow faster guessing of passphrases. If you wanted to wait 1 second (1000ms) then use a command like:
cryptsetup -v luksAddKey --iter-time 1000 <device>
You might then have to delete the old slow passphrase (with luksKillSlot), unless it's key slot is after the new quick one (they're apparently tested in order, so might have to wait for the first slow slot to be tested before the later quick one). Or change your initial open command to specify the new quicker --key-slot number.
The luksChangeKey command can combine the two steps, adding a new key then deleting the old key (even though the v1.7 man page doesn't specifically say it can use --iter-time, apparently it can):
cryptsetup -v luksChangeKey --iter-time 1000 <device>
How slow is it now?
Test how long it takes to decrypt / open your device with:
cryptsetup -v luksOpen --test-passphrase <device>
Or test a specific key slot with the --key-slot option:
cryptsetup -v luksOpen --test-passphrase --key-slot N <device>
Using the time command might help, but also count your typing speed.
You can use the luksDump command to see what the current key slot Iterations: are, this is an example of a very slow slot 0 and a very quick slot 1:
Key Slot 0: ENABLED
Iterations: 4663017
Salt: ......
Key material offset: 8
AF stripes: 4000
Key Slot 1: ENABLED
Iterations: 1000
Salt: ......
Key material offset: 264
AF stripes: 4000
From man cryptsetup:
--iter-time, -i
The number of milliseconds to spend with PBKDF2 passphrase processing. This
option is only relevant for LUKS operations that set or change passphrases, such
as luksFormat or luksAddKey. Specifying 0 as parameter selects the compiled-in
default.
luksChangeKey <device> [<new key file>]
Changes an existing passphrase. The passphrase to be changed must be supplied
interactively or via --key-file. The new passphrase can be supplied interactively
or in a file given as positional argument.
If a key-slot is specified (via --key-slot), the passphrase for that key-slot must
be given and the new passphrase will overwrite the specified key-slot. If no key-
slot is specified and there is still a free key-slot, then the new passphrase will
be put into a free key-slot before the key-slot containing the old passphrase is
purged. If there is no free key-slot, then the key-slot with the old passphrase is
overwritten directly.
WARNING: If a key-slot is overwritten, a media failure during this operation can
cause the overwrite to fail after the old passphrase has been wiped and make the
LUKS container inaccessible.
It's not the passphrase hashing?
There's lots of reasons for a slow boot time, maybe it's unrelated to the encryption.
Or if the actual encryption/decryption itself is too slow, then changing the algorithm or key size might be required, and that would require decrypting and re-encrypting everything. There are programs (or commands in newer versions) that can do it in-place, hopefully without losing anything, but having a backup would be more than an excellent idea.
But in that case, it wouldn't just be a long initial wait but all reads & writes would be a little slower.
You can use the cryptsetup -v benchmark command to see some speed tests, but "NOTE: This benchmark is using memory only and is only informative. You cannot
directly predict real storage encryption speed from it."
| How to change luks encryption difficulty on manjaro full disk encrypt |
1,419,471,821,000 |
I decided to encrypt my root partition with LUKS+LVM.
My ThinkPad setup:
Samsung 830 128GB SSD
750GB HDD
Core 2 Duo 2,5 GHz P9500
8GB RAM
But the more I read, the less I understand about those two following subjects:
1a. The cipher
I was going to use SHA1 instead of 2/512 (as some suggest), because of that quote from cryptsetup FAQ:
5.20 LUKS is broken! It uses SHA-1!
No, it is not. SHA-1 is (academically) broken for finding collisions, but not for using it in a key-derivation function. And that collision vulnerability is for non-iterated use only. And you need the hash-value in verbatim.
This basically means that if you already have a slot-key, and you have set the PBKDF2 iteration count to 1 (it is > 10'000 normally), you could (maybe) derive a different passphrase that gives you the the same slot-key. But if you have the slot-key, you can already unlock the key-slot and get the master key, breaking everything. So basically, this SHA-1 vulnerability allows you to open a LUKS container with high effort when you already have it open.
The real problem here is people that do not understand crypto and claim things are broken just because some mechanism is used that has been broken for a specific different use. The way the mechanism is used matters very much. A hash that is broken for one use can be completely secure for other uses and here it is.
Which I read as "there is no point of using anything other than SHA-1". But then some people tell me, that it's not exactly like that. So I no longer know what to think.
1b.
Also, I could not find any information whether the cipher has any influence on disk read/write/seek performance once the disk is unlocked and system logged into.
So does the complexity of the cipher affect only the "performance" on password entering stage, or also during normal use of the system?
2. The algorithm
I have been reading on this since couple of days, but the more I read, the more confused I get. Everything I read says that AES is the fastest, and Serpent is the slowest. But not according to my laptop:
$ cryptsetup benchmark
Tests are approximate using memory only (no storage IO).
PBKDF2-sha1 344926 iterations per second
PBKDF2-sha256 198593 iterations per second
PBKDF2-sha512 129007 iterations per second
PBKDF2-ripemd160 271933 iterations per second
PBKDF2-whirlpool 134295 iterations per second
# Algorithm | Key | Encryption | Decryption
aes-cbc 128b 149.8 MiB/s 147.9 MiB/s
serpent-cbc 128b 51.0 MiB/s 196.4 MiB/s
twofish-cbc 128b 127.6 MiB/s 152.5 MiB/s
aes-cbc 256b 114.3 MiB/s 113.8 MiB/s
serpent-cbc 256b 51.2 MiB/s 198.9 MiB/s
twofish-cbc 256b 129.8 MiB/s 167.5 MiB/s
aes-xts 256b 153.3 MiB/s 150.6 MiB/s
serpent-xts 256b 176.4 MiB/s 184.1 MiB/s
twofish-xts 256b 160.8 MiB/s 159.8 MiB/s
aes-xts 512b 115.4 MiB/s 112.1 MiB/s
serpent-xts 512b 178.6 MiB/s 184.2 MiB/s
twofish-xts 512b 160.7 MiB/s 158.9 MiB/s
So it appears that Serpent's not only the fastest, but on top of that it is the fastest with the most complex key.
Shouldn't it be the other way around? Am I reading it wrong, or something?
|
1a - it really doesn't matter all that much. which ever hash you use for the key derivation function, LUKS makes sure it will be computationally expensive. It will simply loop it until 1 second real time has passed.
1b - the key derivation method has no influence on performance. the cipher itself does. cryptsetup benchmark shows you as much.
2 - AES is the fastest if your CPU is modern enough to support AES-NI instructions (hardware acceleration for AES). If you go with serpent now you may not be able to utilize the AES-NI of your next laptop.
# Tests are approximate using memory only (no storage IO).
PBKDF2-sha1 1165084 iterations per second
PBKDF2-sha256 781353 iterations per second
PBKDF2-sha512 588426 iterations per second
PBKDF2-ripemd160 726160 iterations per second
PBKDF2-whirlpool 261882 iterations per second
# Algorithm | Key | Encryption | Decryption
aes-cbc 128b 692.9 MiB/s 3091.3 MiB/s
serpent-cbc 128b 94.6 MiB/s 308.6 MiB/s
twofish-cbc 128b 195.2 MiB/s 378.7 MiB/s
aes-cbc 256b 519.5 MiB/s 2374.0 MiB/s
serpent-cbc 256b 96.5 MiB/s 311.3 MiB/s
twofish-cbc 256b 197.9 MiB/s 378.0 MiB/s
aes-xts 256b 2630.6 MiB/s 2714.8 MiB/s
serpent-xts 256b 310.4 MiB/s 303.8 MiB/s
twofish-xts 256b 367.4 MiB/s 376.6 MiB/s
aes-xts 512b 2048.6 MiB/s 2076.1 MiB/s
serpent-xts 512b 317.0 MiB/s 304.2 MiB/s
twofish-xts 512b 368.7 MiB/s 377.0 MiB/s
Keep in mind this benchmark does not use storage so you should verify these results with whatever storage and filesystem you are actually going to use.
| Trying to understand LUKS encryption |
1,419,471,821,000 |
I'm trying to recover my files from a now broken Antergos install, and have run into trouble because the user/non-boot partition is encrypted with LUKS encryption.
I'm booting from an Ubuntu 18.04 bootable USB drive so I can backup the directories where I had data I wanted, and didn't realize it was encrypted until I went to go view the partition in the file explorer, and it didn't show up. It was suggested to me that it may not be mounted, and after looking at GParted it's clear that that was the problem, and it seems like it wasn't mounted because it's encrypted (prior experiences with backing up before reinstalling or switching distros never involved any problems with the partition I was recovering files from not being mounted).
As some additional information:
I have the password that was required in order to boot and get to the greeter. I'm operating under the assumption that that's my encryption key, but I may be mistaken, I'm rather out of my depth here.
The partition/volume in question is sda3 (not sure which is the correct term) and in addition to being encrypted it uses LVM. I'm not sure how that impacts things, but the impression I've gotten from the reading I've been doing to try and resolve this seems to suggest that it matters
I initially tried to mount the partition via the command line trying two different methods, and both returned different errors. Unfortunately I let my computer die because I walked away from my computer for a while before trying again, and I can't find any of the pages I was referencing and attempting to follow along with, or commands I tried, or errors I got back. The error I can provide is that when I tried to follow this guide the command: "cryptsetup luksOpen /dev/sda3/ recoverytarget" returned: "Device /dev/sda3/ doesn't exist or access denied." I assume that I need to mount the partition before I can de-encrypt it, but again I may be mistaken
it's been a while since I worked on any of my Linux machines, and I'm not the most technically competent or linux experienced person in the world, so please forgive any instances where it's painfully clear I don't understand something
EDIT/UPDATE: The error I was getting was because I wasn't running the command with sudo in front, so now I officially feel stupid, but I'm now running into a different problem where "sudo mkdir /mnt/recoverytarget && mount /dev/mapper/recoverytarget /mnt/recoverytarget" returns: "mount: only root can do that"
|
To recover your files you will first need to open your LUKS container. This will make your LVM logical volumes accessible. Then, you can mount the appropriate logical volume to gain access to the files. I'll assume that once you have access to the files you'll know what to do.
Opening the LUKS container
To open the LUKS container run: sudo cryptsetup open /dev/sda3 luksrecoverytarget --type luks
Assuming you enter a valid passphrase, you'll now have the block device /dev/mapper/luksrecoverytarget; it's actually a symlink, but you can ignore that detail. That block device contains your LVM volume group. Next you need to determine which logical volume to mount.
Find the correct logical volume
Upon opening the LUKS container your OS should have scanned for LVM logical volumes. If not you can run sudo vgscan to get things synced up. To get a list of logical volumes run sudo lvdisplay. You'll see a list of one or more logical volumes. Hopefully you'll be able to tell which one you want to recover by looking at the LV Path.
Mount the logical volume
Once you know which logical volume to mount run:
sudo mkdir /mnt/recoverytarget
sudo mount LV_PATH_GOES_HERE /mnt/recoverytarget
Now you may do as you wish with the files.
Clean up
Once you're done, you should unmount the filesystem and close the LUKS container:
sudo umount /mnt/recoverytarget
sudo cryptsetup close luksrecoverytarget
| How to mount and de-encrypt a LUKS encrypted partition to recover files [closed] |
1,419,471,821,000 |
I have a 3TB disk, and I understand I have to use parted if I want to create a partition bigger than 2TB. All right then.
parted /dev/sdb
(parted) mklabel gpt
(parted) mkpart primary
File system type? [ext2]?
Say what? It does not let me to create a partition without specifying a FS type. Why does parted insist on specifying a FS type. AFAIU, a FS type is completly independent from a partition.
In man parted, I read that:
fs-type can be one of "fat16", "fat32", "ext2", "linux-swap", or "reiserfs".
I don't want any of these. I want to create a partition to be used as LUKS partition. What should I select?
|
Parted prompts and goes into an interactive mode when you do not provide enough information to create the partition with the command. The following will create a partition that spans the entire disk and will not prompt for filesystem type:
mkpart primary 1 -1
| parted: create new partition |
1,419,471,821,000 |
I have encrypted an external hard drive using LUKS2 on my machine running Fedora 34 using the cryptsetup command.
When I now plug in the hard drive and enter the passphrase, the drive is unlocked successfully, and I can access my files.
Additionally, I'd like to be able to unlock the drive using my FIDO2 security key.
I have added the key as an unlock option using this command:
sudo systemd-cryptenroll --fido2-device=auto /dev/sdc1
In the documentation for the /etc/crypttab file, I found out how to automatically unlock such a drive during boot.
Unfortunately, I did not find any documentation how to unlock such a drive manually using the FIDO2 key. When I try to unlock it using cryptsetup open /dev/sdc1 myLuks, I have to enter the passphrase. In the manual for cryptsetup I could not find a parameter similar to --fido2-device either.
Can someone explain how to unlock a LUKS2 encrypted drive manually using a FIDO2 key?
Thanks in advance
|
You should be able to manually unlock the device with systemd-cryptsetup
sudo /usr/lib/systemd/systemd-cryptsetup attach myLuks /dev/sdc1 - fido2-device=auto
You can't use cryptsetup to unlock LUKS devices using FIDO (or TPM2) right now, support for these is in systemd only (it uses LUKS2 feature which allows adding "foreign" metadata to the LUKS header, but the code to work with FIDO/TPM2 is only in systemd so cryptsetup doesn't know how to get the key from FIDO/TPM2). This will change, cryptsetup 2.4.0 (not released yet, RC0 is currently available in Fedora Rawhide and Debian Experimental) adds a new plugin interface and it will be possible to use cryptsetup open to automatically open the device using FIDO/TMP2 (and other "tokens" supported by systemd) in the future.
| Mounting external hard drive using LUKS2 and FIDO2 Key |
1,419,471,821,000 |
I have(had) the following setup:
Full disk encryption with LUKS and a separately encrypted /home partition.
Made the mistake to delete my /root but caught early enough so only changes to the partition table where made.
Now I'm left with the following:
sudo hexdump -C /dev/nvme0n1 |grep LUKS
3e900000 4c 55 4b 53 ba be 00 01 61 65 73 00 00 00 00 00 |LUKS....aes.....|
That means that LUKS header is still intact (phew)
Then I create a loop device on that offset
sudo losetup -o 0x3e900000 -r -f /dev/nvme0n1
and mount it with
sudo cryptsetup luksOpen /dev/loop1 luksrecover
so far it works great, things get mounted properly I can see my files and with a few more commands I can get my separate /home back.
However, since I do have an operating system intact I'd like it back.
Only problem as it seems, there is no grub to call the initial Xubuntu LUKS decrypter.
Now, since I see that there is a significant offset in my partitioning, I guess that's where grub used to live
So, what can I do about getting my OS back?
As far as I understand I must somehow mark bytes 0 - $offset as grub and install grub there and the rest as something else.
So I tried grub-install /dev/nvme0n1 and it complained about aufs
grub-install: error: failed to get canonical path of `aufs'.
then tried the same in a chroot in the LUKS system that was mounted but it that filesystem is read-only and of course it never had grub to begin with.
So what can I do to get grub to sit in the empty space before LUKS and decrypt LUKS on start?
|
WARNING:
Make an image (backup) of the drive BEFORE you do all this.
Read the documentation (e.g., "man pages") for all commands,
and make sure you understand what they do, before using them.
YOU HAVE BEEN WARNED
For future reference, here's the solution:
Find where the LUKS partition starts.
All LUKS partitions have a plaintext header containing the word LUKS. So
sudo hexdump -C /dev/<the disk> | grep LUKS
Note where LUKS was.
hexdump should list an offset where it found the start of this header.
Mount the partition as a loopback device starting where the offset you found the LUKS header is
sudo losetup -o <offset> -r -f /dev/nvme0n1
For reference,
my offset, in Xubuntu with an Intel SSD and GRUB2, was 0x3e900000.
Find out which device it got losetup'd as
losetup -a
Decrypt & mount
sudo cryptsetup luksOpen /dev/loop1 luksrecover
At this point the disk should have been mounted under /media/.
However: your /home should still be encrypted.
It's time to decrypt
cd /home/<yourusername>
sudo ecryptfs-recover-private .Private/
This should produce the following
INFO: Found [.Private/].
Try to recover this directory? [Y/n]: Y
INFO: Found your wrapped-passphrase
Do you know your LOGIN passphrase? [Y/n] Y
INFO: Enter your LOGIN passphrase...
Passphrase:
Inserted auth tok with sig [8c5d84b9d7f0cc5b] into the user session keyring
INFO: Success! Private data mounted at [/tmp/ecryptfs.mxsowbiD].
Plug in an external storage device (e.g., an HDD),
save your /home, /opt and whatever else you need.
Re-install and replace the /home with your own. Or just move the existing filesystem to a proper partition.
Crisis averted, and it took only a few hours.
| Recover deleted LUKS partition |
1,419,471,821,000 |
I've created the following [email protected] service for systemd:
[Unit]
Description=Cryptography Setup for '%I'
After=cryptsetup-pre.target
After=dev-mapper-%i.device
Before=cryptsetup.target
Before=umount.target
BindsTo=dev-mapper-%i.device
BindsTo=dev-mapper-%i.luks.device
Conflicts=umount.target
DefaultDependencies=no
IgnoreOnIsolate=true
RequiresMountsFor=/home
[Service]
ExecStart=/usr/lib/systemd/systemd-cryptsetup attach '%I.luks' '/dev/mapper/%I' '%h/%I/secret.key' 'luks,header=%h/%I/header'
ExecStop=/usr/lib/systemd/systemd-cryptsetup detach '%I.luks'
KillMode=none
RemainAfterExit=yes
TimeoutSec=0
Type=oneshot
[Install]
WantedBy=default.target
The idea is to decrypt certain LUKS-encrypted xxx device as xxx.luks only for a given user, who enables the service with, for example:
systemctl --user enable luks@xxx
Unfortunately, even testing it with
systemctl --user start luks@xxx
fails as it always returns with exit code 1 without stating the actual reason. To me it was clear that the problem is likely in permissions. That is I know for sure that in order to manually trigger cryptsetup luksOpen ..., one has to elevate the shell, e.g. with sudo. Indeed, if I issue
sudo systemctl start luks@xxx
it works like a charm and similarly
sudo systemctl enable luks@xxx
would work for boot phase.
NOTE:
For such system-wide installation, it is of course needed to modify the service by replacing %h with the actual home directory of a giver user, which is ugly and does not serve the final purpose anyway.
Now, I'm aware of pam_mount which is capable of doing similar mounting (which I cannot use because it does not support detached LUKS headers and because it actually mounts devices, something what I don't want) on per user basis and, in fact, pam_systemd launches systemctl --user, so there definitely should be a way to obtain privileges during boot on per user basis to perform the device decryption.
By the way, failure symptoms of
systemctl --user enable luks@xxx
are even worse than those of testing it with
systemctl --user start luks@xxx
(which only returns exit code 1). That is I cannot even log in with the given user as it complains about
Failed to create bus connection: No such file or directory
because XDG_RUNTIME_DIR and DBUS_SESSION_BUS_ADDRESS are not set anymore, while they should have been by the systemd-logind.service service. Clearly, luks@xxx somehow breaks the whole initialization process but due to insufficient information in journal, I cannot identify exactly why. Thus, my current suspicion about lack of permissions still remains.
Looking forward to educated proposals. Thank you.
|
An alternative solution would be to edit the sudoers file to add permissions for the user in question to run /usr/lib/systemd/systemd-cryptsetup with root permissions with NOPASSWD option enabled.
You would then edit your (user-specific) service file above to read:
ExecStart=/usr/bin/sudo /usr/lib/systemd/systemd-cryptsetup attach '%I.luks' '/dev/mapper/%I' '%h/%I/secret.key' 'luks,header=%h/%I/header'
ExecStop=/usr/bin/sudo /usr/lib/systemd/systemd-cryptsetup detach '%I.luks'
I'm not sure whether you would also have to enable !requiretty for this to work
Update:
To increase security around this, especially for a multiple-user system, I'd highly recommend creating a couple of scripts to perform the 'attach' and 'detach' steps on behalf of the user rather than giving sudo access to /usr/lib/systemd/systemd-cryptsetup directly, as otherwise any user that is given access to run this command can potentially interfere with other encrypted volumes.
| How to decrypt LUKS-encrypted device on per user basis upon login? |
1,419,471,821,000 |
I'm confused between the various ways that LUKS/dmcrypt/cryptsetup discard /TRIM operations can be enabled via the Linux kernel command line.
The dracut manpage:
rd.luks.allow-discards
Allow using of discards (TRIM) requests on all LUKS partitions.
The systemd-cryptsetup-generator manpage
luks.options=, rd.luks.options=
... If only a list of options, without an UUID, is specified, they apply to any UUIDs not specified elsewhere, and without an entry in /etc/crypttab. ...
The argument rd.luks.options=discard is recommended here.
The Arch wiki section on LUKS and SSDs shows a third colon-seprated field:
cryptdevice=/dev/sdaX:root:allow-discards
Questions:
What is the difference between discard and allow-discards? Is the former mandatory and the second optional?
Will luks.options= or rd.luks.options= apply given cryptdevice=/dev/sda2 (eg not a UUID)? What if cryptdevice= is given a UUID, does that count as "specified elsewhere"?
Will luks.options= or rd.luks.options= overwrite / append / prepend if cryptsetup= already gives options?
Is there any disadvantage to using rd.luks.allow-discards which seems to be simplest if TRIM is wanted everywhere?
|
It depends a little on the distribution you are using and what components are included by dracut in the initramfs.
For example, the cryptdevice= option is interpreted by the encrypt hook. Thus, it's only relevant for initramfs images that include this hook.
The disadvantage of rd.luks.allow-discards and rd.luks.allow-discards= is that it simply doesn't work. The dracut.cmdline(7) description of these options is incorrect. I tested it under Fedora 26 where it doesn't work and there is even a bug report for Fedora 19 where this deviation between documented and actual behavior was discussed and it was closed as wont-fix.
The luks.options= and rd.luks.options= are more generic as you basically can place any valid crypttab option in there, e.g. discard. Since they are interpreted by systemd-cryptsetup-generator which doesn't care about cryptdevice= you can't expect a useful interaction between these options.
Note that luks.options= only has an effect for devices that aren't listed in the initramfs image's etc/crypttab file.
Thus, to enable dm-crypt pass-though SSD trim support (a.k.a. discard) for dm-crypted devices opened during boot you have 2 options:
add rd.luks.options=discard to the kernel command line and make sure that the initramfs image doesn't include a etc/crypttab
add the discard option to the relevant entries in /etc/crypttab and make sure that the current version is included in the initramfs image.
You can use lsinitrd /path/to/initramfs etc/crypttab for checking the initramfs image, dracut -v -f /path/to/initramfs-image for regenerating the image after changes to /etc and dmsetup table to see whether the crypted device was actually opened with the discard option (the relevant entries should include the string allow_discards then).
| LUKS discard/TRIM: conflicting kernel command line options |
1,419,471,821,000 |
Can scrypt be used as the hashing algorithm for LUKS? Can I tune its parameters? How can I do this?
|
No, LUKS 1 only supports PBKDF2 as the password-based key derivation function. PBKDF2 is built on a cryptographic hash function, and you can select the hash function with --hash, as well as the iteration count via --iter-time. All supported hash functions are equally secure for this use case; a higher iteration count makes the job proportionally harder for the attacker but also make normal mounting correspondingly slower.
There is a registered issue for LUKS to support scrypt. This is a significant change because there is no field in the on-disk format to indicate which key stretching is in use. This has been discussed briefly on the dm-crypt mailing list.
LUKS 2 supports Argon2, which is a memory-hard password-based key derivation function (like scrypt) that is the new standard for password hashing.
| Can I use scrypt to hash for LUKS? |
1,419,471,821,000 |
I have two hard drives in a volume group with LVM. All volumes in that volume group hold LUKS containers. If I add an SSD as an LVM cache to that volume group, is all data on the cache device encrypted?
Bonus points for tools that confirm the cache's content.
|
If I add an SSD as an LVM cache to that volume group, is all data on the cache device encrypted?
Yes, it's encrypted because LVM cache works with blocks directly. It has no idea what the underlying data is.
Bonus points for tools that confirm the cache's content.
Fire up any hex editor (hexedit, dhex, etc) and open your logical volume directly. Encrypted data should look like noise.
| Is an LVM cache a security leak when using LUKS on LVM? |
1,419,471,821,000 |
I'm looking for a way to make the following setup happen in Gentoo:
/dev/sda1 -> /boot (ext2)
/dev/sda2 -> Luks encrypted
|
+-lvm-vg1
|
+- /dev/mapper/root-fs -> / (ext4)
+- /dev/mapper/swap -> (swap)
It's basically the same setup as Ubuntu would do when doing a graphical install.
I do know how to manually setup LUKS and even the LVM setup but I get stuck when bringing it together at boot. How do I tell the kernel and grub to unlock the LUKS partition and mount the right LVM partitions?
|
So I did figure it out:
I partitioned the disk partialy following the handbook:
# parted -a optimal /dev/sda
GNU Parted 2.3
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)mklabel gpt
(parted)unit mib
(parted)mkpart primary 1 3
(parted)name 1 grub
(parted)set 1 bios_grub on
(parted)mkpart primary 3 131
(parted)name 2 boot
(parted)mkpart primary 131 -1
(parted)name 3 lvm
(parted)set 2 boot on
(parted)q
The only change I made was not to make a swap and root partition but instead make a single partition and named it lvm (the name doesn't matter). Next I've setup LUKS:
# Load the dm-crypt module (probably not nessesary)
modprobe dm-crypt
# Crypt the partition we named lvm (in my case that would be /dev/sda3)
cryptsetup -c aes-cbc-essiv:sha256 -v luksFormat -s 256 /dev/sda3
# Open the luks volume
cryptsetup luksOpen /dev/sda3 sda3-luks
# Setup a LVM physical volume
lvm pvcreate /dev/mapper/sda3-luks
# Setup a volume group
lvm vgcreate vg0 /dev/mapper/sda3-luks
After that setup the actual volumes:
# Fist setup the swap volume
lvm lvcreate -L 2048M vg0
# Then check how many 'extends' are free (Free PE) using lvm vgdisplay
# use that number to use up the rest of the space:
lvm lvcreate -l 7809 vg0
For the rest we basically follow the handbook except where you would normaly do stuff for /dev/sda3 (swap) or /dev/sda4 (root) you would now use /dev/mapper/vg0-lvol0 (swap) and /dev/mapper/vg0-lvol1.
Important is, when generating the kernel (I used genkernel for this) to first install cryptsetup using emerge -av cryptsetup. and then run genkernel with the following parameters:
genkernel --luks --lvm --busybox --menuconfig all
Be sure to setup the kernel to support LVM and the chosen hashing and encrypting algorithms (in my case aes and sha256). Then continue following the handbook until you start the grub-config.
Before you run grub2-mkconfig you should edit the file /etc/defaults/grub. (I should state, for the record that I', not sure if this is the best solution but it works for me).
In that file I've put the following (find and uncomment the parameter):
GRUB_CMDLINE_LINUX="crypt_root=UUID=<uuid of sda3> dolvm"
You can find the correct UUID by using ls -l /dev/disk/by-uuid. After that grub2-mkconfig should find bother the kernel and the initramfs in /boot. Again, follow the handbook and after the reboot you should get a password prompt.
Hope this helps anyone else.
| Guide for Gentoo setup with full disk encryption using LUKS+LVM |
1,419,471,821,000 |
I was wondering, if it was possible to use LUKS encryption with tape drives, QIC for instance.
I'm using LUKS for USB drives and internal disks, even DVDs and CDROMs. But I was thinking of maybe using it to encrypt tape drives as well.
Should I just use cryptsetup luksFormat directly to the tape drive and then enable the device with cryptsetup luksOpen?
|
You are unlikely to be happy with the huge latencies introduced by LUKS on linear media. A better idea is to pipe the output of tar through OpenSSL, encrypting it with a streaming cipher, before sending it to the tape device.
| LUKS encryption for tape media? |
1,419,471,821,000 |
I have installed Arch Linux with LUKS on a btrfs file system.
When logging in,
I can't mount my filesystem on /dev/sda2 because the keyboard is US (I need a French key map).
I try change /etc/vconsole.conf to FR and generate locale-gen but the keyboard don't change in next boot.
|
Your /etc/mkinitcpio.conf needs to look like this:
HOOKS="... keyboard keymap encrypt..."
You need to load the keymap during boot, which is done by an mkinitcpio hook. Make sure that the keymap or sd-vconsole hook (depending on whether you use sd-* style hooks) occurs before encrypt/sd-encrypt and regenerate your initrd.
| Problem keyboard layout in boot with LUKS |
1,419,471,821,000 |
How to run cryptsetup luksFormat non-interactively
When LUKS formatting a partition, I recieve the message
# cryptsetup luksFormat /dev/sdb
WARNING!
========
This will overwrite data on /dev/sdb irrevocably.
Are you sure? (Type uppercase yes): YES
Followed by Enter passphrase:.
How can I automatically answer YES to the question "Are you sure ?
|
You could make use of the --batch-mode, -q option of cryptsetup to skip the question.
$ cryptsetup -q luksFormat /dev/sdb
This option also disables password verification, so one should use it with care or in an automated environment
| How to answer YES automatically with a cryptsetup luksFormat command? |
1,419,471,821,000 |
UPDATE 1:
userone@desktop:~$ sudo umount "/media/userone/New Volume"
umount: /media/userone/New Volume: mountpoint not found
userone@desktop:~$ sudo cryptsetup luksClose /dev/mapper/luks-04cb4ea7-7bba-4202-9056-a65006fe52d7
Device /dev/mapper/luks-04cb4ea7-7bba-4202-9056-a65006fe52d7 is not active.
userone@desktop:~$ sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:16 1 29.5G 0 disk
└─sdb1 8:17 1 29.5G 0 part
└─luks_USB 252:3 0 29.5G 0 crypt
sr0 11:0 1 1024M 0 rom
userone@desktop:~$ sudo cryptsetup luksOpen /dev/sdb1 luks_USB
Device luks_USB already exists.
userone@desktop:~$ sudo mkdir /media/userone/luks_USB
mkdir: cannot create directory ‘/media/userone/luks_USB’: File exists
userone@desktop:~$ sudo mount /dev/mapper/luks_USB /media/userone/luks_USB
mount: wrong fs type, bad option, bad superblock on /dev/mapper/luks_USB,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.
userone@desktop:~$ dmesg | tail
[20639.663250] JBD2: no valid journal superblock found
[20639.663257] EXT4-fs (dm-3): error loading journal
[20828.133606] JBD2: no valid journal superblock found
[20828.133613] EXT4-fs (dm-3): error loading journal
[20832.682397] JBD2: no valid journal superblock found
[20832.682405] EXT4-fs (dm-3): error loading journal
[20851.042343] JBD2: no valid journal superblock found
[20851.042349] EXT4-fs (dm-3): error loading journal
[21053.115711] JBD2: no valid journal superblock found
[21053.115718] EXT4-fs (dm-3): error loading journal
userone@desktop:~$
ORIGINAL QUESTION:
When I plug in my encrypted USB drive, I get this message in a GNOME dialog:
Error mounting /dev/dm-3 at /media/userone/New Volume:
Command line
mount -t "ext4" \
-o "uhelper=udisks2,nodev,nosuid" \
"/dev/dm-3" "/media/userone/New Volume"'
exited with non-zero exit status 32:
mount: wrong fs type, bad option, bad superblock on
/dev/mapper/luks-04cb4ea7-7bba-4202-9056-a65006fe52d7,
missing codepage or helper program, or other error.
In some cases, useful info is found in syslog - try dmesg | tail or so.
Anyone know how this can be corrected? It was working fine yesterday.
|
It looks as though the journal has become corrupt, doing some searches over the past few days, this seems to not be uncommon on devices that use LUKS.
You could try running an fsck on the device, acknowledging that any data on the device may not be accessible after - you may like to use dd to make a copy of the drive before this.
A common resolution appears to be to create the EXT4 file system from scratch with journaling disabled using mke2fs -t ext4 -O ^has_journal /dev/device. Obviously you would lose the advantages of having a journaled file system by doing this, and lose any data on the device!
Problem
This problem is that the EXT4 file system’s journal has become corrupt. The problem is perhaps made a little obscure due to the fact that the device is encrypted and the file system resides “inside” the encryption.
Resolution
There is a thread of comments below, however I thought a summary here would be more beneficial to anyone who might come across this in the future.
Unencrypt the device, this allows us to get at the device that the EXT4 file system resides on: sudo cryptsetup luksOpen /dev/sdb1 luks_USB
Create an image of the device that has been created in the previous step. We need to do this because file system checking utils generally won’t work on mounted devices, and although the device with EXT4 on isn’t mounted, it’s “parent” is. sudo dd if=/dev/dm-3 of=/tmp/USBimage.dd (add bs and count arguments as you see fit).
Now we have an image, we can run the file system checks: sudo e2fsck /tmp/USBimage.dd any problems found can be evaluated and fixed as required.
You can check to see if your file system has been fixed by attempting to mount the image: sudo mount -o loop /tmp/USBimage.dd /mnt
At this point the OP was able to gain access to their files.
While I would suggest wiping the USB stick and starting over (back to a known state, etc), I think it would be possible to unmount the image from /mnt and then copy if back onto the device that become corrupt: sudo dd if=/tmp/USBimage.dd of=/dev/dm-3
| Mount error when automounting a LUKS-encrypted USB flashdrive |
1,419,471,821,000 |
I'm trying to determine if I should re-setup my RAID array due to poor IO performance. First off, the system:
i7 920
4 4TB WD 5400 Green drives
CentOS 6.3 host
Secondly, the disk setup:
/dev/sda2,b2,c2,d2 are individually LUKS encrypted
/dev/mapper/a2,b2,c2,d2 are all part of a software RAID5 /dev/md1
/dev/md1 has LVM on top of that
LVM is used to separate /, /storage, and swap
I choose this structure to allow for multiple instances of kcryptd, thinking that by doing this, I would get multithread support on encryption since one instance is running per drive. However, I'm beginning to wonder if that was a good idea.
For instance, if I run a heavy decompression routine on a RAR file of random data, my IO Wait goes up to around 25% and it slows the overall system down. I'm wondering if all the instruction sets are getting backed up somehow due to all the kcryptd processes.
Therefore, I'm considering changing to:
/dev/sda2,b2,c2,d2 are put into /dev/md1
/dev/md1 is encrypted and mapped to /dev/mapper/1
LVM on top of /dev/mapper/1
This would drop down to a single kcrpytd process, which could be a bottleneck in it's own right, too. Does anyone think this will help with my IO issue?
|
Your layering is suboptimal because putting the raid 5 on top of the encryption means that you increase the number of encrypt/decrypt operations by 25 % - since 4 * 4 TB are encrypted.
When putting the encryption on top of the raid 5 only 3 * 4 TB are encrypted.
The reasoning behind that is: you don't have to encrypt parity data (which takes up 4 TB in your example) of encrypted data because it does not increase your security.
Your presumption about multiple kcrypt processes is just that. When basing decisions on it, it is a premature optimization that may have quite the opposite effect. Your i7 is quite beefy, probably even including some special instructions that help to speed up AES - and the Linux kernel includes several optimized variants of cryptographic primitives that are automatically selected during boot.
You can verify if the optimized routines for your CPU are used via looking at /proc/cpuinfo (e.g. flag aes there), /proc/crypto, lsmod (unless the aes modules are compiled into the kernel) and the kernel log.
You should benchmark the throughput of kryptd without involving any slow disks to see what the upper bound really is (i.e. on a RAM disk using iozone).
To be able to diagnose potential performance issues later it is also useful to benchmark your RAID-setup of choice without any encryption to get an upper bound on that end.
In addition to the crypto topic, RAID 5 involves more IO-Operations than RAID 1 or 10. Since storage is kind of cheap perhaps it is an option to buy more harddisks and use another RAID level.
| Poor IO due to LUKS/Software RAID/LVM ordering? |
1,419,471,821,000 |
I'm surprised that this question is not asked more frequently, but (in RHEL) does LUKS support TPM's the way that Windows BitLocker does? If so, how is this feature implemented, and does it provide the same type of protections that BitLocker for Windows provides?
BitLocker is very popular among businesses, and now that RHEL6 is getting FIPS certification for the disk encryption modules, it would be great if it also supported the same feature set.
However, I do understand that with the way LUKS works, not every volume can be encrypted, since the system would need to read the /etc/fstab and the /etc/crypttab files in order to mount the volumes. I believe this is OK as long as /home, /var, and other directories chosen by the administrator are encrypted.
I find it odd that "TPM" is not a tag on serverfault.
|
I've implemented support for storing your LUKS key in TPM NVRAM, and RHEL6 happens to be the one platform where all features are fully tested, see this post:
[1] https://security.stackexchange.com/a/24660/16522
| RHEL6 LUKS with TPM support? |
1,419,471,821,000 |
I am on the latest OpenSUSE Tumbleweed and this guide has not worked for me.
I did everything like in the guide except I did not generate a new random key and added it to the harddisk but used the passphrase I always used and wrote that into /.root.key.
But I am still asked for the password but it seems cryptsetup or whatever is smart enough to automatically try it for all my other HDDs that also use the same passphrase as the SSD. So I have to enter it for Grub, then I am asked again to unlock the SSD again during boot.
How can I see if the /.root.key is added to the initramfs?
|
I did everything like in the guide except I did not generate a new random key and added it to the harddisk but used the passphrase I always used and wrote that into a file.
Passphrase in file works fine, but it must not have newline at the end.
Verify that it works with --key-file option:
cryptsetup open --verbose --key-file yourfile --test-passphrase /dev/yourdevice
How can I see if the /.root.key is added to the initramfs?
Use one of lsinitrd, lsinitramfs, lsinitcpio or just unpack it yourself.
mkdir /tmp/initramfs
cd /tmp/initramfs
gunzip < /boot/initrd.gz | cpio -div -H newc --no-absolute-filenames
This command may be different if e.g. it's not gzip compressed but xz or something else. Adapt as you see fit.
Alternatively, if the initrd drops you to a emergency shell, you can of course also use that to explore the initrd state then.
ls -al
hexdump -C .root.key # or similar
it seems cryptsetup or whatever is smart enough to automatically try it for all my other HDDs that also use the same passphrase as the SSD
This is a systemd feature, systemd-ask-password --accept-cached (accept cached passwords, i.e. passwords previously entered). Maybe it has found its way into other flavors of initramfs as well. It's a good solution, typing passphrase twice is still somewhat acceptable, typing it 10 times in a row...
Not all distributions use this feature and I do not know if it cooperates with the keyfile approach as outlined in your guide. You'll have to debug that yourself.
| Grub2/LUKS How to avoid to type the passphrase twice? |
1,419,471,821,000 |
I have been having a lot of issues getting an encrypted multi-disk root filesystem to boot up reliably under systemd on Debian Jessie while only having to enter the password once. Previously I've handled this in Debian by using the decrypt_derived keyscript in /etc/crypttab for every device except the first, and this worked well.
However, this does not play well when systemd is introduced. systemd-cryptsetup-generator does not handle keyscripts, and when trying to find more information about how to solve this, I only found vague references to some custom password agent in an email from one of the systemd developers which only gives the unhelpful advice that it is "easy to write additional agents. The basic algorithm to follow looks like this" and then a list of 13 steps to take. Clearly not meant for an end user.
I Debian, I have got it to work to some degree by playing with a couple of kernel options that tells systemd to ignore /etc/crypttab during boot, or ignore it completely. Debian's update-initramfs will copy the keyscript to the initramfs and unlock the devices before systemd takes over, but I have found that it leads to issues later because systemd now does not have any unit files for the decrypted devices so mounts that rely on them sometimes seem to hang or get delayed. One place where this breaks is when trying to mount btrfs subvolumes; they are mounted from the same physical device as root, but systemd is not aware that the devices are already unlocked, and halts at boot.
TL;DR - my actual question:
What is the systemd way to handle an encrypted root filesystem spanning multiple devices (be it a btrfs system, LVM mirror, etc) where you only need to enter the password once? I hardly consider this to be an exceptionally unusual case, so here's hoping that there is a method in place to do this.
Some possible solutions comes to mind:
Tiny encrypted partition containing a keyfile, which is unlocked before root. The root devices would refer to this keyfile. How would I tell this to systemd?
Some sort of caching password agent running in initramfs, which remembers the password and hands it to all devices needing it at boot.
Someone has already written a systemd agent emulating decrypt_derived. How would I integrate this in my boot procedure?
I do run Debian exclusively, but after having tried for days to find a solution to my problem I feel that this is perhaps a more system wide problem.
|
There is now a solution to this problem (at least in Ubuntu 18.04+, so I assume Debian, and CentOS-7). Described here. Quoting:
Systemd ... will unlock all additional LUKS partitions if
all of the partitions you want to unlock use the same password
you enter the password for the root partition correctly the first time. If you get it wrong, you'll need to enter it again for every other LUKS partition
| What is the proper way to unlock a root filesystem spanning two LUKS devices by only entering the password once, using systemd? |
1,419,471,821,000 |
Can I use the same single LUKS detached header for multiple drives?
What do I should keep in mind doing so? Is this also possible if the drives are fundamentally different (different size, manufacture etc.) ?
Reason: I want to use multiple drives in a single system with LUKS but from security standpoint there is no benefit in using different headers. But maybe there are technical reasons not do so?
|
Technical
Yes, you can absolutely copy a LUKS header from one disk to another. To be exact you can copy it from a block devise to another block device, this means you can safely copy the LUKS header from a partition (a block device) to a block device representing the whole disk. You can simply do:
dd if=/path/to/block/deviceA of=/path/to/block/deviceB bs=2M count=1
There is one technical limitation though, if you are using something like udev to identify block devices by UUID and to assign them to specific device files than udev may get confused since all drives will have the same UUID. This is because the LUKS header contains a UUID.
Note that this is not the same as mounting filesystems in /etc/fstab. mount will be looking at the UUIDs of the filesystems which are on top od LUKS (as long as the drive is decrypted).
The fact that the LUKS header can be used on any block device also means that the size of the device does not matter for the header. If you are using the header on a single partition then the partition table knows the size of the block device, if you are using it on an entire disk then the kernel knows its size.
Security
From a security standpoint copying LUKS headers is a bad idea. The LUKS header contain an encryption key with which the data is encrypted, i.e. the data is encrypted with the key inside the header not with a key generated from the password. The LUKS header then stores this encryption key several times encrypted under a key generated from a password.
If the disk can be decrypted with 3 different passwords the key is stored three times: each time encrypted under a key generated from one password.
As an example let's assume tha you have 2 disks and each can be decrypted with 2 passwords, and you copied the LUKS header from one disk to another. Now, if one of the passwords is compromised the encryption key is compromised. If an attacker managed to get his hands on diskA and got the key by using the compromised password, then you need to destroy the data on diskB since the attacker can decrypt it.
In the same situation (one password is compromised), had you not copied the LUKS header the recovery would be much easier. If diskA is in possession of an attacker and he has the encryption key for diskA he still cannot decrypt the data on diskB. He can, of course, use the compromised password to get the encryption key of diskB from diskB, but, if you are faster than the attacker, you can disable the compromised password from diskB (this happens by overwriting the encryption key stored under the compromised password).
Therefore there are benefits from using different headers. One of the header's purposes is to allow different passwords to be used and to make the data encrypted on each block device to be encrypted under a different key, albeit the password used to decrypt the drives is the same.
| Can I use a luks detached header for multiple drives? |
1,419,471,821,000 |
With the default RHEL 6 installer, how can I choose the LUKS encryption?
Afaik if I prepare the disk like
cryptsetup luksFormat -c cast5-cbc-plain -s 128 /dev/$DEVICE
could be the "fastest" encryption, but the installer only prompts for password, then later, at the partitioning it recognizes it as "unknown" partition.
UPDATE: so in short, I just want to speed up io with using the mentioned faster encryption (? are there faster/but still ""secure""?) with the default install. How can I don it?
UPDATE#2: what would be the fastest encryption that can be still used in the default GUI install??
|
You might be stuck using a kickstart to define the partition with the encryption type instead of using the graphical install interface.
| How to choose LUKS encryption when installing RHEL 6? |
1,419,471,821,000 |
I'm trying to find out what happened to my laptop LUKS drive. I'm sure it ran out of battery since I forgot to plug it in. This morning I booted the system and the LUKS password does not work. I tried several reboots and every time it ends up offering emergency console after 3 tries because it can't decrypt the drive.
My question is, if the laptop lost power and did not have time to suspend/sleep, can that corrupt the password? I had thought a power-off corruption would cause it to not ask for any password at all... corrupted, not just mess up password.
I tried decrypting the crypt volume while booted from live CD but it still fails. In this case would it still be worthwhile to try restore boot files?
|
LUKS works by dedicating a small amount of space, typically on the encrypted partition, to the "LUKS header". That header contains a checksum, so it should detect corruption. Further, there are two copies; each with their own checksum, so it should automatically use the other copy if one is corrupted. Along with the header, there is the keyslot data, which actually stores the encryption keys. That is not duplicated, I believe will at least detect corruption (and you could use a backup key/passphrase if you have one).
Documentation of the format can be found at https://gitlab.com/cryptsetup/LUKS2-docs/blob/master/luks2_doc_wip.pdf
So I think it's very unlikely the on-disk data got corrupted, and even more unlikely that doesn't get a corruption error instead of a wrong passphrase.
More likely, you're just entering the wrong passphrase — possibly you're using a different keyboard layout, had caps lock on, or you've forgotten it. If you have a backup recovery key, you can use that to recover your data.
(Side note, if it did get corrupted and you don't have a backup of the header + keyslots or the master key, the data is entirely unrecoverable).
Frostschutz points out that if you're still on the old LUKS1 format then there isn't a checksum, so corruption could occur (though there are still magic numbers, etc., so if the entire sector were overwritten that'd be noticed). Also, if you've upgraded from a very old cryptsetup/gcrypt (2014-era), then there was a bugfix which broke cryptsetup; see https://gitlab.com/cryptsetup/cryptsetup/-/wikis/FrequentlyAskedQuestions#8-issues-with-specific-versions-of-cryptsetup for details.
| LUKS password is wrong after system power off |
1,419,471,821,000 |
I have a new installation of ubuntu 22.04, with full disk encryption (LUKS) and ZFS picked from the ubuntu installer options.
I need to make some edits to /etc/crypttab so that unlocking my drives works in an automatic way (fancy usb auto unlock), but the edits I'm making to /etc/crypttab aren't persisting to initramfs.
What I'm doing is:
Editing /etc/crypttab
Running update-initramfs -u
Rebooting my machine into the the system that asks for the LUKS password (initramfs)
Checking the contents of /etc/ but crypptab isn't there.
Have I got my concept of how this works incorrect? I need to persist some version of crypttab to the loader but it isn't working.
Any pointers to what I'm doing wrong?
|
I'm here because I ran into the same problem, found this question via Google, and have some information to add. I am attempting to auto-unlock a LUKS drive without having type a passphrase.
First, I edited /etc/crypttab and changed its entry to the following:
sda3_crypt UUID=2d661ff8-d6a8-49c9-ae96-4d6e234bffe2 /dev/zero luks,discard,keyfile-size=32
Then, I added a new key using the following command:
sudo cryptsetup luksAddKey --new-keyfile-size 32 /dev/sda3 /dev/zero
Finally, I ran update-initramfs which produced the following output:
$ sudo update-initramfs -u
update-initramfs: Generating /boot/initrd.img-6.0.0-2-amd64
cryptsetup: WARNING: sda3_crypt: key file /dev/zero has insecure ownership, see
/usr/share/doc/cryptsetup/README.Debian.gz.
cryptsetup: WARNING: Skipping root target sda3_crypt: uses a key file
This already seemed suspicious, but I rebooted anyway. Unfortunately, these actions made the system unbootable:
Gave up waiting for suspend/resume device
Gave up waiting for root file system device: Common problems:
- Boot args (cat /proc/cmdline)
- Check rootdelay= (did the system wait long enough?)
- Missing modules (cat /proc/modules; ls /dev)
ALERT! /dev/mapper/legend--vg-root does not exist. Dropping to a shell!
BusyBox v1.35.0 (Debian 1: 1.135.0-2) built-in shell (ash)
Enter 'help' for a list of built-in commands.
(initramfs) cat /etc/crypttab
cat: can't open '/etc/crypttab': No such file or directory
I was able to successfully boot the system again by entering the following commands at the BusyBox prompt:
cryptsetup luksOpen --key-file /dev/zero --keyfile-size 32 /dev/sda3 sda3_crypt
exit
The original question still stands though: why is /etc/crypttab not available in the initramfs?
Update
After more research, I can now finally answer the original question: /etc/crypttab is not present in initramfs because the default unlock script does not use that location; it uses /cryptroot/crypttab instead.
To make /etc/crypttab available as /cryptroot/crypttab in initramfs, create the following script in the /etc/initramfs-tools/hooks directory and make it executable:
#!/bin/sh
cp /etc/crypttab "${DESTDIR}/cryptroot/crypttab"
exit 0
Finally, let it be noted that using auto-unlocking LUKS devices by using empty passphrases defeats the purpose of encryption. It is just as insecure as using no encryption at all.
| /etc/crypttab not updating in initramfs |
1,419,471,821,000 |
I'm trying to use FIDO2 (YubiKey 5) with Fedora 36 to unlock the LUKS volume on system boot without success as it keeps asking for the regular LUKS passphrase and not using the token to unlock the LUKS volume.
I followed Lennart Poettering's example on his blog and used systemd-cryptenroll to enrol the YubiKey and then modified the /etc/crypttab file with the appropriate config. cryptsetup luksDump shows the token is added to the LUKS header. However on system boot the Plymouth splash screen is displayed prompting for the regular LUKS passphrase to unlock the volume.
I thought Plymouth might not be displaying the prompt to enter the FIDO2 PIN, so I removed and re-added the LUKS keyslot and token with extra parameters to not require user presence or PIN:
systemd-cryptenroll --fido2-device=auto --fido2-with-user-verification=false --fido2-with-client-pin=false /dev/sda3
This still doesn't work and it still prompts for the LUKS passphrase.
Fedora 36 is running systemd version 250.
Any ideas why FIDO2 isn't working to unlock the LUKS volume?
|
TL;DR run dracut --regenerate-all --force
So I found the problem, I didn't execute dracut --regenerate-all --force after modifying /etc/crypttab before rebooting. I believe on Debian based distros you would need to run update-initramfs -uinstead. When requiring a FIDO2 PIN it is entered at the Plymouth interface. It looks identical to when entering a LUKS passphrase but if you hit Esc you will see the prompt asking for the FIDO2 token PIN instead.
For reference here is a complete procedure for configuring a FIDO2 token (e.g. YubiKey) to unlock a LUKS volume on a RH/Fedora distro (Note: This is only supported from systemd version 248. systemctl --version to check.)
View existing LUKS keyslot info. If initially configured to use only a passphrase you will see only one keyslot (slot 0) and zero tokens.
cryptsetup luksDump /dev/sda3 (Replace sda3 with whatever your block device is)
Enroll token(s). In this example, specifying a requirement for FIDO2 PIN and user presence (e.g. 'touch').
systemd-cryptenroll --fido2-device=auto --fido2-with-client-pin=true --fido2-with-user-presence=true /dev/sda3
Check LUKS token(s) and keyslots again. This time you should see an addition keyslot (slot 1) and a new token (token 0) which will also list the above parameters if specified during enrollment.
cryptsetup luksDump /dev/sda3
Modify /etc/crypttab. By default on Fedora 36 it will be using UUIDs.
vim /etc/crypttab
Modify so it looks like this.
luks-a6c32afd-3c35-4628-8653-5be499eaf0ce UUID=a6c32afd-3c35-4628-8653-5be499eaf0ce - fido2-device=auto
Generate new initramfs image
dracut --regenerate-all --force
Reboot and test. As mentioned the Plymouth splash screen will look the same but instead of entering a LUKS passphrase, enter the FIDO2 PIN instead. Or press 'Esc' to verify that it is actually prompting for the FIDO2 PIN, if required. If the presence requirement was specified, you will need to touch the token. The system should boot.
Extras:
To remove a token from a LUKS volume.
cryptsetup token remove --token-id 0 /dev/sda3
And to remove the corresponding key slot.
systemd-cryptenroll --wipe-slot=1 /dev/sda3
A peculiarity I've noticed if enrolling multiple FIDO2 tokens and specifying a PIN and presence requirement is that you will need to touch the token X number of times, where X is the n'th token that's been enrolled. E.g. If you enroll four tokens, when using the 4th enrolled token, you will need to touch it four times before the system boots. I think it's related to this mention in SYSTEMD-CRYPTENROLL(1):
Also note that support for enrolling multiple FIDO2 tokens is
currently not too useful, as while unlocking systemd-cryptsetup cannot
identify which token is currently plugged in and thus does not know
which authentication request to send to the device.
| FIDO2 (YubiKey) to unlock LUKS at boot on Fedora 36 not working |
1,419,471,821,000 |
I try to decrypt my harddrive using the password that I 100% know. The password knowledge is not the problem.
Last thing I remember doing is: installing texlive. Not having enough disk space. Removing texlive again. followed by
apt update
apt upgrade
apt dist-upgrade
I remember the update had an error due to missing internet connection (wifi switch was off) After I switched on wifi, update, upgrade and dist-upgrade went (I don't remember otherwise) smoothly.
Starting my machine this morning brings me to the current state of affairs:
No key available with this passphrase
cryptsetup failed. bad password or option?
The password contains special characters - can I somehow test which
symbols are created by a keypress? Maybe the keyboard layout switched or somithing similar.
This problem is on Debian Jessie.
Except for header backups, what else can help me investigate?
|
In GRUB (or whatever you're using as your bootloader), add this boot option to your kernel command line: break=premount. It should give you a shell prompt while the system is still running on initramfs and the system has not yet made any attempts to mount the real root filesystem.
You can use this shell prompt to check your keyboard layout.
| cryptsetup disc encryption “no key available with this passphrase” - but password known 100% [closed] |
1,419,471,821,000 |
When unlocking a newly-formatted LUKS volume, I received a warning in the kernel log:
kernel: device-mapper: table: 253:14: adding target device sdk1 caused an alignment inconsistency: physical_block_size=4096, logical_block_size=512, alignment_offset=0, start=33553920
According to another question, a false warning is possible, so I confirmed it's a true warning: 33553920 is not divisible by 4096. I further used luksDump to confirm:
cryptsetup luksDump /dev/sdk1 | grep 'Payload offset'
Payload offset: 65535
which is not a multiple of 8 (4096 ÷ 512 = 8)
lsblk -t /dev/sdk confirms Linux is aware of the alignment requirements:
NAME ALIGNMENT MIN-IO OPT-IO PHY-SEC LOG-SEC ROTA SCHED RQ-SIZE RA WSAME
sdk 0 4096 33553920 4096 512 1 cfq 128 128 32M
└─sdk1 0 4096 33553920 4096 512 1 cfq 128 128 32M
dmsetup is documented to handle alignment itself, why did it create a misalignment? And are there arguments to luksFormat to avoid the problem?
|
It appears that dmsetup computes its alignment from the optimal I/O size, without bothering to check that that is actually a multiple of the physical block size. As mentioned in the false warning question, this optimal I/O size makes sense due to USB constraints.
So the solution is simple: use --align-payload to override the detected value. A value of 8 should work (and produce the smallest possible header); the default when cryptsetup can't tell is documented as 2048. So I went with the default:
cryptsetup luksFormat /dev/sdk1 --align-payload 2048 --verify-passphrase --hash sha512 -s 512
After that, the payload offset is now 4096 (from luksDump), and a kernel warning is still produced:
kernel: device-mapper: table: 253:14: adding target device sdk1 caused an alignment inconsistency: physical_block_size=4096, logical_block_size=512, alignment_offset=0, start=2097152
... but 2097152 is divisible by 4096, so that's the false warning mentioned in the other question. So the problem is resolved.
| dmsetup luksFormat creating an alignment inconsistency |
1,419,471,821,000 |
I'm running Debian Buster on a ThinkPad T420 which is equipped with a 250 GB SSD. Since I needed more disk space I used Clonezilla to clone my current Debian installation from the internal 250 GB SSD to a new 500 GB SSD connected via an USB to SATA adapter. Afterwards I replaced the 250 GB SSD with the 500 GB SSD and used GParted live to increase the size of the extended partition (/dev/sda2) and the LVM2 PV partition (/dev/sda5). Everything worked fine and the system is up and running again. Unfortunately, I cannot use the new space yet, because the root LVM also has to be resized:
user@debianbook:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 465,8G 0 disk
├─sda1 8:1 0 243M 0 part /boot
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 465,5G 0 part
└─sda5_crypt 254:0 0 465,5G 0 crypt
├─user--deb--vg-root 254:1 0 204,3G 0 lvm /
└─user--deb--vg-swap_1 254:2 0 7,9G 0 lvm [SWAP]
Which steps are necessary to increase the root LVM on /dev/sda5?
|
it's like Russian dolls: disk -> MBR partition scheme -> extended partition container -> logical partition -> LUKS -> PV -> VG -> LV-> filesystem. So the root filesystem isn't simply on /dev/sda5.
What you already did:
enlarge disk
enlarge extended partition container (/dev/sda2)
enlarge partition (/dev/sda5)
What's left:
LUKS: no special handling. metadata is at the start and thus LUKS isn't affected. LUKS (actually the device-mapper backend) already coped with the change in size. It's just that if the additional space wasn't zeroed inside LUKS (which is not a good idea for SSD endurance), the additional unused data will appear as random data there.
PV: (summary with pvs) while the potential space available to the PV increased, the PV must be told about it to actually use it. To occupy the whole space available no special option is needed to pvresize, as described in the manual:
Expand a PV after enlarging the partition.
pvresize /dev/sda1
For your case:
pvresize /dev/mapper/sda5_crypt
VG: (summary with vgs) nothing to do, VG inherits its available size from the PV(s) it uses so appears larger right after the PV was made larger. VG is a LVM2 abstraction not having a visible direct device mapper counterpart.
LV: (summary with lvs) the generic command is lvresize but better use lvextend which can only make it larger for safety. You can tell it to use as additional space the whole free space available (but see the filesystem part before doing it):
lvextend -l +100%FREE user-deb-vg/root
filesystem: now it has more available space it can be enlarged too.
As it's Debian's default, I'm assuming EXT4 was used here. As / is already mounted, this has to be done in online mode (meaning kernel's filesystem driver must be involved) which is supported by the EXT4 filesystem (and a few others). To enlarge to the available space provided by the LV, again no specific size option is needed:
resize2fs /dev/mapper/user--deb--vg-root
But actually the two last steps (LV+FS) can be combined in a single command using here:
lvextend --resizefs -l +100%FREE user-deb-vg/root
which has the advantage of autodetecting the filesystem and running the right command for the right filesystem.
You don't have to use the whole available size. You could choose +50%FREE to leave ~ 130GB as reserve, especially if you want to create a separate filesystem later (in an additional LV).
| How to increase LVM when using LUKS2 on Debian Buster |
1,552,997,393,000 |
I'm in a (bad) situation where I have multiple correct passwords and used luks slots, but I can't tell which password belongs to which slot
Decryption (during startup thanks to crypttab) works well, but I can't tell which slot has been used. In order to rationalize this situation, is there a way to determine which luks slot has been used?
From this question I've read:
If you've forgotten one of the passphrases then you can only find which slot it's in by elimination, and if you've forgotten two of the passphrases then there's no way to tell which is which (otherwise the passphrase hash would be broken).
... so I'm a bit afraid of testing each slot for each password, even if I haven't found any reference of broken passphrase hashes in the man page.
Nota: luckily the first luks slot is known, so I might back up on my feet by resetting the others.
|
The open LUKS container does not tell which keyslot it was opened with. So no, you can't determine later which slot "has been used".
However, if you know a valid key or passphrase, you can determine which slot it is located in, for example by re-running cryptsetup open with --test-passphrase, --key-slot or --verbose options.
Normal operation (not very informative):
# cryptsetup open --test-passphrase luks.img
Enter passphrase for foobar.img: first
# cryptsetup open --test-passphrase luks.img
Enter passphrase for foobar.img: second
# cryptsetup open --test-passphrase luks.img
Enter passphrase for foobar.img: third
Verbose operation (tells you which keyslot was used):
# cryptsetup --verbose open --test-passphrase luks.img
Enter passphrase for foobar.img: first
Key slot 0 unlocked.
Command successful.
# cryptsetup --verbose open --test-passphrase luks.img
Enter passphrase for foobar.img: second
Key slot 1 unlocked.
Command successful.
# cryptsetup --verbose open --test-passphrase luks.img
Enter passphrase for foobar.img: third
Key slot 2 unlocked.
Command successful.
Specific keyslot operation (only accepts key stored in this slot):
# cryptsetup open --tries 1 --test-passphrase --key-slot 2 luks.img
Enter passphrase for luks.img: first
No key available with this passphrase.
# cryptsetup open --tries 1 --test-passphrase --key-slot 2 luks.img
Enter passphrase for luks.img: second
No key available with this passphrase.
# cryptsetup open --tries 1 --test-passphrase --key-slot 2 luks.img
Enter passphrase for luks.img: third
Normally the verbose mode is informative enough, however specifying the key slot directly can be useful when looking for duplicate passphrases (same key stored in two separate slots). It's also faster to test only one slot vs. going through all of them (optimizing LUKS open speed is a different topic, though).
| Is it possible to determine which luks slot has been used to unlock an encrypted partition? |
1,552,997,393,000 |
I'm running Arch Linux with systemd boot. In /boot/loader/entries/arch.conf I currently specify the luks crypto device with a line like this:
options rw cryptdevice=/dev/sda1:ABC root=/dev/mapper/ABC
I know I can also use UUID instead of /dev/sda1. In that case the kernel options line would look like this:
options rw cryptdevice=UUID=1f5cce52-8299-9221-b2fc-19cebc959f51:ABC root=/dev/mapper/ABC
However, can I instead use either a partition label or a volume label or any other kind of label? If so, what is the syntax?
|
If you're already using the new LUKS2 format, you can set a label:
For new LUKS2 containers:
# cryptsetup luksFormat --type=luks2 --label=foobar foobar.img
# blkid /dev/loop0
/dev/loop0: UUID="fda16145-822e-405c-9fe8-fe7e7f0ddb5e" LABEL="foobar" TYPE="crypto_LUKS"
For existing LUKS2 containers:
# cryptsetup config --label=barfoo /dev/loop0
# blkid /dev/loop0
/dev/loop0: UUID="fda16145-822e-405c-9fe8-fe7e7f0ddb5e" LABEL="barfoo" TYPE="crypto_LUKS"
However, it's not possible to set a label for the more common LUKS1 header.
With LUKS1, you can only set a label on a higher layer. For example, if you are using GPT partitions, you can set a PARTLABEL.
# parted /dev/loop0
(parted) name 1 foobar
(parted) print
Model: Loopback device (loopback)
Disk /dev/loop0: 105MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 104MB 103MB foobar
This sets the partition label of partition 1 to "foobar".
You can identify it with PARTLABEL=foobar or find it in /dev/disk/by-partlabel/
# ls -l /dev/disk/by-partlabel/foobar
lrwxrwxrwx 1 root root 13 Oct 10 20:10 /dev/disk/by-partlabel/foobar -> ../../loop0p1
Similarly, if you use LUKS on top of LVM, you could go with VG/LV names.
As always with labels, take extra care to make sure each label doesn't exist more than once. There's a reason why UUIDs are meant to be "universally unique". You get a lot of problems when trying to use the wrong device; it can even cause data loss (e.g. if cryptswap formats the wrong device on boot).
| How to specify cryptdevice by label using systemd boot? |
1,552,997,393,000 |
On my system, I have two encrypted disks:
crypt containing the root partition of raspbian stretch
usb-crypt is an external usb disk. LVM is used on that disk.
Both disks are protected using the same passphrase, but the master key is different according to "cryptsetup luksDump". Neither of the two disks are configured using a key file (only one key slot is used for each LUKS container).
When the system is booting, it is asking for the passphrase of "crypt", but usb-crypt is automatically mounted without asking for a passphrase. Note: I started with an unencrypted root partition, and with that setup, I was asked for the passphrase of usb-crypt during boot.
Here is the detailed setup:
$ sudo dmsetup ls --target crypt
crypt (254, 0)
usb-crypt (254, 1)
$ sudo cat /etc/fstab
/dev/mmcblk0p1 /boot vfat defaults 0 2
/dev/mapper/crypt / ext4 defaults,noatime 0 1
# ...
UUID=b9fb061f-0877-4d2c-bd3c-9c155b8f88a5 /mountpoint ext4 rw,auto 0 0
$ sudo cat /etc/crypttab
# <target name> <source device> <key file> <options>
crypt /dev/mmcblk0p2 none luks
usb-crypt UUID=31fb8df7-6148-4408-90a2-93b8ec752fa0 none luks
While having only to type the passphrase once is convenient, I am surprised seeing this behaviour. I'd have expected to be asked for both passphrases.
Is this related to using the same passphrase on both disks? Or is the master key of the usb disk automatically saved somewhere in the encrypted root partition of "crypt"? I'd appreciate if someone could explain what's going on here and maybe give some hints to relevant log files, etc.
Thanks in advance!
|
Depends on what the init script that asks the password of you is doing with it.
If it's systemd, it might just be a feature. systemd-ask-password comes with a cache functionality that might be responsible.
https://www.freedesktop.org/software/systemd/man/systemd-ask-password.html
--accept-cached
If passed, accept cached passwords, i.e. passwords previously entered.
--multiple
When used in conjunction with --accept-cached accept multiple passwords.
This will output one password per line.
In this fashion it would first try the passwords you already entered, and only ask for another passwords if that didn't work.
The downside of such an idea is that checking a password takes 1 second of CPU time with LUKS, so if you had a lot of LUKS containers, these attempts might slow you down. But most people have only one or two and it's actually not uncommon for them to use the same passphrase.
I actually couldn't locate the source code specifically responsible for this, so the above is only conjecture and I have no idea if this is a feature you could choose to disable somehow.
Found what seems to be the responsible code, see it here on Github.
There's a for loop that starts with tries = 0 and increments tries by one each iteration.
This loop calls get_password() with bool accept_cached set to true if tries == 0 && !arg_verify. So if there are already passwords cached in the first iteration of the loop, it will just return the cached passwords. If those don't work, next iteration with tries == 1 sets accept_cached to false and only then it will ask you to provide another passphrase to try with.
The list of passwords is passed on to attach_luks_or_plain(). This will be the previously cached password(s) in the first iteration, and the single new password in all following ones, so it won't re-try previously tried passwords (unless perhaps if you keep typing in the same one).
As for keeping passwords plaintext in memory, the list of passwords is declared as a _cleanup_strv_free_erase_ char **passwords = NULL; so that at least makes it sounds like cleanup will be taken care of properly at some point.
Keys are always in memory somewhere, that much can't be helped, crypt needs masterkey to work, as long as the container is open, you can always see it with dmsetup table --showkeys.
It seems like you normally have arg_tries = 3 three attempts to enter a working passphrase, but if you have multiple containers and the cached passwords didn't work, it will only give you two tries to enter the passphrase, since the cached password attempt already counts as the first try. I have no encrypted systemd machine to test if this is true or I'm just misreading the code somewhere.
| Why is my LUKS partition mounted without asking for a passphrase? |
1,552,997,393,000 |
I have HDD with my data (partial backup of most important data available on other HDD), currently it's formatted as Ext4 over LVM over LUKS. I want to remove LUKS layer, but reformatting and data restore from backup is too long/no fun. Is there any possibility/chance to overwrite LUKS partition with it's content without using big buffer and without data corruption?
|
You're going to have to copy all the data around anyway. You should definitely have a backup at this point. Unless your backup device is significantly slower than your active disk, restoring from backup is as fast as it can go.
A LUKS volume starts with a header (up to 2MB). If you lose the header, the data in the volume is lost. As long as the header is intact, you can access data in independent 512-byte sectors.
A strategy like cat /dev/mapper/encrypted >/dev/sdz99 will work, because the ciphertext is located at a positive offset (the header size) relative to the plaintext. However, this may well be slower than restoring from backup, because it's a copy on the same disk (with a disk-to-disk copy, reading and writing are done in parallel). For a same-disk copy, dd with a large block size is only very slightly faster than cat. There is a major caveat with this strategy: if there is a power failure or other system crash during the copy, your whole partition will be hosed, because the header has been overwritten first thing.
You can save the first 2MB of data elsewhere, and move the rest:
dd if=/dev/mapper/encrypted of=/dev/sdz99 bs=2M skip=1 seek=1
This way, you can resume after an interruption (don't try to assemble the logical volume though, let alone mount the filesystem!); however this requires knowing where you left off. This is practically impossible to determine (you'd have to use a copying tool that outputs a trail of the blocks it's copying and writes it to the disk, synchronously with the block copies).
If your backup storage is very slow, then you can use this shifting strategy — the plain cat shifting will do — and fall back to restoring from backup if anything bad happens.
If the backup storage is really unwieldy, then a different approach would be to:
Shrink the filesystem (resize2fs).
Shrink the logical volume (lvreduce).
Shrink the physical volume (pvresize).
Shrink the encrypted volume.
Shrink the partition (fdisk or gdisk), and create a new partition in the freed space.
Create a physical volume in the new partition (pvcreate) and add it to the volume group (vgextend).
Move as many physical extents as possible off the encrypted volume (pvmove).
If the encrypted volume isn't empty, repeat from step 1.
Get rid of the now unused physical volume (vgreduce then pvremove).
Long and tortuous? Yes. Again, my recommendation is to restore from backup.
| Can I overwrite LUKS partition with it's decrypted content? |
1,552,997,393,000 |
I'm using arch linux with an encrypted luks root partition (boot unencrypted), with a passphrase yet.
Now I have a keyfile (3072 bytes), that's written to USB-Stick this way:
sudo dd if=tempKeyFile.bin of=/dev/sdd bs=512 seek=1 count=6
and also set as additional pass
sudo cryptsetup luksAddKey /dev/sdb6 tempKeyFile.bin
When I open the partition manually with:
sudo cryptsetup --key-file tempKeyFile.bin open /dev/sdb6 luks_root
everything works, the partition is mapped and can be mounted.
Now my kernel-parameter-line in grub.cfg looks like this:
linux /vmlinuz-linux root=UUID=$UUID_OF_luks_root$ rw cryptdevice=UUID=$UUID_OF_sdb6$:luks_root cryptkey=/dev/sdd:1:6
But when booting, I get this error:
No key available with this passphrase.
Invalid Keyfile. Reverting to passphrase.
I already tried offset 2 instead of 1, but same result. I noticed it doesn't say, that the keyfile could not be found/read, but was incorrect.
There seems to be little documentation about this way of storing luks keyfile. Arch-wiki mentions it, but very briefly and I seem to be conform, so I think it should be possible.
in my mkinitcpio.conf MODULES, BINARIES and FILES are empty and I set:
HOOKS=(base udev autodetect keyboard modconf block encrypt filesystems fsck)
so block is right before encrypt.
What's the problem here?
|
From the ArchLinux encrypt hook (/lib/initcpio/hooks/encrypt):
*)
# Read raw data from the block device
# ckarg1 is numeric: ckarg1=offset, ckarg2=length
dd if="$resolved" of="$ckeyfile" bs=1 skip="$ckarg1" count="$ckarg2" >/dev/null 2>&1
;;
So while it supports reading a key from a raw block device, it uses a blocksize of 1 (instead of the default 512), so you have to multiply your values by 512 to make it work.
So instead of cryptkey=/dev/sdd:1:6 try cryptkey=/dev/sdd:512:3072.
| Using space before 1st partition of USB-Stick as luks key |
1,552,997,393,000 |
One day, when I turned on the computer, my passphrase for home part /dev/sda7 doesn't worked (I am 147% absolutely sure, that I was writing right pass)! After three times of tries, I have rebooted computer via force shutdown and tried to enter the same pass. That didn't worked. Then instead of default boot "Boot arch" I have chosen "Boot arch with Linux linux". And it helped me. I was working all day and after turned off computer. But at the next boot, this trick didn't help me. Even choosing of "Boot arch with Linux linux (initramfs fallback)" (I have only 3 chooses of boot). Then I decided to boot from Ubuntu LiveUSB. sudo cryptsetup luksOpen /dev/sda7 home saying: No key available with this passphrase.
I have tried to execute sudo cryptsetup --verbose repair /dev/sda7, which said No known problems detected for LUKS header.. I have compiled and executed official cryptsetup tool https://gitlab.com/cryptsetup/cryptsetup/tree/master/misc/keyslot_checker for checking keyslot. It said the same information about keyslots, that saying luksDump.
$ sudo cryptsetup
LUKS header information for /dev/sda7
Version: 1
Cipher name: aes
Cipher mode: xts-plain64
Hash spec: sha256
Payload offset: 4096
MK bits: 256
MK digest: fc 18 49 fe 3a 4e d4 11 b9 6f 0c c7 1d 54 0a 8d 44 01 86 36
MK salt: 5e 59 c8 fc f2 a9 10 b9 bf 7c 68 4b e4 a5 8e 00
5a f9 c7 66 f9 5b 02 ff e7 59 e4 fd 43 f2 dc b5
MK iterations: 249500
UUID: cc2f71c3-f0d9-4642-bf59-87bff4f60b54
Key Slot 0: ENABLED
Iterations: 1996099
Salt: 3e 60 e7 14 02 95 89 c0 c2 bf 8d 61 bb 99 13 aa
9d 9a c4 7d d4 41 78 ee 76 b0 48 b4 ed b0 ff a8
Key material offset: 8
AF stripes: 4000
Key Slot 1: DISABLED
Key Slot 2: DISABLED
Key Slot 3: DISABLED
Key Slot 4: DISABLED
Key Slot 5: DISABLED
Key Slot 6: DISABLED
Key Slot 7: DISABLED
All of that looks like everything is ok. Like header and all partition was not damaged. I have no idea why passphrase doesn't fit. All I can say is that I am fully upgrading my system (via sudo pacman -Syyu) everyday. And probably at one day somehow upgrade caused this consequences.
|
If there is corruption in the LUKS header (more than just a single byte), it's pretty much impossible to recover.
The LUKS header does not have a checksum for its key material, so - if it's damaged in any way, the cryptsetup luksDump will look same as always, but your passphrase simply won't work anymore. If you're unable to make the passphrase work, it's not possible to rule out corruption.
You could check it out with hexdump (manual approach to keyslot checker):
hexdump -C -n 132096 foobar.img | less
00000000 4c 55 4b 53 ba be 00 01 61 65 73 00 00 00 00 00 |LUKS....aes.....|
00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000020 00 00 00 00 00 00 00 00 78 74 73 2d 70 6c 61 69 |........xts-plai|
... 0x00000->0x01000 should be mixed text, zero and random ...
00001000 9f 27 7a 46 8b c7 0e 09 00 82 2d 66 a7 4b b7 76 |.'zF......-f.K.v|
00001010 7a 01 ed 65 91 d0 96 af 3c f1 85 0d 64 48 81 e7 |z..e....<...dH..|
00001020 3a 00 0d d1 23 e0 95 d2 8e 42 34 4d e2 74 c4 d6 |:...#....B4M.t..|
... 0x01000->0x20400 should be 128K of random only ...
000203d0 b6 04 f6 34 08 64 10 3f 4e b7 c4 21 e6 d8 da 56 |...4.d.?N..!...V|
000203e0 0e eb 53 ce d2 a6 94 f0 92 7b 11 4b c1 96 9f 17 |..S......{.K....|
000203f0 94 88 b4 cd 36 a5 e1 b2 e9 ba 27 f3 85 7d cb 3f |....6.....'..}.?|
00020400
The first segment is what luksDump shows, only parts of it are random. The range 00001000..00020400 is the key material for Key Slot 0, this should look random throughout, if there is any segment of that zeroed out or otherwise distinctly lacking in randomness (like a wild plain text string appearing), the header is corrupt.
If you're not using the US layout, try that and whatever layout you usually use. Keyboard layout problems are also a common reason for passphrases to stop working. In this case it helps to add the same passphrase multiple times (one for each layout) so LUKS will accept it, regardless which layout is currently active.
| LUKS passphrase doesn't work |
1,552,997,393,000 |
I have one physical disk (/dev/sda) which is divided in /dev/sda1 (which is /boot bootable GRUB2 partition used and setup with Arch) and /dev/sda2 which is my cryptroot that, when unlocked, is a single large lvmpool with the full size of the partition /dev/sda2. I have installed Arch on 3 lvs, as seen in the image below.
This setup is basically LVM on LUKS as described on the Arch Wiki on Dm-crypt.
Since I read lots of great things about NixOS, I am trying to install NixOS next to my current Arch install, so I created 3 more lvs similar to the arch- lvs above, and I followed the NixOS installation guide. I have specified boot.loader.grub.device = "nodev" so that NixOS will not install GRUB anywhere else, because I want to re-use my existing GRUB2 from Arch which resides on /dev/sda1. It will however write a grub.cfg file for NixOS to /boot/grub/grub.cfg that, in this case, is on the NixOS nix-root lv (/, the filesystem root in NixOS) and thus not on the actual (bootable) GRUB2 partition /dev/sda1.
However, to achieve that, I want to add an extra menu-entry to my grub.cfg and point to the configfile that the NixOS-installer has created on my nix-root lv (/, the filesystem root in NixOS), pretty much what is described here. However, I am unsure how to create an entry that will point to the nix-root lv, since it seems that GRUB wants some syntax like set root='(hd0,X)', but how can I make something like this set root aware of my lv to point to instead of to a physical disk and partition number? Both the options configfile and chainloader are not very well-described in GRUB, and neither is the set root as far as I could find.
I hope that somebody could point me in the right direction, tell me what I am doing wrong or why/how I am making this too hard on myself, to just use one bootable GRUB2 partition for multiple Linux distributions that reside on different LVM lvs on LUKS.
EDIT:
I tried various options for set root= such as (lv/nix-root), (lvmpool/nix-root) and (/dev/mapper/lvmpool-nix--root), however the problem is that the LVM lvs seem not visible to GRUB yet, since at the point that GRUB loads, /dev/sda2/ is still an encrypted LUKS cryptroot.
|
With the help above from Alexander Batischev, and some very useful information from Reddit user cookie_enthusiast on the /r/linuxquestions page on Reddit, I managed to get this working.
It turns out that GRUB2 works well with UUIDs, and not so well with device names. With this knowledge in mind, we need the following 4 UUIDs at hand, before we can (manually) create an extra GRUB menuentry to our NixOS grub.cfg configfile:
The UUID of the LUKS device.
The UUID of the LVM Volume Group.
The UUID of the LVM Logical Volume.
The UUID of the filesystem containing the grub.cfg file we want to load via the configfile directive in GRUB2.
I will list here how to obtain these four UUIDs:
Execute cryptsetup luksUUID /dev/sda2 and remove all the dashes (-) from the UUID, a0cb535a-8468-485f-a220-a5f49e85c9f4 would become a0cb535a8468485fa220a5f49e85c9f4 in my case.
Execute vgdisplay and look for the VG UUID, lvmpool with UUID 5atKN9-PQBi-T9wb-Iyz8-qP4y-HN2E-c5uLOT in my case.
Execute lvdisplay and look for the LV UUID of the LV Name or LV Path that contains your grub.cfg file, nix-root or /dev/lvmpool/nix-root with UUID C9zkjF-IHu0-qQkP-KgLf-8rAy-TVPu-HQ7gtj in my case.
Execute lsblk -p -o +UUID and look for the UUID of the Device Path that contains your grub.cfg file, /dev/mapper/lvmpool-nix--root with UUID cc6a06bb-336f-4e9f-a5f0-fdd43e7f548f in my case.
This will allow you to create the following extra GRUB menuentry for referencing our NixOS grub.cfg configfile, which is on my nix-root lv and because of the boot.loader.grub.device = "nodev"; in my /etc/nixos/configuration.nix there is no GRUB installed for my NixOS installation (in Arch, this would go into /etc/grub.d/40_custom):
menuentry 'NixOS' {
insmod crypto
insmod cryptodisk
insmod luks
insmod lvm
cryptomount -u a0cb535a8468485fa220a5f49e85c9f4
set root='lvmid/5atKN9-PQBi-T9wb-Iyz8-qP4y-HN2E-c5uLOT/C9zkjF-IHu0-qQkP-KgLf-8rAy-TVPu-HQ7gtj'
search --fs-uuid --set=root cc6a06bb-336f-4e9f-a5f0-fdd43e7f548f
configfile '/boot/grub/grub.cfg'
}
To clarify this even more, this contains some literal values such as lvmid which is not supposed to be replaced with the name or ID of your LVM. This is not properly documented anywhere, it seems. The same issue applies for when your put the UUID of your LUKS device in the cryptomount -u line with dashes in it, GRUB will just tell you Press any key to continue, which is (obviously) not very helpful.
The bare template for a manual GRUB menuentry to boot from crypt -> LVM -> root with an LVM on LUKS setup would thus be:
menuentry 'NixOS' {
insmod crypto
insmod cryptodisk
insmod luks
insmod lvm
cryptomount -u <LUKS UUID without dashes>
set root='lvmid/<LVM Volume Group UUID>/<LVM Logical Volume UUID>'
search --fs-uuid --set=root <Filesystem UUID>
configfile '/boot/grub/grub.cfg'
}
For those who are interested in the other half also, I modified my /etc/nixos/configuration.nix file to look like this:
boot.loader.grub.enable = true;
boot.loader.grub.version = 2;
boot.loader.grub.device = "nodev";
boot.initrd.luks.devices = [ { name = "cryptroot"; device = "/dev/sda2"; preLVM = true; } ];
| NixOS installation on multi-boot system with GRUB (from Arch installation) |
1,552,997,393,000 |
I'm curious if there is a filesystem that's unencrypted, making it readable by anyone, but employs a digital signature scheme so as to require that writes be digitally signed.
I suspect the answer is "No because it'd be complicated and probably slower than simply encrypting the drive" but seemed interesting.
|
The two obvious candidates would be ZFS and Btrfs, but as far as I know, they don't do this. Btrfs currently has no crypto at all (for encryption, you're supposed to use LUKS, which provides encryption and optionally block-level integrity but not global integrity). ZFS has an integrity mode where it uses a tree of cryptographic hashes to ensure that the filesystem remains consistent. If the root hash was signed, that would guarantee the authenticity of the filesystem: an adversary could not inject fake content. That would almost guarantee the integrity of the filesystem: all the adversary could do without the key would be to roll back the filesystem to an earlier version. An alternate way to ensure the integrity of the filesystem would be to store an offline copy of the root hash; I can't find a reference of existing tools to do this.
Verifyfs is a FUSE filesystem which verifies the signature of files individually. As far as I can tell from a quick perusal (I hadn't heard of it before today), it does not sign directories, attempt to prevent rollbacks or verify the consistency of the filesystem, so an adversary can downgrade individual files to earlier versions and can erase files.
Why is encryption so common and integrity verification so uncommon? I think there are several reasons: threats to integrity are somewhat less common than threats to confidentiality, they're are harder to combat, and integrity verification has a higher performance cost.
Encryption protects against a disk getting stolen. It's a threat pretty much everywhere, and once the disk is stolen, there is no other remedy. Integrity verification protects against an adversary who has access to the system while the storage is unmounted (if it's mounted, the integrity verification key is in memory) — an evil maid attack. This is rarely a threat against servers, for which tampering is often detectable, but it is a threat against laptops.
Even if you do manage to protect your disk against an evil maid attack by cryptographic means, your computer is still vulnerable to attacks that target firmware. PC usually have several flash memories which can be rewritten with no cryptographic protection (including the firmware of the disk itself).
Integrity protection is costly because it's a global property. Encryption can be performed sector by sector, so the cost is small unless your CPU is very slow and your disk is very fast. If you authenticate sector by sector, an adversary can still partially compromise the system by reverting some sectors to an earlier value, although this is a more sophisticated attack as it may require access to the system at different times. So complete authenticity verification requires comparing a sector's authentication value with a reference value, whose authenticity and freshness itself needs checking, etc.
| Is there an unencrypted but signed filesystems? |
1,552,997,393,000 |
What am I trying to do?
Install Arch with full system encryption (sans boot and media partition) using LVM on top of LUKS on an external hard drive (sdb)
using: http://suddenkernelpanic.blogspot.com/2013/03/arch-linux-lvm-on-top-of-luks-2013-style.html
What is my problem:
System boots grub and it appears there is some confusion on where to find root
Error: Device 'uuid=f7153c4b-e6ea-48a2-9ee1-bf38c037173d' not found. skipping fsck
Error: Unable to find root device 'uuid=f7153c4b-e6ea-48a2-9ee1-bf38c037173d'
Where I deviated from this tutorial
I used Grub Instead of Syslinux as the tutorial suggests (This seems to be the crux) and it's really hazy on the solution for Grub
My partition scheme consists of an extra FAT32 partition that is not involved in the encryption (seems irrelevant to the issue)
Issues on /etc/default/grub:
(I feel like this is where the issue is)
From what I've read I need to update a couple of places in this file specifically:
GRUB_CMDLINE_LINUX="root=/dev/mapper/lvmpool-root cryptdevice=/dev/sdb2:crypt ro"
and I'm supposed to uncomment:
GRUB_DISABLE_LINUX_UUID=true
Issues on /etc/mkinitcpio.conf
I'm supposed to add the hooks as follows
HOOKS="... encrypt lvm2 ... filesystems ..."
Here's my fstab entry for root
<filesystem>
/dev/mapper/lvmpool-root
UUID=f7153c4b-e6ea-48a2-9ee1-bf38c037173d / ext4 rw,relatime,data=ordered 0 1
Current Work-Around
I can still use the system because after it errors out, it drops me into a recovery shell, at which type I can simply do a:
cryptsetup luksOpen /dev/sdb2 crypt
enter password
Then exit recovery shell and it drops me back into a normal arch login prompt.
This wouldn't be so bad, if it weren't so time consuming... (Takes forever to error out on boot, like 20 seconds)
Other Resources I tried
I have also used:
wiki.archlinux.org/index.php/Beginners%27_guide
wiki.archlinux.org/index.php/Gr … encryption
wiki.archlinux.org/index.php/Dm … oot_loader
wiki.archlinux.org/index.php/Dm … VM_on_LUKS
|
Your problem seems to be in the difference of :crypt as volume group for /dev/sdb2 and using lvmpool- as volumegroup name as parameter for root.
GRUB_CMDLINE_LINUX="root=/dev/mapper/lvmpool-root cryptdevice=/dev/sdb2:crypt ro"
The example here:
cryptdevice=/dev/partition:MyStorage root=/dev/mapper/MyStorage-rootvol
has matching :MyStorage and MyStorage-. That page specifically targets grub (and not Syslinux), with LVM on top of LUKS. So I would follow that set up.
That you have an extra, not encrypted partition, doesn't matter.
| LVM Ontop of LUKS using Grub |
1,552,997,393,000 |
I created an encrypted volume with LUKS and uploaded it to a remote directory on an untrusted host.
I can mount it locally though. I first mount the remote directory locally with sshfs and then open my volume with cryptsetup as if it were a local file.
$ sshfs user@host: remote/
# cryptsetup luksOpen remote/disk.img disk
$ mount /dev/mapper/disk mount_point/
My question is: do I thereby make whatever is in mount_point/ visible to users on the remote host? Also, are commands I execute in a directory mounted through sshfs transparent to administrators on the remote host?
|
The remote host sees nothing but the (encrypted) reads and writes to the file.
| Are remote LUKS volumes mounted locally with sshfs made visible to remote users? |
1,552,997,393,000 |
my girlfriend bought Lenovo Essential G500 i5-3230 and I installed Linux Mint 16 on it with full disk encryption. It is standard installation with encryption using dmcrypt and LUKS. But there is a problem with screen brightness, it is set to 0 before it even ask for password to encrypted partitions. I partly fixed it by adding:
echo 50 > /sys/class/backlight/acpi_video0/brightness
to /etc/rc.local but it fixes brightness after typing correct password to mount encrypted partitions. I want to fix brightness before that, so I can see the password input field. /etc/rc.local is loaded after mounting encrypted disk so I think I need to somehow force kernel to change brightness just after it loads itself and before mounting.
Is there a way to tell kernel to adjust brightness just after boot?
Graphic cards on laptop are: AMD® Radeon HD 8570M + Intel HD Graphics 4000
UPDATE
I've tried solution sugested by @derobert. I created initramfs script /etc/initramfs-tools/scripts/init-premount/local-backlight-brightness
#!/bin/sh
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/initramfs-tools/hook-functions
# Begin real processing below this line
echo 50 > /sys/class/backlight/acpi_video0/brightness
And after this:
$ sudo chmod a+rx /etc/initramfs-tools/scripts/init-premount/local-backlight-brightness
$ sudo update-initramfs -u
$ sudo reboot
But it don't work, screen is almost black when asking for password. I'm not even sure if this script was executed. How can I check if it was executed? Maybe I should add some requirements in PREREQ="" to make it work?
UPDATE 2 FINALLY WORKING
Ok, I decided to read manual for initramfs-tools again to check if everything was good and it looks like I used wrong boilerplate for my script. The correct one is:
#!/bin/sh
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
. /scripts/functions
# Begin real processing below this line
echo 50 > /sys/class/backlight/acpi_video0/brightness
The problem was with . /usr/share/initramfs-tools/hook-functions. This line was used for hook scripts that are not included in intramfs image. It should be . /scripts/functions. After changing it, brightness works like I wanted.
I'm marking @derobert answer as correct because it directed me to correct solution.
|
You need to add that script to your initramfs. On Debian (I suspect Mint is the same), it appears that the password prompt comes from /usr/share/initramfs-tools/scripts/local-top/cryptroot. That script arranges itself to be called last out of the local-top scripts. There is a parallel set of directories in /etc intended for local customization. So you just need to plop a file that looks something like:
#!/bin/sh
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
prereqs)
prereqs
exit 0
;;
esac
echo 50 > /sys/class/backlight/acpi_video0/brightness
into either /etc/initramfs-tools/scripts/local-top or /etc/initramfs-tools/scripts/init-premount. The file name doesn't matter, though I'd pick something like local-backlight-brightness to make sure it doesn't conflict with some package-provided script. (The prereqs boilerplate comes straight from the initramfs-tools manpage.)
Then, run update-initramfs -u.
| How to set laptop screen brightness just after boot with full disk encryption |
1,552,997,393,000 |
Is there any way to unlock LUKS partition using keyfile while not having root priviliges? (using sudo is not an option)
I know that udisksctl can open LUKS partition, however it can do it only with a passphrase.
|
No. And even solutions that apparently do it without root privileges, actually do have root privileges. This is just a basic requirement for mounting or accessing raw disk data. If you could do those without root priveleges, you could read files you have no permission to read (by reading and searching the raw data), and if you could mount you could mess up the VFS filesystem tree, possibly in creative ways that let you obtain permissions you're not supposed to have.
What you could do, if you already had read permission to the raw encrypted data, is implement everything needed to access it and extract files from it in software that runs without root permissions. So basically you'd treating a LUKS encrypted image file as you would a GPG-encrypted tar. If this is what you wanted, and for some reason absolutely had no root or sudo available, you'd usually use the tar in the first place since that's what already exists as a read-to-use solution.
To provide a more practical approach to your problem: keyfiles are passphrases and passphrases are keyfiles, really. Apart from some minor details (e.g. how it treats newlines), LUKS does not really make a distinction here. Keyfile just means it reads the passphrase from a file.
So you could just use keyfiles that are printable ASCII and don't have newlines in them.
That is, if udisksctl really doesn't support keyfiles. Kind of hard to understand why.
| Unlock LUKS partition using keyfile without root access? |
1,552,997,393,000 |
So I'm trying to get a fully encrypted boot partition going. I'm running Funtoo, but mostly drawing from the Arch wiki for help.
So I decided to do something crazy/controversial: not separate boot/root partitions. My setup looks like so:
/dev/nvme0n1p1 - EFI parition
/dev/nvme0n1p2 - Swap
/dev/nvme0n1p3 - Encrypted /
In my /etc/default/grub I have the following:
GRUB_ENABLE_CRYPTODISK=y
GRUB_PRELOAD_MODULES="luks cryptodisk"
GRUB_CMDLINE_LINUX="luks enc_root=/dev/nvme0n1p3 root=/dev/mapper/enc_root"
All the linux arguments are for better-initramfs. I include a key to the file system within the ramdisk so it doesn't prompt me for my password twice.
I installed Grub using the following:
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id="Funtoo Linux [GRUB]" --recheck --boot-directory=/boot/efi/EFI
So in its current state, I get a Grub rescue prompt. It can't find its configuration file (it's on the encrypted boot/root disk). So I run the following commands:
insmod luks
cryptomount (hd1,gpt3)
set root=(crypto0)
configfile (crypto)/boot/grub/grub.cfg
..and I have a fully booting/working system! :)
So my question is: how to I configure the Grub EFI loader to attempt automatically load the encrypted partition to (crypt0) and read its configuration file?
Note: Grub identifies the disk as (hd1,gpt3) most likely because my USB stick is still plugged in. That should change to (hd0,gpt3) if I unplug it and reboot.
|
Turns out on Gentoo/Funtoo, the device mapper for grub isn't enabled by default. I added the following to /etc/portage/package.use:
sys-boot/grub device-mapper
Then I re-emerged grub, ran grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id="Funtoo Linux [GRUB]" --recheck and rebooted to find a luks password request screen. After typing it in, everything booted perfectly.
Special thanks to frostschutz who provided the solution in this thread:
https://forums.gentoo.org/viewtopic.php?p=7972812#7972812
| How do I get Grub to automatically run cryptomount to load its config file (encrypted boot) |
1,552,997,393,000 |
Disk/Partition Backup
What are the backup options and good practice to make a solid and easy to use full system backup?
With the following requirement:
Live backup
Image backup
Encrypted backup
Incremental backups
Mount/access the backup disk/files easily
Full system backup, restorable in one shot
Can be scheduled automatically (with cron or else)
Encrypted or classic backup source (luks, dm-crypt, ext3/ext4/btrfs).
|
Linux system backup
When targeting a true full system backup, disk image backup (as asked) offer substantial advantage (detailed bellow) compared to files based backup.
With files based backup disk/partition structure is not saved; Most of the time for a full restore, the process is a huge time consumer in fact many time consuming steps (like system reinstall) are required; and finally backing up installed applications can be tricky; Image disk backup avoid all these cons and restore process is a one shot step.
Tools like clonezilla, fsarchiver are not suitable for this question because they are missing one or multiple requested features.
As a reminder, luks encrypted partition are not dependent on the used file system (ext3/ext4/etc.) keep in mind that the performance are not the same depending on the chosen file system (details), also note that btrfs (video-1, video-2) may be a very good option because of its snapshot feature and data structure. This is just an additional protection layer because btrfs snapshot are not true backups! (classic snapshots reside on the same partition).
As a side note, in addition to disk image backup we may want to do a simple file sync backup for some particular locations, to achieve this, tools like rsync/grsync (or btrfs-send in case of btrfs) can be used in combinaison with cron (if required) and an encrypted backup destination (like luks-partition/vault/truecrypt). Files based backup tools can be: rsync/grsync, rsnapshot, cronopete, dump/restore, timeshift, deja-dup, systemback, freefilesync, realtimesync, luckybackup, vembu.
Annotations
lsblk --fs output:
sda is the main disk
sda1/sda2 are the encrypted partitions
crypt_sda1/crypt_sda2 virtual (mapped) un-encrypted partitions
sda
├─sda1 crypto_LUKS f3df6579-UUID...
│ └─crypt_sda1 ext4 bc324232-UUID... /mount-location-1
└─sda2 crypto_LUKS c3423434-UUID...
└─crypt_sda2 ext4 a6546765-UUID... /mount-location-2
Method #1
Backup the original luks disk/partition (sda or sda1) encrypted as it is to any location
bdsync/bdsync-manager is an amazing tool that can do image backup (full/incremental) by fast block device syncing; This can be used along with luks directly on the encrypted partition, incremental backups works very well in this case as well. This tool support mounting/compression/network/etc.
dd: classic method for disk imaging, can be used with command similar to dd if=/dev/sda1 of=/backup/location/crypted.img bs=128K status=progress but note that imaging a mounted partition with dd may lead data corruption for the used files while the backup is done, like sql databases, x config files, or documents being edited, to guarantee data integrity with such backup closing all running application and data base is recommended, we can also mount the image after its creation and check its integrity with fsck.
Cons for #1: backup size, compression, and incremental backups can be tricky
Method #2
This method is for disk without encryption or to backup the mapped luks un-encrypted partition crypt_sda1/crypt_sda2... An encrypted backup destination location (like luks-partition/vault/truecrypt) or an encrypted archive/image if the backup tool support such feature is recommended.
Veeam: free/paid professional backup solution (on linux only command line and TUI), kernel module is opensource, this tool can not be used for the fist method, backup can be encrypted, incremental and mounting backups are supported.
bdsync/bdsync-manager same as in the first method but the backup is made from the un-encrypted mapped partition (crypt_sda1/crypt_sda2).
dd: classic method for disk imaging, can be used with command similar to dd if=/dev/mapper/crypt_sda1 of=/backup/location/un-encrypted-sda1.img bs=128K status=progress but note that imaging a mounted partition with dd may lead data corruption for the used files while the backup is done, like sql databases, x config files, or documents being edited, to guarantee data integrity with such backup closing all running application and data base is recommended, we can also mount the image after its creation and check its integrity with fsck.
Cons for #2: disk headers, mbr, partitions structure, uid etc. are not saved additional backup steps (detailed bellow) are required for a full backup
Backup luks headers: cryptsetup luksHeaderBackup /dev/sda1 --header-backup-file /backup/location/sda1_luks_heanders_backup
Backup mbr: dd if=/dev/sda of=/backup/location/backup-sda.mbr bs=512 count=1
Backup partitions structure: sfdisk -d /dev/sda > /location/backup-sda.sfdisk
Backup disk uuid
Note:
Images done with dd can be mounted with commands similar to:
fdisk -l -u /location/image.img
kpartx -l -v /location/image.img
kpartx -a -v /location/image.img
cryptsetup luksOpen /dev/mapper/loop0p1 imgroot
mount /dev/mapper/imgroot /mnt/backup/
Alternatives:
Bareos: open source backup solution (demo-video)
Bacula: open source backup solution (demo-video)
Weresync: disk image solution with incremental feature.
Other tools can be found here, here, here or here
There is a Wikipedia page comparing disk cloning software
An analyse by Gartner of some professional backup solutions is available here
Other tools
Acronis backup may be used for both methods but their kernel module is always updated very lately (not working with current/recent kernel version) plus mounting backups is not working as of 02/2020.
Partclone: used by clonezilla, this tool only backup disk used blocks, it support image mounting but does not support live/hot backup nor encryption/luks.
Partimage: dd alternative with a TUI, it support live/hot backups but images can not be mounted and it does not support luks (but ext4/btrfs).
Doclone: very nice live/hot backup imaging solution, supporting many systems (but not lucks...) ext4 etc. support network, mounting is not possible.
Rsnapshot: snapshot file backup system using rsync. used in many distro (like mageia) the backup jobs are scheduled with cron, when running in background the backup status is not automatically visible.
Rsync/Grsync: sync folders with rsync command, grsync is the gui...
Cronopete: file backup alternative to rsync (the application is limited on how it work compared to modern solution)
Simple-backup: file backup solution with tray icon and incremental feature, backup are made to tars archives
Backintime: python backup app for file based backup (the app have many unsolved issues)
Shadowprotect: acronis alternative with mount feature... luks support is not obvious.
Datto: professional backup solution, luks support is not obvious, linux agent need to be networked to a backup server... kernel module is opensource on github... the interface is web based without using a modern design.
FSArchiver: live/hot image backup solution, backup can not be mounted.
Dump: image backup system, mount is not supported.
| Serious backup options for linux disk (dmcrypt, luks, ext4, ext3, btrfs) normal and encrypted system |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.