Fri Nov 22, 2013 12:53 pm
#!/bin/bash
set -x
# scriptname: mkloopfile
# make a loopback filesystem (luks or not)
# use for live-persistence or whatever else.
########################################################
###### EDIT TO SUIT ####################################
# size of the loopback file in MB
#SIZE="500"
SIZE="100"
# if it will be used for persistence
PERSISTENCE="yes"
# name of the loopback file.. (if for persistence) it *should* be labelled "persistence"
# except where "persistence-label=LABEL" is used
# else choose another name
#LOOP_FILENAME="persistence"
# make the loopback file user-owned (uncomment and edit next line)
NORMAL_USER_ID="1000"
# filesystem format
# will be labelled the same as $LOOP_FILENAME
FILESYSTEM="ext2"
# choose "full" or "home".. Ignored if $LOOP_FILENAME is not "persistence"
# other persistence options: choose either and edit.conf manually
PERSISTENCE_TYPE="home"
# mountpoint for the loopback file (script can create it)
LOOP_MOUNTPOINT="/tmp/loopmount"
# Use LUKS container (yes/other)
IS_LUKS="no"
########################################################
########################################################
source /usr/lib/refracta2usb/functions_r2u
yad_zenity_compat
if [ "$1" = "-debug" ]; then
set -x
fi
error_log="/var/log/errors_mkloopback"
exec 2>"$error_log"
# script must be called from a root terminal
if ! [ -t 0 ]; then
echo "Error: Not a terminal"
exit 1
fi
if ! [[ $(id -u) -eq 0 ]]; then
echo "Error: You are not root"
exit 1
fi
device=$(cat /tmp/r2u_device)
usb_mountpoint="/media/${device##*/}1"
work_dir=$($DIALOG --file-selection --directory --filename="${usb_mountpoint}/*" \
--text=" Select the folder to contain the loop file. Normally, this is the root
directory of the device. For a multiboot device, choose the folder
for the system that will use this loop file.
" \
--width=500 --height=400 --${BUTTON0}="OK"${BUTTON0NUM} --${BUTTON1}="Quit Task"${BUTTON1NUM})
if [[ $? = 1 ]] ; then
exit 0
fi
cd "$work_dir"
finished_message="work_dir is $work_dir.
current directory is $(pwd)"
finished_dialog
LOOP_FILENAME=$($DIALOG --entry --entry-text="persistence" --text="Enter a name for the loop file,
or just ENTER to use \"persistence\"." --${BUTTON0}="OK"${BUTTON0NUM} --${BUTTON1}="Quit Task"${BUTTON1NUM})
if [[ $? = 1 ]] ; then
exit 0
fi
setup_file () {
dd if=/dev/zero of=${LOOP_FILENAME} bs=1M count=${SIZE}
if [ -n "$NORMAL_USER_ID" ]; then
chown ${NORMAL_USER_ID}:${NORMAL_USER_ID} ${LOOP_FILENAME}
fi
losetup -f > /tmp/nextloop
LOOPDEV=$(cat /tmp/nextloop)
losetup ${LOOPDEV} ${LOOP_FILENAME}
}
format_file () {
if [ "$IS_LUKS" = "yes" ]; then
cryptsetup luksFormat ${LOOPDEV}
cryptsetup luksOpen ${LOOPDEV} ${LOOP_FILENAME}
LOOP_FS="/dev/mapper/$LOOP_FILENAME"
CLOSE_LOOPDEV="cryptsetup luksClose $LOOP_FILENAME && losetup -d $LOOPDEV"
else
LOOP_FS="$LOOPDEV"
CLOSE_LOOPDEV="losetup -d $LOOPDEV"
fi
mke2fs -t ext2 -L ${LOOP_FILENAME} ${LOOP_FS}
/sbin/tune2fs -c 0 ${LOOP_FS}
}
mount_fs () {
mkdir ${LOOP_MOUNTPOINT} || echo "Mountpoint exists"
DIR_FILES=$(ls ${LOOP_MOUNTPOINT}|wc -l)
if [ "$DIR_FILES" -ne "0" ]; then
echo "Error: Mountpoint ${LOOP_MOUNTPOINT} is not empty" && exit 1
fi
mount ${LOOP_FS} ${LOOP_MOUNTPOINT}
}
write_persistence_conf () {
if [ "$PERSISTENCE" = "yes" ]; then
echo -e "# home persistence example:" > ${LOOP_MOUNTPOINT}/persistence.conf
echo -e "# /home bind,source=.\n" >> ${LOOP_MOUNTPOINT}/persistence.conf
echo -e "# full persistence example (entire filesystem writable):" >> ${LOOP_MOUNTPOINT}/persistence.conf
echo -e "# / union,source=.\n" >> ${LOOP_MOUNTPOINT}/persistence.conf
if [ "$PERSISTENCE_TYPE" = "home" ]; then
echo -e "/home union,source=." >> ${LOOP_MOUNTPOINT}/persistence.conf
fi
if [ "$PERSISTENCE_TYPE" = "full" ]; then
echo -e "/ union,source=." >> ${LOOP_MOUNTPOINT}/persistence.conf
fi
fi
}
cleanup () {
#echo "Umount and close now? (y/n)" && read RESP
#if [ "$RESP" = "y" ]; then
while true ; do
echo " Unmount and close now? (y/n)
"
read ans
case $ans in
y) umount ${LOOP_FS}
${CLOSE_LOOPDEV}
rm -f /tmp/nextloop
rmdir /tmp/loopmount
break ;;
#else
n)
echo -e "\n ${LOOP_FS} is still mounted at ${LOOP_MOUNTPOINT}\n"
echo -e " To umount and close manually:"
echo -e " umount ${LOOP_FS} "
echo -e " ${CLOSE_LOOPDEV}"
break ;;
#fi
esac
done
LOCATION="$(pwd)"
echo -e "\n Loopback File was written to ${LOCATION}/${LOOP_FILENAME}"
}
setup_file
format_file
mount_fs
write_persistence_conf
source_initrd=$($DIALOG --file-selection --height=550 --width=650 --title="$TITLE" \
--text=" Select the custom initrd that will be used with this loopfile.\n" \
--filename="$source_dir")
custom_initrd="${source_initrd##*/}"
if [[ $work_dir = "$usb_mountpoint" ]] ; then
warning_message="work_dir = usb_mountpoint
$work_dir = usb_mountpoint "
live_dir="/live"
else
live_dir="/${work_dir##*/}/live"
fi
finished_message="
Persistent loopback file is ready.
If you select Edit at the Main Menu, an entry
for this file will be added to your boot menu. "
echo "$finished_message"
if [[ $LOOP_FILENAME = "persistence" ]] ; then
menu_text="
label persistence
menu label Refracta (persistence)
kernel ${live_dir}/vmlinuz quiet
append initrd=${live_dir}/$custom_initrd boot=live ip=frommedia union=aufs persistence
"
else
menu_text="
label $LOOP_FILENAME
menu label Refracta ($LOOP_FILENAME)
kernel ${live_dir}/vmlinuz quiet
append initrd=${live_dir}/$custom_initrd boot=live ip=frommedia union=aufs persistence config=openssh-server persistence-label=$LOOP_FILENAME
"
fi
echo "$menu_text" > /tmp/boot_menu_text
# chmod 666 /tmp/boot_menu_text
username=$(cat /tmp/r2u_user)
chown "$username" /tmp/boot_menu_text
finished_dialog
umount ${LOOP_FS}
${CLOSE_LOOPDEV}
rm -f /tmp/nextloop
rmdir /tmp/loopmount
exit 0
Fri Nov 22, 2013 7:00 pm
Sat Nov 23, 2013 12:37 pm
Sat Nov 23, 2013 3:33 pm
label my_snapshot
menu label my_snapshot
kernel /my_snapshot/vmlinuz quiet
append initrd=/my_snapshot/initrd.img boot=live other_opts union=aufs live-media-path=/my_snapshot/
Sun Nov 24, 2013 2:52 am
label persistence
menu label Refracta (persistence)
kernel /live/vmlinuz quiet
append initrd=/live/initrd.custom.img boot=live ip=frommedia union=aufs live-media-path=/live persistence basemountmode=rw,noatime,umask=000
label persistence
menu label Refracta (persistence)
kernel /sidfracta/live/vmlinuz quiet
append initrd=/sidfracta/live/initrd.custom.img boot=live ip=frommedia union=aufs live-media-path=/sidfracta/live persistence persistence-path=/sidfracta/ basemountmode=rw,noatime,umask=000
label loop6
menu label Refracta (loop6)
kernel /sidfracta/live/vmlinuz quiet
append initrd=/sidfracta/live/initrd.custom.img boot=live ip=frommedia union=aufs persistence config=openssh-server live-media-path=/sidfracta/live basemountmode=rw,noatime,umask=000 persistence-path=/sidfracta/ persistence-encryption=none,luks persistence-label=loop6
label myloop
menu label Refracta (myloop)
kernel /sidfracta/live/vmlinuz quiet
append initrd=/sidfracta/live/initrd.custom.img boot=live ip=frommedia union=aufs persistence config=openssh-server live-media-path=/sidfracta/live basemountmode=rw,noatime,umask=000 persistence-path=/sidfracta/ persistence-encryption=none,luks persistence-label=myloop
deb_netinstall pkglist_refracta_7.2_i386-20131020_0352 syslinux
live Release_Notes testfile6
persistence sidfracta
live loop6 myloop persistence pkglist_sid-refracted-20131107_1123 syslinux
Sun Nov 24, 2013 2:27 pm
label Sid-snap persistence
menu label Sid-snap persistence
kernel /live/vmlinuz quiet
append initrd=/live/initrd.img boot=live ip=frommedia union=aufs noeject persistence persistence-media=removable-usb persistence-path=/test/ persistence-label=sidrw
label Sid-snap luks-persistence
menu label Sid-snap luks-persistences
kernel /live/vmlinuz quiet
append initrd=/live/initrd.custom.img boot=live ip=frommedia union=aufs noeject persistence persistence-media=removable-usb persistence-path=/test/ persistence-label=sidrw persistence-encryption=none,luks
Sun Nov 24, 2013 3:12 pm
Sun Nov 24, 2013 3:19 pm
Sun Nov 24, 2013 4:39 pm
Sun Nov 24, 2013 5:49 pm