1. 備份整塊區塊. sd card.
windows : Win32DiskImager
Linux : sudo dd bs=4M if=/dev/mmcblok0 | zip backup-raspbian.zip -
看狀態改用 : sudo dd bs=4M if=/dev/mmcblok0 status=progress | zip backup-raspbian.zip -
解壓 unzip backup-raspbian.zip backup-raspbian.img
2. fdisk -l backup-raspbian.img
記下要掛載修改的start address. 通常是last partition.
假設主要Linux : start : 8192 磁區 在第一個partition. 每個sector 512byte
3. 掛載loop
sudo losetup /dev/loop10 backup-raspbian.img -o $((512*8192))
4. 用gparted resize
sudo gparted /dev/loop10
點resize 不要縮到有資料的地方
記下最後resize 的size. 假設是5447008K
5. 重新掛整個img 在loop上
sudo losetup --detach /dev/loop10
sudo losetup /dev/loop10 backup-raspbian.img
6. fdisk /dev/loop10
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-62333951, default 2048): 8192
Last sector, +sectors or +size{K,M,G,T,P} (8192-62333951, default 62333951): +5447008K
Created a new partition 1 of type 'Linux' and of size 5.2 GiB.
Partition #1 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: N
Command (m for help): w
出現 Re-reading the partition table failed.: Invalid argument
使用 partprobe 指令
7. truncate
sudo losetup --detach /dev/loop10
fdisk -l backup-raspbian.img
記下最後磁區的end . 假設是 10901503
truncate -s $((512*(10901503+1))) backup-raspbian.img
https://blog.cavedu.com/2018/03/22/raspberry-pi-
%E4%B8%8D%E5%86%8D%E5%82%99%E4%BB%BD%E6%95%B4%E5%BC%B5sd%E5%8D%A1%EF%BC%8C%E7%B8%AE%E5%B0%8Fraspberrypi%E5%82%99%E4%BB%BD%E5%AE%B9%E9%87%8F/
沒有留言:
張貼留言