Add a new repo using the console

Hi

Sometimes, it can happen that you just have to rely on a TTY. At that precise moment, you may have to add a new repo in your /etc/pacman.d/mirrorlist.

You can do it this way:

# echo "## Worldwide
Server = http://mirrors.evowise.com/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist

This almost succeeded, but it failed to add the final $arch of the copied text. Anyone can do better?

First off, your command would be assigning

http://mirrors.evowise.com/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist 

to a variable named Server.

The only way to add a mirror to the mirrorlist would be to use either vi or nano to edit the /etc/pacman.d/mirrorlist file. As root or using sudo, edit /etc/pacman.d/mirrorlist and add

Server = http://mirrors.evowise.com/archlinux/$repo/os/$arch" >> /etc/pacman.d/mirrorlist

to the top of the mirror list. Pacman reads the mirrorlist from top to bottom, so whatever uncommented mirror appears first will be used, unless it fails, then the next mirror will be selected. Even if your command worked, the >> would append the entry to the end of the mirrorlist so it would be the last mirror tried if everything on top of it failed.

You could use printf to write your mirror’s URL to the mirrorlist, but redirecting with > would erase the existing mirrorlist, then write your new mirror’s URL. If you redirected with >> it would append the new URL to the end of the file. Neither of which I would recommend.

Be sure to make a copy of your current mirrorlist before playing around with it.

# cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist-bkup

Pudge

EDIT:
You could write the new mirror’s URL to the beginning of /etc/pacman.d/mirrorlist used sed. However, this situation is not going to come up very often, so editing the mirrorlist file would be easier and faster than trying to remember a sed command.

1 Like

@Pudge

Thank you for your detailed explanation. Yes this situation is just going to happen when you are left only with a TTY and an otherwise black screen. Unluckily, it happened to me some weeks ago. I tried to save myself by installing linux-lts (now, I have it installed), but my mirrorlist was not adequate. You know troubles come in swarms (“les emmerdements volent en escadrille”)

That’s why I was trying to use not nano but the terminal with the echo command which seems to be useful in this case. I took as an example the “world” server given by Arch. I just failed to copy the $arch part, maybe I should have escaped the $?

I understand that my copied text will be appended at the end of the file. Not very efficient for sure and that another way would be to destroy and then recreate the mirrorlist. For brave hearts only…

after googling a while, I found the answer:

  1. the dollar sign should have been escaped with a backward slash: $arch (not shown here)

  2. using a single output > creates a new file or append the text on top of the existing file (not checked…)

  3. using a double output >> appends the copied text at the end of the existing file

1 Like

Use single quotes instead to prevent bash from interpreting $:

# echo '## Worldwide
Server = http://mirrors.evowise.com/archlinux/$repo/os/$arch' >> /etc/pacman.d/mirrorlist

Also, as @Pudge said, the mirror you want to use should be the first in the list.

To make this mirror the only one, use single > instead of >>.

3 Likes

Thank you Manuel and Pudge.

1 Like