2020年7月15日 星期三

重裝 Ubuntu 20.04 on ZFS root

使用 Ubuntu on ZFS root 大約一個星期之後,覺得 ZFS 在做系統快照的時候,不像 Btrfs 會讓整個系統 CPU Usage 飆高,所有的 UI 反應幾乎都停格,整個卡頓過程大概會有 30 秒,真的有點令人受不了。像我試著嘗試每小時快照一次,每次一到整點,就好像要強迫你要起來走走,真的有點要裝狂。。。

這一次的目標是把之前安裝在分區5的 Btrfs 刪除,將完整的一半 SSD 空間做成 ZFS 給 Ubuntu 使用。暫時對 Btrfs 說聲抱歉,之後成熟度再高些的時候再來看看,畢竟 Btrfs 配上 TimeShift 在 Ubuntu 上還算整合滿好的,安裝設定都很簡單,又有不錯的圖形界面,有些接近 MAC 上的 Time-Machine 體驗。唯一的遺憾就是 Btrfs 模式下 TimeShift 只能把快照放在本機的硬碟,如果想要把快照儲存在外接硬碟的話,就要配合像 btrbk 這樣的工具,也就沒有圖形界面可用了。而且 btrbk 又會產生另外一組快照,總覺得有些重複多餘。

首先使用 Ubuntu 20.04 安裝碟開機,執行 Disks,重裝前的 SSD 分割狀況如下:
第一步就是用 Disks 把分區 5, 6, 7 都刪除,然後用命令列執行 sgdisk 加上需要的 ZFS 分區(因為 sgdisk 可以指定分區的格式碼為 BF01:Solaris),看到有文件說 bpool 最好不要劃的太小,以免 kernel 版本比較多的時候,/boot 可能會空間不夠放。所以這一次 bpool 預計是 2GB,其餘的都劃給 rpool 使用。
ubuntu@ubuntu:~$ sudo sgdisk -p /dev/nvme0n1
Disk /dev/nvme0n1: 2000409264 sectors, 953.9 GiB
Model: INTEL SSDPEKKW010T7                     
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): C85DF9DB-279D-4D14-83DC-4D49489E105A
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2000409230
Partitions will be aligned on 2048-sector boundaries
Total free space is 1025223277 sectors (488.9 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  EF00  EFI system partition
   2         2099200         2361343   128.0 MiB   0C01  Microsoft reserved ...
   3         2361344       955197439   454.3 GiB   0700  Basic data partition
   4      1980418048      2000408575   9.5 GiB     2700  Basic data partition

ubuntu@ubuntu
:~$ sudo sgdisk -n5:0:+2G -t5:BF01 /dev/nvme0n1 The operation has completed successfully. ubuntu@ubuntu:~$ sudo sgdisk -n6:0:0 -t6:BF01 /dev/nvme0n1 The operation has completed successfully.
ubuntu@ubuntu
:~$ sudo sgdisk -p /dev/nvme0n1 Disk /dev/nvme0n1: 2000409264 sectors, 953.9 GiB Model: INTEL SSDPEKKW010T7 Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): C85DF9DB-279D-4D14-83DC-4D49489E105A Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 2000409230 Partitions will be aligned on 2048-sector boundaries Total free space is 2669 sectors (1.3 MiB) Number Start (sector) End (sector) Size Code Name 1 2048 2099199 1024.0 MiB EF00 EFI system partition 2 2099200 2361343 128.0 MiB 0C01 Microsoft reserved ... 3 2361344 955197439 454.3 GiB 0700 Basic data partition 4 1980418048 2000408575 9.5 GiB 2700 Basic data partition 5 955197440 959391743 2.0 GiB BF01 6 959391744 1980418047 486.9 GiB BF01  
我在這次安裝之前有把系統ZFS快照存在我的一張大容量SD卡上,現在我只須要先把zpool import進來,然後再把整個系統拷貝過去即可。
ubuntu@ubuntu:~$ sudo zpool import -d /dev/mmcblk0 sd256gpool
ubuntu@ubuntu:~$ zpool list
NAME         SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
sd256gpool   240G  85.3G   155G        -         -     0%    35%  1.00x    ONLINE  -

