How do I forcefully unmount a Linux disk partition?

It happens many times you try to unmount a disk partition or mounted CD/DVD disk and if you try to unmount device, which is accessed by other users, then you will get error umount: /xxx: device is busy.

What happens basically, is that Linux / UNIX will not allow you to unmount a device that is busy. There are many reasons for this (such as program accessing partition or open file) ,but the most important one is to prevent data loss.

1 the first method

Try the following command to find out what processes have activities on the device/partition. If your device name is /dev/sdb1, enter the following command as root user:

# lsof | grep '/dev/sda1' 
Output: vi 4453 vivek 3u BLK 8,1 8167 /dev/sda1

Above output tells that user vivek has a vi process running that is using /dev/sda1. All you have to do is stop vi process and run umount again. As soon as that program terminates its task, the device will no longer be busy and you can unmount it with the following command:

# kill 4453
# umount /dev/sda1

 2 the second method

Linux fuser command to forcefully unmount a disk partition

Suppose you have /dev/sda1 mounted on /mnt directory then you can use fuser command as follows:Type the command to unmount /mnt forcefully:

# fuser -km /mnt 

Where, 
    -k : Kill processes accessing the file. 
    -m : Name specifies a file on a mounted file system or a block 
device that is mounted. In above example you are using /mnt

 3 the third method

# umount -l /mnt

Where,
    -l : Also known as Lazy unmount. Detach the filesystem from 
the filesystem hierarchy now, and cleanup all references to the 
filesystem as soon as it is not busy anymore. This option works 
with kernel version 2.4.11+ and above only.

4 the fourth method

# umount -f /mnt

Where,

    -f: Force unmount in case of an unreachable NFS system

Caution: Using these commands or option can cause data loss for open files;      programs which access files after the file system has been unmounted will get an error.

关于amd64和ia64的理解

现在买的PC或者服务器都有64位的机器,而有时我们安装系统,不管是Windows还是Linux系统,要发挥机器的最高性能,必须也要安装64位的OS,否则,就达不到最好的性能。

比如:32位操作系统,配合32位CPU,寻址空间位2^32次方,计算出来是4294967296字节,就是4G,32位系统最大支持4G空间,如果想要32位

系统支持4G以上空间的话,就要用PAE的特殊内核,采用特殊方式访问,但是系统效率会比原生的64位系统低。当然有时有的Linux只能识别到3G多,因为据说是当初在设计上的缺陷。这里不做详解。

而64位操作系统配合64位CPU,寻址空间是2^64次方,计算出来是18446744073709551616字节,换算一下4G个G,太大了,反正是N多G,一辈子也用不完。当然这是64位系统的理论最大内存支持,实际上谁也用不了这么大内存.

等等…

因此我们要下载64的操作系统,而我们看到有64的操作系统最经常见到的有ia64/amd64,它们如何区分呢,哪些CPU是属于AMD64,哪些是属于IA64呢?

其实很多人从字面上,都以为AMD64就是针对AMD CPU的,IA64是针对INTEL CPU,其实是错的,我最初也是这样认为,其实不然:

你在市面上买的到的intel 64位 CPU都属于amd64范畴这个架构应该称为 x86_64,因此不管是AMD的64位CPU,还是INTEL的64位CPU,都是属于AMD64范畴.

而IA64指的是Intel安腾系列CPU,不是X86架构的。ia64主要用在服务器上面,而不是我们平常使用的桌面,通常这些cpu很贵,相关的内存以及硬盘同样很贵!

因此你以后你PC的CPU是64位的[有Intel,也有AMD],非安腾的CPU的话,你就下载AMD64的OS进行安装即可.

使用inode来重命名或删除文件

最近通过服务器下载了一部电影,存放在服务器的家目录下。但是电影的文件名是乱码,表现为一大堆乱码和无意义字符。无法通过文件名来对文件名进行重命名,删除和复制。面对这种情况,解决方法为:

1 首先通过命令查看该文件的inode。

#ls -ilh

 2 通过命令来对文件进行重命名或删除。

