Reduce the Risk of RM commands-after accidental deletion of the portage Database

Source: Internet
Author: User

Some time ago, I accidentally deleted the/usr/livecd/folder (# rm-RF/usr/livecd/
), It is actually the location of the portage database (portage database, Gentoo Chinese manual explanation: portage sets the status of your system (which software packages are installed, what files belong to which software packages ......) Save it in/var/DB/PKG. Do not manually change these files! It may damage portage's understanding of your system ).
The consequence is that the emerge fails and the new software cannot be installed (the reason is explained later ). On the Gentoo forum, I found that the same mistake was also made, and the time was much earlier than me (here
). This is the consequence of misuse of root permissions. I have found two solutions:
First, if you install Gentoo from livecd like me, you can use livecd to start the system and copy the DB directory under/usr/livecd/to/var.
Second, use the log file/var/log/emerge. log to restore the portage database. Someone on the Gentoo Forum wrote such a script. You can click here to download it.

After the database is restored, the system should be updated through emerge to restore the records in the database (# emerge -- update -- deep -- newuse System
), It is recommended to use the system keyword, which will be faster; then search for the corresponding missing library and re-emerge the corresponding package (# revdep-Rebuild
). The update system found that Gentoo used the new openrc to manage the configuration file. It took a long time to start the AutoConfig script to automatically configure Portmap and DHCP, so I accidentally deleted the AutoConfig script (# rm/etc/runlevels/default/AutoConfig
), It is much faster after the restart, but cannot enter the X Window, and startx cannot be started. The error message is displayed, to ensure that the AGP module is not loaded, so I manually loaded intel_agp, modprobe intel_agp, run startx again and you can enter X Window, which is a little slow (ER, I have been playing for two days in the command line). This is because OpenGL is not configured, after entering Kde, we found that the sound card and nic were not working properly. lsmod found that the corresponding module was not loaded and loaded (# modprobe sky2, SND-hda-intel
).

 

At this point, I realized the role of AutoConfig, and the introduction of AutoConfig in Google Project is indeed the same (the livecd-Tools Package is a simple set of tools used to perform
Auto-detection
On a Gentoo Linux (or Gentoo-based) livecd, fig
With
Catalyst .)

The root cause is that I copied and installed Gentoo from livecd, so/var/DB/is actually a soft link of/usr/livecd/DB, deleting the/usr/livecd directory naturally causes portage to crash. Similarly, livecd needs to be able to run on different hardware, so all hardware will be scanned each time it is started by default, use the AutoConfig script to configure the modules to be loaded. Therefore, Linux can enable 10 s of boot, on the premise that you have to selectively compile the kernel, load modules, and remove unnecessary scripts based on hardware information. Gentoo is actually so advocate (it is not recommended to use the genkernel command ..)

How can I reduce the risk of RM commands? Although data recovery software (such as mondo rescue, testdisk, safecopy, photorec, and ddrescue) is available in Linux, it is inconvenient to use. Even if you do not use root users for logon, you still need to know the root password, which can be deleted, and the prompt permission denied will be displayed, which is very troublesome. I think of two methods. The first is regular backup of the system...
Method 2: Use the trash folder, the recycle bin of KDE. Delete files in the KDE environment. By default, files are moved to trash ($ home/. Local/share/trash
If you execute RM in konsole, you can also move the file to be deleted to trash, which reduces the risk of RM commands. Trash is automatically cleared after a period of time (for example, 7 days. How can this problem be achieved? In fact, bash provides the alias mechanism to make it easier to use commands.
Open. bashrc and add the following lines:
# Useful aliases
Alias Rm = "/root/RM. Sh"

Create RM. Sh in the root directory and add the following lines:
#! /Bin/bash
Kioclient move $1 trash :/

If you want to manually clear trash, you can use ktrash -- empty
Command, also use ktrash -- Restore in principle
Command. (In addition, the directory can be moved to the recycle bin without adding the-R parameter)

Of course, this is in the KDE environment, and kioclien and ktrash commands are used. However, the principle is the same, and the effect can be achieved without the KDE environment: replace kioclient move with the MV command, you can customize a trash directory (such as/var/trash), define a Cron scheduled task, and regularly delete files in the trash Directory, which can also achieve the recycle bin effect. It usually takes a long time to delete files by mistake. Using this "Custom" RM command can reduce the risks, but it may also cause inconvenience. There are both advantages and disadvantages.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.