或者有根目上有 ubuntu.img 文件 就用它来保存
代码: 全选
find_cow_device() {
for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop); do
for dev in $(subdevices "${sysblock}"); do
devname=$(sys2dev "${dev}")
case $(get_fstype "${devname}") in
ext2|ext3|reiserfs|jfs|xfs|minix)
modprobe $(get_fstype "${devname}")
mount -t $(get_fstype "${devname}") -o rw "${devname}" /cow_tmp || continue
if [ -e /cow_tmp/ubuntu_rw ] ; then
mount -o bind /cow_tmp /cow
return
elif [ -f /cow_tmp/ubuntu.img ]; then
modprobe loop
mount -t $(get_fstype /cow_tmp/ubuntu.img ) -o loop /cow_tmp/ubuntu.img /cow
return
else
umount /cow_tmp
fi
;;
vfat|ntfs)
modprobe $(get_fstype "${devname}")
mount -t $(get_fstype "${devname}") -o utf8 "${devname}" /cow_tmp || continue
if [ -f /cow_tmp/ubuntu.img ]; then
modprobe loop
mount -t $(get_fstype /cow_tmp/ubuntu.img ) -o loop /cow_tmp/ubuntu.img /cow
return
eles
umount /cow_tmp
fi
;;
*)
;;
esac
done
done
return 1
}
setup_unionfs() {
backdev="$1"
rootmnt="$2"
modprobe -Qb unionfs
mkdir -p /cow
if grep -q use_hd_unionfs /proc/cmdline; then
mkdir -p /cow_tmp
i=0
# We love udev and the kernel!
while [ "$i" -lt 10 ]; do
cowdevice=$(find_cow_device)
sleep 1
i=$(( $i + 1 ))
done
else
mount -t tmpfs tmpfs /cow
fi
mkdir -p /rofs
if [ "$(get_fstype $backdev)" = "unknown" ]; then
panic "Unknown file system type on $backdev"
fi
mount -t $(get_fstype "$backdev") -o ro "$backdev" /rofs || panic "Can not mount $backdev on /rofs"
mount -t unionfs -o dirs=/cow=rw:/rofs=ro unionfs "$rootmnt"
if grep -q show-cow /proc/cmdline; then
mkdir -p "$rootmnt/cow"
mount -o bind /cow "$rootmnt/cow"
fi
mkdir -p "$rootmnt/rofs"
mount -o bind /rofs "$rootmnt/rofs"
}