Hi all,

Sometimes it is desired to boot Debian Live from NTFS. When you ask?
Well, for instance, if we want to install Debian on a Windows machine, and
we can't change the partitions, don't want to use CDs and don't have a USB
stick.
That's the scenario I'm facing, so I'll explain what need to be done to make
a "Live NTFS"

The first step is to add the NTFS module to the initramfs. To do it, add the
following line to hooks/casper:
manual_add_modules ntfs

Now you can use this NTFS partition, just as any other read only media.
bootfrom param helps probing the partition (usually bootfrom=/dev/sda1).

To have persistence (RW) on this partition is much more complicated and
risky. if you don't need persistence on NTFS , you can stop reading :)
CAUTION: the following might cause damage, use at your own risk!

From my experiments, the kernel's NTFS driver is very strict about the state
of the partition, and refusing to mount it RW very easily.
To overcome this problem, one can patch the kernel to be less strict (but
more risky) or to use ntfs-3g.
AFAIK, no one have yet integrated ntfs-3g into casper nor any other fuse
based fs.
I would be delighted to see such an integration...

I decided to change the ntfs kernel's driver to be less strict - you can see
the attached patch.
Thanks to Yura Pakhuchiy who contributed an older patch - see
http://www.mail-archive.com/[EMAIL PROTECTED]/msg02061.html
With this patch you can mount the partition using "-o force_rw" (another
change to casper)
It is not safe to write strait to the NTFS, so I use an EXT3 image and loop
mount it (see loop persistence patch)
Any changes to the files will be written using the EXT3 driver, while the
NTFS will do only "safe" writes.

This is a hack, but until there is a proper writable NTFS in Debian, I think
some people will find it useful.

Hadar.
--- /mnt/newkernel/devel/xen_dom0_kernel/linux-2.6.16.33-xen/Documentation/filesystems/ntfs.txt 
+++ /home/hadar/dev/xen_dom0_kernel/linux-2.6.16.33-xen/Documentation/filesystems/ntfs.txt 
@@ -173,6 +173,11 @@
 			default, creation of sparse regions is enabled, which
 			is consistent with the behaviour of traditional Unix
 			filesystems.
+
+force_rw=<BOOL>		If force_rw is specified, then volume will be mounted
+			read-write even it has dirty or unsuppoted flags set.
+			WARNING: This option is mostly for developers, use it
+			only if you really know what are you doing
 
 errors=opt		What to do when critical filesystem errors are found.
 			Following values can be used for "opt":
--- /mnt/newkernel/devel/xen_dom0_kernel/linux-2.6.16.33-xen/fs/ntfs/super.c 
+++ /home/hadar/dev/xen_dom0_kernel/linux-2.6.16.33-xen/fs/ntfs/super.c 
@@ -106,6 +106,7 @@
 	mode_t fmask = (mode_t)-1, dmask = (mode_t)-1;
 	int mft_zone_multiplier = -1, on_errors = -1;
 	int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1;
+	int force_rw = -1;
 	struct nls_table *nls_map = NULL, *old_nls;
 
 	/* I am lazy... (-8 */
@@ -173,6 +174,7 @@
 		else NTFS_GETOPT_WITH_DEFAULT("sloppy", sloppy, TRUE)
 		else NTFS_GETOPT_BOOL("show_sys_files", show_sys_files)
 		else NTFS_GETOPT_BOOL("case_sensitive", case_sensitive)
+		else NTFS_GETOPT_BOOL("force_rw", force_rw)
 		else NTFS_GETOPT_BOOL("disable_sparse", disable_sparse)
 		else NTFS_GETOPT_OPTIONS_ARRAY("errors", on_errors,
 				on_errors_arr)
@@ -318,6 +320,12 @@
 				NVolSetSparseEnabled(vol);
 		}
 	}
+	if (force_rw != -1) {
+		if (force_rw)
+			NVolSetForceRW(vol);
+		else
+			NVolClearForceRW(vol);
+	}
 	return TRUE;
 needs_arg:
 	ntfs_error(vol->sb, "The %s option requires an argument.", p);
@@ -468,16 +476,16 @@
 					es);
 			return -EROFS;
 		}
-		if (vol->vol_flags & VOLUME_IS_DIRTY) {
+		if (!NVolForceRW(vol) && vol->vol_flags & VOLUME_IS_DIRTY) {
 			ntfs_error(sb, "Volume is dirty and read-only%s", es);
 			return -EROFS;
 		}
-		if (vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) {
+		if (!NVolForceRW(vol) && vol->vol_flags & VOLUME_MODIFIED_BY_CHKDSK) {
 			ntfs_error(sb, "Volume has been modified by chkdsk "
 					"and is read-only%s", es);
 			return -EROFS;
 		}
-		if (vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
+		if (!NVolForceRW(vol) && vol->vol_flags & VOLUME_MUST_MOUNT_RO_MASK) {
 			ntfs_error(sb, "Volume has unsupported flags set "
 					"(0x%x) and is read-only%s",
 					(unsigned)le16_to_cpu(vol->vol_flags),
@@ -1873,15 +1881,18 @@
 		/* If a read-write mount, convert it to a read-only mount. */
 		if (!(sb->s_flags & MS_RDONLY)) {
 			if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
-					ON_ERRORS_CONTINUE))) {
+							ON_ERRORS_CONTINUE))) {
 				ntfs_error(sb, "%s and neither on_errors="
 						"continue nor on_errors="
 						"remount-ro was specified%s",
 						es1, es2);
 				goto iput_vol_err_out;
 			}
-			sb->s_flags |= MS_RDONLY;
-			ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
+			if (!NVolForceRW(vol)) {
+				sb->s_flags |= MS_RDONLY;
+				ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
+			} else
+				ntfs_error(sb, "%s.  Forced read-write mount.",	es1);
 		} else
 			ntfs_warning(sb, "%s.  Will not be able to remount "
 					"read-write%s", es1, es2);
