这已经不是第一次做OS的迁移了,T7早已经迁移过多台设备了。所以,其实只需要如下三步:

1.  rsync

  我一直有全系统备份的习惯,T7一直会不定期的全系统rsync到Tstation上面去。所以我只需要将最新的T7 rsync进Tstattion,在从Tstation将T7 rsync进T470,就行了。

2. filesystem

  文件系统。T460s是一块1TB的ssd,T470是一块128GB的ssd+1TB的HDD。需要对T470重新做分区规则,并做好加密,然后挂载好之后,进行第一步。

3. boot

  启动设置。这里包括了UEFI,GRUB,dm-crypt,initrd等相关的配置。其实并不复杂,只有是我忘了,而忘了也是因为理解的并不深。所以,还有在学一下,以及会涉及到如何对文件系统进行规划。

一: 回顾之前的操作:

[archlinux][crypto] 从T450迁移archlinux操作系统至T460s笔记本

[cipher][archlinux][disk encryption][btrfs] 磁盘分区加密 + btrfs

二:

  因为是两块硬盘,我的规划是这样的,SSD分出16GB做swap,剩下的做根分区。HDD全盘挂载为home。文件系统将选用luks+btrfs。

  swap实际上是可以选择swap file的。这样在不想要swap的时候,就可以还回root分区。提高利用率,不过,仿佛记得btrfs+swap file目前好像有bug?恩,是的 https://wiki.archlinux.org/index.php/Btrfs#Swap_file

  那么,接下来。第一个要解决的问题就是。怎么在boot的时候,解密俩个加密分区。

  思路是这样的,在root分区里保存home的密钥,这样,只需要解密root就可以了。

  见:https://wiki.archlinux.org/index.php/Dm-crypt/Encrypting_a_non-root_file_system#Automated_unlocking_and_mounting

  由上文可知,使用crypttab文件,可以解决这一需求。即:在root挂载后,从root分区读取密钥解密home分区。

  另外,有一段话,值得注意:

Note: When using systemd-boot and the sd-encrypt hook, if a non-root partition's passphrase is the same as root's, there is no need to put that non-root partition 
in crypttab due to passphrase caching. See this forum thread for more information.

三: bootloader和fstab的参数怎么写?

  1. 在/etc/default/grub中,指定加密盘,剩下的grub会处理。  

rd.luks.uuid=

  2. arch有个脚本,生成fstab。

    genfstab

  弱线索阅读链接:https://wiki.archlinux.org/index.php/Dm-crypt/System_configuration#Boot_loader

  摘要:

o activate all devices in /etc/crypttab do not specify any luks.* parameters and use rd.luks.*. To activate all devices in /etc/crypttab.initramfs do not specify any luks.* or rd.luks.* parameters.

四:swap怎么弄?

  swap分区也是一个单独的分区,和home分区的设置是类似的,区别只在下面这些设置。

  参考:https://wiki.archlinux.org/index.php/Dm-crypt/Swap_encryption#With_suspend-to-disk_support

  1.  设置为swap的分区,本身是加密的。

  2.  修改grub,正确设置resume设备。

  3。修改mkinitcpio.conf 怎就resume属性。

开始之前:

  通篇复习:https://wiki.archlinux.org/index.php/Dm-crypt/Encrypting_an_entire_system

SSD trim:

  https://wiki.archlinux.org/index.php/Dm-crypt/Specialties#Discard.2FTRIM_support_for_solid_state_drives_.28SSD.29

  我用btrfs https://wiki.archlinux.org/index.php/Solid_State_Drive#TRIM

  所以,只要带着discard参数挂载,就可以了。

分区:

  https://wiki.archlinux.org/index.php/Btrfs

  并参考之前的blog:链接在本文最开始的地方。

  这里突然想到一个问题,两个硬盘,做两个btrfs,就是要被分开管理了。那么做快照之类的也是要分开做快照。于是如此的话,是否还有必要用btrfs呢?

  需要思考一下,迁移工作先暂停一周。

好,准备阶段结束 》》》》》》 开始:

1. 分区。

  128GB  GTP分区

    512MB   EFI分区,即ESP。文件系统为FAT32

    16GB  LUKS  swap分区

    110GB  LUKS btrfs  挂载根分区

  1024GB 无分区  LUKS  btrfs   挂载/home分区

