Pacman ipuçları
| Özet |
|---|
| Pacman' ı yeni kullananlar için ipuçlarını veren bir yazıdır.
|
| Okuyun: |
| pacman |
| Paket oluşturma
|
Görünüm ve Kullanım Kolaylığı
Renkli Çıktılar
Pacman çıktılarını renklendirmek için en etkili yol Arch Kullanıcı Deposundan pacman-color paketini kurmaktır.
Kısayollar
Aşağıdaki yönergeler, kullanıcıların sık kullanılan pacman komutlarını uzun uzadıya yazmadan kullanmalarını sağlayan bazı lakaplar sunmaktadır.
Kabuğu Yapılandırın
Hem Bash hem de Zhs kabukları ile çalışan örnekleri ekleyin:
alias pacupg='sudo pacman -Syu' # Yerel sistemdeki güncelliğini yitirmiş paketleri yükseltmeden önce depo
# bilgilerini günceller ve yükseltmeyi yapar.
alias pacin='sudo pacman -S' # Belirli paketleri depolardan kurar.
alias pacins='sudo pacman -U' # Belirli paketleri depolardan değil bilgisayardan kurar.
alias pacre='sudo pacman -R' # Paketleri, yapılandırma dosyaları ve bağımlılıklara dokunmadan kaldırır.
alias pacrem='sudo pacman -Rns' # Paketleri, bunların yapılandırma dosyalarını ve bağımlılıklarını kaldırır.
alias pacrep='pacman -Si' # Verilen paketin bilgilerini depolardan sorgulayarak görüntüler.
alias pacreps='pacman -Ss' # Verilen paketleri depolardan sorgular.
alias pacloc='pacman -Qi' # Verilen paketleri yerel veritabanından sorgulayarak bilgilerini görüntüler.
alias paclocs='pacman -Qs' # Paketleri yerel veritabanından sorgular.
# Ek pacman lakap örnekleri
alias pacupd='sudo pacman -Sy && sudo abs' # Depolardan, yerel veritabanını ve ABS ağacını günceller.
alias pacinsd='sudo pacman -S --asdeps' # Paketleri bir başka paketin bağımlılığı olarak kurar
alias pacmir='sudo pacman -Syy' # /etc/pacman.d/mirrorlist dosyasının düzenlenmesinden sonra tüm veritabanlarını
# güncellemeye zorlar.
Yukarıda verilenler Sudo aracının sisteminizde kurulu olmasını ve doğru biçimde yapılandırılmış olmasını gerektirir.
Kullanımı
Komutları, basitçe lakapları kullanarak çalıştırın. Mesela, kurulu bulunan ancak güncelliğini yitirmiş paketleri yükseltmeden önce depo bilgilerini de güncellemek için:
$ pacupg
Depolardan paket kurmak için:
$ pacin <paket1> <paket2> <paket3>
Kendi derlediğiniz bir paketi kurmak için:
$ pacins /paketin/konumu/<paket>
Sistemde kurulu bulunan bir paketi tümden kaldırmak için:
$ pacrem <paket>
Depolarda bulunan paketler arasında aramak için:
$ pacreps <arama sözcükleri>
Depolarda bulunan bir paketin bilgilerini (mesela, boyutu, bağımlılıkları v.b.) görüntülemek için:
$ pacrep <keywords>
Diğer Bilgiler
Yukarıda verilen lakaplar örnek kabilinden verilmiştir. Yukarıdaki örneklerde kullanılan söz dizimini kullanarak arzu ettiğiniz lakapları oluşturabilirsiniz:
alias pacrem='sudo pacman -Rns' alias pacout='sudo pacman -Rns'
Yukarıdaki örnekte pacrem ve pacout lakapları Bash' e aynı komutu çalıştırmasını söyler.
İşlemler ve Bash söz dizimi
Pacman' in standart özelliklerine ek olarak Bash komutları/söz dizimleri yoluyla kullanılabilirliği arttırabilirsiniz.
- İsimlerinde aynı sözcükleri barındıran birden fazla sayıdaki paketi kurmak için - tüm bir gurp veya tüm eşleşen paketler değil; örneğin kde:
pacman -S kde-{applets,theme,tools}
- Elbette ki, bu sınırlı bir işlem değildir ve gereksindiğiniz bir çok seviyeye genişletilebilir:
pacman -S kde-{ui-{kde,kdemod},kdeartwork}
- Bazen,
-sişlecinin dahili süzgeci sorunlar yaratabilir ve bu nedenle sadece paket ismini (açıklaması veya başka bir alan değil) döndürecek şekilde sınırlandırılabilir:
pacman -Ss '^vim-'
- Pacman, sürüm sütununu gizlemek üzere
-qişlecini kullanır. Bu şekilde mesela isminin bir kısmında "compiz" olan ve sistemde kurulu bulunan tüm paketleri sorgulamak ve yeniden kurmak için:
pacman -S $(pacman -Qq | grep compiz)
Bakım
Sistemi temiz tutmak ve Arch Tarzını korumak için sistem bakımı
Paket önbelleğini temizlemek için CacheClean kullanımı
CacheClean, /var/cache/pacman/pkg dizinini temizleyen ve bunu yaparken geride aynı paketin kaç sürümünün bırakılacağını size soran bir Python betiğidir. [1]
Bu betik için oluşturulan Cacheclean paketini Arch Kullanıcı Deposundan kurabilirsiniz.
Kurulu tüm paketleri boyutlarıyla birlikte listelemek
- Kurulu tüm paketleri, sabit diskinizde yer açmak için boyutuna göre sıralanmış biçimde listelemek isteyebilirsiniz:
pacman -Qi | awk '/^Name/ {pkg=$3} /Size/ {print $4$5,pkg}' | sort -n
-
pacman-contribpaketindenpacsyscleanaracını kullanabilirsiniz. - expac paketini kurduktan sonra
expac -s "%-30n %m"komutunu çalıştırabilirsiniz. - [community] deposundan kuracağınız pacgraph paketi içindeki
pacgraphkomutunu -c seçeneği ile çalıştırarak kurulu olan tüm paketleri sistemdeki boyutları ile birlikte listeleyebilirsiniz.
Her hangi bir pakete ait olmayan dosyaları belirlemek
Pacman veritabanı dışındaki dosyaların düzenli olarak denetlenmesi önerilmektedir. Bu dosyalar genellikle geleneksel kurulum yöntemi ile (mesela ./configure && make && make install) kurulan 3. şahıs uygulamalarınca sisteme yerleştirilmektedir. Şu basit betiği kullanarak dosya sistemini bu dosyalar (veya symlinkler) için araştırın:
#!/bin/sh tmp=${TMPDIR-/tmp}/pacman-disowned-$UID-$$ db=$tmp/db fs=$tmp/fs mkdir "$tmp" trap 'rm -rf "$tmp"' EXIT pacman -Qlq | sort -u > "$db" find /bin /etc /lib /sbin /usr \ ! -name lost+found \ \( -type d -printf '%p/\n' -o -print \) | sort > "$fs" comm -23 "$fs" "$db"
Listeyi üretmek için:
$ pacman-disowned > non-db.txt
Öksüz paketleri kaldırmak
Öksüz paketleri yinelemeli olarak kaldırmak için:
# pacman -Rs $(pacman -Qtdq)
Aşağıdaki fonksiyon kolayca $HOME/.bashrc dosyasına eklenebilir ve öksüz paketler bulunduğunda bunları kaldırır:
orphans() { if [[ ! -n $(pacman -Qdt) ]]; then echo no orphans to remove else sudo pacman -Rs $(pacman -Qdtq) fi }
Yukarıdaki fonksiyon Sudo aracının sisteminizde kurulu olmasını ve doğru biçimde yapılandırılmış olmasını gerektirir.
base paket grubu haricindeki tüm paketleri kaldırmak
Base paket grubu dışındaki tüm paketleri kaldırmanız zorunluysa şu tek satırlık kodu çalıştırın:
# pacman -Rs $(comm -23 <(pacman -Qeq|sort) <((for i in $(pacman -Qqg base); do pactree -ul $i; done)|sort -u|cut -d ' ' -f 1))
Kaynak: Arch Linux Forum başlığı
Notlar:
-
commsıralanmış girdi gerektirir; aksi haldecomm: file 1 is not in sorted orderbenzeri bir hata alırsınız. -
pactreepaket adını ve sunduklarını listeler.
$ pactree -lu logrotate
logrotate popt glibc linux-api-headers tzdata dcron cron bash readline ncurses gzip
'dcron cron' satırı sorunlara yol açabilir bu nedenle sadece paket adını tutmak için cut -d ' ' -f 1 kullanılması gerekmektedir.
Kurulum ve kurtarma
Paketleri edinmek ve kurtarmak için farklı yollar
Paketleri bir CD/DVD/ISO içinden kurmak
- Öncelikle CDROMu sisteme bağlayın (gerekiyorsa cdrom ibaresini dvd ile değiştirin):
# mount /mnt/cdrom
- Bunun yerine bir .iso dosyası ile çalışılıyorsa öncelikle /mnt dizini altında bir dizin oluşturun:
# mkdir /mnt/iso
- Sonrasında imajı bağlayın:
# mount -t iso9660 -o ro,loop /path/to/iso /mnt/iso
- Pacman' i yapılandırın:
# nano -w /etc/pacman.conf
- Aşağıdakini diğer depolardan (extra, core v.b.) önce ekleyin. Bu sayede CD/DVD/ISO üzerindeki dosyaların, depolarda bulunanlardan öncelikli ele alınması sağlanmış olur:
# Bir CDROMu bir depo olarak ayarlamak. [custom] Server = file:///mnt/cdrom/arch/pkg
cdromuygun bir başka ortamla değiştirebilirsiniz.
pacman.conf dosyası düzenlendikten sonra yeni depoyu kullanmak için pacman veritabanlarını güncelleyin (pacman -Sy).
Bir Arch core imajındaki paketleri kullanma
Bir Arch core imajı içindeki paketleri kullanmak için, mesela ağ bağlantısı yokken bir kablosuz ağa bağlanabilmek için, imajdaki core deposunu sisteme bağlayın:
# mount -o loop /path/to/arch_core_image/i686/repo-core-i686.sfs /mnt/iso
Daha sonra /etc/pacman.conf dosyasındaki [core] bölümünü düzenleyin ve (geçici olarak) öntanımlı girdiyi bağlanan imaj bilgisi ile değiştirin:
[core] #Include = /etc/pacman.d/mirrorlist Server = file:///mnt/iso
Sonra da pacman veritabanını güncelleyin:
# pacman -Syu
Custom local repository
pacman 3 introduced a new script named repo-add which makes generating a database for a personal repository much easier. Use repo-add --help for more details on its usage.
Simply store all of the built pakets to be included in the repository in one directory, and execute the following command (where repo is the name of the custom repository):
$ repo-add /path/to/repo.db.tar.gz /path/to/*.pkg.tar.xz
Note that when using repo-add, the database and the pakets do not need to be in the same directory. But when using pacman with that database, they should be together.
To add a new paket (and remove the old if it exists), run:
$ repo-add /path/to/repo.db.tar.gz /path/to/pakettoadd-1.0-1-i686.pkg.tar.xz
Once the local repository has been made, add the repository to pacman.conf. The name of the db.tar.gz file is the repository name. Reference it directly using a file:// url, or access it via FTP using ftp://localhost/path/to/directory.
If willing, add the custom repository to the list of unofficial user repositories, so that the community can benefit from it.
In order to share pakets between multiple computers, simply share /var/cache/pacman/ using any network-based mount protocol. This section shows how to use shfs or sshfs to share a paket cache plus the related library-directories between multiple computers on the same local network. Keep in mind that a network shared cache can be slow depending on the file-system choice, among other factors.
First, install any network-supporting filesystem; for example sshfs, shfs, ftpfs, smbfs or nfs
Then, to share the actual pakets, mount /var/cache/pacman/pkg from the server to /var/cache/pacman/pkg on every client machine.
To have shared paket databases, mount /var/lib/pacman/sync/{core,extra,testing,community} in the same way. Proceed to place the appropriate lines in /etc/fstab.
Preventing unwanted cache purges
By default, pacman -Sc removes paket tarballs from the cache that correspond to pakets that are not installed on the machine the command was issued on. Because pacman cannot predict what pakets are installed on all machines that share the cache, it will end up deleting files that should not be.
To clean up the cache so that only outdated tarballs are deleted, add this entry in the [options] section of /etc/pacman.conf:
CleanMethod = KeepCurrent
Backing up and retrieving a list of installed pakets
It is good practice to keep periodic backups of all pacman-installed pakets. In the event of a system crash which is unrecoverable by other means, pacman can then easily reinstall the very same pakets onto a new installation.
- First, backup the current list of non-local pakets:
$ comm -23 <(pacman -Qeq|sort) <(pacman -Qmq|sort) > pkglist
- Store the pkglist on a USB key or other convenient medium or gist.github.com or evernote or dropbox.
- Copy the pkglist file to the new installation, and navigate to the directory containing it.
- Issue the following command to install from the backup list:
# pacman -S $(< pkglist)
In the case you have a list which was not generated like mentioned above, there may be foreign pakets in it (i.e. pakets not belonging to any repos you have configured, or pakets from the AUR).
In such a case, you may still want to install all available pakets from that list:
# pacman -S --needed $(diff <(cat badpkglist|sort) <(diff <(cat badpkglist|sort) <(pacman -Slq|sort)|grep \<|cut -f2 -d' ')|grep \<|cut -f2 -d' ')
Explanation:
-
pacman -Slqlists all available softwares, but the list is sorted by repository first, hence the sort command - Sorted files are required in order to make the
diffcommand work. - The first diff returns all unavailable pakets; the second all available pakets.
- The
--neededswitch is used to skip already installed pakets.
You may also try to install all unavailable pakets (those not in the repos) from the AUR using yaourt (not recommended unless you know exactly what you are doing):
$ yaourt -S --noconfirm $(diff <(cat badpkglist|sort) <(pacman -Slq|sort) |grep \<|cut -f2 -d' ')
Finally, you may want to remove all the pakets on your system that are not mentioned in the list. Warning: use this command wisely, and always check the result prompted by pacman.
# pacman -Rsu $(diff <(cat badpkglist|sort) <(pacman -Qq|sort) | grep \>|cut -f2 -d' ')
List downloaded pakets that are not in base or base-devel
The following command will list any installed pakets that are not in base/base-devel, and as such were likely installed manually by the user:
comm -23 <(pacman -Qeq|sort) <(pacman -Qgq base base-devel|sort)
Reinstalling all installed pakets
If you mess up your system (rm -rf) you can repair by having pacman reinstall all of your pakets.
If your system does not contain any foreign (AUR) pakets you can run:
# pacman -Qeq | pacman -S - # pacman -Qdq | pacman -S --asdeps -
If you have foreign pakets this will error as pakets will not be found in the repositories. The following will make a list of all pakets and remove the foreign pakets seen with pacman -Qmq. Combining a command to list all pakets, and another to hide the list of foreign pakets is required.
The following will reinstall every paket found in the repositories, preserving asdeps/explicitly installed info:
# comm -23 <(pacman -Qeq|sort) <(pacman -Qmq|sort) | pacman -S - # comm -23 <(pacman -Qdq|sort) <(pacman -Qmq|sort) | pacman -S --asdeps -
Restore pacman's local database
Signs that pacman needs a local database restoration:
pacman -Qgives absolutely no output, andpacman -Syuerroneously reports that the system is up to date.- When trying to install a paket using
pacman -S paketit outputs a list of already satisfied dependencies.
Most likely, pacman's database of installed software, /var/lib/pacman/local, has been corrupted or deleted. While this is a serious problem, it can be restored by following the instructions below.
Firstly, make sure pacman's log file is present:
$ ls /var/log/pacman.log
If it does not exist, it is not possible to continue with this method. You may be able to use Xyne's paket detection script to recreate the database. If not, then the likely solution is to re-install the entire system.
Günlük kaydı süzme betiği
Aşağıdaki içeriğe sahip bir betik oluşturun alıntı: [2]:
#!/bin/awk -f $3 ~ /^(installed|upgraded)$/ { pkg[$4] = 1 next } $3 == "removed" { pkg[$4] = 0 } END { for (i in pkg) if (pkg[i]) print i }
Betiğe çalıştırılabilir izni verin:
$ chmod +x log2pkglist.awk
Generating the paket recovery list
Run the script and pipe the output to a temporary list:
$ ./log2pkglist.awk /var/log/pacman.log > pkglist.orig
Optionally edit pkglist.orig and remove anything that should not be re-installed. This might be the situation with custom pakets made with ABS, for example.
Here is a way to automatically restrict the list to pakets available in a repository:
$ { cat pkglist.orig; pacman -Slq; } | sort | uniq -d > pkglist
Check if some important base paket are missing, and add them to the list:
$ comm -23 <(pacman -Sgq base) pkglist.orig >> pkglist
Proceed once the contents of pkglist are satisfactory, since they will be used it restore pacman's installed paket database; /var/lib/pacman/local/.
Performing the recovery
As a normal user, make temporary directories for the cache, database, and root:
tmp=~/tmp
mkdir -p "${tmp}"
pushd "${tmp}"
dbpath=$(readlink -f ./dbpath)
root=$(readlink -f ./root)
cache=$(readlink -f ./cache)
log=/dev/null
mkdir -p "${dbpath}" "${cache}" "${root}"
popd
recovery-pacman() {
fakeroot pacman "$@" \
--dbpath "${dbpath}" \
--root "${root}" \
--cache "${cache}" \
--log "${log}" \
--noscriptlet \
#
}
Populate the temporary sync database:
$ recovery-pacman -Sy
or copy the system's sync database:
$ cp -r /var/lib/pacman/sync "${dbpath}"
To avoid downloading and/or processing pakets that are present in the system's local database (or whatever remains of it), optionally copy it into the temporary location:
$ cp -r /var/lib/pacman/local "${dbpath}"
Generate the temporary local recovery database from the previously generated pkglist:
$ recovery-pacman -S --nodeps --needed $(< pkglist)
After revising the database, conclude by copying it to the real destination:
# cp -r "${dbpath}"/local /var/lib/pacman
Finally update the local database so that pakets that are not required by any other paket are marked as explicitly installed and the other as dependences. You will need be extra careful in the future when removing pakets, but with the original database lost is the best we can do.
# pacman -D --asdeps $(pacman -Qq) # pacman -D --asexplicit $(pacman -Qtq)
Recovering a USB key from existing install
If you have Arch installed on a USB key and manage to mess it up (e.g. removing it while it is still being written to), then it is possible to re-install all the pakets and hopefully get it back up and working again (assuming USB key is mounted in /newarch)
# pacman -S $(pacman -Qq --dbpath /newarch/var/lib/pacman) --root /newarch --dbpath /newarch/var/lib/pacman
Extracting contents of a .pkg file
The .pkg files ending in .xz are simply tar'ed archives that can be decompressed with:
$ tar -Jxvf paket.tar.xz
If you want to extract a couple of files out of a .pkg file, this would be a way to do it.
Viewing a single file inside a .pkg file
for example, if you want to see the contents of "/etc/conf.d/ntpd.conf" supplied within the ntp paket:
$ tar -xOf /var/cache/pacman/pkg/ntp-4.2.6.p5-6-i686.pkg.tar.xz etc/conf.d/ntpd.conf