first commit
This commit is contained in:
107
huong-dan-di-chuyen-linux-sang-o-moi.md
Normal file
107
huong-dan-di-chuyen-linux-sang-o-moi.md
Normal file
@@ -0,0 +1,107 @@
|
||||
# Hướng dẫn chuyển Linux (root + home) sang ổ cứng mới
|
||||
|
||||
**Máy:** Dual boot Windows/Ubuntu, UEFI, GPT.
|
||||
**Ổ hiện tại:** `/dev/nvme0n1` — root `nvme0n1p5` (30,7GB, gần đầy), home `nvme0n1p6` (104GB), ESP `nvme0n1p2`.
|
||||
**Ổ mới:** `/dev/nvme1n1` (500GB) — sẽ chia root 100GB + home ~390GB.
|
||||
**Không dùng LVM**, partition ext4 thường.
|
||||
|
||||
⚠️ **Backup dữ liệu quan trọng ra ổ thứ 3 hoặc cloud trước khi làm**, dù quy trình dưới đây là copy (không xóa nguồn) nên rủi ro mất dữ liệu thấp nếu làm đúng thứ tự.
|
||||
|
||||
---
|
||||
|
||||
## Bước 1 — Dọn ổ mới
|
||||
|
||||
Trong Windows, mở Disk Management, xóa các volume NTFS đang có trên ổ mới để chuyển thành Unallocated. Giữ nguyên partition `msftres` (~16,8MB), không cần đụng vào.
|
||||
|
||||
## Bước 2 — Boot Live USB Ubuntu (cùng phiên bản đang dùng)
|
||||
|
||||
Không thao tác resize/copy trong khi hệ thống đang chạy trực tiếp trên ổ đó.
|
||||
|
||||
## Bước 3 — Tạo partition mới bằng GParted
|
||||
|
||||
Trên `nvme1n1`, tạo:
|
||||
- 1 partition ext4 ~100GB → dùng làm root
|
||||
- 1 partition ext4 ~390GB → dùng làm home
|
||||
|
||||
(Chừa dư vài GB so với tổng 500GB để tránh lỗi thiếu dung lượng do đơn vị GiB/GB và partition `msftres` đã chiếm chỗ.)
|
||||
|
||||
## Bước 4 — Mount nguồn và đích
|
||||
|
||||
```bash
|
||||
sudo mkdir -p /mnt/oldroot /mnt/oldhome /mnt/newroot /mnt/newhome
|
||||
sudo mount /dev/nvme0n1p5 /mnt/oldroot
|
||||
sudo mount /dev/nvme0n1p6 /mnt/oldhome
|
||||
sudo mount /dev/nvme1n1pX /mnt/newroot # partition root mới vừa tạo
|
||||
sudo mount /dev/nvme1n1pY /mnt/newhome # partition home mới vừa tạo
|
||||
```
|
||||
|
||||
## Bước 5 — Copy dữ liệu bằng rsync
|
||||
|
||||
```bash
|
||||
sudo rsync -aAXH --info=progress2 /mnt/oldroot/ /mnt/newroot/ \
|
||||
--exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found","/home/*"}
|
||||
|
||||
sudo rsync -aAXH --info=progress2 /mnt/oldhome/ /mnt/newhome/
|
||||
```
|
||||
|
||||
## Bước 6 — Chroot, sửa fstab, cài lại GRUB
|
||||
|
||||
```bash
|
||||
sudo mount --bind /dev /mnt/newroot/dev
|
||||
sudo mount --bind /proc /mnt/newroot/proc
|
||||
sudo mount --bind /sys /mnt/newroot/sys
|
||||
sudo mkdir -p /mnt/newroot/home
|
||||
sudo mount /dev/nvme1n1pY /mnt/newroot/home
|
||||
sudo mount /dev/nvme0n1p2 /mnt/newroot/boot/efi # dùng chung ESP hiện có
|
||||
|
||||
sudo chroot /mnt/newroot
|
||||
```
|
||||
|
||||
Trong chroot:
|
||||
|
||||
```bash
|
||||
blkid # lấy UUID mới của partition root và home
|
||||
nano /etc/fstab # sửa 2 dòng root và home theo UUID mới
|
||||
update-grub
|
||||
grub-install /dev/nvme1n1 # cài GRUB vào ổ mới (ESP vẫn dùng chung ở nvme0n1p2)
|
||||
exit
|
||||
```
|
||||
|
||||
## Bước 7 — Thoát, unmount, reboot
|
||||
|
||||
```bash
|
||||
sudo umount -R /mnt/newroot
|
||||
sudo umount /mnt/oldroot /mnt/oldhome
|
||||
reboot
|
||||
```
|
||||
|
||||
Rút Live USB, chọn Ubuntu ở GRUB menu, kiểm tra:
|
||||
|
||||
```bash
|
||||
df -h
|
||||
```
|
||||
|
||||
Xác nhận `/` và `/home` đang trỏ vào `nvme1n1` với dung lượng đúng (~100GB / ~390GB).
|
||||
|
||||
## Bước 8 — Sau khi xác nhận ổn định
|
||||
|
||||
Giữ lại partition cũ (`nvme0n1p5`, `p6`) vài ngày làm backup, sau đó có thể xóa/format lấy lại dung lượng ổ cũ.
|
||||
|
||||
---
|
||||
|
||||
## Lưu ý quan trọng
|
||||
|
||||
- `grub-install` cài vào `nvme1n1` nhưng **ESP vẫn nằm ở `nvme0n1p2`** — nghĩa là máy vẫn cần ổ cũ (`nvme0n1`) cắm sẵn để boot (ESP + Windows boot entry đều ở đó). Nếu muốn ổ mới có thể boot độc lập (rút ổ cũ vẫn chạy được), cần tạo ESP riêng trên `nvme1n1` và thêm boot entry bằng `efibootmgr`.
|
||||
- Nếu quên xóa `--exclude="/home/*"` lúc rsync root, dữ liệu home cũ sẽ bị copy lẫn vào root mới — kiểm tra kỹ lệnh trước khi chạy.
|
||||
- Sau khi đổi UUID trong `fstab`, nếu gõ sai UUID hệ thống sẽ không boot được vào được — luôn double-check bằng `blkid` trước khi sửa.
|
||||
|
||||
---
|
||||
|
||||
## Link tham khảo
|
||||
|
||||
- [ArchWiki – GRUB (cài lại bootloader qua chroot)](https://wiki.archlinux.org/title/GRUB)
|
||||
- [Moving Arch Linux to a new SSD with rsync – rdeeson.com](https://www.rdeeson.com/weblog/157/moving-arch-linux-to-a-new-ssd-with-rsync)
|
||||
- [Migrating a Linux system from one disk to another using chroot – itstorage.net](https://itstorage.net/index.php/ldce/laa/571-migrating-a-linux-system-from-one-disk-to-another-using-chroot)
|
||||
- [Backup and restore with rsync – BunsenLabs forum](https://forums.bunsenlabs.org/viewtopic.php?id=3586)
|
||||
- [Increase an ext4 partition with GParted – jesusamieiro.com](https://www.jesusamieiro.com/increase-an-ext4-partition-with-gparted/)
|
||||
- [How To Resize Active/Primary root Partition Using GParted – 2DayGeek](https://www.2daygeek.com/linux-resize-active-primary-root-partition-gparted/)
|
||||
Reference in New Issue
Block a user