分区:

parted /dev/sda
mklabel gpt
mkpart primary fat32 1MB 513MB
mkpart primary 513MB 17GB
mkpart primary 17GB %
set 1 esp on

mkfs:

mkfs.fat -F  /dev/sda1
cryptsetup luksFormat --type luks2 /dev/sda3
cryptsetup open /dev/sda3 LUKS_ROOT

cryptsetup 使用KeyFile https://wiki.archlinux.org/index.php/Dm-crypt/Device_encryption#Keyfiles

dd bs= count= if=/dev/random of=./keyfile
chmod ./keyfile
cryptsetup luksFormat --type luks2 /dev/sda2 ./keyfile
cryptsetup luksFormat --type luks2 /dev/sdb ./keyfile
cryptsetup open /dev/sda2 LUKS_SWAP --key-file ./keyfile
cryptsetup open /dev/sdb LUKS_HOME --key-file ./keyfile

mkfs

mkfs.btrfs -L vd_root /dev/mapper/LUKS_ROOT
mkfs.btrfs -L vd_home /dev/mapper/LUKS_HOME
mount /dev/mapper/LUKS_ROOT mnt
btrfs subvolume create mnt/real_root
btrfs subvolume snapshot mnt/real_root mnt/snapshot
btrfs subvolume set-default mnt/real_root
umount mnt
mount /dev/mapper/LUKS_HOME mnt
# 同上。。。

压缩挂载:

https://wiki.archlinux.org/index.php/Btrfs#Compression

zstd: https://github.com/facebook/zstd

mount -o compress=lzo /dev/mapper/LUKS_ROOT mnt
mount -o compress=lzo /dev/mapper/LUKS_HOME mnt/home
mount /dev/sda1 mnt/boot

2 rsyc bak

  http://www.cnblogs.com/hugetong/p/6984632.html

#! /usr/bin/bash

cd $(dirname $)

#if [[ $# -lt 2 || $# -gt 3 ]]; then
# echo "usage: $0 SRC_DIR DEST_DIR [-w]"
# exit
#fi
#
#src=$
#dest=$
#doit=$ if [[ $# -lt || $# -gt ]]; then
echo "usage: $0 [-w]"
exit
fi src=/
dest=tong@192.168.20.50:/home/tong/Storage/System/T7-rsync/ROOT_FS
doit=$ if [[ $doit == -w ]]; then
dry=
else
dry='-n'
fi sudo rsync --archive --acls --xattrs --numeric-ids \
--delete \
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} \
--sparse \
--hard-links \
--human-readable --itemize-changes --progress \
--verbose \
-M--fake-super \
$src $dest $dry # --delete-excluded
# --one-file-system \

SWAP

mkswap /dev/mapper/LUKS_SWAP
swapon --discard /dev/mapper/LUKS_SWAP

chroot

arch-chroot nmt/

fstab

genfstab -U nmt > nmt/etc/fstab.new
╰─>$ sudo cat /etc/crypttab
LUKS_HOME UUID="9f6b69f1-d2b8-4eed-b8b2-74c4ec6e8eaa" /etc/keys/luks_home.key
LUKS_SWAP UUID="5f649ea7-3e91-43c9-aaa2-b3afa97c1d7e" /etc/keys/luks_home.key
─>$ sudo cat /etc/fstab
/dev/mapper/LUKS_ROOT / btrfs discard,rw,relatime,compress=lzo,ssd,space_cache,subvolid=,subvol=/real_root,subvol=real_root
UUID=CD04-A96B /boot vfat discard,rw,relatime,fmask=,dmask=,codepage=,iocharset=iso8859-,shortname=mixed,utf8,errors=remount-ro
/dev/mapper/LUKS_HOME /home btrfs rw,relatime,compress=lzo,space_cache,subvolid=,subvol=/real_home,subvol=real_home
/dev/mapper/LUKS_SWAP none swap discard,defaults,pri=-

mkinitcpio.conf

. /usr/bin/btrfs
. -udev +systemd +sd-encrypt
mkinitcpio -g /boot/initramfs-linux.img -k 4.17.3-1-ARCH

efimanager

