2017-04-04

Linux mount disk


Step 1. 查看硬碟資訊,發現有兩顆 /dev/vad 與 /dev/vab

[root@xxxxx tmp]# fdisk -lu

Disk /dev/vda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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: 0x0003a7b4

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048   104855551    52426752   83  Linux
Disk /dev/vdb: 536.9 GB, 536870912000 bytes
16 heads, 63 sectors/track, 1040253 cylinders, total 1048576000 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


Step 2. 新增磁區

[root@xxxxx tmp]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x492efa4a.
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)

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): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit

   x   extra functionality (experts only)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4):1
First cylinder (1-1040253, default 1): default 
Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-1040253, default 1040253): default 
Command (m for help): w

Step 3. 設定磁區格式 ext4
[root@xxxxx tmp]# mkfs -t ext4 /dev/vdb
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
32768000 inodes, 131072000 blocks
6553600 blocks (5.00%) reserved for the super user
.....

Step 4. 建立disk UUID
[root@xxxxx tmp]# tune2fs -U random /dev/vdb
tune2fs 1.41.12 (17-May-2010)

Step 5. 查看UUID
[root@xxxxx tmp]# blkid /dev/vdb

/dev/vdb: UUID="8217a44e-70f1-4f84-850d-c9e8f30ae5bb" TYPE="ext4"

Step 6. 註冊UUID
[root@xxxxx tmp]# vim /etc/fstab
UUID=b7aae0d4-268c-4b60-914a-f3b48e22819c /                       ext4    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

UUID=8217a44e-70f1-4f84-850d-c9e8f30ae5bb /project ext4


Step 6. 掛載磁區到你要的目錄
[root@xxxxx tmp]# mount -t ext4 /dev/vdb /project



完成
[root@ICN-Beta-IXBataAll01 salt]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G  1.3G   46G   3% /
tmpfs           3.9G     0  3.9G   0% /dev/shm

/dev/vdb        493G   70M  467G   1% /project