rsync備份系統以及grub重新安裝 - Linux

Odelette avatar
By Odelette
at 2021-03-03T21:40

Table of Contents

原來的系統硬碟怪怪的,又有not start from physical sectors問題。
怕重新開機後開不了,以及想用新的分割,網路找到最佳方案似乎是用
rsync做系統移動。使用的OS是fedora21,以下是操作過程。

#Issue: some original OS SSD partitions do not start from physical sectors
and encounter failing probability. This may comes from direct system backup
using clonezilla from 256G SSD to 500G SSD
# Original SSD has 3 primary partitions, 1 extended partition, 1 logical
partition. New goal is to eliminate sector alignment issue and to
re-partition SSD


#Step A: partition new Disk
#Step A.1: make disk label as msdos
parted /dev/sdX mklabel msdos # (it seems gpt partition cannot work as
bootable device)

#Step A.2: partition new disk with parted.
#(This step could also be done with fdisk)
parted /dev/sdX mkpart primary 1M 1G # creat /boot
parted /dev/sdX mkpart primary 1G 3G # creat swap
parted /dev/sdX mkpart primary 3G 99% # creat /
parted /dev/sdX mkpart primary 99% 100% # creat /home

#Step A.3: assign bootable partition
parted /dev/sdX set 1 boot on # make /dev/sdX1 bootable

Step A.4: format partitions and make swap
mkfs -t ext4 /dev/sdX1
mkswap /dev/sdX2
mkfs -t ext4 /dev/sdX3
mkfs -t ext4 /dev/sdX4

#Step B: Assign Old UUIDs into new Disk
#Step B.1: Show All UUIDs
blkid

#Step B.2: Update All UUIDs in new Disk
tunefs2 -U Old_bootPartion_UUID /dev/sdX1
mkswap -U Old_swapPartition_UUID /dev/sdX2
tunefs2 -U Old_rootPartition_UUID /dev/sdX3
tunefs2 -U Old_homePartition_UUID /dev/sdX4

#Step C:mount new Disk partions in /mnt
mount /dev/sdX3 /mnt
mount /dev/sdX1 /mnt/boot
mount /dev/sdX4 /mnt/home

#Step D:synchronize all system. Sometimes /boot must be
synchronize seperately
rsync -aAxHAX --progress /
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*",
"/media/*","/lost+found"} /mnt

#Step E:grub install
#Step E.1: grub install in new disk. Without this step,
BIOS could not identify new Disk as bootable device
grub2-install --boot-directory=/mnt/boot /dev/sdX

#Step E.2 make grub configurations
for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
chroot /mnt
dracut -f #(Without this step, dracut could keep searching old disk
settings in booting process)
grub2-mkconfig -o /boot/grub2/grub.cfg
# after chroot /mnt, system regard /mnt/boot as /boot.

--
Tags: Linux

All Comments

Quintina avatar
By Quintina
at 2021-03-08T10:14
為什麼不止備份資料碟就好
Frederic avatar
By Frederic
at 2021-03-12T22:49
還要用dracut 跟grub粉麻煩
Liam avatar
By Liam
at 2021-03-17T11:24
其實已經有分別用dd跟rsync備兩份到資料碟了
Barb Cronin avatar
By Barb Cronin
at 2021-03-21T23:58
dd還原是我惡搞不成後的最後手段
Mason avatar
By Mason
at 2021-03-26T12:33
為了debug 跟bypass physical sector issue
clonezilla我只好捨棄不用
Suhail Hany avatar
By Suhail Hany
at 2021-03-31T01:08
最後採取這種繞了一大圈的rsync+grub install,在原系
統重開機前,把系統備份到新系統碟
Ivy avatar
By Ivy
at 2021-04-04T13:43
bypass 是啥意思 壞掉的磁區直接改成\0ㄇ
Doris avatar
By Doris
at 2021-04-09T02:17
在新系統碟用新partition裝舊系統而已
Andrew avatar
By Andrew
at 2021-04-13T14:52
Fedora 21... 為什麼不乾脆直接用 CentOS 7 @@
Blanche avatar
By Blanche
at 2021-04-18T03:27
還是那是原本的系統XD
Edward Lewis avatar
By Edward Lewis
at 2021-04-22T16:02
這招會用,很多問題皆可解

無法安裝Python-numpy-dbg及其他的套件

Genevieve avatar
By Genevieve
at 2021-03-03T12:54
各位前輩好,因為不知道這是ubuntu還是python的問題, 因此我兩邊都放,若有不適合 會立刻刪除,我在安裝uhd的套件時,發現系統出現了python-numpy-dbg、python-qt4-db g、python-dev無法安裝的問題,我有使用sudo apt install python-numpy ...

evolution 收信 yahoo gmail之 設定

Edith avatar
By Edith
at 2021-03-02T21:52
※ [本文轉錄自 digitalk 看板 #1WFVED6z ] 作者: BASICA (西門彼得) 看板: digitalk 標題: [問題] evolution 收信 yahoo gmail之 設定 時間: Tue Mar 2 16:12:53 2021 小的是用LINUX裏面裝的evolution ...

ubuntu不加sudo讀取不到usrp(硬體pi 4)

Annie avatar
By Annie
at 2021-03-02T11:25
各位前輩您好,目前想要使用gnuradio搭配usrp來錄製訊號,但在建立流程圖的時候發現 ,usurp source block顯示成紅色,如下圖: https://i.imgur.com/Yg0u5qt.jpg 因此我先到terminal輸入uhd_find_devices,卻發現找不到USB open ...

Ubuntu突然scp可以登入但ssh不能登入

Kyle avatar
By Kyle
at 2021-03-01T16:49
有一陣子沒有登入實驗室主機(Ubuntu), 今天使用terminal登入時, 發現無法登入. 嘗試登入太多次後, 有時會出現 ssh: connect to host XX port 22: Connection timed out 有時會出現 ERROR: ssh: connect to hos ...

fcitx5+rime+lua擴充版嘸蝦米 安裝

Sandy avatar
By Sandy
at 2021-02-28T03:41
有版友在詢問如何安裝與透過fcitx5+rime來使用嘸蝦米輸入法 網路上已經有很多範例可以參考了,在這邊簡單分享一下自己整理後的流程 我非程式開發人員,對Linux的瞭解程度非常淺薄 屬於會割磁區會安裝多重開機能調整桌面環境到符合自己使用的習慣這種程度而已 當了十幾年的Windows用戶,因為研究上碰到要 ...