shell
sudo blkid |grep sd [0]
/dev/sda1: LABEL="M-gM-3M-;M-gM-;M-^_" UUID="09C1B27DA5EB573A" TYPE="ntfs" PARTUUID="2e18ee5d-01"
/dev/sda5: UUID="4195c904-7888-47d2-939d-0e9faeefe3d2" TYPE="ext4" PARTUUID="2e18ee5d-05"
/dev/sda6: UUID="4aaad3b1-cf45-4884-ba24-073dae892eda" TYPE="ext4" PARTUUID="2e18ee5d-06"
/dev/sdb: UUID="4912fe5f-dc51-438c-9c50-4982c676abf9" TYPE="ext4"
yiidata@server proxyserver-1.4 cat /etc/fstab [0]
# /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/sda6 during installation
UUID=4aaad3b1-cf45-4884-ba24-073dae892eda / ext4 errors=remount-ro 0 1
UUID=4195c904-7888-47d2-939d-0e9faeefe3d2 /opt/software ext4 defaults 0 0
UUID=4912fe5f-dc51-438c-9c50-4982c676abf9 /disk ext4 defaults 0 0
/swapfile none swap sw 0 0
NEW
shell
sudo blkid |grep sd [0]
/dev/sdc: UUID="4912fe5f-dc51-438c-9c50-4982c676abf9" TYPE="ext4"
/dev/sda1: LABEL="M-gM-3M-;M-gM-;M-^_" UUID="09C1B27DA5EB573A" TYPE="ntfs" PARTUUID="2e18ee5d-01"
/dev/sda5: UUID="4195c904-7888-47d2-939d-0e9faeefe3d2" TYPE="ext4" PARTUUID="2e18ee5d-05"
/dev/sda6: UUID="4aaad3b1-cf45-4884-ba24-073dae892eda" TYPE="ext4" PARTUUID="2e18ee5d-06"
/dev/sdb1: UUID="e227adc3-2d38-4bab-a37d-9f44252519da" TYPE="ext4" PARTUUID="992dc0da-5178-4716-b372-17277a02ad95"
/dev/sdb2: UUID="be300612-fe0e-4f7d-aaa6-cdfe352b57cf" TYPE="swap" PARTUUID="92c7a8db-c880-438d-ac0f-f9eeb13462ab"
/dev/sdb3: UUID="bae603d0-4852-4f90-95c2-c392aec47db7" TYPE="ext4" PARTUUID="7bc5eb7a-170d-4ebb-a116-c7f229efaf88"
那这里使用dd 命令来进行字节级别的迁移,我的根目录所在的分区是/dev/nvme0n1p5,新硬盘划分的是/dev/nvme1n1p2。
dd 命令支持整盘迁移,会迁移磁盘的分区信息,剩余空间以独立空分区存在。
shell
sudo dd if=/dev/sda5 of=/dev/sdb3
sudo dd if=/dev/sda6 of=/dev/sdb1
# 由于dd命令没有展示中间过程,因此使用另一条命令来让他输出中间过程:
watch -n 5 killall -USR1 dd
这里要注意,dd命令也会拷贝uuid过去,意味着,新分区与旧分区的uuid是一样的。后面修改挂载信息会再提到.
拷贝完之后,还要更新一下分区信息,否则挂载后还是会显示原来的分区大小和使用情况:
shell
sudo umount /dev/sdb3
sudo e2fsck -f /dev/sdb3
sudo resize2fs /dev/sdb3
sudo e2fsck -f /dev/sdb1
sudo resize2fs /dev/sdb1
# 重新生成 uid
sudo uuidgen | xargs tune2fs /dev/sdb3 -U
fstab 样式
shell
UUID=e227adc3-2d38-4bab-a37d-9f44252519da / ext4 errors=remount-ro 0 1
UUID=bae603d0-4852-4f90-95c2-c392aec47db7 /opt/software ext4 defaults 0 0
UUID=4912fe5f-dc51-438c-9c50-4982c676abf9 /disk ext4 defaults 0 0
/swapfile none swap sw 0 0