例如,我下载的电影原本名称为《龙门飞甲.rmvb》,但下载下来后名称为乱码《???ŷɼ?(?????ſ?ջ)HD??????????????.rmvb》,其inode号码为7077900。

#mv -i `find . -maxdepth 1 -inum 7077900 -print` 龙门飞甲.rmvb。
#rm -i `find . -maxdepth 1 -inum 7077900 -print`

 

递归更改目录权限为775,常规文件权限为644

在windows系统上copy文件到linux系统上后,肯定是权限放到了最大了,全部为777的权限。当然,肯定要限制权限了。我们的目的是要把目录权限全部设定为775,文件权限全部设定为664。这两者被设定的权限不一致,应以如下方式解决。

$chmod 775 -R the_file_you_just_coped/

#-R的参数表示递归处理,将所有的文件目录和文件都设为775的权限。

$find the_file_you_just_coped/ -type f -exec chmod a-x {} \;

#-type参数表示查找文件类型,f代表一般正规文件;-exec参数表示对查找结果进行其它命令处理,在此对查找结果进行的处理是chmod a-x {},即删除x权限;\;是必须带的。

CentOS系统的安装

CentOS系统的安装。

#本说明书版本v2012.1.14.002。

#选择安装CentOS6.2 64位系统。

#该系统的安装文件为DVD文件,其中DVD1为主安装文件,DVD2为软件盘。安装过程中只使用
DVD1即可。

1 在官网上选择镜像站点,下载DVD文件。

2 在Windows系统下通过UltraISO软件和刻录机将DVD1刻录到DVD盘上。

#该系统无法使用U盘安装,使用DVD光驱安装是最简便的方法了。

3 使用DVD光驱按提示安装系统。

4 下载r8168网卡驱动并安装。

系统自带的驱动为r8169,在此驱动下网络的丢包率高达50%,因此在远程操作服务器时会卡的
不行。驱动下载地址为ftp://WebUser:AxPL9s3k@95.130.192.218/cn/nic/r8168-
8.027.00.tar.bz2。解压驱动包,在root权限下运行驱动包里面的autorun.sh文件即可
自动安装驱动。
介绍几个网络相关命令:
#lspci    用于查看pci设备,可以看到网卡的型号。
#ethtool -i eth0    用于查看网卡eth0的驱动。
#lsmod    用于查看所安装的驱动。

5 在联网下进行系统更新。

6 安装rpmforge来扩增套件来源。

根据使用的Unix版本到http://pkgs.repoforge.org/rpmforge-release/自行下载
相应的rpm包并安装。

7 通过yum命令安装常规程序。

常用的程序以及安装命令分别如下。
#sudo yum install 
gcc gcc-c++ gcc-gfortran  readline-devel libXt-devel    #安装R语言所需要的。
kernel-devel kernel-headers kernel    #安装显卡驱动所需要。
ffmpeg git yasm    #安装mplayer所需要的。
fuse-sshfs    #使用sshfs来进行ssh远程文件系统的挂载。
gstreamer-plugins-ugly gstreamer-plugins-bad gstreamer-ffmpeg #rhythmbox播放mp3格式解码所必须的。
libGL.so.1 libXmu.so.6 libXrender.so.1 libstdc++.so.5	#安装cinema5软件所需。
sharutils	#编码压缩打包--uudecode。
expat-devel	#安装perl模块XML::Parser所需,该模块为iprscan软件所需。
screen

8 安装ntfs-3g,用于挂载文件系统为ntfs的磁盘。

源码包的下载页面为http://www.tuxera.com/community/ntfs-3g-download/。

9 下载最新稳定版perl源码包并安装。

源码包下载页面为http://www.perl.org/get.html。

10 下载bioperl源码包并安装。

源码包的下载页面为http://bioperl.org/DIST/。
Bioperl的安装可以参考:
http://www.hzaumycology.com/chenlianfu_blog/?p=11

11 下载Adobe Flash Player并安装。

源码包下载页面为http://get.adobe.com/flashplayer/。

12 下载ClustalW2并安装。

源码包下载页面为ftp://ftp.ebi.ac.uk/pub/software/clustalw2/。

13 下载R源码包并安装。

源码包下载页面为http://mirrors.ustc.edu.cn/CRAN/。

14 下载mplayer源码包并安装。

源码包下载页面为http://www.mplayerhq.hu/design7/dload.html。
要是遇到播放视频有声音没画面,出现“"Can't open /dev/fb0: "这样的错误提示。
则进行如下操作
#yum install gtk+****devel zlib****devel;
#yum install *x11*;
然后再重新编译安装mplayer就好啦。

15 下载显卡驱动并安装。

****************************************************************************
安装命令:
#sh NVIDIA-Linux-x86-XXXX.-pkg1.run -k $(uname -r)

在安装结束时,它会询问是否由安装程序自动生成新的xorg.conf文件,建议选“YES”。若出现X Window无法启动等问题,将/etc/X11/xorg.conf.backup恢复即可。

安装过程中可能会出现的错误:

    ERROR: Unable to find the kernel source tree for the currently running kernel.
    Please make sure you have installed the kernel source files for your
    kernel and that they are properly configured; on Red Hat Linux systems, cant.t
    for example, be sure you have the ‘kernel-source’ RPM installed. If you
    know the correct kernel source files are installed, you may specify the
    kernel source path with the ‘–kernel-source-path’ command line option.

如果出现这个错误,则说明引用了错误的kernel source,可以在安装命令后添加参数指定。
#sh NVIDIA-Linux-x86-1.0-9755-pkg1.run --kernel-source-path=/usr/src/kernels/2.6.18-1.2798.fc6-i686

原因在于nvidia installer默认会去/lib/modules/2.6.18-1.2798.fc6/build寻找核源码,而该链接指向/usr/src /kernels/2.6.18-1.2798.fc6-i586,正确应为/usr/src/kernels/2.6.18-1.2798.fc6- i686。

    ERROR:
    Unable to load the kernel module ‘nvidia.ko’. This happens most frequently when this kernel was built against the wrong or improperly configured kernel sources, with a version of gcc that differs from the one used to build the kernel target, or if a driver such as rivafb/nvidiafb is present and prevents the NVIDIA kernel module from obtaining ownership of the NVIDIA graphics device(s).

则是因为没有指明所要安装的内核版本,即需要添加参数“-k $(uname -r)”。
****************************************************************************

 

Bioperl安装

1 更新CPAN

>perl -MCPAN -e shell
cpan>install Bundle::CPAN
cpan>q

修改CPAN源

perl -p -i -e "s#urllist.*#urllist' => [q[http://mirrors.aliyun.com/CPAN/], q[http://mirrors.163.com/CPAN/]],#" /usr/share/perl5/CPAN/Config.pm

2 安装/更新 Module::Build,并设置为默认的安装工具

>cpan
cpan>install Module::Build
cpan>o conf prefer_installer MB
cpan>o conf commit
cpan>q

3 安装expat library

>cpan
cpan>o conf makepl_arg "EXPATLIBPATH=/non-standard/lib EXPATINCPATH=/non-standard/include"
cpan>o conf commit

4 使用最简易的方法安装bioperl

1.到http://www.bioperl.org/wiki/Getting_BioPerl下载最新的源码包

$ wget -c http://bioperl.org/DIST/BioPerl-1.6.1.tar.bz2

2.解压缩文件,并改变目录到解压缩的文件夹中

$ tar jxvf BioPerl-1.6.1.tar.bz2
$ cd BioPerl-1.6.1

3.安装bioperl

>perl Build.PL
>./Build test
>./Build install (需要在perl5/site_perl/source中有写权限)

5 使用CPAN shell来安装BioPerl

1.打开cpan

>perl -MCPAN -e shell
>cpan

2.查看安装的BioPerl版本很文件

cpan>d /bioperl/

3. 安装BioPerl

cpan>install C/CJ/CJFIELDS/BioPerl-1.6.1.tar.gz
cpan>force install C/CJ/CJFIELDS/BioPerl-1.6.1.tar.gz (强制安装)

6 编译安装

perl Makefile.PL # makes the system specific makefile
make # builds all the libaries
make test # runs a short test
make install # installs the package correctly.