ubuntu@ubuntu:~$ ls /media/SD256GB/backup/ BOOT HOME ROOT

建立 ZFS pool

因為之前分區5是Btfrs,分區6是另一個pool所使用,所以在建立zpool時要加上 -f 強制覆蓋。
ubuntu@ubuntu:~$ sudo zpool create -f \
>     -o ashift=12 \
>     -O acltype=posixacl -O canmount=off -O compression=lz4 \
>     -O dnodesize=auto -O normalization=formD -O relatime=on \
>     -O xattr=sa -O mountpoint=/ -R /mnt \
>     rpool /dev/nvme0n1p6
ubuntu@ubuntu:~$ zpool list
NAME         SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP    HEALTH  ALTROOT
rpool       1.88G   444K  1.87G        -         -     0%     0%  1.00x    ONLINE  /mnt
sd256gpool   240G  63.3G   177G        -         -     0%    26%  1.00x    ONLINE  -

ubuntu@ubuntu:~$ sudo zpool create -f \ > -o ashift=12 -d \ > -o feature@async_destroy=enabled \ > -o feature@bookmarks=enabled \ > -o feature@embedded_data=enabled \ > -o feature@empty_bpobj=enabled \ > -o feature@enabled_txg=enabled \ > -o feature@extensible_dataset=enabled \ > -o feature@filesystem_limits=enabled \ > -o feature@hole_birth=enabled \ > -o feature@large_blocks=enabled \ > -o feature@lz4_compress=enabled \ > -o feature@spacemap_histogram=enabled \ > -o feature@zpool_checkpoint=enabled \ > -O acltype=posixacl -O canmount=off -O compression=lz4 \ > -O devices=off -O normalization=formD -O relatime=on -O xattr=sa \ > -O mountpoint=/boot -R /mnt \ > bpool /dev/nvme0n1p5 ubuntu@ubuntu:~$ zpool list NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT bpool 1.88G 444K 1.87G - - 0% 0% 1.00x ONLINE /mnt rpool 484G 516K 484G - - 0% 0% 1.00x ONLINE /mnt sd256gpool 240G 63.3G 177G - - 0% 26% 1.00x ONLINE -

建立 ZFS Dataset 容器

ubuntu@ubuntu:~$ sudo zfs create -o canmount=on -o mountpoint=/ rpool/ROOT
ubuntu@ubuntu:~$ sudo zfs create -o canmount=on -o mountpoint=/home rpool/HOME
ubuntu@ubuntu:~$ sudo zfs create -o canmount=on -o mountpoint=/boot  bpool/BOOT

ubuntu@ubuntu:~$ zfs list
NAME USED AVAIL REFER MOUNTPOINT bpool 516K 1.75G 96K /mnt/boot bpool/BOOT 96K 1.75G 96K /mnt/boot rpool 704K 469G 96K /mnt rpool/HOME 96K 469G 96K /mnt/home rpool/ROOT 104K 469G 104K /mnt sd256gpool 63.3G 169G 24K /media/SD256GB sd256gpool/Pictures 38.2G 169G 38.2G /media/SD256GB/Pictures sd256gpool/backup 25.1G 169G 27K /media/SD256GB/backup sd256gpool/backup/BOOT 185M 169G 185M /media/SD256GB/backup/BOOT sd256gpool/backup/HOME 19.0G 169G 17.6G /media/SD256GB/backup/HOME sd256gpool/backup/ROOT 5.89G 169G 5.04G /media/SD256GB/backup/ROOT