┬─[tong@T7:~]─[:: PM]
╰─>$ ll /boot/
total 51M
-rwxr-xr-x root root 31M Jul : initramfs-linux-fallback.img*
-rwxr-xr-x root root 13M Jul : initramfs-linux.img*
-rwxr-xr-x root root 1.6M May : intel-ucode.img*
-rwxr-xr-x root root 856K Jul : shellx64_v2.efi*
-rwxr-xr-x root root Jul : t7.nsh*
-rwxr-xr-x root root 5.1M Jun : vmlinuz-linux*
┬─[tong@T7:~]─[:: PM]
╰─>$
efibootmgr --disk /dev/sda --part  --create -L T7 --loader /vmlinuz-linux --unicode 'root=/dev/mapper/LUKS_ROOT rw rootflags=subvol=real_root rd.luks.name=8506ce5c-9a9d-407d-bccd-a2b4c7320914=LUKS_ROOT initrd=/intel-ucode.img initrd=/initramfs-linux.img'
efibootmgr --disk /dev/sda --part --create -L T7-fallback --loader /vmlinuz-linux --unicode 'root=/dev/mapper/LUKS_ROOT rw rootflags=subvol=real_root rd.luks.name=8506ce5c-9a9d-407d-bccd-a2b4c7320914=LUKS_ROOT initrd=/intel-ucode.img initrd=/initramfs-linux-fallback.img'

UEFI Shell

yaourt -S uefi-shell-git
cp /usr/share/uefi-shell/shellx64_v2.efi /boot/
efibootmgr --disk /dev/sda --part --create -L 'UEFI Shell V2' --loader /shellx64_v2.efi

/etc/udev/rules.d/ 修改mac地址

支持resume

1 如果不是systemd的就需要添加resume,如下。如果是systemd的,就略过这一条。

┬─[tong@T7:~]─[:: PM]
╰─>$ cat /etc/mkinitcpio.conf |grep resume
HOOKS=(base systemd autodetect modconf block sd-encrypt filesystems keyboard resume fsck)
┬─[tong@T7:~]─[:: PM]
╰─>$ sudo mkinitcpio -P -g ./initramfs-linux.img

2 之前我的swap分区是加密的,但是是在root挂载之后,systemd起来之后才解密的,很显然kernel是找不到它的,在那个时机里。所以,我简单粗暴的,不做swap加密了。如下:

把swap分区变成了明文分区。

sudo efibootmgr --disk /dev/sda --part 1 --create -L T7 --loader /vmlinuz-linux --unicode 'root=/dev/mapper/LUKS_ROOT rw rootflags=subvol=real_root rd.luks.name=8506ce5c-9a9d-407d-bccd
-a2b4c7320914=LUKS_ROOT initrd=/intel-ucode.img initrd=/initramfs-linux.img resume=UUID=c932854d-0a49-4a09-91a3-50b67ba1ddd1'

完!

  

    

