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

By Joe
at 2016-12-09T22:18
at 2016-12-09T22:18
Table of Contents
近幾年隨著MS 從XP推到了win10 如此肥大 感到$與心有點累 就棄坑了
之前有玩過Ubuntu12.04 就由14.04開始用到16.04
版本變化也是很快 =="
後來由於要自編kernel 支援hifi codec 與更多mmc partitions, loopdevices 數
想說乾脆找source base的distro 更透明 而且rolling change的
參考板上這兩篇#1NQ38WOA #1NnCjETB 所提 將Arch 與Gentoo列入選擇
首先從人多的Arch著手
但Arch似乎 / 與 /usr 必需在同個partition
google到回應多是質疑為何會有分開不同partittion的需求 (arch distro user 的傲慢?)
再來就開始試用gentoo 目前還蠻滿意的
有趣的是gentoo user也有一種傲慢
質疑為何要將driver 編成 module, 為何需要dkms... 就像distros嘲諷M$ 一樣?
因為virtualbox 常常會壞掉啊 ╮(╯_╰)╭
有關雙系統 除了
1. 正規安裝 然後用boot loader選取 保有效能 但需另備檔案系統FS
2. 安裝於虛擬機上 保有原FS 犧牲效能
還有標題所提的 安裝於loopdevice (imagefile) 的另種選擇
必要條件是boot loader 認識原FS 例如grub認識vfat ntfs
就能犧牲更少效能 而且只需另備bootloader
以gentoo而言 只需準備32~64MB boot partition 放grub,vmlinuz,initramfs
如果是efi主機板 或安裝grub4dos 或同種OS 則可沿用原FS
目前個人可由
a. Grub boots gentoo@loop_device
b. Grub boots Win10 loader to boot Win10 on imagefile
c. Win10 loader boots Win10 on imagefile
以下介紹a在gentoo 舉例做法
1, 製作或新安裝gento 於ImageFile /dev/sda41/loop_live.ext4上 並改好其/etc/fstab
以下面fstab為例 除了/ 以外其餘都用原舊OS 這樣只需512M
本例 / 是copy 原舊gentoo 然後修改/etc/fstab,/etc/host,/etc/conf.d/hostname
非新安裝
#====/etc/fstab====
/dev/sda41 /mnt/loops ext2 noatime 0 0
LABEL=loop_live / ext4 loop,noatime 0 1
/mnt/loops /boot ext2 bind,noatime 0 0
LABEL=g_usr /usr ext2 ro,noatime 0 2
LABEL=g_share /usr/share ext2 ro,noatime 0 2
LABEL=g_fonts /usr/share/fonts ext2 ro,noatime 0 2
LABEL=g_portage /usr/portage ext2 ro,noatime 0 2
LABEL=g_distfiles /usr/portage/distfiles ext2 ro,noatime 0 0
LABEL=ssd_swap none swap sw 0 0
tmpfs /var/tmp tmpfs size=2048m,mode=1777 0 0
/mnt/loops/G64_EFI.vfat /boot/efi vfat loop,noatime 0 0
/mnt/loops/g64_src.ext2 /usr/src ext2 loop 0 0
#====/etc/fstab====
如果不共用 全靠下載與自編 不裝X 不含swap,/var/tmp,/boot/efi 共預留5GiB
( 因為目錄與小檔案極多 mkfs 要下-b 1024 -N 1048576 不然保險點是8GiB )
如果不共用 全靠下載與自編 要裝X 不含swap,/var/tmp,/boot/efi 共預留8GiB
( 同上 不然保險點是16GiB)
要自編firefox 必須/var/tmp > 4096M
2, kernel必須加入支援 loop device driver及其載體的FS 如ext*/vfat/ntfs (optional).
3, 修改 /etc/initramfs.mounts 加入一行
/mnt/loops
4, 另製initramfs
4-1, 抽出原initramfs/init 在# Determine root device 這行前放入下面3行 存成myinit
mkdir -p /mnt
mount /dev/sda41 /mnt
losetup /dev/loop0 /mnt/loop_live.ext4
4-2, genkernel --linuxrc=myinit --install initramfs
5, 修改 /boot/grub/grub.cfg 舉例
search --no-floppy --label --set=root loop_test
echo 'Loading Linux 4.4.26-gentoo ...'
linux /vmlinuz root=/dev/loop0 rootfstype=ext4 ro
echo 'Loading initial ramdisk ...'
initrd /initramfs
6, reboot
========
這樣如果全系統都放在loop devices
Ubuntu distro user 說disk效能減少10%
其他效能 我想應該極接近實機 優於虛擬機 尤其是需要GPU時
其他虛擬機的好處也兼備
不過snapshot就得靠自己了
google到 可以安裝openSUSE:Snapper 它有支援ext4
BUT BUT BUT
如果imagefile loop_live.ext4 多加個文檔loop_live.vmdk與1MB的mbr
在partition table劃好後 可讓虛擬機讀
重編kernel 增加支援vm 硬體的driver 應該可讓虛擬機跑 我還沒試
若成 覺得這真的是超讚的選擇方案 自誇一下 呵
做好的vmdk 內含gentoo kernel 4.4.26 已實驗:
在Ubuntu16.04+VituralBox5.0.24上跑 OK
在Gentoo同版本+VituralBox4.3.28 跑到textmode login畫面 能輸入passwd但進不去
在Gentoo同版本+VituralBox4.3.28+adminCD 20161020+chroot+su=illegal instruction
舉例
==== loop_live.vmdk ====
# Disk DescriptorFile
version=1
CID=c2871f16
parentCID=ffffffff
createType="monolithicFlat"
# Extent description
RW 2048 FLAT "loop_live.mbr" 0
RW 1048576 FLAT "loop_live.ext4" 0
# The disk Data Base
#DDB
ddb.virtualHWVersion = "4"
ddb.adapterType="ide"
ddb.uuid.image="8c14b2f3-440d-4410-b6b4-aa026ab7c966"
ddb.uuid.parent="00000000-0000-0000-0000-000000000000"
ddb.uuid.modification="c1fce25a-f344-44ee-9089-d41b84f8a5f9"
ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"
ddb.geometry.cylinders="4104"
ddb.geometry.heads="16"
ddb.geometry.sectors="16"
ddb.geometry.biosCylinders="4104"
ddb.geometry.biosHeads="16"
ddb.geometry.biosSectors="16"
======================
延伸運用此法
/usr/portage/distfiles 與 /usr/src 都只要一份image放原FS上就夠了
不管有多少實機 虛擬機
※ 編輯: czm (118.161.50.147), 12/09/2016 22:48:34
已經成功將ImageFiles放在原來的OS 硬碟的檔案系統上
只要硬碟有足夠的連續空間
Grub4dos 可以放ntfs,fat上
grub boot partion 也可以與原OS efi 放一起 或在硬碟騰出64M來放
所以可避掉插拔動作
※ 編輯: czm (118.161.50.147), 12/10/2016 10:24:32
還好前陣子裝的arch 231 已經有支援可分離/ 與/usr了
但win10 loader 都會多restart 1次
如果grub能直接boot win10 img 就更好了
※ 編輯: czm (118.161.46.179), 12/11/2016 09:18:52
我試過把/bin /sbin /lib 的link都弄成 hardcopy 發現...
那些bin files不是用static lib連結做成的 links就單純等效於設PATH 根本是做好玩的
再試更暴力把 /usr/bin,/usr/sbin 整個搬到 /bin 與/sbin; /usr/lib搬到/lib
又有PATH設定的問題 想想即使如此累人地解決了 就只是一道87%的排骨酥湯
失去/bin 與/usr/bin分開的本意
於是換到gentoo
※ 編輯: czm (1.163.160.180), 12/12/2016 12:40:20
之前有玩過Ubuntu12.04 就由14.04開始用到16.04
版本變化也是很快 =="
後來由於要自編kernel 支援hifi codec 與更多mmc partitions, loopdevices 數
想說乾脆找source base的distro 更透明 而且rolling change的
參考板上這兩篇#1NQ38WOA #1NnCjETB 所提 將Arch 與Gentoo列入選擇
首先從人多的Arch著手
但Arch似乎 / 與 /usr 必需在同個partition
google到回應多是質疑為何會有分開不同partittion的需求 (arch distro user 的傲慢?)
再來就開始試用gentoo 目前還蠻滿意的
有趣的是gentoo user也有一種傲慢
質疑為何要將driver 編成 module, 為何需要dkms... 就像distros嘲諷M$ 一樣?
因為virtualbox 常常會壞掉啊 ╮(╯_╰)╭
有關雙系統 除了
1. 正規安裝 然後用boot loader選取 保有效能 但需另備檔案系統FS
2. 安裝於虛擬機上 保有原FS 犧牲效能
還有標題所提的 安裝於loopdevice (imagefile) 的另種選擇
必要條件是boot loader 認識原FS 例如grub認識vfat ntfs
就能犧牲更少效能 而且只需另備bootloader
以gentoo而言 只需準備32~64MB boot partition 放grub,vmlinuz,initramfs
如果是efi主機板 或安裝grub4dos 或同種OS 則可沿用原FS
目前個人可由
a. Grub boots gentoo@loop_device
b. Grub boots Win10 loader to boot Win10 on imagefile
c. Win10 loader boots Win10 on imagefile
以下介紹a在gentoo 舉例做法
1, 製作或新安裝gento 於ImageFile /dev/sda41/loop_live.ext4上 並改好其/etc/fstab
以下面fstab為例 除了/ 以外其餘都用原舊OS 這樣只需512M
本例 / 是copy 原舊gentoo 然後修改/etc/fstab,/etc/host,/etc/conf.d/hostname
非新安裝
#====/etc/fstab====
/dev/sda41 /mnt/loops ext2 noatime 0 0
LABEL=loop_live / ext4 loop,noatime 0 1
/mnt/loops /boot ext2 bind,noatime 0 0
LABEL=g_usr /usr ext2 ro,noatime 0 2
LABEL=g_share /usr/share ext2 ro,noatime 0 2
LABEL=g_fonts /usr/share/fonts ext2 ro,noatime 0 2
LABEL=g_portage /usr/portage ext2 ro,noatime 0 2
LABEL=g_distfiles /usr/portage/distfiles ext2 ro,noatime 0 0
LABEL=ssd_swap none swap sw 0 0
tmpfs /var/tmp tmpfs size=2048m,mode=1777 0 0
/mnt/loops/G64_EFI.vfat /boot/efi vfat loop,noatime 0 0
/mnt/loops/g64_src.ext2 /usr/src ext2 loop 0 0
#====/etc/fstab====
如果不共用 全靠下載與自編 不裝X 不含swap,/var/tmp,/boot/efi 共預留5GiB
( 因為目錄與小檔案極多 mkfs 要下-b 1024 -N 1048576 不然保險點是8GiB )
如果不共用 全靠下載與自編 要裝X 不含swap,/var/tmp,/boot/efi 共預留8GiB
( 同上 不然保險點是16GiB)
要自編firefox 必須/var/tmp > 4096M
2, kernel必須加入支援 loop device driver及其載體的FS 如ext*/vfat/ntfs (optional).
3, 修改 /etc/initramfs.mounts 加入一行
/mnt/loops
4, 另製initramfs
4-1, 抽出原initramfs/init 在# Determine root device 這行前放入下面3行 存成myinit
mkdir -p /mnt
mount /dev/sda41 /mnt
losetup /dev/loop0 /mnt/loop_live.ext4
4-2, genkernel --linuxrc=myinit --install initramfs
5, 修改 /boot/grub/grub.cfg 舉例
search --no-floppy --label --set=root loop_test
echo 'Loading Linux 4.4.26-gentoo ...'
linux /vmlinuz root=/dev/loop0 rootfstype=ext4 ro
echo 'Loading initial ramdisk ...'
initrd /initramfs
6, reboot
========
這樣如果全系統都放在loop devices
Ubuntu distro user 說disk效能減少10%
其他效能 我想應該極接近實機 優於虛擬機 尤其是需要GPU時
其他虛擬機的好處也兼備
不過snapshot就得靠自己了
google到 可以安裝openSUSE:Snapper 它有支援ext4
BUT BUT BUT
如果imagefile loop_live.ext4 多加個文檔loop_live.vmdk與1MB的mbr
在partition table劃好後 可讓虛擬機讀
重編kernel 增加支援vm 硬體的driver 應該可讓虛擬機跑 我還沒試
若成 覺得這真的是超讚的選擇方案 自誇一下 呵
做好的vmdk 內含gentoo kernel 4.4.26 已實驗:
在Ubuntu16.04+VituralBox5.0.24上跑 OK
在Gentoo同版本+VituralBox4.3.28 跑到textmode login畫面 能輸入passwd但進不去
在Gentoo同版本+VituralBox4.3.28+adminCD 20161020+chroot+su=illegal instruction
舉例
==== loop_live.vmdk ====
# Disk DescriptorFile
version=1
CID=c2871f16
parentCID=ffffffff
createType="monolithicFlat"
# Extent description
RW 2048 FLAT "loop_live.mbr" 0
RW 1048576 FLAT "loop_live.ext4" 0
# The disk Data Base
#DDB
ddb.virtualHWVersion = "4"
ddb.adapterType="ide"
ddb.uuid.image="8c14b2f3-440d-4410-b6b4-aa026ab7c966"
ddb.uuid.parent="00000000-0000-0000-0000-000000000000"
ddb.uuid.modification="c1fce25a-f344-44ee-9089-d41b84f8a5f9"
ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"
ddb.geometry.cylinders="4104"
ddb.geometry.heads="16"
ddb.geometry.sectors="16"
ddb.geometry.biosCylinders="4104"
ddb.geometry.biosHeads="16"
ddb.geometry.biosSectors="16"
======================
延伸運用此法
/usr/portage/distfiles 與 /usr/src 都只要一份image放原FS上就夠了
不管有多少實機 虛擬機
※ 編輯: czm (118.161.50.147), 12/09/2016 22:48:34
推 Gold740716: 所以是裝在光碟或隨身碟上,要用才插入? 12/10 00:37
→ noonee: 我個人覺得這種很危險 12/10 03:38
→ noonee: 危險的不是軟體 而是硬體 長期使用後接口會鬆掉 12/10 03:39
→ noonee: 然後就是接觸不良導致的記憶體錯誤 12/10 03:39
→ noonee: 或許你會說 不要那麼長拔插就好了 真那樣的話為何不直接 12/10 03:40
→ noonee: 用筆電或平板就好? 12/10 03:41
已經成功將ImageFiles放在原來的OS 硬碟的檔案系統上
只要硬碟有足夠的連續空間
Grub4dos 可以放ntfs,fat上
grub boot partion 也可以與原OS efi 放一起 或在硬碟騰出64M來放
所以可避掉插拔動作
※ 編輯: czm (118.161.50.147), 12/10/2016 10:24:32
推 Adama: 其實就是wubi的做法 12/10 13:26
感謝資訊 → s8321414: /跟/usr要放在同一個分割區好像是因為systemd? 12/10 17:57
壞處是/usr 不能隨時mount ro/rw , 如果boot from net 要等超久? 還好前陣子裝的arch 231 已經有支援可分離/ 與/usr了
推 neutrino: 請教一下關於 boot Windows 10 on imagefile, 12/11 02:53
推 neutrino: 是step1. grub boot Win10 loader step2. Win10 loader 12/11 02:57
→ neutrino: boots windows on vhd 這樣嗎? 12/11 02:58
推 neutrino: 還是說, 不是用vhd? 12/11 03:12
對的 是用vhd 靠grub chainload winboot.efi 但win10 loader 都會多restart 1次
如果grub能直接boot win10 img 就更好了
※ 編輯: czm (118.161.46.179), 12/11/2016 09:18:52
→ danny8376: 哪來/usr必須跟/同part 只是要讓/掛上/usr也馬上跟著掛 12/11 09:00
→ danny8376: 這是因為/sbin跟/bin都是/usr/bin的symlink 12/11 09:00
→ danny8376: /起來但/usr沒馬上掛的話 你就等著沒bin可用了XD 12/11 09:01
wiki上確實寫著/usr可和/分開 是後來才支援的 我試過把/bin /sbin /lib 的link都弄成 hardcopy 發現...
那些bin files不是用static lib連結做成的 links就單純等效於設PATH 根本是做好玩的
再試更暴力把 /usr/bin,/usr/sbin 整個搬到 /bin 與/sbin; /usr/lib搬到/lib
又有PATH設定的問題 想想即使如此累人地解決了 就只是一道87%的排骨酥湯
失去/bin 與/usr/bin分開的本意
於是換到gentoo
※ 編輯: czm (1.163.160.180), 12/12/2016 12:40:20
Tags:
Linux
All Comments

By Puput
at 2016-12-10T01:35
at 2016-12-10T01:35

By Enid
at 2016-12-11T21:28
at 2016-12-11T21:28

By Madame
at 2016-12-16T11:17
at 2016-12-16T11:17

By Una
at 2016-12-19T17:22
at 2016-12-19T17:22

By Eartha
at 2016-12-20T06:00
at 2016-12-20T06:00

By Barb Cronin
at 2016-12-24T13:20
at 2016-12-24T13:20

By Olga
at 2016-12-28T01:27
at 2016-12-28T01:27

By Olga
at 2016-12-29T11:28
at 2016-12-29T11:28

By John
at 2016-12-30T22:04
at 2016-12-30T22:04

By Kelly
at 2016-12-31T11:51
at 2016-12-31T11:51

By Dinah
at 2017-01-02T18:16
at 2017-01-02T18:16

By Thomas
at 2017-01-03T21:33
at 2017-01-03T21:33

By Caroline
at 2017-01-08T01:17
at 2017-01-08T01:17
Related Posts
Kbuntu console 中文顯示問題

By Iris
at 2016-12-09T20:17
at 2016-12-09T20:17
排除特定檔案,判斷資料夾最後寫入時間

By Agnes
at 2016-12-09T15:50
at 2016-12-09T15:50
Kbuntu console 中文顯示問題

By Harry
at 2016-12-08T22:17
at 2016-12-08T22:17
NMAP 偵測得到使用 virtio網卡

By Quanna
at 2016-12-07T11:53
at 2016-12-07T11:53
網曝 Solaris 系統被砍

By Candice
at 2016-12-06T19:46
at 2016-12-06T19:46