0 前言: 要把机器硬盘挂载到linux文件系统,操作流程如下:
1 目前情况:
[root@localhost ~]# df -lh 目前是linux文件系统只挂载如下硬盘 Filesystem Size Used Avail Use% Mounted on /dev/sda3 193G 1.8G 181G 1% / tmpfs 32G 0 32G 0% /dev/shm /dev/sda1 194M 32M 153M 18% /boot [root@localhost ~]# fdisk -l 查看硬盘情况, 现在是下面这些磁盘都没有被挂载到linux文件系统中, Disk /dev/sda: 1000.2 GB, 1000204886016 bytes Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes Disk /dev/sdd: 1000.2 GB, 1000204886016 bytes Disk /dev/sdc: 1000.2 GB, 1000204886016 bytes Disk /dev/sde: 1000.2 GB, 1000204886016 bytes Disk /dev/sdf: 1000.2 GB, 1000204886016 bytes
2 如下是以其中一个磁盘挂载为例,其余磁盘挂载请顺序按照如下方式执行:
[root@localhost ~]# fdisk /dev/sdb 创建分区/dev/sdb WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n (n表示新创建) Command action e extended p primary partition (1-4) p (p表示主分区) Partition number (1-4): 1 输入分区号 First cylinder (1-121601, default 1): 2 Last cylinder, +cylinders or +size{K,M,G} (2-121601, default 121601): Using default value 121601 Command (m for help): w 输入w表示写入 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost ~]# mkfs.ext3 /dev/sdb 格式化分区 mke2fs 1.41.12 (17-May-2010) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) y Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 61054976 inodes, 244190646 blocks 12209532 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 7453 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, 71663616, 78675968, 102400000, 214990848 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: disksdb done This filesystem will be automatically checked every 38 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
3 硬盘挂载:
[root@localhost ~]# mkdir /mnt/disk1 linux文件系统中创建挂载文件 [root@localhost ~]# mount /dev/sdb /mnt/disk1 将格式化的磁盘挂载到 /mnt/disk1文件系统中 [root@localhost ~]# df -lh 查看挂载效果 Filesystem Size Used Avail Use% Mounted on /dev/sda3 193G 1.8G 181G 1% / tmpfs 32G 0 32G 0% /dev/shm /dev/sda1 194M 32M 153M 18% /boot /dev/sdb 917G 200M 871G 1% /mnt/disk1 此时已经挂载上
此时,需要将格式化的磁盘id加入到/etc/fstab下 否则重启机器后 挂载消失,
如下是 将磁盘变更为 ext4格式的流程和 磁盘id加入到 etc/fstab下:
[root@chinadaas11 mnt]# blkid 查看id /dev/sda3: UUID="e39fe821-b9bf-4c5f-9cba-44e3894fbb5f" TYPE="ext4" /dev/sda1: UUID="f752b4fd-c214-433c-8e85-3d25952c7c01" TYPE="ext4" /dev/sda2: UUID="8e327f42-89e1-4188-9448-45493b6706a1" TYPE="swap" /dev/sde: UUID="772ff875-b41f-44cd-9b43-c8c73e4c1c54" SEC_TYPE="ext2" TYPE="ext3" /dev/sdc: UUID="6cc8d885-cee6-4572-a4fc-08364c042232" SEC_TYPE="ext2" TYPE="ext3" /dev/sdb: UUID="daf891c2-1ed4-4c86-8abb-49f9fd653a16" SEC_TYPE="ext2" TYPE="ext3" /dev/sdf: UUID="f2d704e6-874d-44be-bcb9-501caf653fd9" SEC_TYPE="ext2" TYPE="ext3" /dev/sdd: UUID="1a3cd2ff-1e0e-4c17-8b51-80b2e3fbb2c7" SEC_TYPE="ext2" TYPE="ext3" [root@chinadaas11 mnt]# mkfs.ext4 /dev/sde 将盘格式化成ext4格式 都格式化后,查看为: [root@chinadaas11 mnt]# blkid /dev/sda3: UUID="e39fe821-b9bf-4c5f-9cba-44e3894fbb5f" TYPE="ext4" /dev/sda1: UUID="f752b4fd-c214-433c-8e85-3d25952c7c01" TYPE="ext4" /dev/sda2: UUID="8e327f42-89e1-4188-9448-45493b6706a1" TYPE="swap" /dev/sde: UUID="af7114ea-347a-4560-b545-cb4ccfa3b676" TYPE="ext4" /dev/sdc: UUID="6d6bd411-178e-47d7-ad55-8ef1529f1253" TYPE="ext4" /dev/sdb: UUID="4671f6c4-eb6e-42a6-8de9-4800f23e1065" TYPE="ext4" /dev/sdf: UUID="65139d07-0a7b-4992-8d1e-94b68170fa32" TYPE="ext4" /dev/sdd: UUID="8542eb1d-a6e3-435e-baab-1d05bb7d79b3" TYPE="ext4" 然后将格式化好的挂载到 /mnt下的各个目录下, [root@chinadaas11 mnt]# df -lh Filesystem Size Used Avail Use% Mounted on /dev/sda3 193G 16G 168G 9% / tmpfs 32G 0 32G 0% /dev/shm /dev/sda1 194M 32M 153M 18% /boot /dev/sde 917G 200M 871G 1% /mnt/disk1 /dev/sdc 917G 200M 871G 1% /mnt/disk2 /dev/sdb 917G 200M 871G 1% /mnt/disk3 /dev/sdf 917G 200M 871G 1% /mnt/disk4 /dev/sdd 917G 200M 871G 1% /mnt/disk5 格式化后,需要 #vi /etc/fstab 将你格式化好的盘通过 blkid的id加到fstab去 否则重启机器的话,格式化好的盘数据将会丢失 加入的写法如下: UUID=e39fe821-b9bf-4c5f-9cba-44e3894fbb5f / ext4 defaults 1 1 UUID=f752b4fd-c214-433c-8e85-3d25952c7c01 /boot ext4 defaults 1 2 UUID=8e327f42-89e1-4188-9448-45493b6706a1 swap swap defaults 0 0 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 UUID=af7114ea-347a-4560-b545-cb4ccfa3b676 /mnt/disk1 ext4 defaults 0 0 UUID=6d6bd411-178e-47d7-ad55-8ef1529f1253 /mnt/disk2 ext4 defaults 0 0 UUID=4671f6c4-eb6e-42a6-8de9-4800f23e1065 /mnt/disk3 ext4 defaults 0 0 UUID=65139d07-0a7b-4992-8d1e-94b68170fa32 /mnt/disk4 ext4 defaults 0 0 UUID=8542eb1d-a6e3-435e-baab-1d05bb7d79b3 /mnt/disk5 ext4 defaults 0 0
4 参考链接:
http://blog.chinaunix.net/uid-25829053-id-3067619.html