[archlinux] 迁移T7从T460s到T470的更多相关文章

  1. [archlinux][crypto] 从T450迁移archlinux操作系统至T460s笔记本

    从T450笔记本迁移archlinux操作系统之T460s笔记本,同时: 1.  使用cryptsetup做底层块加密. 2.    全新使用btrfs文件系统. 一,硬盘分区. 1T的SSD,使用U ...

  2. [archlinux][hardware] ThankPad T450自带SSD做bcache之后的使用寿命分析

    这个分析的起因,是由于我之前干了这两个事: [troubleshoot][archlinux][bcache] 修改linux文件系统 / 分区方案 / 做混合硬盘 / 系统转生大!手!术!(调整底层 ...

  3. [troubleshoot][archlinux][bcache] 修改linux文件系统 / 分区方案 / 做混合硬盘 / 系统转生大!手!术!(调整底层架构,不!重!装!)

    目标: 我要做的事情是:修改文件系统,硬盘分区方案,但是不重装系统,整个操作不被应用层感知. 背景: 我的笔记本 ThinkPad T450.8G内存 + 16GB SSD + 1TB HDD.预装w ...

  4. [daily][archlinux][fonts] 在linux下管理字体

    序: linux是社区搞出来, 商业应用也都是服务器场景.社区里又都是技术人员.字体又是细节.而且会英文早成了标配.所以没有很多社区以外的人力来搞字体这个毫无回报的东西. 结果很自然的,装linux桌 ...

  5. [daily][troubleshoot][archlinux][wps][font] wps文档中的图内容无法显示中文

    序 用linux作为工作生产环境的几个需要解决的问题之一是:文档协作,即如何兼容Micro$oft Office格式的文档. 我一般的工作方式是:在linux下创建一个win7的虚拟机,安装常用的wi ...

  6. [daily][device][bluetooth] 蓝牙怎么办!(archlinux下驱动蓝牙鼠标,以及三星手机)

    去年地摊买的破无线鼠标坏掉了.看上微软的Designer Mouse蓝牙鼠,但是买之前我要确认我能不能驱起来. 这款鼠标只支持蓝牙4.0.系统支持windows8以上,不支持xp和windows7. ...

  7. [troubleshoot][archlinux][X] plasma(KDE) 窗口滚动刷新冻结(约延迟10s)(已解决,root cause不明,无法再次复现)

    现象: konsole,setting等plasma的系统应用反应缓慢,在滚动条滚动时,尤为明显. 触发条件: 并不是十分明确的系统滚动升级(Syu)后,产生. 现象收集: 可疑的dmesg [ :: ...

  8. [daily][archlinux][pacman] local database 损坏

    下午,开心的看着dpdk的文档,做做各种小实验. 后台正常yaourt -Syu,三个多G的下载,我总是过很久才update一次. 然后KDE窗口各种异常,我知道又在开始更x相关的东西了.可是因为X异 ...

  9. 升级树莓派archlinux系统到新sd卡

    由于之前把树莓派系统安装在4gb的sd卡上,随着系统的更新及安装了一大堆软件包之后,系统提示空间不足了.网上搜索了下,把所有数据迁移到新的sd卡上还是比较简单的. 克隆sd卡: 1,关闭树莓派电源,取 ...

随机推荐

  1. 译: 2. RabbitMQ Spring AMQP 之 Work Queues

    在上一篇博文中,我们写了程序来发送和接受消息从一个队列中. 在这篇博文中我们将创建一个工作队列,用于在多个工作人员之间分配耗时的任务. Work Queues 工作队列(又称:任务队列)背后的主要思想 ...

  2. Android遍历API (1) 动画篇——克隆动画AnimationCloning

    从我学Android开始,一直就想做一件事.就是好好把APIDemo看一遍.今天开始会抽时间把Android官方的APIDemo程序全部过一遍.主要是为了两个目的:第一,复习以前学习的API用法.第二 ...

  3. Java 继承中构造方法的执行顺序问题

    在Java中,如果一个类没有任何显式创建的构造器则该类默认会有一个无参构造器:如果显式创建了有参构造器则该类就不再有默认无参构造器. 在Java继承中,构造器并不能被继承,而是被显示或隐式调用. 1. ...

  4. 【转】WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等 本文主要内容: CheckBox复选框的自定义样式,有两种不同的风格实现: RadioB ...

  5. 【转】在xcode5中修改整个项目名

    本文转载自:http://www.cnblogs.com/tbfirstone/p/3601541.html 总会遇到几个项目,在做到一半的时候被要求改项目名,网上找了下相关的资料,大多数是xcode ...

  6. Mac 挂载树莓派nfs

    vim /etc/export /data_sda1/  192.168.1.*(rw,sync,insecure,no_root_squash) mac端自带rpcbind 挂载 sudo moun ...

  7. 原生App切图的那些事儿

    如何切图? 了解iphone界面的尺寸 最小的分辨率是320x480,我们把这个尺寸定为基准界面尺寸(baseline),基准尺寸所用的图标定为1倍图(1x). 在实际设计过程中,为了降低设计成本,一 ...

  8. IntelliJ IDEA连接TFS local workspace无法正常签入

    前几天为了便于在本地修改,将TFS workspace的类型从Server修改为Local.基于Visual Studio的开发正常没有问题,用IntelliJ IDEA时却提示以下错误: Error ...

  9. 【BZOJ2671】Calc 数学

    [BZOJ2671]Calc Description 给出N,统计满足下面条件的数对(a,b)的个数: 1.1<=a<b<=N 2.a+b整除a*b Input 一行一个数N Out ...

  10. B - Calculation 2

    Given a positive integer N, your task is to calculate the sum of the positive integers less than N w ...