LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-16-2013, 06:06 PM   #1
otaviolb
LQ Newbie
 
Registered: Oct 2012
Location: Minas Gerais, Brazil
Distribution: Opensuse and Debian
Posts: 13

Rep: Reputation: Disabled
lvm and cryptsetup


Hi: I would appreciate comments on this problem. I want to learn, not just solve the problem.

I would like to backup a directory structure greater than 4GB in an encrypted usb device, under the following restrictions: keep the usb device formatted as FAT32, with a single partition; leave some unencrypted space for ordinary use.

Since FAT32 is limited to 4GB files, I thought I could create two or more files and mount a logical volume with them. It worked for the first time, but not anymore. I am failing somewhere, but I cannot figure out how to improve. It follows what I have done:

Create three files, two limited to 4Gb and another one (it could have been the three same size):
Code:
dd if=dev/urandom of=/media/usbdevice/0 bs=1M count=2000
dd if=dev/urandom of=/media/usbdevice/1 bs=1M count=4000
dd if=dev/urandom of=/media/usbdevice/2 bs=1M count=4000
Associate the files with a loop device:
Code:
su
for i in `seq 0 1 2`;do losetup /dev/loop$i /media/usbdevice/$i;done
Open them:
Code:
for i in `seq 0 1 2`;do cryptsetup --key-file="/home/fooname/passwordfile" luksOpen /dev/loop$i cryptfun$i ;done
Create the logical volumes, leaving some unused room:
Code:
pvcreate /dev/mapper/cryptfun0 /dev/mapper/cryptfun1 /dev/mapper/cryptfun2
vgcreate vgpendrive_fooname /dev/mapper/cryptfun0 /dev/mapper/cryptfun1 /dev/mapper/cryptfun2
lvcreate -L 9700M vgpendrive_fooname
vgchange -a y vgpendrive_fooname
Make a file system compatible with files greater than 4GB. I like ext2
Code:
mkfs -t ext2 /dev/vgpendrive_fooname/lvol0
Mount it:
Code:
mount /dev/vgpendrive_fooname/lvol0 /mnt/lvm
For some reason, I was not able to mount with my uid: mount -t ext2 -o rw,uid=1000 dev/vgpendrive_fooname/lvol0 /mnt/lvm, but this is another question for another time. So, I simply changed permissions:
Code:
chown root:fooname /mnt/lvm
chmod g+rwx /mnt/lvm/
As normal user, check whether it works or not: just copy some stuff into the mounted volume
Code:
su fooname
cp morethan4GBfile /mnt/lvm
Great. It works!

Now, I want undo each step:
Code:
su
umount /mnt/lvm/
vgchange -a n vgpendrive_fooname
vgremove vgpendrive_fooname
pvremove /dev/mapper/cryptfun0 /dev/mapper/cryptfun1 /dev/mapper/cryptfun2
for i in `seq 0 1 2`;do cryptsetup luksClose cryptfun$i ;done
for i in `seq 0 1 2`;do  losetup -d /dev/loop$i ;done
Great again. It works fine. Now, I want repeat almost the same steps another day; I tried:
Code:
for i in `seq 0 1 2`;do losetup /dev/loop$i /media/usbdevice/$i;done
for i in `seq 0 1 2`;do cryptsetup --key-file="/home/fooname/passwordfile" luksOpen /dev/loop$i cryptfun$i ;done
pvcreate /dev/mapper/cryptfun0 /dev/mapper/cryptfun1 /dev/mapper/cryptfun2
vgcreate vgpendrive_fooname /dev/mapper/cryptfun0 /dev/mapper/cryptfun1 /dev/mapper/cryptfun2
lvcreate -L 9700M vgpendrive_fooname
vgchange -a y vgpendrive_fooname
mount /dev/vgpendrive_fooname/lvol0 /mnt/lvm
Here I cannot go further because of an error message:
Quote:
mount: you must specify the filesystem type
If I try:
Code:
mount -t ext2 /dev/vgpendrive_fooname/lvol0 /mnt/lvm
I get:
Quote:
mount: wrong fs type, bad option, bad superblock on /dev/mapper/vgpendrive_fooname-lvol0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so
This shows I am thinking wrong, but I do not know why. What should I have done?

Aditional information:
Code:
uname -a
Quote:
Linux hostname 2.6.32-5-686 #1 SMP Fri Feb 15 15:48:27 UTC 2013 i686 GNU/Linux
Code:
lvcreate --version
Quote:
LVM version: 2.02.66(2) (2010-05-20)
Library version: 1.02.48 (2010-05-20)
Driver version: 4.15.
USB device: 16GB

