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

Suhail Hany avatar
By Suhail Hany
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 #

--
Tags: Linux

All Comments

Steve avatar
By Steve
at 2017-07-05T05:26
推~
Madame avatar
By Madame
at 2017-07-08T17:54
這是不是就像是LIVECD的做法?

新手學習的階段性目標

Hedda avatar
By Hedda
at 2017-07-02T14:04
最近剛加入企鵝家族, 有沒有大大可以提供一下, 階段性的目標啊? 我現在是想說把以為學過的程式語言在Ubuntu上再寫過一次,大大們會建認還要什麼目標嗎? - ...

請問 find 排除某些檔案的方式

Skylar DavisLinda avatar
By Skylar DavisLinda
at 2017-06-30T17:08
※ 引述《s8454158 (′‧ω‧‵)》之銘言: : 小弟想要每日刪除在/opt/123/log 內的所有檔案,但是要排除連結指向的檔案... : 以下是目錄底下的資料: : /opt/123/log/aaa.ERROR -andgt; ERROR20170622-091436.1204 : /opt/1 ...

請問 find 排除某些檔案的方式

Donna avatar
By Donna
at 2017-06-30T02:59
小弟想要每日刪除在/opt/123/log 內的所有檔案,但是要排除連結指向的檔案... 以下是目錄底下的資料: /opt/123/log/aaa.ERROR -andgt; ERROR20170622-091436.1204 /opt/123/log/aaa.WARNING -andgt; ERROR2 ...

mac terminal 2>&1 導向的問題

Donna avatar
By Donna
at 2017-06-29T16:30
想請教一下我在 macOS 用 terminal ssh linux server 和 win7 putty ssh linux server 下相同的指令 java -jar xxx.war --spring.profiles.active=dev andgt; /dev/null 2andgt;an ...

使用Gnome-terminal,如何儲存記錄檔?

Catherine avatar
By Catherine
at 2017-06-28T14:51
Hi 各位Linux高手 小弟最近在使用linux上,遇到的一個困難, 就是我在使用iperf的程式時, 我透過gnome-terminal的方式, 開新視窗跑資料,但是資料一直在流, 想要把流過的資料都儲存下來, 我應該用什麼方法儲存這些資料? 我下的command如下 rootat~: gnome-ter ...