服务器系统是 Ubuntu 14.04 Trusty LTS 64bit,下面是挂载磁盘的笔记,仅供参考,注意参数要根据具体情况修改。
# fdisk -l root@BBY-Dev02:~# fdisk -l Disk /dev/xvda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000da36d Device Boot Start End Blocks Id System /dev/xvda1 * 2048 41940991 20969472 83 Linux Disk /dev/xvdb: 214.7 GB, 214748364800 bytes 255 heads, 63 sectors/track, 26108 cylinders, total 419430400 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/xvdb doesn't contain a valid partition table
最后一句 Disk /dev/xvdb doesn't contain a valid partition table
说明有未挂载的磁盘
root@BBY-Dev02:~# fdisk /dev/xvdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0xc9a280eb. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): Using default value 1 First sector (2048-419430399, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-419430399, default 419430399): Using default value 419430399 Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
貌似分区成功,用 fdisk
命令检查一下:
root@BBY-Dev02:~# fdisk -l Disk /dev/xvda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000da36d Device Boot Start End Blocks Id System /dev/xvda1 * 2048 41940991 20969472 83 Linux Disk /dev/xvdb: 214.7 GB, 214748364800 bytes 86 heads, 25 sectors/track, 195083 cylinders, total 419430400 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xc9a280eb Device Boot Start End Blocks Id System /dev/xvdb1 2048 419430399 209714176 83 Linux
Disk /dev/xvdb: 214.7 GB, 214748364800 bytes
至少说明挂载成功了。
使用 mksf.ext3
格式化分区
root@BBY-Dev02:~# mkfs.ext3 /dev/xvdb mke2fs 1.42.9 (4-Feb-2014) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 13107200 inodes, 52428800 blocks 2621440 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 1600 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
mount /dev/xvdb /projects
干了一件错事,由于 /projects 目录下有文件,mount 后 /projects 文件消失了。。。我晕!挂载点必须是一个已经存在的目录,这个目录可以不为空,但挂载后这个目录下以前的内容将不可用,umount以后会恢复正常
重启后发现挂载的磁盘不见了,原来 mount 命令只是临时的,所以把它写入开机启动注意一下 /etc/fstab 和 /etc/mtab 的区别:
etc/fstab: 记录了计算机上硬盘分区的相关信息,启动 Linux 的时候,检查分区的 fsck 命令,和挂载分区的 mount 命令,都需要 fstab 中的信息,来正确的检查和挂载硬盘。 /etc/mtab: This changes continuously as the file /proc/mount changes. In other words, when filesystems are mounted and unmounted, the change is immediately reflected in this file. 记载的是现在系统已经装载的文件系统,包括操作系统建立的虚拟文件等;而/etc/fstab是系统准备装载的。 每当 mount 挂载分区、umount 卸载分区,都会动态更新 mtab,mtab 总是保持着当前系统中已挂载的分区信息,fdisk、df 这类程序,必须要读取 mtab 文件,才能获得当前系统中的分区挂载情况。 当然我们自己还可以通过读取/proc/mount也可以来获取当前挂载信息
在linux中 /etc/fstab
的数据项如下所示:
设备名称 挂载点 分区的类型 挂载选项 dump选项 fsck选项 LABEL=/ / ext3 defaults 1 1 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0
设备名称项,可以是实际的设备名称/dev/sda1,也可以是实际设备的标签例如LABLE=/,我们可以知道 LABEL=/1是/dev/sda1的标签;那我们用什么命令来为实际的设备设置标签的方法,对于ext3和ext2文件系统,我们可以用 e2label 来设置 e2label device [newlabel],比如我们想把文件系统为ext3 的分区/dev/hda1的标签设备为 /1 ,我们应该执行如下的命令:[root@localhost beinan]# e2label /dev/hda1 /1
挂载点,没什么多说的,/、 /usr、 swap 都是系统安装时分区的默认挂载点。方法如下:root@localhostbeinan]# mkdir /mnt/hda1 注:创建挂载/dev/hda1分区的目录;
[root@localhost beinan]# chmod 777 /mnt/hda1 注:打开权限,所有用户可读可写可执行,执行完了以上两步就可以再/etc/fstab里 使用这个挂载点了
文件系统类形:
Linux file systems: ext2, ext3, jfs, reiserfs, reiser4, xfs, swap. Windows: vfat = FAT 32, FAT 16 ntfs= NTFS Note: For NTFS rw ntfs-3g CD/DVD/iso: iso9660 Network file systems: nfs: server:/shared_directory /mnt/nfs nfs <options> 0 0 smb: //win_box/shared_folder /mnt/samba smbfs rw,credentials=/home/user_name/winbox-credentials.txt 0 0 auto: The file system type (ext3, iso9660, etc) it detected automatically. Usually works. Used for removable devices (CD/DVD, Floppy drives, or USB/Flash drives) as the file system may vary on thesedevices.
挂载选项,下面列举几个常用的:
auto: 系统自动挂载,fstab默认就是这个选项
defaults: rw, suid, dev, exec, auto, nouser, and async.
noauto 开机不自动挂载
nouser 只有超级用户可以挂载
ro 按只读权限挂载
rw 按可读可写权限挂载
user 任何用户都可以挂载请注意光驱和软驱只有在装有介质时才可以进行挂载,因此它是noauto
dump
选项,设置是否让备份程序dump备份文件系统,0为忽略,1为备份,如果上次用dump备份,将显示备份至今的天数。
fsck
选项,告诉fsck程序以什么顺序检查文件系统,为0就表示不检查,(/)分区永远都是1,其它的分区只能从2开始,当数字相同就同时检查(但不能有两1), 注意:当你修改了 /etc/fstab
后,一定要重新引导系统才会有效。