Linux磁盤添加與掛載

[root@dns ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_dns-LogVol03
                      100G   34G   61G  36% /
tmpfs                 3.8G   72K  3.8G   1% /dev/shm
/dev/sda1             188M  114M   61M  66% /boot
/dev/mapper/vg_dns-LogVol01
                      9.1G   45M  8.6G   1% /tmp

通過 fdisk -l 查看新加入的磁盤

Disk /dev/sda: 211 MB, 211812352 bytes
4 heads, 32 sectors/track, 3232 cylinders
Units = cylinders of 128 * 512 = 65536 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1dc3657a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           2        3201      204800   83  Linux

Disk /dev/sdc: 3298.5 GB, 3298534883328 bytes
255 heads, 63 sectors/track, 401024 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


Disk /dev/sdb: 135.3 GB, 135297761280 bytes
197 heads, 4 sectors/track, 335347 cylinders
Units = cylinders of 788 * 512 = 403456 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3372e156

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1      335342   132124672   8e  Linux LVM

我們可以看到 /dev/sdc 這塊爲新增加的磁盤,他並沒有分區

我們下面開始分區,使用 fdisk /dev/sdc 命令初始化分區,輸入m可以獲取幫助

[root@dns ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x49a73bdf.
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: The size of this disk is 3.3 TB (3298534883328 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID 
partition table format (GPT).


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)

分析:各個參數的解析

  1. 輸入 m 顯示所有命令列示。
  2. 輸入 p 顯示硬盤分割情形,打印分區表。
  3. 輸入 a 設定硬盤啓動區。
  4. 輸入 n 設定新的硬盤分割區。
    4.1. 輸入 e 硬盤爲[延伸]分割區(extend)。
    4.2. 輸入 p 硬盤爲[主要]分割區(primary)。
  5. 輸入 t 改變硬盤分割區屬性。          
    t:分區系統id號:L:82:linux swap 83:linux 86:NTFS window分區
  6. 輸入 d 刪除硬盤分割區屬性。
  7. 輸入 q 結束不存入硬盤分割區屬性。
  8. 輸入 w 結束並寫入硬盤分割區屬性

輸入 p 以查看分區表,此時無分區,分區表爲空

Command (m for help): p

Disk /dev/sdc: 3298.5 GB, 3298534883328 bytes
255 heads, 63 sectors/track, 401024 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: 0x49a73bdf

   Device Boot      Start         End      Blocks   Id  System

輸入 n 以創建分區表
1.選擇分區類型,e:擴展分區,p:主分區(可以創建四個主分區)
2.輸入主分區編號
3.輸入分區的第一個柱面
4.輸入分區的最後一個柱面,或者直接輸入分區大小(單位:K,M,G)
5.分區表設置完成後,輸入 w 以保存分區表

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-401024, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-267349, default 267349): 
Using default value 267349

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

分區創建完畢

Disk /dev/sdc: 3298.5 GB, 3298534883328 bytes
255 heads, 63 sectors/track, 401024 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: 0xcc008e5f

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1      267349  2147480811   83  Linux

接下來,我們指定分區的文件系統,我們可以通過 df -hT 查詢當前系統下其他分區的文件系統

[root@dns ~]# df -hT
Filesystem           Type   Size  Used Avail Use% Mounted on
/dev/mapper/vg_dns-LogVol03
                     ext4   100G   34G   61G  36% /
tmpfs                tmpfs  3.8G   72K  3.8G   1% /dev/shm
/dev/sda1            ext4   188M  114M   61M  66% /boot
/dev/mapper/vg_dns-LogVol01
                     ext4   9.1G   45M  8.6G   1% /tmp

這裏其他的分區都是ext4的,這裏也爲我們創建的分區指定ext4的文件系統,通過 mkfs 命令

-t 參數後面跟上要指定的文件系統
最後跟上要指定的分區名稱,我們這裏是 /dev/sdc1

[root@dns ~]# mkfs -t ext4 /dev/sdc1
mke2fs 1.43-WIP (20-Jun-2013)
文件系統標籤=
OS type: Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
134217728 inodes, 536870202 blocks
26843510 blocks (5.00%) reserved for the super user
第一個數據塊=0
Maximum filesystem blocks=4294967296
16384 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, 512000000

Allocating group tables: 完成                            
正在寫入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成    

指定文件系統後,我們就可以掛載磁盤了,可以選擇永久掛載或臨時掛載

永久掛載

[root@dns ~]# vim /etc/fstab

在文件末尾新增以下內容

/dev/sdc1  /data  ext4  defaults  1  1

臨時掛載

[root@dns ~]# mount -t ext4 /dev/sdc1 /data

OK,至此文件掛載完畢,可以通過 df -h 查詢一下掛載情況

[root@dns ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_dns-LogVol03
                      100G   34G   61G  36% /
tmpfs                 3.8G   72K  3.8G   1% /dev/shm
/dev/sda1             188M  114M   61M  66% /boot
/dev/mapper/vg_dns-LogVol01
                      9.1G   45M  8.6G   1% /tmp
/dev/sdc1             2.0T   71M  1.9T   1% /data

END

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章