How to transfer an existing Arch install onto a new laptop.

Quite recently I realized that I needed  a new laptop because my old one  was in pretty bad shape. It had been through 4 years of constant abuse and as a result it had busted speakers, a faulty touchpad and non-responding keys.

But I faced a daunting task. All of my work over the past one year and a half had gone into the Arch install on my old laptop. How was I supposed to ensure that the whole thing remained as it was on the new laptop? I looked at a few pages on the Arch wiki such as this one here, which dealt with this exact issue. I finally decided that I needed to take this plunge and so I went ahead with that article’s instructions.

Step 1 :

First, I followed this page and backed up my entire root tree onto my external hard disk with the command

# rsync --info=progress2-aAX --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} /* /path/to/backup/folder

The contents of /dev, /proc, /sys, /tmp and /run were excluded because they are populated at boot (while the folders themselves are not created), /lost+found is filesystem-specific. If you are running this on the same folder, you may want to include the –delete option to keep the two folders in sync.

Step 2 :

In your old system, enter the following.

$ pacman -Qqe | grep -vx "$(pacman -Qqm)" > Packages
$ pacman -Qqm > Packages.aur

This creates a list of all installed packages on your system via pacman and also those from the Arch User Repository.

Step 3 :

Next, I installed Arch all over again on the new laptop, following the Beginner’s guide. Edit the pacman mirrors as you deem them fit.

Step 4 :

Plug your external hard disk into the new laptop, mount it and copy the old pacman cache (/var/cache/pacman/pkg) onto the new install. Now, the next command

# xargs -a Packages pacman -S --noconfirm --needed

Was not working for me as just read the existing package names and said it was skipping them as it was already installed. I didn’t figure out why that was exactly, and proceeeded as follows. I made a new list of installed packages on the new system ;

$ pacman -Qqe | grep -vx "$(pacman -Qqm)" > Packages-new

Next, get the old “Packages” file which you made on the old system and now sort the two files.

$ sort Packages-new > 1
$ sort Packages > 2

And finally.

diff 1 2 | grep "\>" | sed -e 's/> //' > final

The file “final” now contains File2 – File1, that is, the list of packages which are not in the new system. Now do the following.

for x in $(cat final); do pacman -S $x --noconfirm; done

Actually, this whole sorting and subtracting thing could have been avoided with an additional flag “–needed” for pacman, but somehow that wasn’t working for me. Hence this. Repeat the same process for AUR packages. If you use yaourt, replace “pacman” by “yaourt” in the last command and feed in the AUR package list.

Step 5 :

Create a non-priviledged user, and make sure you’re able to execute startx as that user. Once you do, X creates an .Xauthority file in the home directory. Preserve that file somehow, say by changing it to .Xauthority-old temporarily. The reason I did this was before, I pulled in everything and it was using the .Xauthority file of the backup when I executed startx. This resulted in a “timeout in locking authority file” error and X wouldn’t start. I did the following for a fix.
Next, pull in your entire home directory from the backup.

rsync --info=progress2 -avh /path/to/backup/home/user /home/user

After this is done, make sure to delete the old .Xauthority file and rename the .Xauthority-old file to .Xauthority. Now startx should work normally.

I found it pretty amazing that in essence, it’s just your home directory and your packages which control your entire system. Even though this might sound a little trivial, it still amazed me when everything worked perfectly finally. I even recovered my open tabs in firefox!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s