ubuntu@ubuntu:~$ mount
...
sd256gpool on /media/SD256GB type zfs (rw,xattr,noacl) sd256gpool/Pictures on /media/SD256GB/Pictures type zfs (rw,xattr,noacl) sd256gpool/backup on /media/SD256GB/backup type zfs (rw,xattr,noacl) sd256gpool/backup/HOME on /media/SD256GB/backup/HOME type zfs (rw,xattr,noacl) sd256gpool/backup/ROOT on /media/SD256GB/backup/ROOT type zfs (rw,xattr,noacl) sd256gpool/backup/BOOT on /media/SD256GB/backup/BOOT type zfs (rw,xattr,noacl) rpool/ROOT on /mnt type zfs (rw,relatime,xattr,posixacl) rpool/HOME on /mnt/home type zfs (rw,relatime,xattr,posixacl)
bpool/BOOT on /mnt/boot type zfs (rw,nodev,relatime,xattr,posixacl)

使用 rsync 完整拷貝系統檔案

拷貝 ROOT
ubuntu@ubuntu:~$ sudo rsync -av --info=progress2 --no-inc-recursive \
>    --human-readable /media/SD256GB/backup/ROOT/ /mnt
building file list ...
...
...
...
var/tmp/systemd-private-96661d6909d9419ba0c1e66f7193125f-upower.service-wvp5Ng/ var/tmp/systemd-private-96661d6909d9419ba0c1e66f7193125f-upower.service-wvp5Ng/tmp/ 8.45G 99% 44.37MB/s 0:03:01 (xfr#161021, to-chk=0/216830) sent 8.47G bytes received 3.23M bytes 46.15M bytes/sec total size is 8.45G speedup is 1.00
ubuntu@ubuntu:~$ zpool list NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT bpool 1.88G 624K 1.87G - - 0% 0% 1.00x ONLINE /mnt rpool 484G 5.54G 478G - - 0% 1% 1.00x ONLINE /mnt sd256gpool 240G 63.3G 177G - - 0% 26% 1.00x ONLINE - ubuntu@ubuntu:~$ zpool status rpool pool: rpool state: ONLINE scan: none requested config: NAME STATE READ WRITE CKSUM rpool ONLINE 0 0 0 nvme0n1p6 ONLINE 0 0 0 errors: No known data errors

拷貝 BOOT
ubuntu@ubuntu:~$ sudo rsync -av --info=progress2 --no-inc-recursive \
>    --human-readable /media/SD256GB/backup/BOOT/ /mnt/boot building file list ... done ./ System.map-5.4.0-31-generic 4.74M 2% 106.81MB/s 0:00:00 (xfr#1, to-chk=300/302)
...
...
grub/x86_64-efi/zstd.mod 207.41M 99% 39.84MB/s 0:00:04 (xfr#293, to-chk=0/302) sent 207.48M bytes received 5.61K bytes 37.73M bytes/sec total size is 207.41M speedup is 1.00
ubuntu@ubuntu:~$ zpool list NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT bpool 1.88G 187M 1.69G - - 0% 9% 1.00x ONLINE /mnt rpool 484G 5.54G 478G - - 0% 1% 1.00x ONLINE /mnt sd256gpool 240G 63.3G 177G - - 0% 26% 1.00x ONLINE - ubuntu@ubuntu:~$ zpool status bpool pool: bpool state: ONLINE scan: none requested config: NAME STATE READ WRITE CKSUM bpool ONLINE 0 0 0 nvme0n1p5 ONLINE 0 0 0 errors: No known data errors

拷貝 HOME
ubuntu@ubuntu:~$ sudo rsync -av --info=progress2 --no-inc-recursive \
>    --human-readable /media/SD256GB/backup/HOME/ /mnt/home building file list ...
...
...
...
rick/toolchains/gcc-arm-8.3-2019.03-x86_64-arm-eabi/share/man/man7/gpl.7 27.77G 99% 23.46MB/s 0:18:48 (xfr#337485, to-chk=0/359204) sent 27.80G bytes received 6.48M bytes 23.58M bytes/sec total size is 27.77G speedup is 1.00
ubuntu@ubuntu:~$ zpool list NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT bpool 1.88G 187M 1.69G - - 0% 9% 1.00x ONLINE /mnt rpool 484G 24.3G 460G - - 0% 5% 1.00x ONLINE /mnt sd256gpool 240G 63.4G 177G - - 0% 26% 1.00x ONLINE - ubuntu@ubuntu:~$ zpool status rpool pool: rpool state: ONLINE scan: none requested config: NAME STATE READ WRITE CKSUM rpool ONLINE 0 0 0 nvme0n1p6 ONLINE 0 0 0 errors: No known data errors

安裝 GRUB

準備 chroot
ubuntu@ubuntu:~$ sudo su
root@ubuntu:/home/ubuntu# for d in proc sys dev; do mount --rbind /$d /mnt/$d; done
root@ubuntu:/home/ubuntu# chroot /mnt root@ubuntu:/# cat /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> # / was on /dev/nvme0n1p5 during installation #UUID=123f16e7-43b5-412d-8872-ee464f237c12 / btrfs defaults,subvol=@ 0 1 # /boot/efi was on /dev/nvme0n1p1 during installation UUID=0E18-3C17 /boot/efi vfat umask=0077 0 1 # /home was on /dev/nvme0n1p5 during installation #UUID=123f16e7-43b5-412d-8872-ee464f237c12 /home btrfs defaults,compress=lzo,subvol=@home 0 2 #/swapfile none swap sw 0 0 /dev/disk/by-id/wwn-0x5000cca77ff2de2b /media/brtbkhd btrfs noatime,nodiratime,compress=lzo,discard,space_cache,nosuid,nodev,nofail,noauto,x-gvfs-show 0 0 /dev/disk/by-id/usb-PNY_USB_3.0_FD_7FF55046ABD74833890F0B63E0BFD5-0:0-part1 /media/PNY-USB30 btrfs noatime,nodiratime,compress=lzo,discard,space_cache,nosuid,nodev,nofail,noauto,x-gvfs-show 0 0 /dev/disk/by-id/usb-PNY_USB_3.0_FD_7FF55046ABD74833890F0B63E0BFD5-0:0 /media/PNY-USB30 btrfs noatime,nodiratime,compress=lzo,discard,space_cache,nosuid,nodev,nofail,noauto,x-gvfs-show 0 0 root@ubuntu:/# ls /boot/efi/ root@ubuntu:/# mount /boot/efi
root@ubuntu:/# ls -l /boot/efi total 12 drwx------ 5 root root 4096 Oct 16 2019 EFI drwx------ 3 root root 4096 Jan 16 11:57 McAfee -rwx------ 1 root root 68 Oct 15 2019 _SMSTSVolumeID.7159644d-f741-45d5-ab29-0ad8aa4771ca
檢查 grub-probe 結果
root@ubuntu:/# grub-probe /boot
zfs
更新 initrd
root@ubuntu:/# update-initramfs -c -k all
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LANGUAGE = (unset),
	LC_ALL = (unset),
	LANG = "zh_TW.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
update-initramfs: Generating /boot/initrd.img-5.4.0-31-generic
update-initramfs: Generating /boot/initrd.img-5.4.0-33-generic
確認 /etc/default/grub 的 GRUB_CMDLINE_LINUX_DEFAULT 包含 init_on_alloc=0

root@ubuntu:/# cat /etc/default/grub 
# If you change this file, run &apos;update-grub&apos; afterwards to update # /boot/grub/grub.cfg. # For full documentation of the options in this file, see: # info -f grub -n &apos;Simple configuration&apos; GRUB_DEFAULT=0 GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=10 GRUB_DISTRIBUTOR=`lsb_release -i -s 2&gt; /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet splash init_on_alloc=0" GRUB_CMDLINE_LINUX=""

更新 grub
root@ubuntu:/# update-grub
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
cannot open 'bpool/BOOT/ROOT': dataset does not exist
Found linux image: vmlinuz-5.4.0-31-generic in rpool/ROOT
Found initrd image: initrd.img-5.4.0-31-generic in rpool/ROOT
Found linux image: vmlinuz-5.4.0-33-generic in rpool/ROOT
Found initrd image: initrd.img-5.4.0-33-generic in rpool/ROOT
device-mapper: reload ioctl on osprober-linux-nvme0n1p6  failed: Device or resource busy
Command failed.
grub-probe: error: cannot find a GRUB drive for /dev/sda1.  Check your device.map.
Adding boot menu entry for UEFI Firmware Settings
done

root@ubuntu:/# grub-install --target=x86_64-efi --efi-directory=/boot/efi \
>     --bootloader-id=ubuntu --recheck --no-floppy
Installing for x86_64-efi platform.Installation finished. 
No error reported.

設定 ZFS pool 開機自動掛載

先要確認 /etc/zfs/zfs-list.cache 目錄下有要自動掛載的 pool 檔案,而且內容非空白。

root@ubuntu:/# cat /etc/zfs/zfs-list.cache/bpool 
bpool	/boot	off	on	on	off	on	off	on	off	-none
bpool/BOOT	/boot	on	on	on	off	on	off	on	off	-	none
root@ubuntu:/# cat /etc/zfs/zfs-list.cache/rpool 
rpool	/	off	on	on	on	on	off	on	off	-	none
rpool/HOME	/home	on	on	on	on	on	off	on	off	-	none
rpool/ROOT	/	on	on	on	on	on	off	on	off	-	none
root@ubuntu:/# cat /etc/zfs/zfs-list.cache/sd256gpool 
sd256gpool	/media/SD256GB	on	on	off	on	on	off	on	off	-	none
sd256gpool/Pictures	/media/SD256GB/Pictures	on	on	off	on	on	off	on	off	-	none
sd256gpool/backup	/media/SD256GB/backup	on	on	off	on	on	off	on	off	-	none
sd256gpool/backup/BOOT	/media/SD256GB/backup/BOOT	on	on	off	on	on	off	on	off-	none
sd256gpool/backup/HOME	/media/SD256GB/backup/HOME	on	on	off	on	on	off	on	off-	none
sd256gpool/backup/ROOT	/media/SD256GB/backup/ROOT	on	on	off	on	on	off	on	off-	none
現在可以離開 chroot 環境,最後就是安全解除掛載 zpool。
root@ubuntu:/# exit
exit
root@ubuntu:/home/ubuntu# mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | xargs -i{} umount -lf {}
root@ubuntu:/home/ubuntu# zpool export -a
root@ubuntu:/home/ubuntu# 

大工告成!如果一切正常,重新開機後應該要看到 grub 選單,然後開機進入 Ubuntu 桌面~

2020年6月5日 星期五

Ubuntu 20.04 ZFS on root 安裝筆記

不知不覺中 Ubuntu 20.04 於五月底正式發行了,看到 ZFS on Linux 好像差不多快成熟了,就很想體會一下 ZFS 的 Copy-on-Write 以及強大的 checksum, snapshot, incremental backup 功能。 但是我的 Dell Latitude 5480 筆電必須是 dual-boot Windows 10 & Ubuntu,而 Ubuntu 20.04 的內建 ZFS on root 安裝選項是會把整個硬碟都格式化給 ZFS 使用。所以我只能自己另闢蹊徑想辦法用一些旁門左道的方式,看看有沒有可能整出一個 Ubuntu on ZFS root + dual boot。

當然要 google 一下網路上前人的經驗,比較有參考性的文件連結都收集在下面的【參考文件】。因為之前也想要體驗 Btrfs 的好處,所以我的 SSD 已經安裝了一版 Ubuntu 20.04 在分區 5,格式為 Btrfs 。在這次 ZFS 安裝前,SSD 是採用 GPT 的分區表,容量為 1T,分割如下:

 1 2 3 4 5 -
 FAT32 - BitLocker  NTFS Btrfs Free
 1024M 128M 488G 10GB 200G 324G
 EFI
 System 
 Windows 
 Reserved 
 Win 10
 System
 Windows
 Recovery 
 Ubuntu
 20.04
 -

準備分割區

基本上這次安裝就是利用 Free 的空間,多加入 2 個分割區,一個是給 boot , 主要是為了 UEFI 開機的支援,建議大小為 512M ,剩下的空間就都留給 Ubuntu System 。我的 Latitude 5480 安裝了 32GB 的 RAM,所以我是沒有使用 swap。這次安裝的起點是:我開機進入已經安裝在分區5的 Ubuntu 20.04 on Btrfs,首先就是用 sgdisk 來做增加分割的部分。
sgdisk -n6:0:+512M -t6:BF01 /dev/nvme0n1  # 在分割區5之後,切出512M給分區6,格式碼設為BF01
sgdisk -n7:0:0 -t7:BF01 /dev/nvme0n1  # 把分割區6之後所有的空間給分區7,格式碼設為BF01
檢查分區增加後的結果如下:
rick@E5480:~$ sudo sgdisk -p /dev/nvme0n1
Disk /dev/nvme0n1: 2000409264 sectors, 953.9 GiB
Model: INTEL SSDPEKKW010T7                     
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): C85DF9DB-279D-4D14-83DC-4D49489E105A
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 2000409230
Partitions will be aligned on 2048-sector boundaries
Total free space is 2669 sectors (1.3 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2099199   1024.0 MiB  EF00  EFI system partition
   2         2099200         2361343   128.0 MiB   0C01  Microsoft reserved ...
   3         2361344       955197439   454.3 GiB   0700  Basic data partition
   4      1980418048      2000408575   9.5 GiB     2700  Basic data partition
   5       955197440      1345822719   186.3 GiB   8300  
   6      1345822720      1346871295   512.0 MiB   BF01  
   7      1346871296      1980418047   302.1 GiB   BF01

建立 boot pool

zpool create \
    -o ashift=12 -d \
    -o feature@async_destroy=enabled \
    -o feature@bookmarks=enabled \
    -o feature@embedded_data=enabled \
    -o feature@empty_bpobj=enabled \
    -o feature@enabled_txg=enabled \
    -o feature@extensible_dataset=enabled \
    -o feature@filesystem_limits=enabled \
    -o feature@hole_birth=enabled \
    -o feature@large_blocks=enabled \
    -o feature@lz4_compress=enabled \
    -o feature@spacemap_histogram=enabled \
    -o feature@zpool_checkpoint=enabled \
    -O acltype=posixacl -O canmount=off -O compression=lz4 \
    -O devices=off -O normalization=formD -O relatime=on -O xattr=sa \
    -O mountpoint=/boot -R /mnt \
    bpool /dev/nvme0n1p6
參數重點
➤ ashift=12 是為了要讓新一代 4KB block size 硬碟發揮最好的效能。
➤ canmount=off 表示 bpool 不是主要的掛載點,而是下面接著建立的 filesystem datasets。
➤ muntpoint=/boot 將來這個 bpool 要掛在 /boot
➤ -R /mnt 表示等一下會被掛在另一個指定的地方 /mnt

建立 root pool

zpool create \
    -o ashift=12 \
    -O acltype=posixacl -O canmount=off -O compression=lz4 \
    -O dnodesize=auto -O normalization=formD -O relatime=on \
    -O xattr=sa -O mountpoint=/ -R /mnt \
    rpool /dev/nvme0n1p7

建立 filesystem datasets 當作容器

zfs create -o canmount=off -o mountpoint=none rpool/ROOT
zfs create -o canmount=off -o mountpoint=none rpool/USERDATA
zfs create -o canmount=off -o mountpoint=none bpool/BOOT

建立並掛載真正的 rootfs, boot & home filesystem datasets

zfs create -o canmount=on -o mountpoint=/     rpool/ROOT/ubuntu
zfs create -o canmount=on -o mountpoint=/home rpool/USERDATA/ubuntu
zfs create -o canmount=on -o mountpoint=/boot bpool/BOOT/ubuntu
現在 filesystem datasets 都已經掛在 /mnt 之下,接下來就是將整個系統拷貝進去。

拷貝現有系統

先建立一個現有系統 Btrfs 的唯獨快照
mkdir /media/btrfs
mount /dev/nvmen0p5 /media/btrfs
btrfs subvolume snapshot -r /media/btrfs/@ /media/btrfs/@.latest
btrfs subvolume snapshot -r /media/btrfs/@home /media/btrfs/@home.latest
接下來就是用 rsync 做完整的系統拷貝
rsync -av --info=progress2 --no-inc-recursive --human-readable /media/btrfs/ /mnt
umount /media/btrfs

將系統 chroot 到 /mnt

for d in proc sys dev; do mount --rbind /$d /mnt/$d; done
chroot /mnt
echo "nameserver 8.8.8.8" >> /etc/resolv.conf  # 設定chroot下的DNS

安裝 GURB

mount /boot/efi  # 掛上EFI分區
grub-probe /boot # 確定目前系統可以認得ZFS
update-initramfs -c -k all # 更新initrd
vi /etc/default/grub
# Add init_on_alloc=0 to: GRUB_CMDLINE_LINUX_DEFAULT # Save and quit.
update0grub # 更新boot紀錄
grub-install --target=x86_64-efi --efi-directory=/boot/efi \ --bootloader-id=ubuntu --recheck --no-floppy

修正 filesystem 掛載的順序

mkdir /etc/zfs/zfs-list.cache
touch /etc/zfs/zfs-list.cache/bpool
touch /etc/zfs/zfs-list.cache/rpool
ln -s /usr/lib/zfs-linux/zed.d/history_event-zfs-list-cacher.sh /etc/zfs/zed.d
zed -F &
# 用以下命令確認快取的檔案不是空的
cat /etc/zfs/zfs-list.cache/bpool
cat /etc/zfs/zfs-list.cache/rpool
# 確認後停止 zed
fg
Press Ctrl-C.

離開 chroot 然後準備重新開機

mount | grep -v zfs | tac | awk '/\/mnt/ {print $3}' | \
xargs -i{} umount -lf {}
zpool export -a  # 為了確保安全, 卸載 zpool
reboot           # 重新開機
如果一切正常,重開機應該就會看到grub開機選單,選擇 Ubuntu 開機之後就會看到登入畫面。

後記

我這次運氣不錯,一方面也是有仔細參考前人的文件,所以很順利的轉換成 ZFS 系統,沒有把硬碟搞爛掉,造成無法開機。如果遇到開機的問題,一定要有 Ubuntu 的開機碟在身邊,用Live-CD 的環境把 filesystem 再掛載上來,才能進行系統修復。

參考文件

2020年6月1日 星期一

How to make smartcard reader on Dell Latitude 5480 working with Ubuntu

Dell Latitude 5480 has an embedded smartcard reader which should be based on BCM5880 secure processor from Broadcom. BCM5880 supports not only smartcard reader but also fingerprint reader. This article deals only the smartcard reader part. As for fingerprint reader, as of today, Ubuntu 20.04, still cannot have a working driver for that (see ref 1).

rick@E5480:~$ lsusb
Bus 002 Device 003: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter
Bus 002 Device 002: ID 0424:5807 Microchip Technology, Inc. (formerly SMSC) Hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 8087:0a2b Intel Corp. 
Bus 001 Device 014: ID 413c:3016 Dell Computer Corp. Optical 5-Button Wheel Mouse
Bus 001 Device 011: ID 05e3:0610 Genesys Logic, Inc. 4-port hub
Bus 001 Device 010: ID 0bda:4014 Realtek Semiconductor Corp. 
Bus 001 Device 015: ID 05e3:0723 Genesys Logic, Inc. GL827L SD/MMC/MS Flash Card Reader
Bus 001 Device 017: ID 1a2c:0c21 China Resource Semico Co., Ltd 
Bus 001 Device 012: ID 13fd:1340 Initio Corporation Hi-Speed USB to SATA Bridge
Bus 001 Device 009: ID 05e3:0608 Genesys Logic, Inc. Hub
Bus 001 Device 018: ID 058f:9520 Alcor Micro Corp. Watchdata W 1981
Bus 001 Device 005: ID 0424:2807 Microchip Technology, Inc. (formerly SMSC) Hub
Bus 001 Device 004: ID 0c45:6717 Microdia Integrated_Webcam_HD
Bus 001 Device 003: ID 0a5c:5834 Broadcom Corp. 5880
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The default Ubuntu 20.04 desktop installation does not install the necessary driver for smartcard reader to work. Did a search on google and find ref.2 is kind of close to my problem. But the document is quite old and it is referring to Ubuntu 9.04!! Since my Ubuntu 20.04 is installed on ZFS file system I decided to try that procedure. Before the installation I can do a quick zfs snapshot of my root filesystem and if anything go wrong I can take the chance to practice how to rollback to previous snapshot, I hope...

The installation turns out pretty strait forward. Just one command line and you are all set.
rick@E5480:~$ sudo apt install pcscd libpcsc-perl pcsc-tools libccid 
Per the instruction, pcscd needs to be restarted.
rick@E5480:~$ sudo /etc/init.d/pcscd restart
Restarting pcscd (via systemctl): pcscd.service.
Then use pcsc_scan to make sure smartcard reader is really working. I have card inserted and I can see ATR response from my card, nice ~
rick@E5480:~$ pcsc_scan 
Using reader plug'n play mechanism
Scanning present readers...
0: Broadcom Corp 5880 [Contacted SmartCard] (0123456789ABCD) 00 00
1: Broadcom Corp 5880 [Contactless SmartCard] (0123456789ABCD) 01 00
2: Alcor Micro AU9520 02 00
 
Mon Jun  1 14:04:07 2020
 Reader 0: Broadcom Corp 5880 [Contacted SmartCard] (0123456789ABCD) 00 00
  Event number: 0
  Card state: Card removed, 
 Reader 1: Broadcom Corp 5880 [Contactless SmartCard] (0123456789ABCD) 01 00
  Event number: 0
  Card state: Card removed, 
 Reader 2: Alcor Micro AU9520 02 00
  Event number: 0
  Card state: Card inserted, 
  ATR: 3B D8 96 00 81 B1 FE 45 1F 07 43 48 54 47 50 4B 49 4A DD

ATR: 3B D8 96 00 81 B1 FE 45 1F 07 43 48 54 47 50 4B 49 4A DD
+ TS = 3B --> Direct Convention
+ T0 = D8, Y(1): 1101, K: 8 (historical bytes)
  TA(1) = 96 --> Fi=512, Di=32, 16 cycles/ETU
    250000 bits/s at 4 MHz, fMax for Fi = 5 MHz => 312500 bits/s
  TC(1) = 00 --> Extra guard time: 0
  TD(1) = 81 --> Y(i+1) = 1000, Protocol T = 1 
-----
  TD(2) = B1 --> Y(i+1) = 1011, Protocol T = 1 
-----
  TA(3) = FE --> IFSC: 254
  TB(3) = 45 --> Block Waiting Integer: 4 - Character Waiting Integer: 5
  TD(3) = 1F --> Y(i+1) = 0001, Protocol T = 15 - Global interface bytes following 
-----
  TA(4) = 07 --> Clock stop: not supported - Class accepted by the card: (3G) A 5V B 3V C 1.8V 
+ Historical bytes: 43 48 54 47 50 4B 49 4A
  Category indicator byte: 43 (proprietary format)
+ TCK = DD (correct checksum)

Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
3B D8 96 00 81 B1 FE 45 1F 07 43 48 54 47 50 4B 49 4A DD
	Citizen Digital Certificate, Taiwan (PKI)
	http://moica.nat.gov.tw/

Now I can happily use online ATM and report my tax on Ubuntu (^_^)

[Reference]

2011年10月3日 星期一

2011 聖誕新心 練習錄音

以下是 10/2 的練習錄音
  1. Hosanna - Hymn Of Christ 4:57 (4.53MB)
  1. The Word Made Flash 2:35 (2.36MB)


2011 聖誕新心 練習錄音

  1. Hosanna - Hymn Of Christ 4:57 (5.53MB)

  1. The Word Made Flash 2:35 (2.36MB)