查看当前分区状态:
[root@localhost ~]# fdisk -cul
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078e53
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 37814271 18598912 83 Linux
/dev/sda3 37814272 41943039 2064384 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
139 heads, 49 sectors/track, 6158 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1d3fabd1
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
为第二块磁盘进行分区:
[root@localhost ~]# fdisk -cu /dev/sdb
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)
p
Partition number (1-4): 2
First sector (20973568-41943039, default 20973568):
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +5G
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: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
分区后查看当前分区状态:
[root@localhost ~]# fdisk -cul
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00078e53
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 616447 307200 83 Linux
/dev/sda2 616448 37814271 18598912 83 Linux
/dev/sda3 37814272 41943039 2064384 82 Linux swap / Solaris
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x1d3fabd1
Device Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
/dev/sdb2 20973568 31459327 5242880 83 Linux
尝试格式化新分区失败,原因是被分区所在设备有分区被挂载,并且需要内核重新读取新的分区表:
[root@localhost ~]# mkfs.ext4 /dev/sdb2
mke2fs 1.41.12 (17-May-2010)
Could not stat /dev/sdb2 --- No such file or directory
The device apparently does not exist; did you specify it correctly?
[root@localhost ~]# partprobe /dev/sdb
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.
[root@localhost ~]# umount /data1
[root@localhost ~]# mkfs.ext4 /dev/sdb2
mke2fs 1.41.12 (17-May-2010)
Could not stat /dev/sdb2 --- No such file or directory
The device apparently does not exist; did you specify it correctly?
不重启系统,让内核立即读取新的分区表,识别新分区:
[root@localhost ~]# partprobe /dev/sdb
格式化文件系统:
[root@localhost ~]# mkfs.ext4 /dev/sdb2
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
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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
Writing inode tables: done
Creating journal (32768 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 ~]# mkdir /data2
将sdb2挂载至/data2目录:
[root@localhost ~]# mount /dev/sdb2 /data2/
[root@localhost ~]# cd /
创建测试文件:
[root@localhost /]# ls -l > /data2/test.txt
查看测试文件:
[root@localhost /]# cat /data2/test.txt
total 94
dr-xr-xr-x. 2 root root 4096 Jul 24 17:41 bin
dr-xr-xr-x. 5 root root 1024 Jul 25 00:06 boot
drwxr-xr-x. 2 root root 4096 Jul 25 00:46 data1
drwxr-xr-x. 3 root root 4096 Jul 25 00:59 data2
drwxr-xr-x. 18 root root 3860 Jul 25 00:57 dev
drwxr-xr-x. 94 root root 4096 Jul 25 00:58 etc
drwxr-xr-x. 4 root root 4096 Jul 24 23:49 home
dr-xr-xr-x. 17 root root 12288 Jul 24 17:40 lib
drwx------. 2 root root 16384 Jul 24 23:52 lost+found
drwxr-xr-x. 2 root root 4096 Sep 23 2011 media
drwxr-xr-x. 3 root root 4096 Jul 25 00:08 mnt
drwxr-xr-x. 3 root root 4096 Jul 24 16:09 opt
dr-xr-xr-x. 164 root root 0 Jul 25 00:26 proc
dr-xr-x---. 2 root root 4096 Jul 25 00:13 root
dr-xr-xr-x. 2 root root 12288 Jul 24 23:19 sbin
drwxr-xr-x. 7 root root 0 Jul 25 00:26 selinux
drwxr-xr-x. 2 root root 4096 Sep 23 2011 srv
drwxr-xr-x. 13 root root 0 Jul 25 00:26 sys
drwxrwxrwt. 19 root root 4096 Jul 25 00:51 tmp
drwxr-xr-x. 12 root root 4096 Jul 24 23:53 usr
drwxr-xr-x. 21 root root 4096 Jul 25 00:05 var
卸载sdb2文件系统:
[root@localhost /]#umount /dev/sdb2
删除分区:
fdisk -cu /dev/sdb 命令执行后有删除分区的选项
格式化swap分区:
mkswap命令
本文出自 “Linux巨人” 博客,请务必保留此出处http://xyzlinux.blog.51cto.com/8588974/1530157
创建分区、格式化分区、挂载分区,布布扣,bubuko.com
原文地址:http://xyzlinux.blog.51cto.com/8588974/1530157