[arch-releng] [PATCH 2/2] [archiso] Allow persistent cow dm-snapshots.
Gerardo Exequiel Pozzi
vmlinuz386 at yahoo.com.ar
Tue Aug 23 03:42:28 EDT 2011
Add some options to control where all COW files will be located.
Until this moment all files are located in a tmpfs filesystem.
Now is posible to set a device via a filesystem label or device node
plus a directory, where all these files will be stored.
All dm-snapshot devices will be persistent by default,
but this can be changed if wanted.
Take care, a filesystem that does not support sparse files maybe
is not the best choice for COW files, because they are created with
the same size (is apparent) like the read-only device (the image.fs inside .sfs).
Of course sooner or later, depending on use, these files actually end up
being as big as the read-only device.
Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386 at yahoo.com.ar>
---
README | 10 ++++++++++
archiso/hooks/archiso | 48 +++++++++++++++++++++++++++++++++++++++---------
2 files changed, 49 insertions(+), 9 deletions(-)
diff --git a/README b/README
index 88b3243..55e84d8 100644
--- a/README
+++ b/README
@@ -35,6 +35,16 @@ INDEX
performs a self-test of all files inside ${install_dir},
and continue booting if ok.
Default: (unset)
+* cow_label= Set the filesystem label where COW (dm-snapshot)
+ files must be stored.
+ Default: (unset)
+* cow_device= Set the device node where COW (dm-snapshot) files
+ must be stored.
+ Default: (unset) or "/dev/disk/by-label/${cow_label}"
+* cow_directory= Set a directory inside ${cow_device}.
+ Default: "/persistent_${archisolabel}"
+* cow_persistent= Set if snapshots are persistent "P" or non-persistent "N".
+ Default: "N" (if no ${cow_device} is used) otherwise "P".
* cowspace_size= Set the size of tmpfs /cowspace. This space is used for
Copy-On-Write files of dm-snapshot.
(directory not visible outside initramfs)
diff --git a/archiso/hooks/archiso b/archiso/hooks/archiso
index d846689..c524544 100644
--- a/archiso/hooks/archiso
+++ b/archiso/hooks/archiso
@@ -39,11 +39,25 @@ _mnt_fs() {
ro_dev_size=$(blockdev --getsz ${ro_dev})
ro_dev_fs_type=$(blkid -o value -s TYPE -p ${ro_dev} 2> /dev/null)
- dd of="/cowspace/${img_name}.cow" count=0 seek=${ro_dev_size} &> /dev/null
+
+ if [[ "${cow_persistent}" == "P" ]]; then
+ if [[ ! -f "/cowspace/${cow_directory}/${img_name}.cow" ]]; then
+ msg ":: Creating '/cowspace/${cow_directory}/${img_name}.cow' for first time."
+ dd of="/cowspace/${cow_directory}/${img_name}.cow" count=0 seek=${ro_dev_size} &> /dev/null
+ fi
+ else
+ if [[ -f "/cowspace/${cow_directory}/${img_name}.cow" ]]; then
+ msg ":: /cowspace/${cow_directory}/${img_name}.cow already exists but non-persistent requested, removing..."
+ rm -f "/cowspace/${cow_directory}/${img_name}.cow"
+ fi
+ msg ":: Creating '/cowspace/${cow_directory}/${img_name}.cow' for first time."
+ dd of="/cowspace/${cow_directory}/${img_name}.cow" count=0 seek=${ro_dev_size} &> /dev/null
+ fi
+
_next_loop_dev
- rw_dev=$(_make_loop_dev "/cowspace/${img_name}.cow")
+ rw_dev=$(_make_loop_dev "/cowspace/${cow_directory}/${img_name}.cow")
- echo "0 ${ro_dev_size} snapshot ${ro_dev} ${rw_dev} N 8" | dmsetup create ${dm_snap_name}
+ echo "0 ${ro_dev_size} snapshot ${ro_dev} ${rw_dev} ${cow_persistent} 8" | dmsetup create ${dm_snap_name}
msg ":: Mounting '/dev/mapper/${dm_snap_name}' (${ro_dev_fs_type}) to '${mnt}'"
if ! mount -t "${ro_dev_fs_type}" "/dev/mapper/${dm_snap_name}" "${mnt}" ; then
@@ -132,11 +146,24 @@ run_hook() {
[[ -z "${archisobasedir}" ]] && archisobasedir="arch"
[[ -z "${dm_snap_prefix}" ]] && dm_snap_prefix="arch"
[[ -z "${archisodevice}" ]] && archisodevice="/dev/disk/by-label/${archisolabel}"
+
if [[ -z "${aitab}" ]]; then
aitab="/bootmnt/${archisobasedir}/aitab"
else
aitab="/bootmnt/${aitab}"
fi
+
+ if [[ -n "${cow_label}" ]]; then
+ cow_device="/dev/disk/by-label/${cow_label}"
+ [[ -z "${cow_persistent}" ]] && cow_persistent="P"
+ elif [[ -n "${cow_device}" ]]; then
+ [[ -z "${cow_persistent}" ]] && cow_persistent="P"
+ else
+ cow_persistent="N"
+ fi
+
+ [[ -z "${cow_directory}" ]] && cow_directory="persistent_${archisolabel}"
+
# set mount handler for archiso
mount_handler="archiso_mount_handler"
}
@@ -174,14 +201,17 @@ archiso_mount_handler() {
fi
if [[ "${copytoram}" == "y" ]]; then
- msg -n ":: Mounting /copytoram (tmpfs) filesystem, size=${copytoram_size}..."
+ msg ":: Mounting /copytoram (tmpfs) filesystem, size=${copytoram_size}"
mount -t tmpfs -o "size=${copytoram_size}",mode=0755 copytoram /copytoram
- msg "done."
fi
- msg -n ":: Mounting /cowspace (tmpfs) filesystem, size=${cowspace_size}..."
- mount -t tmpfs -o "size=${cowspace_size}",mode=0755 cowspace /cowspace
- msg "done."
+ if [[ -n "${cow_device}" ]]; then
+ _mnt_dev "${cow_device}" "/cowspace"
+ else
+ msg ":: Mounting /cowspace (tmpfs) filesystem, size=${cowspace_size}..."
+ mount -t tmpfs -o "size=${cowspace_size}",mode=0755 cowspace /cowspace
+ fi
+ mkdir -p "/cowspace/${cow_directory}"
local aitab_img aitab_mnt aitab_arch aitab_sfs_comp aitab_fs_type aitab_fs_size
while read aitab_img aitab_mnt aitab_arch aitab_sfs_comp aitab_fs_type aitab_fs_size; do
@@ -202,7 +232,7 @@ archiso_mount_handler() {
if [[ "${copytoram}" == "y" ]]; then
umount /bootmnt
else
- mkdir "${newroot}/bootmnt"
+ mkdir -p "${newroot}/bootmnt"
mount --bind /bootmnt "${newroot}/bootmnt"
fi
}
--
1.7.6
More information about the arch-releng
mailing list