@@ -1903,27 +1914,29 @@
 		const char *es1;
 
 		es1 = !vol->logfile_ino ? es1a : es1b;
+		if (!NVolForceRW(vol)) {
 		/* If a read-write mount, convert it to a read-only mount. */
-		if (!(sb->s_flags & MS_RDONLY)) {
-			if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
-					ON_ERRORS_CONTINUE))) {
-				ntfs_error(sb, "%s and neither on_errors="
-						"continue nor on_errors="
-						"remount-ro was specified%s",
-						es1, es2);
-				if (vol->logfile_ino) {
-					BUG_ON(!rp);
-					ntfs_free(rp);
+			if (!(sb->s_flags & MS_RDONLY)) {
+				if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
+								ON_ERRORS_CONTINUE))) {
+					ntfs_error(sb, "%s and neither on_errors="
+							"continue nor on_errors="
+							"remount-ro was specified%s",
+							es1, es2);
+					if (vol->logfile_ino) {
+						BUG_ON(!rp);
+						ntfs_free(rp);
+					}
+					goto iput_logfile_err_out;
 				}
-				goto iput_logfile_err_out;
-			}
-			sb->s_flags |= MS_RDONLY;
-			ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-		} else
-			ntfs_warning(sb, "%s.  Will not be able to remount "
-					"read-write%s", es1, es2);
-		/* This will prevent a read-write remount. */
-		NVolSetErrors(vol);
+				sb->s_flags |= MS_RDONLY;
+				ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
+			} else
+				ntfs_warning(sb, "%s.  Will not be able to remount "
+						"read-write%s", es1, es2);
+			/* This will prevent a read-write remount. */
+			NVolSetErrors(vol);
+		}
 	}
 	ntfs_free(rp);
 #endif /* NTFS_RW */
@@ -1952,23 +1965,25 @@
 		const char *es1;
 
 		es1 = err < 0 ? es1a : es1b;
-		/* If a read-write mount, convert it to a read-only mount. */
-		if (!(sb->s_flags & MS_RDONLY)) {
-			if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
-					ON_ERRORS_CONTINUE))) {
-				ntfs_error(sb, "%s and neither on_errors="
-						"continue nor on_errors="
-						"remount-ro was specified%s",
-						es1, es2);
-				goto iput_root_err_out;
-			}
-			sb->s_flags |= MS_RDONLY;
-			ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
-		} else
-			ntfs_warning(sb, "%s.  Will not be able to remount "
-					"read-write%s", es1, es2);
-		/* This will prevent a read-write remount. */
-		NVolSetErrors(vol);
+		if (!NVolForceRW(vol)) {
+			/* If a read-write mount, convert it to a read-only mount. */
+			if (!(sb->s_flags & MS_RDONLY)) {
+				if (!(vol->on_errors & (ON_ERRORS_REMOUNT_RO |
+								ON_ERRORS_CONTINUE))) {
+					ntfs_error(sb, "%s and neither on_errors="
+							"continue nor on_errors="
+							"remount-ro was specified%s",
+							es1, es2);
+					goto iput_root_err_out;
+				}
+				sb->s_flags |= MS_RDONLY;
+				ntfs_error(sb, "%s.  Mounting read-only%s", es1, es2);
+			} else
+				ntfs_warning(sb, "%s.  Will not be able to remount "
+						"read-write%s", es1, es2);
+			/* This will prevent a read-write remount. */
+			NVolSetErrors(vol);
+		}
 	}
 	/* If (still) a read-write mount, mark the volume dirty. */
 	if (!(sb->s_flags & MS_RDONLY) &&
--- /mnt/newkernel/devel/xen_dom0_kernel/linux-2.6.16.33-xen/fs/ntfs/volume.h 
+++ /home/hadar/dev/xen_dom0_kernel/linux-2.6.16.33-xen/fs/ntfs/volume.h 
@@ -145,6 +145,8 @@
 	NV_QuotaOutOfDate,	/* 1: $Quota is out of date. */
 	NV_UsnJrnlStamped,	/* 1: $UsnJrnl has been stamped. */
 	NV_SparseEnabled,	/* 1: May create sparse files. */
+	NV_ForceRW,		/* 1: Force R/W mount, even volume has
+				      dirty or unsupported flags set. */
 } ntfs_volume_flags;
 
 /*
@@ -173,6 +175,7 @@
 DEFINE_NVOL_BIT_OPS(QuotaOutOfDate)
 DEFINE_NVOL_BIT_OPS(UsnJrnlStamped)
 DEFINE_NVOL_BIT_OPS(SparseEnabled)
+DEFINE_NVOL_BIT_OPS(ForceRW)
 
 #endif /* _LINUX_NTFS_VOLUME_H */
_______________________________________________
Debian-live-devel mailing list
Debian-live-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/debian-live-devel

Reply via email to