1.先用Fdisk -l 來檢視目前狀态下磁盤情況 或 lsblk
[root@linux1 ~]# fdisk -l
Disk /dev/hda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 652 5132767 8e Linux LVM
Disk /dev/hdb: 2147 MB, 2147483648 bytes
16 heads, 63 sectors/track, 4161 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk /dev/hdb doesn't contain a valid partition table
上面紅色辨別行可以看出,我添加了一塊新硬碟/dev/hdb,大小為2G,未分區格式化狀态
2.用Fdisk /dev/hdb來進行分區操作
[root@linux1 ~]# fdisk /dev/hdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 4161.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n //輸入N表示建立一個分區
Command action
e extended
p primary partition (1-4)
p //p 表示建立一個原始分區
Partition number (1-4): 1 //1 表示此分區編号為1.
First cylinder (1-4161, default 1): 1 //1表示使用預設起始柱面号.如果要分多個區的話,先盤算好要多大,再輸入數字
Last cylinder or size or sizeM or sizeK (1-4161, default 4161): // 輸入: 回車 表示使用預設結束柱面号.即此分區使用整個硬碟空間
Using default value 4161
Command (m for help): w //儲存分區
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.再次檢視目前分區狀态:
[root@linux1 ~]# fdisk -l
Disk /dev/hda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 652 5132767 8e Linux LVM
Disk /dev/hdb: 2147 MB, 2147483648 bytes
16 heads, 63 sectors/track, 4161 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Device Boot Start End Blocks Id System
/dev/hdb1 1 4161 2097112 83 Linux
可以看出,已經出來了一個/dev/hdb1的新分區。下一步将其格式化,再使用
4.用mkfs.ext4格式化新分區
[root@linux1 ~]# mkfs.ext4 /dev/hdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
262144 inodes, 524278 blocks
26213 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
5.挂載使用。
[root@linux1 ~]# mkdir /mnt/hdb1 //建立一個挂載點。
[root@linux1 ~]# mount -t ext4 /dev/hdb1 /mnt/hdb1 //挂載。
[root@linux1 ~]# df -h
檔案系統 容量 已用 可用 已用% 挂載點
/dev/mapper/VolGroup00-LogVol00
4.3G 3.6G 487M 89% /
/dev/hda1 99M 12M 82M 13% /boot
tmpfs 125M 0 125M 0% /dev/shm
/dev/hdb1 2.0G 3.0M 1.9G 1% /mnt/hdb1
6 .開機自動挂載
三.設定新硬碟開機自動挂載
#vim /etc/fstab 添加下面一行:
/dev/hdb1 /mnt/hdb1 ext4 defaults 1 2(如果還有一個分區就是1 3,以此類推)
這樣,每次開機後,系統會自動将/dev/hdb1挂載到/mnt/hdb1
這裡最好使用UUID進行挂載
#ls -l /dev/disk/by-uuid/ 檢視該分區的UUID
lrwxrwxrwx. 1 root root 10 May 17 08:42 28cc8f0f-bd42-4ab9-b62a-c24a42cfddcb -> ../../hdb1
lrwxrwxrwx. 1 root root 10 Apr 18 05:42 5c330a93-fdfe-486f-b7a7-52b820fb6213 -> ../../sdb1
lrwxrwxrwx. 1 root root 10 Apr 18 05:41 d5700297-be02-4034-9e76-07aec5581082 -> ../../sda1
複制第一行,然後新增并粘貼剛複制的,修改UUID和最後兩個參數改為0
UUID=28cc8f0f-bd42-4ab9-b62a-c24a42cfddcb /mnt/hdb1 ext4 defaults 0 0