一种实现 ubuntu “一键还原”的思路
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
- Tenyears
- 帖子: 2245
- 注册时间: 2005-06-30 15:46
- 来自: 成都
- skyx
- 论坛版主
- 帖子: 9202
- 注册时间: 2006-12-23 13:46
- 来自: Azores Islands
- 联系:
- ptptptptptpt
- 帖子: 3711
- 注册时间: 2006-09-19 18:16
Re: 一种实现 ubuntu “一键还原”的思路
啊哟,没想到这么热烈,谢谢,谢谢,请耐心等下
06年时 unionfs 问题多多,我一直不大信任它。后来有了 aufs ,据说稳定性好很多,现在也似乎用的越来越广泛,才又又有了兴趣
系统没必要做成 iso 或 squishfs 映像,就用正常安装在分区中的系统,启动时有几种模式可选:1,正常启动,可以添加、删除软件;2,保护模式,就是用 联合文件系统 ,以只读方式挂载系统分区,3,还原模式……
也不用 loop image文件 ,直接用一个分区作为可写部分,需要还原时,直接格式化该分区
没错,相信很多人一眼就能看出怎么回事,不过我更愿意说是本论坛 gnix_oag 倡导过的技术( viewtopic.php?t=21688 ),或者更应该说,是 slax 一直以来就在使用的技术。yaska 写了:
pt兄,我估计你的方法 就是prayaya livesystem现在用的技术。
把系统做成一个iso,然后用aufs联合一个loop image文件,当然也可以是linux分区上的目录。
iso是只读的,所以数据都保存在loop文件里面,所谓的还原,把loop文件去掉就可以了。
嗯,还有其他新东西的话,大家一起讨论吧。。
06年时 unionfs 问题多多,我一直不大信任它。后来有了 aufs ,据说稳定性好很多,现在也似乎用的越来越广泛,才又又有了兴趣
系统没必要做成 iso 或 squishfs 映像,就用正常安装在分区中的系统,启动时有几种模式可选:1,正常启动,可以添加、删除软件;2,保护模式,就是用 联合文件系统 ,以只读方式挂载系统分区,3,还原模式……
也不用 loop image文件 ,直接用一个分区作为可写部分,需要还原时,直接格式化该分区
- yaska
- 帖子: 1169
- 注册时间: 2007-10-28 21:35
- yjcong
- 帖子: 2470
- 注册时间: 2006-02-28 3:11
- ptptptptptpt
- 帖子: 3711
- 注册时间: 2006-09-19 18:16
显然是要在initrd里面做,稍微定制一下就行—— livecd 不就是把 squashfs文件系统 和 内存盘 联合吗,把内存盘用一个分区替换,不就行了吗
压成 squashfs文件系统 的好处是 —— 空间占用小,读取速度快,因为是压缩格式,同一个文件,读取时数据量小,但会增大cpu负荷,因为要解压,不过这点负荷对现在的cpu来说只是毛毛雨
另一好处是 squashfs 映像 不可写,系统文件更加安全。但同时也是缺点,配置好的系统,如果想做些更改,就得重新压制 squashfs 映像,比较麻烦
还有一个缺点,squashfs 映像须放在另一个文件系统中,fat32 也好,ntfs也好,ext3也好,逻辑上多了一层,安全性上差了一点
综合考虑,mid设备上使用 squashfs 映像 是不错的选择 ,而日常用的系统,我认为还是分区安装较为合适,当然并非绝对。
- ptptptptptpt
- 帖子: 3711
- 注册时间: 2006-09-19 18:16
- ptptptptptpt
- 帖子: 3711
- 注册时间: 2006-09-19 18:16
刚才试验了下,可以用,能起到还原效果。但使用感受不好,有时卡,通知区域 还老打哆嗦
如果用内存盘作为可写部分,相信会好很多,缺点是比较占内存,可写空间也不会很大(受内存容量限制),而且每次重启都会还原
用的 unionfs ,不知 aufs 会不会好些。
步骤如下:
简单起见,系统只分一个区,即 / 。
1,定制initrd。新建两个目录 /tmp-rootmnt 和 /rwfs 。简单修改了 /scripts/local ,改后内容如下:
2,创建一个 reiserfs (目前只支持这一种格式)分区,在其中建立 ubunturwfs 目录。
3,把 fstab 中 挂载跟分区 那一行注释掉
menu.lst 只需修改 initrd 行,指向定制的 initrd 文件。
如果用内存盘作为可写部分,相信会好很多,缺点是比较占内存,可写空间也不会很大(受内存容量限制),而且每次重启都会还原
用的 unionfs ,不知 aufs 会不会好些。
步骤如下:
简单起见,系统只分一个区,即 / 。
1,定制initrd。新建两个目录 /tmp-rootmnt 和 /rwfs 。简单修改了 /scripts/local ,改后内容如下:
代码: 全选
# Local filesystem mounting -*- shell-script -*-
# Parameter: Where to mount the filesystem
mountroot ()
{
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top"
run_scripts /scripts/local-top
[ "$quiet" != "y" ] && log_end_msg
# If the root device hasn't shown up yet, give it a little while
# to deal with removable devices
if [ ! -e "${ROOT}" ] || ! /lib/udev/vol_id "${ROOT}" >/dev/null 2>&1; then
log_begin_msg "Waiting for root file system..."
# Default delay is 180s
if [ -z "${ROOTDELAY}" ]; then
slumber=180
else
slumber=${ROOTDELAY}
fi
if [ -x /sbin/usplash_write ]; then
/sbin/usplash_write "TIMEOUT ${slumber}" || true
fi
slumber=$(( ${slumber} * 10 ))
while [ ! -e "${ROOT}" ] || ! /lib/udev/vol_id "${ROOT}" >/dev/null 2>&1; do
/bin/sleep 0.1
slumber=$(( ${slumber} - 1 ))
[ ${slumber} -gt 0 ] || break
done
if [ ${slumber} -gt 0 ]; then
log_end_msg 0
else
log_end_msg 1 || true
fi
if [ -x /sbin/usplash_write ]; then
/sbin/usplash_write "TIMEOUT 15" || true
fi
fi
# We've given up, but we'll let the user fix matters if they can
while [ ! -e "${ROOT}" ] || ! /lib/udev/vol_id "${ROOT}" >/dev/null 2>&1; do
echo " Check root= bootarg cat /proc/cmdline"
echo " or missing modules, devices: cat /proc/modules ls /dev"
panic -r "ALERT! ${ROOT} does not exist. Dropping to a shell!"
done
# Get the root filesystem type if not set
if [ -z "${ROOTFSTYPE}" ]; then
eval $(fstype < ${ROOT})
else
FSTYPE=${ROOTFSTYPE}
fi
if [ "$FSTYPE" = "unknown" ] && [ -x /lib/udev/vol_id ]; then
FSTYPE=$(/lib/udev/vol_id -t ${ROOT})
[ -z "$FSTYPE" ] && FSTYPE="unknown"
fi
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
run_scripts /scripts/local-premount
[ "$quiet" != "y" ] && log_end_msg
if [ ${readonly} = y ] && \
[ -z "$LOOP" ]; then
roflag=-r
else
roflag=-w
fi
# FIXME This has no error checking
modprobe -Qb ${FSTYPE}
# FIXME This has no error checking
# Mount root
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /tmp-rootmnt
mountroot_status="$?"
if [ "$LOOP" ]; then
if [ "$mountroot_status" != 0 ]; then
if [ ${FSTYPE} = ntfs ] || [ ${FSTYPE} = vfat ]; then
panic "
Could not mount the partition ${ROOT}.
This could also happen if the file system is not clean because of an operating
system crash, an interrupted boot process, an improper shutdown, or unplugging
of a removable device without first unmounting or ejecting it. To fix this,
simply reboot into Windows, let it fully start, log in, run 'chkdsk /r', then
gracefully shut down and reboot back into Windows. After this you should be
able to reboot again and resume the installation.
(filesystem = ${FSTYPE}, error code = $mountroot_status)
"
fi
fi
mkdir -p /host
mount -o move /tmp-rootmnt /host
while [ ! -e "/host/${LOOP#/}" ]; do
panic "ALERT! /host/${LOOP#/} does not exist. Dropping to a shell!"
done
# Get the loop filesystem type if not set
if [ -z "${LOOPFSTYPE}" ]; then
eval $(fstype < "/host/${LOOP#/}")
else
FSTYPE="${LOOPFSTYPE}"
fi
if [ "$FSTYPE" = "unknown" ] && [ -x /lib/udev/vol_id ]; then
FSTYPE=$(/lib/udev/vol_id -t "/host/${LOOP#/}")
[ -z "$FSTYPE" ] && FSTYPE="unknown"
fi
if [ ${readonly} = y ]; then
roflag=-r
else
roflag=-w
fi
# FIXME This has no error checking
modprobe -Qb loop
modprobe -Qb ${FSTYPE}
# FIXME This has no error checking
mount ${roflag} -o loop -t ${FSTYPE} ${LOOPFLAGS} "/host/${LOOP#/}" /tmp-rootmnt
if [ -d /tmp-rootmnt/host ]; then
mount -o move /host /tmp-rootmnt/host
fi
fi
for i in 1 2 3 4 5 6 7 8 9 ; do
for device in /dev/[hs]d[a-z][0-9]*; do
mount -t reiserfs ${device} -o rw,noatime /rwfs || continue
if [ -d /rwfs/ubunturwfs ]; then
break
else
umount /rwfs
fi
done
if [ -d /rwfs/ubunturwfs ]; then
break
else
/bin/sleep 3
fi
done
modprobe -Qb unionfs
mount -t unionfs -o noatime,dirs=/rwfs/ubunturwfs=rw:/tmp-rootmnt=ro unionfs "$rootmnt" || panic "${UNIONFS} mount failed"
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
run_scripts /scripts/local-bottom
[ "$quiet" != "y" ] && log_end_msg
}
3,把 fstab 中 挂载跟分区 那一行注释掉
menu.lst 只需修改 initrd 行,指向定制的 initrd 文件。
上次由 ptptptptptpt 在 2008-07-10 18:38,总共编辑 1 次。
- ptptptptptpt
- 帖子: 3711
- 注册时间: 2006-09-19 18:16
- ptptptptptpt
- 帖子: 3711
- 注册时间: 2006-09-19 18:16
- ptptptptptpt
- 帖子: 3711
- 注册时间: 2006-09-19 18:16