LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-28-2023, 03:59 AM   #1
stoorky
Member
 
Registered: Sep 2015
Posts: 63

Rep: Reputation: Disabled
Is it possible to access a partition's content in GRUB_CMD_LINE


TL;DR

I have Debian 11 with 2 LUKS encrypted partitions (root and swap), and an unencrypted boot partition. Swap is encrypted with a key file, located on the root partition, because I want to type the decryption passphrase only once.

My /etc/crypttab is empty. In grub.cfg, I have :

Code:
GRUB_CMDLINE_LINUX="resume=/dev/nvme0n1p6_crypt cryptopts=source=/dev/disk/by-partlabel/DEBIAN,target=nvme0n1p7_crypt cryptopts=source=/dev/disk/by-partlabel/SWAP,target=nvme0n1p6_crypt,key=/root/.keys/swap.key"
But GRUB can't access the key file :

Code:
Please unlock disk nvme0n1p7_crypt: (passphrase)
cryptsetup: nvme0n1p7_crypt: set up successfully
cryptsetup: ERROR: Skipping target nvme0n1p6_crypt: non-existing key file /root/.keys/swap.key
(...)
Given that the root partition has been successfully decrypted, I suppose there is a way to retrieve the key file from it and decrypt the swap partition. Can it be done ? How ? Is there a syntax like

Code:
... cryptopts=source=/dev/disk/by-partlabel/SWAP,target=nvme0n1p6_crypt,key=/path/to/keyfile/on/decrypted/nvme0n1p7"
PLEASE NOTE : this question is GRUB specific, I am NOT looking for other solutions to achieve my goals, I already successfully tested a few of them (read below THE FULL STORY for more details). I'd specifically like to know if what I try to do in GRUB can be done or not.


THE FULL STORY :

With a key file encrypted swap, resuming from hibernation doesn't work. From what I understand it's because systemd opens the swap partition too late, after the kernel has already given up looking for hibernation data in swap. In fact # update-initramfs -u even triggers a warning when encrypting swap with a keyfile :

Code:
# update-initramfs -u
(...)
WARNING: Resume target nvme0n1p6_crypt uses a key file
There are several ways to solve this problem. I successfully tested 2 of them : ditching the keyfile and using Debian's decrypt_keyctl script to cache the passphrase, or baking the keyfile into initramfs and encrypt the boot partition to ensure its security. Both work fine, so I am not looking for a solution to solve this hibernation problem, which I already solved.

I am specifically trying to know if that third solution I tried could work or not, and if yes, how. That third solution consists of decrypting the partitions through GRUB's GRUB_CMDLINE_LINUX options.

Last edited by stoorky; 01-28-2023 at 04:05 AM.
 
Old 01-28-2023, 05:10 AM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,534

Rep: Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495Reputation: 2495
If the / partition is decrypted, you can access and read files from Grub with the cat command. To access the file in your case, you would go to the grub prompt (grub>) and enter: set root=(hd0,6) then hit the enter key and enter: cat /root/.keys/swap.key

Quote:
cryptsetup: ERROR: Skipping target nvme0n1p6_crypt: non-existing key file /root/.keys/swap.key
The error above which you report indicates the file swap.key does not exist. Does it exist at that location?

If you are looking for an entry to work in the grub.cfg file, I can't help with that.
 
Old 01-28-2023, 07:08 AM   #3
stoorky
Member
 
Registered: Sep 2015
Posts: 63

Original Poster
Rep: Reputation: Disabled
Thanks,

Quote:
Originally Posted by yancek View Post
If you are looking for an entry to work in the grub.cfg file, I can't help with that.
Yes that's what I am looking for. I'd like to know if it's even possible or not.
 
Old 02-04-2023, 12:41 AM   #4
stoorky
Member
 
Registered: Sep 2015
Posts: 63

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by yancek View Post
To access the file in your case, you would go to the grub prompt (grub>) and enter: set root=(hd0,6) then hit the enter key and enter: cat /root/.keys/swap.key
No need to set (hd0,6) as root, just type cat /(hd0,6)/.keys/swap.key
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP: $posts[0]['content'] = $posts[0]['content']; gacl Programming 1 11-02-2019 11:12 PM
debian lenny corrupt partition recover - possible content but no structure toucan Linux - General 1 08-02-2011 08:11 PM
Dividing content of one file by content of another larspend Linux - Newbie 5 04-12-2011 08:00 PM
Apache serving content after the content is removed? jrbush82 Linux - Software 6 05-05-2004 04:39 AM
Possible to search by content of package not downloaded yet? davidas Debian 4 04-09-2004 03:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration