linux下新增一個磁盤需要先掛載,然後才能使用,以下是日常使用掛載的場景,簡單總結使用方法,實驗環境均爲虛擬機:
一、掛載新增硬盤
新增硬盤分區格式化後就可以掛載使用了。我們可以通過命令:fdisk -l查看新增加的分區:
[root@localhost /]# fdisk -l Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0006dc39 Device Boot Start End Blocks Id System /dev/sda1 * 1 26 204800 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 26 281 2048000 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 281 2611 18717696 83 Linux Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xdff11876 Device Boot Start End Blocks Id System /dev/sdb1 1 132 1060258+ 83 Linux /dev/sdb2 133 394 2104515 83 Linux /dev/sdb3 395 787 3156772+ 83 Linux Disk /dev/mapper/vgdata-lvdata1: 3221 MB, 3221225472 bytes 255 heads, 63 sectors/track, 391 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
這裏是虛擬機,添加了兩塊硬盤,其中sdb是新增的。掛載方法如下:
[root@localhost /]# mount /dev/sdb1 /wangchengjun/ [root@localhost /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 18G 5.3G 12G 32% / tmpfs 504M 0 504M 0% /dev/shm /dev/sda1 194M 25M 160M 14% /boot /dev/sdb1 1020M 34M 935M 4% /wangchengjun
sdb的第一個分區已經掛載成功。
二、掛載光盤
[root@localhost /]# mount /dev/cdrom /wangchengjun/ mount: block device /dev/sr0 is write-protected, mounting read-only
三、掛載iso文件
光盤鏡像文件就是以iso爲後綴名的文件。在linux下,你可以把光盤直接複製成鏡像文件,當然也可以把鏡像文件掛載到某一個目錄下。
1. 把光盤複製成鏡像文件
cp /dev/cdrom /tmp/linux.iso
這樣就可以把光盤製作成鏡像文件,同樣也可以把鏡像文件當成光盤一樣來掛載
2. 掛載鏡像文件
[root@localhost tmp]# mount -o loop /tmp/linux.iso /wangchengjun/ [root@localhost tmp]# ls /wangchengjun/ CentOS_BuildTag p_w_picpaths RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Debug-6 TRANS.TBL EULA isolinux repodata RPM-GPG-KEY-CentOS-Security-6 GPL Packages RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Testing-6
四、掛載優盤
在電腦上插入優盤後,需要在虛擬機上連接一下,才能識別,方法如下:
然後通過fdisk -l ,可以看到新增的優盤:
Device Boot Start End Blocks Id System /dev/sdc4 * 1 488 3915648 b W95 FAT32 Partition 4 has different physical/logical endings: phys=(486, 254, 63) logical=(487, 125, 22)
當前優盤的格式爲fat32,可以直接掛載:
[root@localhost ~]# mount /dev/sdc4 /wangchengjun/ [root@localhost ~]# ls /wangchengjun/ 111 1.txt 2.txt 4.txt COMMAND.COM install.log.syslog stringdoc.txt 1.sh 2.sh 3.txt anaconda-ks.cfg install.log sllllllllllll.txt userch.log
五、掛載windows共享文件夾
[root@localhost ~]# mount -t cifs -o username=administrator,password= //192.168.16.2/公司內部文件共享 /mnt [root@localhost ~]# ls /mnt/ 1.txt 採購部 定稿樣本 計劃部 生產部 體系文件 銷售部
六、掛載nfs
mount -t nfs -o nolock 192.168.16.10:/home/ /mnt/
其中t指定掛載類型,o指定掛載不加鎖
七、掛載samba
mount -t cifs //10.0.4.67/myshare /mnt -o username=user1,password=123456
八、掛載ftp
Linux掛載ftp服務器,需要用到一個名爲fuse-curlftpfs的包。正常情況下無法通過yum的方式獲取此包,因此需要先安裝DAG repository
Centos5 64位 wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el5.rf.x86_64.rpm
Centos5 32位 wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el5.rf.i386.rpm
Centos6 64位 wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
Centos6 32位 wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm
然後是安裝下載的rpm包
rpm -ivh rpmforge-release-0.5.3-1.el5.rf.x86_64.rpm
然後就可以通過yum的方式安裝fuse-curlftpfs了
yum install fuse-curlftpfs -y
在Centos6上執行此命令,可能會遇到 Requires: libcurl.so.3 的錯誤,解決方法:編輯 /etc/yum.repos.d/rpmforge.repo 文件,把 [rpmforge-extras] 項打開,再執行 yum clean all 即可。
接下來就可以掛載ftp了
寫法1:curlftpfs ftp://用戶名:密碼@ftp地址 掛載點 -o codepage=utf8
寫法2:curlftpfs ftp://ftp地址 掛載點 -o user="用戶名:密碼"