一、磁盤及分區
1.檢測並確認新硬盤
# fdisk -l
Disk /dev/sda:21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00078511
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinderboundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
Disk /dev/sdb:21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000
Disk /dev/sdc:26.8 GB, 26843545600 bytes
255 heads, 63 sectors/track, 3263 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0x00000000
2.規劃硬盤中的分區
# fdisk /dev/sdb
Device contains neither a valid DOSpartition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with diskidentifier 0xae03f6ac.
Changes will remain in memory only, untilyou decide to write them.
After that, of course, the previous contentwon'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 forhelp): p ←查看分區信息,看是否創建過分區,以免重複
Disk /dev/sdb:21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0xae03f6ac
Device Boot Start End Blocks Id System
Command (m forhelp): n ←新建分區
Command action
e extended
p primary partition (1-4)
p ←選擇主分區
Partition number (1-4): 1 ←選擇分區號
First cylinder (1-2610, default 1):
Using defaultvalue 1
Last cylinder, +cylinders or +size{K,M,G}(1-2610, default 2610): +100M ←分區的大小
Command (m forhelp): p ←查看是否創建成功
Disk /dev/sdb:21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0xae03f6ac
Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux
Command (m forhelp): w ←保存並退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.刪除分區
# fdisk /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 forhelp): p ←查看分區信息
Disk /dev/sdb:21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
Disk identifier: 0xae03f6ac
Device Boot Start End Blocks Id System
/dev/sdb1 1 14 112423+ 83 Linux
/dev/sdb2 15 21 56227+ 83 Linux
Command (m forhelp): d ←刪除分區
Partition number (1-4): 2 ←選擇要刪除的分區
Command (m forhelp): w ←保存並退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
二、LVM
l 介紹最常用的幾個命令:
1)pvcreate用於將分區或整個硬盤轉換成物理卷,主要是添加LVM屬性信息並劃分PE存儲單位。該命令需要使用分區或硬盤設備名作爲參數
2)vgcreate用於將一個或多個物理卷創建爲一個卷組,第一個命令參數指定定義的新卷組名稱,其後依次指定需要加入到該卷組的物理卷作爲參數
3)lvcreate用於從指定的卷組中分割空間,以創建新的邏輯卷。需要指定邏輯卷大小、名稱及所在的卷組名作爲參數
4)lvextend用於動態擴展邏輯卷的空間,當目前使用的邏輯卷空間不足時,可以從所在卷組中分割額外的空間進行擴展
# pvcreate /dev/sdb1 ←轉化物理卷
Physical volume "/dev/sdb1"successfully created
# pvcreate /dev/sdc1 ←轉化物理卷
Physical volume "/dev/sdc1"successfully created
# vgcreate group /dev/sdb1 /dev/sdc1 ←創建組group
Volume group "group" successfullycreated
# lvcreate -L 50M -n lv_data group ←創建邏輯卷lv_data
Rounding up size to full physical extent 52.00 MiB
Logical volume "lv_data" created
# lvextend -L +100M /dev/group/lv_data ←擴展邏輯卷
Extending logical volume lv_data to 152.00 MiB
Logical volume lv_data successfully resized
格式化文件系統有3中方法:
mkfs -t ext4 /dev/卷組名/邏輯卷名
mkfs.ext4 /dev/卷組名/邏輯卷名
mke2fs -t ext4 /dev/卷組名/邏輯卷名
# mkfs.ext4 /dev/group/lv_data
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
38912 inodes, 155648 blocks
7782 blocks (5.00%) reserved for the superuser
First data block=1
Maximum filesystem blocks=67371008
19 block groups
8192 blocks per group, 8192 fragments pergroup
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inodetables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystemaccounting information: done
This filesystemwill be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
三、掛載
Linux系統中,文件系統創建後,還需將其安裝到Linux目錄樹的某個位置上才能使用,這個過程稱爲掛載,文件系統所掛載到的目錄稱爲掛載點。文件系統使用完畢,還可對其進行卸載
1.掛載文件系統
在Linux系統中,磁盤設備被掛接到一個已存在的目錄上,以後的磁盤的存取就變成了對該掛接目錄的讀寫訪問。通常選擇已存在的空目錄作爲掛接目錄,因爲如果掛接目錄已經包含文件,在掛接操作完成後,原文件將臨時被掛接磁盤中的文件覆蓋,直到從系統中卸載該磁盤爲止。文件系統的掛載,可以在系統引導過程中自動加載,也可以使用命令手工掛載
# mkdir /data ←創建掛載點目錄
# mount /dev/group/lv_data /data ←掛載
# cd /data
# ll
total 12
drwx------ 2 root root 12288 Aug 20 04:47lost+found
2.卸載文件系統
如果系統已掛接的磁盤不再使用,爲了節省系統資源,可以將該磁盤從系統中卸下。與掛載相比,卸載文件系統簡單很多,卸載文件系統使用umount命令
# umount /dev/group/lv_data ←卸載
# cd /data
# ll
total 0