Hardware recognition
UAS computer protocol is blacklisted on Linux Mint 20.1 by default, and exactly this one is required for most of M2 NVMe SSD to be mounted in your system.
If it’s true for your system, please check with
$ sudo grep uas /etc/modprobe.d/*
/etc/modprobe.d/blacklist-uas.conf:blacklist uas
In my case it was true and UAS was blacklisted.
If it’s true for you, open the file above and comment the line and reboot system.
# cat /etc/modprobe.d/blacklist-uas.conf
#blacklist uas
Hardware connection
I plugged my new NVMe SSD (1Tb) with USB-SSD adapter to my Linux Mint. Now I’m gonna check if the system recognise it:
Keep in mind: It’s depends on your SSD Enclosure type which type of device Linux recognise.
I used ASUS ROG Strix Arion SSD Enclosure and my M2 NVMe SSD was recognised assdX
, but when I finished migration and install this device in my laptop it was recognised asnvmeX
device.
$ dmesg | grep sd[a-z] # assuming SATA
or
$ sudo fdisk -l | grep '^Disk /dev/' | egrep -v '/dev/(loop|mapper|md)'
or if you want a bit readable description
$ sudo lshw -short -C disk
Note. It’s important to figure out correct disc otherwise you will just wipe out your data.
In my case it was SSD device /dev/sda
.
Partitioning and file system creation
This step you can make with fdisk
and mkfs
, but if you have gparted
installed I recommend to use it.
$ sudo gparted /dev/sda # replace "sda" with your recognized hardware
First, you have to create partition table. In gparted
in the top menu select Device – Create Partition Table…. I recommend single ext4
on gpt
, so select gpt
and Apply.
The next partitions structure is recommended in most cases, otherwise if you’re advanced Linux user and know what to do:
/boot
– in a manual partitioning set up one must include at least 35mb EFI boot partition for thegrub
and other boot data to go into./root
– a Linux Mint operating system takes about 15GB and grows as you install additional software. If you can spare the size, give it 100GB (or more if you use Docker containers). Keep most of your free space for thehome
partition./home
– directory where all files such as projects, media will be placed. User data (downloads, videos, pictures) takes a lot more space./swap
– this partition is used for hibernation and as a safety buffer in case your computer runs out of RAM. Give this partition a size equal to the amount of RAM in your computer.
Note: On internet it’s recommended don’t create separate
/boot
partition, Firstly I tried without it and got stack, so I was forced to start from the beginning but at this time with this partition included.
Until the recommended filesystem for Linux is ext4
(Aug 2021), due to its implemented ATA Trim features. You can check your SSD for ATA Trim support with hdparm
:
$ sudo hdparm -I /dev/sda | grep TRIM
* Data Set Management TRIM supported (limit 16 blocks)
* Deterministic read ZEROs after TRIM
I’ve got the next partitions on my 1 Tb SSD:
- Partition #1 –
fat32, 525.00 MiB - /boot/efi
- Partition #2 –
ext4, 186.78 GiB - /
- Partition #3 –
ext4, 712.98 GiB - /home
- Partition #4 –
linux-swap, 31.76 GiB - /swap
$ sudo fdisk -l /dev/sda
Disk /dev/sda: 931,53 GiB, 1000204886016 bytes
[...]
Device Start End Sectors Size Type
/dev/sda1 2048 1077247 1075200 525M EFI System
/dev/sda2 1077248 391702527 390625280 186,3G Linux filesystem
/dev/sda3 391702528 1886926847 1495224320 713G Linux filesystem
/dev/sda4 1886926848 1953523711 66596864 31,8G Linux swap
Mounting the SSD
Now we can now "mount" the device with this command:
$ sudo mkdir /mnt/ssd
$ sudo mount /dev/sda2 /mnt/ssd/
Initial data sync
Before an initial sync, I recommend to do some cleanup work.
This may include deleting unnecessary files, folders, test-, temp- or cache files.
In my case, I had to remove some "bind" mounts from other file systems.
rsync
is the tool of my choice to sync data from a running Linux system to the SSD NVMe.
Recommendation:
- It is important to exclude some system folders. I do
rsync
with the-a
(archive mode) and the-P
(--partial --progress
) option, my running root as source and/mnt/ssd/
as destination. - To avoid having to exclude mounted filesystems, I used
sudo rsync -a -x / /mnt/ssd
. The-x
flag means that mount points will be created for proc, dev etc. but the actual contents of the mounted filesystems will not be copied. - Use absolute path in
--exclude /tmp --exclude /proc
etc. If you do it with a relative path (without/
at the beginning),/var/tmp
will be excluded as well, after the clone this is being missed bysystemd-resolved.service
resulting in name-resolution not working; the option--exclude "sys"
excludes all paths withsys
like/usr/local/go/src/cmd/vendor/golang.org/x/sys/unix/str.go
, etc.
I ended up with the next command:
$ sudo rsync -axP --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/usr/tmp/*","/mnt/*","/media/*","/lost+found","/run/*","/cdrom/*"} / /mnt/ssd/
This can take a while, depending on SDD size and performance.
I transfered approximatly 80GB.
### Create system directories
$ mkdir /mnt/ssd/{sys,proc,dev,tmp,media,mnt,run}
Prepare new /etc/fstab
This part is really important and sensitive, you have to build your new /etc/fstab
(actually it is /mnt/ssd/etc/fstab
) file with /dev/sdX entries or you can use universally unique identifiers (UUIDs).
I decided to use UUIDs – a more robust way to name devices, that works even if disks are added and removed. See fstab(5).
To get your new UUIDs from your SSD, you can do the following:
$ sudo blkid /dev/sda1 # for boot partition
$ sudo blkid /dev/sda2 # for root partition
$ sudo blkid /dev/sda3 # for home partition
$ sudo blkid /dev/sda4 # for swap
It is recommended to modify the mount options for SSDs.
It is also recommended to disable read-logging by append the options noatime
and nodiratime
. Just do not forget to omit discard
option – TRIM is implemented via cron since Ubuntu 14.04.
Important: Check matching of
UUID
to partition twice, otherwise you risk to get unbootable system.
My /etc/fstab
looks like this:
$ head /etc/fstab
# file system mount point type options dump pass
#proc /proc proc nodev,noexec,nosuid 0 0
UUID=BBC0-1A0F /boot/efi vfat umask=0077 0 1
UUID=c4331566-5478-4ab1-a297-af0a632e0c3d / ext4 noatime,nodiratime,errors=remount-ro 0 1
UUID=5c799832-769b-48da-97a7-0d21ef1b1da7 /home ext4 defaults 0 2
UUID=6832087c-3030-4f8b-afae-0e12ffd4fb9f none swap sw 0 0
In a next step, some system directories have to be mounted:
$ sudo mount -o bind /dev/ /mnt/ssd/dev
$ sudo mount -o bind /sys/ /mnt/ssd/sys
$ sudo mount -o bind /proc/ /mnt/ssd/proc
Because we want to install Grub on the SSD NWMe, we have to mount ESP. The ESP is normally a FAT partition with the "boot flag" set.
Now you should mount yours:
$ sudo mount /dev/sda1 /mnt/ssd/boot/efi
~~Because we want to install Grub on the SSD, we have to provide an up-to-date /etc/mtab file:
$ sudo cp /proc/mounts /mnt/ssd/etc/mtab~~
The next step is very usual for Gentoo Linux user, because they need it for installing a Gentoo base system – also Unix/Linux veterans will know about it. Modern Ubuntu users are likely not very familiar with this process.
Enter the new system on the SSD by doing a change root command:
$ sudo chroot /mnt/ssd /bin/bash
Now Grub should be installed on the SSD:
$ grub-install /dev/sda
$ grub-install --recheck /dev/sda # only in case of errors in the step before
$ update-grub
It’s done! With Ctrl-D the chroot
environment can be left now.
Migrate /home directory
Actually, this step isn’t required in the general workflow and you can make it later but I prefer to complete the task at once.
It’s expected you want to migrate /home
directory too. Follow the next steps.
Check partition on which your /home
directory is:
$ sudo fdisk -l /dev/sda
Create temp directory and mount your home partition:
$ sudo mkdir /mnt/home
$ sudo mount /dev/sda3 /mnt/home/
And last but not least, copy your file from old SSD to new NVMe SSD:
$ sudo rsync -aXP /home/. /mnt/home/.
Finally stop your system, install your SSD in your computer and modify your BIOS (change boot order) to boot from your SSD.
Voila! Now, drink a milk and enjoy your new system!!