Dull afternoon writing code, suddenly the system pop-up window :”/ directory space insufficient!!” “, a “check” a look, the original or just learn Linux when the allocation of 20G poor space, and now do not want to open Windows, sigh, the status of Linux. So buy a 250GB NVMe SSD, and do not want to reinstall the system, want to perfect migration of the system disk not a byte, so began the migration of the journey ~~~

The environment that

My environment information is as follows:

  • The original 250GB nvme SSD came with two systems: 200 gb was shipped to Windows 10 and 20 gb was shipped to Ubuntu20
  • 8Gx2 = 16GB memory
  • Ubuntu partition status
    • /: Root directory 17GB primary partition
    • /boot: 1 gb logical partition for boot
    • Swap: Swap partition 2G logical partition
    • /home: stored on a mechanical hard disk, separate out: 100 GB

Conclusions first, details later

The whole trip down, stepped on a lot of pits, finally straighten out the process and thinking! I consulted a lot of Linux knowledge that I didn’t understand before, and I also gained a lot

For record

Purchase and install SSDS

Knowledge here:

  1. Is SATA SSD better or M.2 better?
  2. What is NVMe in one article

Today’s SSD price is not very expensive, the 250GB Western Digital NVMe card on some east bought 308+, have to say that today’s hardware is very delicate ah, THE M.2 SSD interface is small and delicate, plug and play. Of course, a special screw is needed to fix the motherboard (screws are not attached with the card oh! General motherboard support several M.2 slots will be matched with a few, MINE is 2 slots.

Soon installed, cover the case glass, HMMM, there is that satisfaction of +1 enhancement, hahaha.

Create an Ubuntu boot USB flash drive to access the Live environment

The reason for creating a boot disk was that we needed a sandbox environment that could manipulate the hard disk, and ubuntu’s Live environment was friendly to the unskilled compared to a command-only environment like GRUB Secure.

I am in the Windows environment using UltraISO to download the Ubuntu 20 image file to the USB disk, here directly look at the existing tutorial: Ubuntu 20.04 LTS desktop version detailed installation guide

Format the partition of the new hard disk

There are many options:

  • fdisk
  • parted
  • Ubuntu implements Disks

They are both Linux disk management commands. Fdisk can only operate partitions of less than 2TB. Parted is a newer and more powerful partitioning tool that supports the GPT partition format.

Here step pothole warning!! If you want to migrate the system disk perfectly, you can divide the disk according to the partition type. For example, I used to be an MSDOS partition, tried to use a GPT partition, and failed to fix grub boot…

The second pitfall is a 4k alignment warning when manually setting up partitions. It looks like hard disk storage doesn’t start at 0 as we imagined

Okay, I’m not going to install it. I’ll just throw in my own Disks partition

Linux Primary partition, Extended partition, logical partition connection and difference What is the recommended size of Linux/boot partition?

After consideration, the whole 250GB card is given to Ubuntu. My partition scheme is as follows:

Hard disk full copy of root directory data

See article: Migrating Linux to a new hard disk

First thing to know: Linux is all about files, so copying a system is actually copying files!

My root partition is /dev/nvme0n1p5, and my new hard disk is /dev/nvme1N1P2.

dd if=/dev/nvme0n1p5 of=/dev/nvme1n1p2
Copy the code

Since the dd command does not show the intermediate procedure, use another command to make it print the intermediate procedure:

watch -n 5 killall -USR1 dd
Copy the code

17 GIGABytes of data can be transferred between NVMe SSDS with little pressure and quickly

Note here that the DD command also copies the UUID over, meaning that the NEW partition has the same UUID as the old partition. This will be mentioned later when modifying mount information.

After copying the partition, update the partition information; otherwise, the original partition size and usage will be displayed after mounting:

umount /dev/nvme1n1p2
e2fsck -f /dev/nvme1n1p2
resize2fs /dev/nvme1n1p2
Copy the code

BOOT Copying data from the BOOT disk

/boot = /boot = /boot = /boot = /boot = /boot = /boot = /boot

  1. useddCopy, and then modify the UUID
  2. After the partition automatically generates a new UUID, usecpCopy boot disk data in file copy mode

I chose the latter here. In the live environment, you should use the mount command to mount the drive letter.

Updated the new root path partition UUID

Reference article: Linux modifies partition UUID

Since I am not sure whether I can succeed, I want to keep the original drive letter unchanged (convenient for rollback), which will cause the same UUID of the two partitions of the root directory, which may be wrong during boot, so I consult the information and try to change the UUID of the new partition.

You can use the uuidgen command to generate the ID, update the partition as a parameter, and write the id to the /etc/fstab file in the new root directory

uuidgen | xargs tune2fs /dev/nvme1n1p2 -U
Copy the code

Run the following command to view the UUID of the latest drive letter

sudo blkid
Copy the code

Copy the uUID of the latest root directory and write the uUID of the new root directory/etc/fstab, here still need to mount drive letter ohAt this point, data replication is complete

Modifying Grub Boot

You are advised to use boot-Repair. The installation method is as follows:

sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt install -y boot-repair
Copy the code

After installation, running commands will bring up the interface

boot-repair
Copy the code

Note here to select the advanced option, manually specify a new boot disk, and then repair the boot as prompted.

After the repair, restart the system again, the system has not changed, but the capacity has become a comfortable 184G!

Afterword.

It took me a beautiful Sunday afternoon to step down and a whole night to write the article, but we are coder. We learned a lot of hard disk related hardware and Linux knowledge, and finally upgraded successfully, just like a lot of trouble ~~

Finally, the gear is beefed up, and you’re happy to write code again. Go!