1、磁盘分区
Linux系统默认所有设备文件都在/dev下面
/dev/sda --硬盘1 sda1 第一个分区 sda2 第二个分区 sda3 第三个分区
[root@localhost dev]# ll |grep 'sd'
lrwxrwxrwx. 1 root root 4 Sep 30 22:49 root -> sda3
brw-rw----. 1 root disk 8, 0 Sep 30 22:49 sda
brw-rw----. 1 root disk 8, 1 Sep 30 22:49 sda1
brw-rw----. 1 root disk 8, 2 Sep 30 22:49 sda2
brw-rw----. 1 root disk 8, 3 Sep 30 22:49 sda3
/dev/sdb --硬盘2 sdb1 第一个分区 sdb2 第二个分区 sdb3 第三个分区
/dev/sdc --硬盘3
2、# fdisk -l 查看系统所有硬盘的分区情况
(1)系统一共有几块硬盘,每个硬盘的容量大小
(2)每个硬盘的分区情况(硬盘空间是否还有剩余)
[root@localhost dev]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x0009d896
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 543 4046848 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 543 5222 37587968 83 Linux
3、添加硬盘,先关机后添加
[root@localhost ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x0009d896
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 543 4046848 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 543 5222 37587968 83 Linux
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
4、分区操作
分区步骤:
(1) fdisk 设备名称(/dev/sdb)
(2)partx -a /dev/sdb 使系统重新识别分区
(3)mkfs.ext4 /dev/sdb6 格式化 分区完必须要格式化后才能用哈
(4)# mount /dev/sdb5 /mnt 挂载 (临时生效)
永久生效需要就修改/etc/fstab (例如:将 /dev/sdb5 /wwwroot ext4 defaults 0 0 按列填写至后面)
文件系统:ext2 ext3 ext4 xfs (如windows有NTFS)
block:
--Linux 操作系统管理文件的最小(逻辑)单位
--大小有1k 2k 4k
[root@localhost dev]# mkfs.ext4 /dev/sdb5
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
348816 inodes, 1393630 blocks
69681 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1430257664
43 block groups
如用ext4下block大小为4k,如果一个文件是1k,会用一个block存储它,剩余3k会浪费掉。
注:记住哈,hadoop中还会见面的。
----------------------------------------------------------------------------分区步骤---------------------------------------------------------------------------------
添加分区:
[root@localhost dev]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd2d759dc.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won'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 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): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +15G
Command (m for help): p
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: 0xd2d759dc
Device Boot Start End Blocks Id System
/dev/sdb1 1 1959 15735636 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (1960-2610, default 1960):
Using default value 1960
Last cylinder, +cylinders or +size{K,M,G} (1960-2610, default 2610):
Using default value 2610
Command (m for help): p
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: 0xd2d759dc
Device Boot Start End Blocks Id System
/dev/sdb1 1 1959 15735636 83 Linux
/dev/sdb2 1960 2610 5229157+ 5 Extended
再分扩展分区为逻辑分区:
Command (m for help): p
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: 0xd2d759dc
Device Boot Start End Blocks Id System
/dev/sdb1 1 1959 15735636 83 Linux
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (1960-2610, default 1960):
Using default value 1960
Last cylinder, +cylinders or +size{K,M,G} (1960-2610, default 2610):
Using default value 2610
Command (m for help): p
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: 0xd2d759dc
Device Boot Start End Blocks Id System
/dev/sdb1 1 1959 15735636 83 Linux
/dev/sdb2 1960 2610 5229157+ 5 Extended
Command (m for help): m^H
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^H
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1960-2610, default 1960):
Using default value 1960
Last cylinder, +cylinders or +size{K,M,G} (1960-2610, default 2610): 2500
Command (m for help): p
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: 0xd2d759dc
Device Boot Start End Blocks Id System
/dev/sdb1 1 1959 15735636 83 Linux
/dev/sdb2 1960 2610 5229157+ 5 Extended
/dev/sdb5 1960 2500 4345551 83 Linux
写入退出保存:
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 dev]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x0009d896
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 543 4046848 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 543 5222 37587968 83 Linux
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: 0x0a4a3d6d
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
/dev/sdb2 1307 2610 10474380 5 Extended
/dev/sdb5 1307 2000 5574523+ 83 Linux
格式化:
[root@localhost dev]# mkfs.ext4 /dev/sdb5
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
348816 inodes, 1393630 blocks
69681 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1430257664
43 block groups
32768 blocks per group, 32768 fragments per group
8112 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 22 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost dev]# mkfs.ext4 /dev/sdb1
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
655776 inodes, 2622603 blocks
131130 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2688548864
81 block groups
32768 blocks per group, 32768 fragments per group
8096 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost dev]# mkfs.ext4 /dev/sdb2
mke2fs 1.41.12 (17-May-2010)
mkfs.ext4: inode_size (128) * inodes_count (0) too big for a
filesystem with 0 blocks, specify higher inode_ratio (-i)
or lower inode count (-N).
挂载:
[root@localhost dev]# mount /dev/sdb5 /mnt
[root@localhost dev]# cd /mnt
[root@localhost mnt]# ls
lost+found
[root@localhost mnt]# cd lost+found/
[root@localhost lost+found]# ls
[root@localhost lost+found]# cd ..
[root@localhost mnt]# cd ..
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 3.5G 30G 11% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 283M 65M 204M 25% /boot
/dev/sdb5 5.2G 11M 4.9G 1% /mnt
卸载-->装载:
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 3.5G 30G 11% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 283M 65M 204M 25% /boot
/dev/sdb5 5.2G 11M 4.9G 1% /mnt
[root@localhost /]# umount /mnt
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 3.5G 30G 11% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 283M 65M 204M 25% /boot
[root@localhost /]# mkdir /wwwroot
[root@localhost /]# mount /dev/sdb5 /wwwroot
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 3.5G 30G 11% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 283M 65M 204M 25% /boot
/dev/sdb5 5.2G 11M 4.9G 1% /wwwroot
[root@localhost /]# mount /dev/sdb1 /mnt
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 36G 3.5G 30G 11% /
tmpfs 1.9G 72K 1.9G 1% /dev/shm
/dev/sda1 283M 65M 204M 25% /boot
/dev/sdb5 5.2G 11M 4.9G 1% /wwwroot
/dev/sdb1 9.8G 23M 9.3G 1% /mnt
目录是分区的访问入口,如果在目录下创建文件后卸载分区,目录下的文件就不存在了哈,不信可以试试~~~