閒聊+雙系統另種選擇 loopdevice - Linux

By Suhail Hany
at 2017-07-04T07:25
at 2017-07-04T07:25
Table of Contents
繼上次完全使用loopfiles boot起來後
後續發現有些不明情況 會看不到放loopfiles的partition
如今可成功使用 mount --move 的方式改進
又順便修改成參數化的方式設定
所以原本只新增3行到linuxrc 變成新增3部份
part1: 參數讀取
part2: 解析UUID=, LABEL=; mount and losetup.
part3: mount --move
在grub.cfg內的用法: ( 因過長 實為為同一行)
linux vmlinuz loops_dev=LABEL=LOOPS loops_mnt=/loops loop_file=loop.ext4
root=LABEL=ROOT rootfstype=ext4 ro
ROOT起來後 可以在//ROOT/loops/ 內再掛其他loopfiles 到/usr, /var, /home ...
以下為執行diff比較 原與新的差異結果
====================================
49a50,59
> # zm 1: for boot from loop file
> loops_dev=*)
> LOOPS_DEV=${x#*=}
> ;;
> loops_mnt=*)
> LOOPS_MNT=${x#*=}
> ;;
> loop_file=*)
> LOOP_FILE=${x#*=}
> ;; #
485a496,543
> # zm 2: find the device which contains loop files, mount and losetup.
> if [ -n "${LOOP_FILE}" ]; then
>
> if [ -z "${LOOPS_MNT}" ]; then
> LOOPS_MNT='/loops'
> fi
>
> MNT_DEV=""
> while [ "${MNT_DEV}" = '' ]
> do
> case "${LOOPS_DEV}" in
> LABEL=*|UUID=*)
>
> retval=1
>
> if [ ${retval} -ne 0 ]; then
> MNT_DEV=$(findfs "${LOOPS_DEV}" )
> # MNT_DEV=$(findfs "${LOOPS_DEV}" 2>/dev/null)
> retval=$?
> fi
>
> if [ ${retval} -ne 0 ]; then
> MNT_DEV=$(busybox findfs "${LOOPS_DEV}" )
> # MNT_DEV=$(busybox findfs "${LOOPS_DEV}" 2>/dev/null)
> retval=$?
> fi
>
> if [ ${retval} -ne 0 ]; then
> MNT_DEV=$(blkid -o device -l -t "${LOOPS_DEV}")
> retval=$?
> fi
>
> if [ ${retval} -eq 0 ] && [ -n "${MNT_DEV}" ]; then
> good_msg "Detected loops_dev=${MNT_DEV}"
> else
> prompt_user "MNT_DEV" "block device"
> continue
> fi
> ;;
>
> esac
> done;
>
> mkdir -p ${LOOPS_MNT}
> mount ${MNT_DEV} ${LOOPS_MNT}
> losetup /dev/loop0 "${LOOPS_MNT}/${LOOP_FILE}"
> fi # zm
>
521a580
>
995a1055
> #
1006a1067,1075
>
> # zm 3: move LOOPS_MNT from initramfs to real root
> if [ -n "${LOOP_FILE}" ]; then
> if [ ! -e "${CHROOT}${LOOPS_MNT}" ]; then
> mkdir -p "${CHROOT}${LOOPS_MNT}"
> fi
> mount --move "${LOOPS_MNT}" "${CHROOT}${LOOPS_MNT}"
> good_msg "Remounting loop_dev=${LOOPS_DEV} to ${CHROOT}${LOOPS_MNT}"
> fi #
--
後續發現有些不明情況 會看不到放loopfiles的partition
如今可成功使用 mount --move 的方式改進
又順便修改成參數化的方式設定
所以原本只新增3行到linuxrc 變成新增3部份
part1: 參數讀取
part2: 解析UUID=, LABEL=; mount and losetup.
part3: mount --move
在grub.cfg內的用法: ( 因過長 實為為同一行)
linux vmlinuz loops_dev=LABEL=LOOPS loops_mnt=/loops loop_file=loop.ext4
root=LABEL=ROOT rootfstype=ext4 ro
ROOT起來後 可以在//ROOT/loops/ 內再掛其他loopfiles 到/usr, /var, /home ...
以下為執行diff比較 原與新的差異結果
====================================
49a50,59
> # zm 1: for boot from loop file
> loops_dev=*)
> LOOPS_DEV=${x#*=}
> ;;
> loops_mnt=*)
> LOOPS_MNT=${x#*=}
> ;;
> loop_file=*)
> LOOP_FILE=${x#*=}
> ;; #
485a496,543
> # zm 2: find the device which contains loop files, mount and losetup.
> if [ -n "${LOOP_FILE}" ]; then
>
> if [ -z "${LOOPS_MNT}" ]; then
> LOOPS_MNT='/loops'
> fi
>
> MNT_DEV=""
> while [ "${MNT_DEV}" = '' ]
> do
> case "${LOOPS_DEV}" in
> LABEL=*|UUID=*)
>
> retval=1
>
> if [ ${retval} -ne 0 ]; then
> MNT_DEV=$(findfs "${LOOPS_DEV}" )
> # MNT_DEV=$(findfs "${LOOPS_DEV}" 2>/dev/null)
> retval=$?
> fi
>
> if [ ${retval} -ne 0 ]; then
> MNT_DEV=$(busybox findfs "${LOOPS_DEV}" )
> # MNT_DEV=$(busybox findfs "${LOOPS_DEV}" 2>/dev/null)
> retval=$?
> fi
>
> if [ ${retval} -ne 0 ]; then
> MNT_DEV=$(blkid -o device -l -t "${LOOPS_DEV}")
> retval=$?
> fi
>
> if [ ${retval} -eq 0 ] && [ -n "${MNT_DEV}" ]; then
> good_msg "Detected loops_dev=${MNT_DEV}"
> else
> prompt_user "MNT_DEV" "block device"
> continue
> fi
> ;;
>
> esac
> done;
>
> mkdir -p ${LOOPS_MNT}
> mount ${MNT_DEV} ${LOOPS_MNT}
> losetup /dev/loop0 "${LOOPS_MNT}/${LOOP_FILE}"
> fi # zm
>
521a580
>
995a1055
> #
1006a1067,1075
>
> # zm 3: move LOOPS_MNT from initramfs to real root
> if [ -n "${LOOP_FILE}" ]; then
> if [ ! -e "${CHROOT}${LOOPS_MNT}" ]; then
> mkdir -p "${CHROOT}${LOOPS_MNT}"
> fi
> mount --move "${LOOPS_MNT}" "${CHROOT}${LOOPS_MNT}"
> good_msg "Remounting loop_dev=${LOOPS_DEV} to ${CHROOT}${LOOPS_MNT}"
> fi #
--
Tags:
Linux
All Comments

By Steve
at 2017-07-05T05:26
at 2017-07-05T05:26

By Madame
at 2017-07-08T17:54
at 2017-07-08T17:54
Related Posts
新手學習的階段性目標

By Hedda
at 2017-07-02T14:04
at 2017-07-02T14:04
請問 find 排除某些檔案的方式

By Skylar DavisLinda
at 2017-06-30T17:08
at 2017-06-30T17:08
請問 find 排除某些檔案的方式

By Donna
at 2017-06-30T02:59
at 2017-06-30T02:59
mac terminal 2>&1 導向的問題

By Donna
at 2017-06-29T16:30
at 2017-06-29T16:30
使用Gnome-terminal,如何儲存記錄檔?

By Catherine
at 2017-06-28T14:51
at 2017-06-28T14:51