Greetings.
 
Old 06-17-2013, 01:17 AM   #2
lvvloten
LQ Newbie
 
Registered: Mar 2011
Posts: 2

Rep: Reputation: 1
Just a small thought - did you actually create the filesystem in your second attempt? I miss the mkfs command, you did use it in the first attempt. Since you recreate everything, including the encryption, all information including the filesystem information has been erased.
Hope this helps,
Lucas
 
Old 06-17-2013, 05:28 AM   #3
r0b0
Member
 
Registered: Aug 2004
Location: Europe
Posts: 608

Rep: Reputation: 50
When you wanted to "repeat" the steps, did you expect to find all data intact? If not, you forgot to run mkfs (as Lucas above said).

If you did, too bad, it's not going to work this way. I don't know for sure but some of the LVM commands (most probably lvcreate) gave different result the second time than the first time and your data is gone.

I wouldn't bother with cryptsetup & LVM over loopback. Too much hassle and too little gain. Maybe you could use truecrypt, which works on file-based storage natively as opposed to cryptsetup which works on block devices.
 
Old 06-17-2013, 06:00 AM   #4
otaviolb
LQ Newbie
 
Registered: Oct 2012
Location: Minas Gerais, Brazil
Distribution: Opensuse and Debian
Posts: 13

Original Poster
Rep: Reputation: Disabled
Thank you for your comments. That is the point, I expected to find the data intact! This works without lvm:
1st step: dd if=dev/urandom of=/media/usbdevice/0 bs=1M count=2000; losetup /media/usbdevice/0; cryptsetup luksFormat /dev/loop0; cryptsetup luksOpen /dev/loop0 somename; mkfs -t ext2 /dev/mapper/somename; mount /dev/mapper/somename mnt/mntpoint; cp data /mnt/mntpoint; umount /mnt/mntpoint; cryptsetupluksClose /dev/mapper/somesame; losetup -d /dev/loop0

2nd step All the above except luksFormat and mkfs. Copied data are intact.

I susepct that vgremove is important to understand. After running this command, it asks if I am sure. Perhaps vgremove cannot be used if data must be preserved. However, without removing the volume, luksClose and losetup -d fail.
 
Old 06-17-2013, 06:29 AM   #5
r0b0
Member
 
Registered: Aug 2004
Location: Europe
Posts: 608

Rep: Reputation: 50
Try vgexport and vgimport instead of vgremove & vgcreate. They are designed to keep your data intact while fiddling with underlying PVs.
 
Old 06-17-2013, 08:06 PM   #6
otaviolb
LQ Newbie
 
Registered: Oct 2012
Location: Minas Gerais, Brazil
Distribution: Opensuse and Debian
Posts: 13

Original Poster
Rep: Reputation: Disabled
Solved: encrypted file system greater than 4 GB in a single partition FAT32 usb device

Thank you! It works!

This is what I did: After mounting the logical volume as described above, I run:
umount /dev/vgpendrive_fooname/lvol0
vgchange -a n vgpendrive_fooname
vgexport vgpendrive_fooname
for i in `seq 0 1 2`;do cryptsetup luksClose cryptfun$i ;done
for i in `seq 0 1 2`;do losetup -d /dev/loop$i ;done
umount /media/usbdevice

Data are supposed to be protected.

When the data must be accessed again, mount or hotplug the usb device and:
for i in `seq 0 1 2`;do losetup /dev/loop$i /media/usbdevice/$i;done
for i in `seq 0 1 2`;do cryptsetup --key-file="/home/fooname/password" luksOpen /dev/loop$i cryptfun$i ;done
pvscan
vgchange -a y vgpendrive_otavio
mount /dev/vgpendrive_fooname/lvol0 /mnt/lvm

Data are intact in /mnt/lvm! We have got an encrypted file system greater than 4 GB in a single partition FAT32 usb device ;-)

Only use vgremove and pvremove if data can be lost.

Greetings
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Cryptsetup problem Nikosis Slackware 14 12-23-2015 01:49 PM
[SOLVED] CURRENT: LVM/CRYPTSETUP duplicate devices in /dev/mapper again. GazL Slackware 11 01-31-2011 06:36 PM
cryptsetup question... dbrazeau Linux - Software 1 09-22-2010 04:06 PM
luks cryptsetup and lvm question ruzzed Linux - Software 3 09-16-2007 07:21 PM
probs with cryptsetup ankscorek Linux - Security 5 02-15-2006 04:13 AM


All times are GMT -5. The time now is 10:06 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration