[archiso] Allow persistent cow dm-snapshots.

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.

KNOW-ISSUE: On shutdown in step "Unmounting Filesystems" will [FAIL],
    all filesystem except $cow_device, will be unmounted/remounted-ro.
    For this reason this change needs an archiso_shutdown hook, thats
    unmount all block devices used by archiso. (Work in progress)

Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
This commit is contained in:
Gerardo Exequiel Pozzi 2011-10-23 21:24:17 -03:00
parent 91e11c30f4
commit e2055835fd
2 changed files with 58 additions and 11 deletions

10
README
View File

@ -35,6 +35,16 @@ INDEX
performs a self-test of all files inside ${install_dir}, performs a self-test of all files inside ${install_dir},
and continue booting if ok. and continue booting if ok.
Default: (unset) 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}/${arch}"
* 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 * cowspace_size= Set the size of tmpfs /cowspace. This space is used for
Copy-On-Write files of dm-snapshot. Copy-On-Write files of dm-snapshot.
(directory not visible outside initramfs) (directory not visible outside initramfs)

View File

@ -38,11 +38,27 @@ _mnt_fs() {
ro_dev_size=$(blockdev --getsz ${ro_dev}) ro_dev_size=$(blockdev --getsz ${ro_dev})
ro_dev_fs_type=$(blkid -o value -s TYPE -p ${ro_dev} 2> /dev/null) 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
_next_loop_dev
rw_dev=$(_make_loop_dev "/cowspace/${img_name}.cow")
echo "0 ${ro_dev_size} snapshot ${ro_dev} ${rw_dev} N 8" | dmsetup create ${dm_snap_name} if [[ "${cow_persistent}" == "P" ]]; then
if [[ -f "/cowspace/${cow_directory}/${img_name}.cow" ]]; then
msg ":: Found '/cowspace/${cow_directory}/${img_name}.cow', using as persistent."
else
msg ":: Creating '/cowspace/${cow_directory}/${img_name}.cow' as persistent."
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 ":: Found '/cowspace/${cow_directory}/${img_name}.cow' but non-persistent requested, removing."
rm -f "/cowspace/${cow_directory}/${img_name}.cow"
fi
msg ":: Creating '/cowspace/${cow_directory}/${img_name}.cow' as non-persistent."
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/${cow_directory}/${img_name}.cow")
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}'" 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 if ! mount -t "${ro_dev_fs_type}" "/dev/mapper/${dm_snap_name}" "${mnt}" ; then
@ -132,11 +148,24 @@ run_hook() {
[[ -z "${archisobasedir}" ]] && archisobasedir="arch" [[ -z "${archisobasedir}" ]] && archisobasedir="arch"
[[ -z "${dm_snap_prefix}" ]] && dm_snap_prefix="arch" [[ -z "${dm_snap_prefix}" ]] && dm_snap_prefix="arch"
[[ -z "${archisodevice}" ]] && archisodevice="/dev/disk/by-label/${archisolabel}" [[ -z "${archisodevice}" ]] && archisodevice="/dev/disk/by-label/${archisolabel}"
if [[ -z "${aitab}" ]]; then if [[ -z "${aitab}" ]]; then
aitab="/bootmnt/${archisobasedir}/aitab" aitab="/bootmnt/${archisobasedir}/aitab"
else else
aitab="/bootmnt/${aitab}" aitab="/bootmnt/${aitab}"
fi 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}/${arch}"
# set mount handler for archiso # set mount handler for archiso
mount_handler="archiso_mount_handler" mount_handler="archiso_mount_handler"
} }
@ -149,7 +178,12 @@ archiso_mount_handler() {
_init_loop_dev _init_loop_dev
_mnt_dev "${archisodevice}" "/bootmnt" "-r" if [[ "${archisodevice}" -ef "${cow_device}" ]]; then
_mnt_dev "${archisodevice}" "/bootmnt"
else
_mnt_dev "${archisodevice}" "/bootmnt" "-r"
fi
if [[ ! -f "${aitab}" ]]; then if [[ ! -f "${aitab}" ]]; then
echo "ERROR: '${aitab}' file does not exist." echo "ERROR: '${aitab}' file does not exist."
echo " Falling back to interactive prompt" echo " Falling back to interactive prompt"
@ -174,14 +208,17 @@ archiso_mount_handler() {
fi fi
if [[ "${copytoram}" == "y" ]]; then 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 mount -t tmpfs -o "size=${copytoram_size}",mode=0755 copytoram /copytoram
msg "done."
fi fi
msg -n ":: Mounting /cowspace (tmpfs) filesystem, size=${cowspace_size}..." if [[ -n "${cow_device}" ]]; then
mount -t tmpfs -o "size=${cowspace_size}",mode=0755 cowspace /cowspace _mnt_dev "${cow_device}" "/cowspace"
msg "done." 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 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 while read aitab_img aitab_mnt aitab_arch aitab_sfs_comp aitab_fs_type aitab_fs_size; do
@ -202,7 +239,7 @@ archiso_mount_handler() {
if [[ "${copytoram}" == "y" ]]; then if [[ "${copytoram}" == "y" ]]; then
umount /bootmnt umount /bootmnt
else else
mkdir "${newroot}/bootmnt" mkdir -p "${newroot}/bootmnt"
mount --bind /bootmnt "${newroot}/bootmnt" mount --bind /bootmnt "${newroot}/bootmnt"
fi fi
} }