本章重点提示:
1):理解基础命令,df,fdisk.
2):磁盘分区的理论基础。
1:查看当前系统分区与挂载情况:
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda2 18208184 2984040 14292560 18% /
tmpfs 502176 80 502096 1% /dev/shm
/dev/sda1 289293 28473 245460 11% /boot
2:查看系统所有能识别的分区情况(包括系统已识别,未挂载的分区):
1 [root@localhost ~]# fdisk -l
2
3 Disk /dev/sda: 21.5 GB, 21474836480 bytes
4 255 heads, 63 sectors/track, 2610 cylinders
5 Units = cylinders of 16065 * 512 = 8225280 bytes
6 Sector size (logical/physical): 512 bytes / 512 bytes
7 I/O size (minimum/optimal): 512 bytes / 512 bytes
8 Disk identifier: 0x00077367
9
10 Device Boot Start End Blocks Id System
11 /dev/sda1 * 1 39 307200 83 Linux
12 Partition 1 does not end on cylinder boundary.
13 /dev/sda2 39 2358 18631680 83 Linux
14 /dev/sda3 2358 2611 2031616 82 Linux swap / Solaris
15
16 Disk /dev/sdb: 21.5 GB, 21474836480 bytes
17 255 heads, 63 sectors/track, 2610 cylinders
18 Units = cylinders of 16065 * 512 = 8225280 bytes
19 Sector size (logical/physical): 512 bytes / 512 bytes
20 I/O size (minimum/optimal): 512 bytes / 512 bytes
21 Disk identifier: 0x00000000
22
23
24 Disk /dev/sdc: 7776 MB, 7776239616 bytes
25 240 heads, 62 sectors/track, 1020 cylinders
26 Units = cylinders of 14880 * 512 = 7618560 bytes
27 Sector size (logical/physical): 512 bytes / 512 bytes
28 I/O size (minimum/optimal): 512 bytes / 512 bytes
29 Disk identifier: 0xcb2e3fe7
30
31 Device Boot Start End Blocks Id System
其中Disk /dev/sdc: 7776 MB,是外接的8G U盘
3:进入分区(8G U盘):
[root@localhost ~]# fdisk /dev/sdc
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):
4:m,查看帮助命令:
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)
5:n,新增分区:
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1020, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1020, default 1020): +500
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): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
6:显示分区信息,可以发现刚才新建的分区:
[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00077367
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2358 18631680 83 Linux
/dev/sda3 2358 2611 2031616 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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/sdc: 7776 MB, 7776239616 bytes
240 heads, 62 sectors/track, 1020 cylinders
Units = cylinders of 14880 * 512 = 7618560 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcb2e3fe7
Device Boot Start End Blocks Id System
/dev/sdc1 1 501 3727409 83 Linux
7:重复刚才的操作,先新建一个扩展分区,再新建一个逻辑分区:
[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00077367
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2358 18631680 83 Linux
/dev/sda3 2358 2611 2031616 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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/sdc: 7776 MB, 7776239616 bytes
240 heads, 62 sectors/track, 1020 cylinders
Units = cylinders of 14880 * 512 = 7618560 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcb2e3fe7
Device Boot Start End Blocks Id System
/dev/sdc1 1 501 3727409 83 Linux
[root@localhost ~]# fdisk /dev/sdc
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): 2
First cylinder (502-1020, default 502):
Using default value 502
Last cylinder, +cylinders or +size{K,M,G} (502-1020, default 1020):
Using default value 1020
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): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00077367
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2358 18631680 83 Linux
/dev/sda3 2358 2611 2031616 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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/sdc: 7776 MB, 7776239616 bytes
240 heads, 62 sectors/track, 1020 cylinders
Units = cylinders of 14880 * 512 = 7618560 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcb2e3fe7
Device Boot Start End Blocks Id System
/dev/sdc1 1 501 3727409 83 Linux
/dev/sdc2 502 1020 3861360 5 Extended
[root@localhost ~]# fdisk /dev/sdc
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
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (502-1020, default 502):
Using default value 502
Last cylinder, +cylinders or +size{K,M,G} (502-1020, default 1020):
Using default value 1020
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x00077367
Device Boot Start End Blocks Id System
/dev/sda1 * 1 39 307200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 39 2358 18631680 83 Linux
/dev/sda3 2358 2611 2031616 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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/sdc: 7776 MB, 7776239616 bytes
240 heads, 62 sectors/track, 1020 cylinders
Units = cylinders of 14880 * 512 = 7618560 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcb2e3fe7
Device Boot Start End Blocks Id System
/dev/sdc1 1 501 3727409 83 Linux
/dev/sdc2 502 1020 3861360 5 Extended
/dev/sdc5 502 1020 3861329 83 Linux
8:查看当前系统格式:
[root@localhost ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 19G 3.1G 15G 18% /
tmpfs tmpfs 515M 82k 515M 1% /dev/shm
/dev/sda1 ext4 297M 30M 252M 11% /boot
9:格式化分区:
[root@localhost ~]# ]mkfs -t ext3 /dev/sdc1
-bash: ]mkfs: command not found
[root@localhost ~]# mkfs -t ext4 /dev/sdc1
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
233392 inodes, 931852 blocks
46592 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=956301312
29 block groups
32768 blocks per group, 32768 fragments per group
8048 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mkfs -t ext4 /dev/sdc5
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
241440 inodes, 965332 blocks
48266 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=989855744
30 block groups
32768 blocks per group, 32768 fragments per group
8048 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information:
done
This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
10:挂载分区:
[root@localhost ~]# mount /dev/sdc1 /mnt/; mount /dev/sdc5 /mnt/
11:查看当前系统挂载分区信息:
[root@localhost ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda2 ext4 19G 3.1G 15G 18% /
tmpfs tmpfs 515M 82k 515M 1% /dev/shm
/dev/sda1 ext4 297M 30M 252M 11% /boot
/dev/sdc1 ext4 3.9G 7.8M 3.7G 1% /mnt
/dev/sdc5 ext4 3.9G 7.8M 3.7G 1% /mnt