⑴ linux伺服器下誤刪除文件的解決方法
伺服器誤刪了/usr/bin和/usr/sbin目錄,然後,從別的地方拷貝這兩個目錄過來,發現可能很多是鏈接等非普通文件,可拷貝的時候對鏈接的處理不知道應加什麼參數,所以,一百多兆的東西拷貝了近一個G;最後,先給tar了一下,在拷貝。
這樣,伺服器基本弄好,建議:
1.不要直接用root登入,特別是不熟悉的人。
2.建議需要執行root許可權命令的使用sudo,少用su;
3.可用visudo來配置需要執行的root許可權命令
eg: xxx ALL=/sbin/mount,/sbin/unmount,/sbin/ifconfig NOPASSWD: ALL
rm命令不行;但是,還有「後遺症」:
1.登入時,'linux': unknown terminal type;
2.使用top, clear (知道的)時, 因為 terminal type問題;
3.vim也是類似問題,不可操作;已解決,但只能用基本模式;
4.tftp、telnet服務,已解決。
⑵ 我在linux下敲了一條 mv*的命令,結果文件夾(比如usr,bin等等)全都不見了,該怎麼恢復
你在那個路徑,用ls -a 查看所有文件, 應該有個隱藏文件夾,文件應該都在裡面。直接mv出來就可以了,你用mv * 意思是把本文件的所有文件放到最後一個文件夾中。
⑶ 在linux系統下用rm命令誤刪了一個文件,怎樣才能恢復這個文件
1、先要進行重啟ubuntu,隨即長按shirft進入grub菜單,這時候注意的是再進行選擇recovery mode,按"e"鍵進入編輯頁面,如下圖所示。
⑷ linux誤刪/bin目錄怎麼辦
解決思路:
1、找一台操作系統環境相同的機器,拷貝目錄到該機器。
2、估計的重新安裝內核,因為找不到內核映射了。
詳細解決步驟如下:
1、重新啟動機器,插入光碟,進入帶網路環境的救援模式。
2、把另外一個系統的bin目錄的壓縮包拷貝過來,然後解壓。
3、因為系統內核丟失了,所以我們需要先安裝內核,在安裝內亂漏明核時會自動生成initrd
a、cd /mnt/
b、mkdir cd
c、mount -t iso9660 -o ro /dev/hda /mnt/cd/ (注意,使用dmesg命令詳細查看光碟機掛載的設備,我的是/dev/hda)
d、rpm -Uvh --force kernel-2.6.18-164.el5.i686.rpm
4、安裝grub
a、grup-install /dev/sda
5、編輯grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda7
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-164.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-164.el5 ro root=LABEL=/dev/VolGroup00/LogVol00 rhgb quiet
initrd /initrd-2.6.18-164.el5.img
注意搜核,如果你是邏輯卷需要修改根目錄的標簽,我的是邏輯卷。
6,重新啟動系統
重新啟動系統未成功,出現以下錯誤:
mount: could not find filesystem '/dev/root'
setuproot: moving /嘩告dev failed: No such file or directory
setuproot: error mounting /proc: No such file or directory
setuproot: error mounting /sys: No such file or directory
switchroot: mount failed: No such file or directory
Kernel panic - not syncing: Attempted to kill init!
經過搜索後,發現此類問題多集中在邏輯卷管理的情況,具體原因是我們在重新安裝內核的時候,沒有載入一些邏輯卷,解決方法如下:
1) Boot with the rescue CD
2) Type 'chroot /mnt/sysimage'
3) 'cd /boot'
4) 'mkdir newinit'
5) 'cd newinit'
6) 'gunzip -c ../initrd-2.6.18-164.el5.img | cpio -idmv'
7) 'vi init'
8) Find 'mount /sysroot'
9) Delete or comment this out
10) Replace with 'mount -o defaults --ro -t ext3 /dev/VolGroup00/LogVol00 /sysroot' where /dev/VolGroup00/LogVol00 is the mount point for /
11) ':wq' out of vi
12) 'find . | cpio --quiet -c -o >../newinitrd'
13) 'cd ..' - you are now in /boot
14) 'mv initrd-2.6.18-164.el5.img initrd-2.6.18-164.el5.img.bak' - backup current initrd img file
15) 'gzip -9 < newinitrd > initrd-2.6.18-164.el5.img'
16) Reboot the computer without the CD
再次重新啟動系統,OK,問題解決。
7、嘗試進行遠程連接,因為遠程伺服器不允許root直接連接,可以用普通用戶進行登錄,登錄後執行 su - root 命令,輸入密碼總是提示密碼錯誤,但是在終端直接用root是可以登錄的,奇怪,後來發現問題出在 su 命令上,是文件許可權粘貼位的問題,因為拷貝過來的su命令許可權如下:
[root@localhost ~]# ll /bin/su
-rwxr-xr-x 1 root root 23960 Oct 18 21:46 /bin/su
正確如下:
[root@localhost ~]# ll /bin/su
-rwsr-xr-x 1 root root 23960 Oct 18 21:46 /bin/su
這樣就簡單了,設置粘貼位如下:
[root@localhost ~]# chmod u+s mount
除了su命令外,還有另外幾個需要設置粘貼位,mount,ping,ping6,traceroute,traceroute6,umount。
另外還要注意一些軟連接。