How to copy from one disk to another, the best way

If you are migrating, say, your /home directory to a new drive, I found the following commands to be the most useful. We assume you went into gparted or a similar tool and formatted the new drive/partition to ext4.

Step 1: Remount the drive

First, remount the new drive with the most efficient parameters. Here the new drive is an SSD and it’s re-mounted in ‘as fast as possible’ parameters. We assume that /dev/sdc1 is your new drive’s partition and that you wanted to mount it to, say, /newhome

# mount -oremount,defaults,noiversion,auto_da_alloc,noatime,errors=remount-ro,inode_readahead_blks=32,discard /dev/sdc1 /newhome

Step 2: The actual copying of data

Here is the rsync command that I found that was the safest and most useful:

# rsync -axHAXWSv  --numeric-ids --info=progress   --delete-excluded  /home/turgut   /newhome  --delete --ignore-times  --exclude='/home/*/.gvfs'   --exclude='/home/*/.l
ocal/share/Trash'   --exclude='/var/run/*'   --exclude='/var/lock/*'   --exclude='/lib/modules/*/volatile/.mounted'   --exclude='/var/cache/apt/archives/*'   --exclude='/home/*/.mozilla/f
irefox/*/Cache'   --exclude='/home/*/.cache/chromium'

This excludes lots of temporary files, and does a checksum-based comparison of the copied files, should you have to re-run this command a second time — and you know you will 🙂   Because we excluded the access times with the remount command, we need the –checksum parameter. This keeps all symlinks, all access rights, dates, etc, all the same. Handles sparse files efficiently and more.

If the verbosity is too much, exclude the ‘v’ parameter and change the –info=progress to –info=progress2  which will give you an ‘animated’ progress line.

 

How to automatically mount a disk partition to a specific folder

I have an external USB drive that is normally assigned to /dev/sdc1 and mounted at /media2 when the system starts.. But when the laptop is bumped, it disconnects, and then /media2  is unreachable. Furthermore, the system then re-mounts it as  /dev/sdd1  instead of /dev/sdc1 so even if you have a script to remount it manually, it won’t work. Using systemd under Fedora 36, I was able to auto-re-mount it as /media2 even if it’s disconnected an re-connected. Here is how:

1) Find the UUID of the partition.

# blkid

(...)
/dev/sdc1: UUID="daa01b07-430d-40f0-8fa6-4e0a83e856c1" BLOCK_SIZE="4096" TYPE="ext3" PARTLABEL="MYEXTERNAL" PARTUUID="bc2 822f8-6208-1bef-a88f-f2040ba12130"
(...)

 

and note the UUID of your drive partition that you want to auto-mount. It’s the thing that starts with “daa01…”.  We will need this later on.

2) Learn the vendor and product ID’s of your USB drive.

Plug in your USB drive and run this. From the long list, fish out your USB drive’s line:

# lsusb

(....)
Bus 001 Device 009: ID 1f75:0621 Innostor Technology Corporation IS621 SATA Storage Controller
(....)

In my case, the 1f75 is the vendor ID, and 0621 is the product ID.

3) Now create a new UDEV rule — this gets executed when the USB is attached:

edit /etc/udev/rules.d/99-turgut-automount.rules

ACTION=="add",ATTRS{idVendor}=="1f75",ATTRS{idProduct}=="0621",ENV{SYSTEMD_WANTS}="remount-media2.service"

You need to change the idVendor and idProduct to the ones you found in step 2. Likewise you can give it a better filename 🙂 I like to keep my changes obvious so I remember it later on.

4) Write the systemd service

Now create a file like this:

# nano /etc/systemd/system/remount-media2.service

It should contain:

[Unit]
Description=Remount Media2

[Service]
ExecStart=/usr/local/bin/remount-media2
StandardOutput=null

[Install]
WantedBy=multi-user.target
Alias=remount-media2.service

5) Creating the executable

Now we need to create the actual script that will be run every time that USB is added to the system. Replace the UUID you see below to what your drive is..  Mine looks like this, you can change it to anything you like:

# nano /usr/local/bin/remount-media2

#!/bin/bash
echo "Remount-media2 running" >> /var/log/remount-media2.log
umount /dev/sdc1
umount /dev/sdd1
sleep 1
umount -f /dev/sdc1
umount -f /dev/sdd1
sleep 1
mount -o rw,noexec,nosuid,nodev,sync,data=ordered UUID="daa01b07-430d-40f0-8fa6-4e0a83e856c1"  /media2
exit 0

(The whole long mount line is just one line.. It might have wrapped around for you)

Just make this an executable now, like:

# chmod +x /usr/local/bin/remount-media2

Conclusion

That’s it! Now reboot your computer and check the /var/log/remount-media2.log file.. try unplugging your drive and re-plugging it back.. a new line should be added to that log file, and the drive should be remounted to the same path.

 

How to set up Windows 11 without a Microsoft account

To stop Microsoft from asking you to create/use an email address during the setup, (which is irritating and infuriating to say the least):

When it asks you to create/use an email address:

  1. Use the Shift + F10 keyboard shortcut to open Command Prompt.
  2. Type the following command to release the current network configuration and press Enter:ipconfig /release
  3. Close the Command Prompt console.
  4. Click the Back button.
  5. Confirm the name of the local account.
  6. Click the Next button.
  7. Create a password for the account.