[root@localhost linuxidc]# df -Th
#查看已经挂载上的文件分区大小以及格式(当然你的系统必须有空闲的空间不用了)
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sda1 ext3 2.9G 2.2G 505M 82% /
/dev/sda2 ext3 965M 22M 894M 3% /home
tmpfs tmpfs 345M 12K 345M 1% /dev/shm
[root@localhost linuxidc]# /sbin/fdisk /dev/sda
#fdisk命令来进行磁盘分区
#如果你有第二块硬盘,那么后面的设备符号是/dev/sdb,第三块以此类推
The number of cylinders for this disk is set to 1044.
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)
Command (m for help): m #查看fdisk命令的帮助
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): p #打印/查看已有的分区表
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000e25d9
Device Boot Start End Blocks Id System
/dev/sda1 * 1 382 3068383+ 83 Linux
/dev/sda2 383 509 1020127+ 83 Linux
/dev/sda3 510 636 1020127+ 82 Linux swap / Solaris
Command (m for help): n #开始增加新的分区
Command action
e extended #扩展分区
p primary partition (1-4) #主分区,一块硬盘中可以有4个主分区
#例如:XP下C盘为主分区,DEF为逻辑分区(DEF合起来就是扩展分区)
e #增加扩展分区
Selected partition 4 #分区4作为扩展分区,分区4开始是未分配空闲空间
First cylinder (637-1044, default 637): <Enter>
Using default value 637 #分区的开头,1044是块结尾
Last cylinder or +size or +sizeM or +sizeK (637-1044, default 1044): <Enter>
#也可在这里直接输入想要建立分区的大小,比如+5000MB,表示建立5000MB大小的分区
Using default value 1044 #分区的结尾
Command (m for help): n #建立完扩展分区,然后建立逻辑分区
First cylinder (637-1044, default 637): <Enter>
Using default value 637
Last cylinder or +size or +sizeM or +sizeK (637-1044, default 1044): <Enter>
Using default value 1044
Command (m for help): p #建立完了逻辑分区,打印/查看
#可以看到增加了一个分区,逻辑分区是建立在扩展分区上的
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000e25d9
Device Boot Start End Blocks Id System
/dev/sda1 * 1 382 3068383+ 83 Linux
/dev/sda2 383 509 1020127+ 83 Linux
/dev/sda3 510 636 1020127+ 82 Linux swap / Solaris
/dev/sda4 637 1044 3277260 5 Extended
/dev/sda5 637 1044 3277228+ 83 Linux
Command (m for help): w #把新的分区表写入并保存,记住一定要保存
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@localhost linuxidc]# df -Th
#因为这个时候还没有挂载,所以在df命令下并不能看到新的分区
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sda1 ext3 2.9G 2.2G 505M 82% /
/dev/sda2 ext3 965M 22M 894M 3% /home
tmpfs tmpfs 345M 12K 345M 1% /dev/shm
[root@localhost linuxidc]# /sbin/mkfs.ext3 /dev/sda5
#在挂载之前应该先格式化,比如ext2,ext3格式
#还可以使用/sbin/mkfs –t ext3 /dev/sda5
#其实我们已经看到在fdisk命令中已经自动将其格式化为ext3格式了
mke2fs 1.40.2 (12-Jul-2007)
warning: 107 blocks unused.
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
410400 inodes, 819200 blocks
40965 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=838860800
25 block groups
32768 blocks per group, 32768 fragments per group
16416 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost linuxidc]# /sbin/e2label /dev/sda5 backup #给新分区添加一个标签
[root@localhost linuxidc]# mkdir /mnt/bak #创建目录
[root@localhost linuxidc]# mount /dev/sda5 /mnt/bak #将新分区挂载到指定目录上
[root@localhost linuxidc]# df -Th #这时候就可以看到挂载上了
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sda1 ext3 2.9G 2.2G 505M 82% /
/dev/sda2 ext3 965M 22M 894M 3% /home
tmpfs tmpfs 345M 12K 345M 1% /dev/shm
/dev/sda5 ext3 3.1G 69M 2.9G 3% /mnt/bak
[root@localhost linuxidc]# vim /etc/fstab #添加一行到/etc/fstab中开机自动挂载
#其实不用设置,系统也可以开机自动挂载的,因为它的格式跟linux系统格式是一样的
[root@localhost linuxidc]# cat /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/home /home ext3 defaults 1 2
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
LABEL=SWAP-sda3 swap swap defaults 0 0
LABEL=backup /mnt/bak ext3 defaults 1 2
Linux下的分区工具
转载请注明出处:服务器评测 » Linux下的分区工具