cryptsetup luksFormat fails with obscure error message when device is mounted

Bug #116633 reported by Michael Vogt on 2007-05-24
2
Affects Status Importance Assigned to Milestone
cryptsetup (Ubuntu)
Undecided
Reinhard Tartler

Bug Description

Binary package hint: cryptsetup

When runing cryptsetup luksFormat on a mounted device (auto mounted by gnome without noticing it) it runs for a bit and then gives a obscure error message.

It should indicate that the device is mounted upfront and fail.

Michael Vogt (mvo) wrote :

Here is a small patch to add a check for this to luksformat:

diff -u cryptsetup-1.0.4+svn29/debian/scripts/luksformat cryptsetup-1.0.4+svn29/debian/scripts/luksformat
--- cryptsetup-1.0.4+svn29/debian/scripts/luksformat
+++ cryptsetup-1.0.4+svn29/debian/scripts/luksformat
@@ -29,6 +29,14 @@

 $device = $ARGV[0];

+open(MOUNTS, "/proc/mounts");
+foreach $line (<MOUNTS>) {
+ if ($line =~ $device) {
+ print STDERR "Error: device mounted: $device\n";
+ exit 1;
+ }
+}
+
 $mkfs = "/sbin/mkfs.$fs";
 if (! -x $mkfs) {
     print STDERR "Error: invalid file system: $fs\n";

Michael Vogt (mvo) wrote :

someone with more perl-foo than me will probably want to review the patch :)

Michael Vogt (mvo) wrote :

Updated debdiff after some review from #ubuntu-devel

diff -u cryptsetup-1.0.4+svn29/debian/scripts/luksformat cryptsetup-1.0.4+svn29/debian/scripts/luksformat
--- cryptsetup-1.0.4+svn29/debian/scripts/luksformat
+++ cryptsetup-1.0.4+svn29/debian/scripts/luksformat
@@ -29,6 +29,11 @@

 $device = $ARGV[0];

+open(MOUNTS, "/proc/mounts");
+while (<MOUNTS>) {
+ die "Error: device mounted: $device\n" if (/\Q$device\E/)
+}
+
 $mkfs = "/sbin/mkfs.$fs";
 if (! -x $mkfs) {
     print STDERR "Error: invalid file system: $fs\n";

Reinhard Tartler (siretart) wrote :

fix released in gutsy

Changed in cryptsetup:
assignee: nobody → siretart
status: Unconfirmed → Fix Released
Michael Vogt (mvo) wrote :

Thanks a lot for applying the patch and upload the updated version :)

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers