歡迎於授權範圍內自由使用本作品
點此查看本簡報的來源碼
強烈主觀意見,僅供參考
還在學QAQ
# parted /dev/sdX --script unit MiB print
型號:JetFlash Transcend 64GB (scsi)
磁碟 /dev/sdX:60160MiB
磁區大小 (邏輯/物理):512B/512B # 假的
分割區:msdos
磁碟旗標: # 不需要 boot 旗標,會需要的你的主板韌體有問題
編號 起始點 結束點 大小 類型 檔案系統 旗標
1 4.00MiB 5120MiB 5116MiB primary fat32 lba
2 5120MiB 60160MiB 55040MiB primary ext2
# parted /dev/sdX --script unit MiB print
型號:JetFlash Transcend 64GB (scsi)
磁碟 /dev/sdX:60160MiB
磁區大小 (邏輯/物理):512B/512B
分割區:msdos
磁碟旗標:
編號 起始點 結束點 大小 類型 檔案系統 旗標
1 4.00MiB 5004MiB 5000MiB primary fat32
2 5004MiB 6004MiB 1000MiB primary ext2
3 6004MiB 60160MiB 54156MiB primary
$ sudo mkdir --parents /mnt/debootstrap/rootfs
$ cd /mnt/debootstrap
$ sudo mount /dev/sdX3 rootfs
# debootstrap [OPTION]... <suite> <target> [<mirror> [<script>]]
$ sudo debootstrap xenial rootfs http://tw.archive.ubuntu.com/ubuntu
$ sudo mount /dev/sdX2 rootfs/boot
$ sudo mkdir rootfs/boot/efi
$ sudo mount /dev/sdX1 rootfs/boot/efi
$ sudo arch-chroot rootfs
由於是異機可用系統所以沒「主機」名稱可設,選個自己好記的吧:
$ sudo printf 'MY-USB\n' >/etc/hostname
主機名稱→網路地址映射設定也要新增對應的項目:
$ sudo printf '127.0.1.1\tMY-USB\n' >>/etc/hosts
$ sudo hostname -f /etc/hostname
$ bash
Debootstrap 預設給的軟體來源清單是不完整的,弄一個相對完整的給它
$ sudo apt install nano # 或是你慣用的純文字文件編輯器
$ sudo cp --force /usr/share/doc/apt/examples/sources.list /etc/apt/sources.list
$ sudo apt edit-sources # 注意目前 Ubuntu 16.04 提供的範本使用的是 14.04(trusty) 的軟體來源,請手動修正
由於使用的 suite 是 xenial 而非 xenial-updates 故需要如此
$ sudo apt update # 更新本地軟體來源快取資料
$ sudo apt full-upgrade
$ sudo dpkg-reconfigure locales
# 勾選 `zh_TW UTF-8 UTF-8`、`zh_HK UTF-8 UTF-8` 跟 `zh_CN UTF-8 UTF-8`
# 預設語系選 zh_TW.UTF-8
$ sudo update-locale LANGUAGE=zh_TW:zh_HK:zh:en
基本系統預設是沒有作業系統核心的(因為某些情境其實不需要)
$ sudo apt install linux-signed-generic
# 安裝舊式PC開機支援的 GRUB 的提問,選擇根裝置(/dev/sdX)而非底下的分區裝置(/dev/sdXN)
這邊直接安裝簽好 SecureBoot 的版本(-signed)
一樣,基本系統預設是沒有開機載入程式(bootloader)的(因為某些情境不需要),這個步驟實際上已在上個步驟進行
$ sudo apt install grub-pc-bin grub2-common
$ sudo grub-install --verbose /dev/sdX
$ sudo chmod a-x /etc/grub.d/30_os-prober
$ sudo update-grub
$ sudo apt install grub-efi-amd64-signed shim-signed grub-efi-ia32-bin
$ sudo grub-install --target=x86_64-efi --uefi-secure-boot --removable --verbose
$ sudo grub-install --target=i386-efi --removable --verbose
$ sudo sh -c 'mkdir --parents /boot/.disk && touch /boot/.disk/info' # 讓有簽章的 GRUB 能找到 /boot 分區的 workaround
/boot/efi
└── EFI
├── BOOT
│ ├── BOOTIA32.EFI # 沒有簽章的 Intel 32位元處理器架構 GRUB 開機載入程式
│ ├── BOOTX64.EFI # 有簽 Microsoft 簽章的 Intel 64位元處理器架構 SHIM 開機載入程式,可驗證 Canonical 簽章
│ ├── grub.cfg # 實際上這個不會被讀到
│ ├── grub.efi # 跟 BOOTIA32.EFI 一樣,因軟體缺陷冗餘生出來的檔案?
│ ├── grubx64.efi # 有簽 Canonical 簽章的 GRUB 開機載入程式
│ └── mmx64.efi # 自簽章需要
└── ubuntu # 完全用不到但因為 GRUB 的軟體缺陷會自動安裝
├── fw
├── fwupx64.efi
├── grub.cfg
├── grubx64.efi
├── mmx64.efi
└── shimx64.efi
# sudo mkdir /etc/default/grub.d
$ sudo nano /etc/default/grub.d/10-local-force-to-use-uuid-for-rootfs-device-specification.cfg
# 在 GRUB_CMDLINE_LINUX_DEFAULT 的值後面加上 `root=UUID=〈根目錄檔案系統的UUID,查閱 `blkid` 命令的輸出〉` 其會覆越掉前面自動插入的 root 核心參數設定
$ sudo update-grub # 重新產生開機選單
在部份的硬體配置下早期的開機訊息將無法顯示在螢幕上,此法可以迴避此問題
printf "# Force boot in text mode to avoid blank screen during early boot stages.\nGRUB_GFXPAYLOAD_LINUX=text\n" > /etc/default/grub.d/10-local-force-text-mode.cfg
參閱 fstab(5) 的 manpage 使用手冊頁面
$ sudoedit /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
vfat
,且 options 須填入 utf8=1
以支援 Unicode 檔名$ sudo apt install f2fs-tools
# 檢查有沒有包入initramfs
$ lsinitramfs /boot/initrd* | grep 'fsck\.f2fs'
sbin/fsck.f2fs
這樣系統才能成功掛載根目錄檔案系統
注意:理論上應該要自動包入才對,可能是個軟體缺陷
$ printf '# F2FS根目錄檔案系統掛載支援\nf2fs\n\n' \
| sudo tee --append /etc/initramfs-tools/modules
# F2FS根目錄檔案系統掛載支援
f2fs
$ update-initramfs -k all -uv
# 檢查有沒有包入核心模組
$ lsinitramfs /boot/initrd* | grep 'f2fs\.ko'
$ printf '# WORKAROUND: 迴避F2FS沒有依賴crc32模組的問題\n# https://bugzilla.kernel.org/show_bug.cgi?id=187471\ncrypto-crc32\n\n' \
| sudo tee --append /etc/initramfs-tools/modules
# WORKAROUND: 迴避F2FS沒有依賴crc32模組的問題
# https://bugzilla.kernel.org/show_bug.cgi?id=187471
crypto-crc32
$ update-initramfs -k all -uv
如果開機的時候一直卡在呼叫 fsck.f2fs 的話可以將 fastboot
參數加入 Linux 作業系統核心參數列中
$ sudoedit /etc/fstab
# 在 / 項目的掛載選項中加入 `fastboot`
記得給他 sudo 的使用權限
$ sudo adduser _user_name_
$ sudo gpasswd --add _user_name_ sudo
# apt install xubuntu-desktop
注意:如果設定軟體途中在 blueman 軟體包發生錯誤,此為 blueman 軟體包打包的已知缺陷:#878814 - fails to install in a chroot - Debian Bug report logs
# exit
$ sudo umount --recursive rootfs
$ udisksctl power-off --block-device /dev/sdX
# 可以拔儲存裝置了
‘GRUB_GFXPAYLOAD_LINUX’
Set to ‘text’ to force the Linux kernel to boot in normal text mode, ‘keep’ to preserve the graphics mode set using ‘GRUB_GFXMODE’, ‘widthxheight’\[‘xdepth’\] to set a particular graphics mode, or a sequence of these separated by commas or semicolons to try several modes in sequence. See [gfxpayload](https://www.gnu.org/software/grub/manual/grub/grub.html#gfxpayload).
Depending on your kernel, your distribution, your graphics card, and the phase of the moon, note that using this option may cause GNU/Linux to suffer from various display problems, particularly during the early part of the boot sequence. If you have problems, set this option to ‘text’ and GRUB will tell Linux to boot in normal text mode.