查看系统可用磁盘大小:
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 7.3G 12G 39% /
tmpfs 32G 72K 32G 1% /dev/shm
查看服务器可用磁盘:
[[email protected] ~]# fdisk -l
Disk /dev/sdb: 8589 MB, 8589934592 bytes
64 heads, 32 sectors/track, 8192 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
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: 0x00026e4e
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2611 20970496 83 Linux
Disk /dev/sdc: 53.7 GB, 53687091200 bytes
64 heads, 32 sectors/track, 51200 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
格式化磁盘/dev/sdc:
[[email protected] ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xfb75b574.
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 ----分区号为1
First cylinder (1-51200, default 1): ---默认从1开始
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-51200, default 51200): --默认51200结束
Using default value 51200
Command (m for help): w ---对以上更改报错到磁盘
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
格式化成相应文件系统类型:
查看系统磁盘分区:
[[email protected] ~]# fdisk -l
Disk /dev/sdb: 8589 MB, 8589934592 bytes
64 heads, 32 sectors/track, 8192 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
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: 0x00026e4e
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2611 20970496 83 Linux
Disk /dev/sdc: 53.7 GB, 53687091200 bytes
64 heads, 32 sectors/track, 51200 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xfb75b574
Device Boot Start End Blocks Id System
/dev/sdc1 1 51200 52428784 83 Linux
格式化具体挂载分区:
[[email protected] ~]# mkfs.ext4 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
3276800 inodes, 13107196 blocks
655359 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
400 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, 1605632, 2654208,
4096000, 7962624, 11239424
Writing inode tables: done
Creating journal (32768 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.
创建挂载磁盘目录:
[[email protected] ~]# mkdir /data
挂载/dev/sdc1到目录/data:
[[email protected] ~]# mount /dev/sdc1 /data
[[email protected] ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 20G 7.3G 12G 39% /
tmpfs 32G 72K 32G 1% /dev/shm
/dev/sdc1 50G 180M 47G 1% /data
设置linux系统开机自动挂载磁盘:
1)查看磁盘UUID
[[email protected] ~]# blkid /dev/sdc1
/dev/sdc1: UUID="0c43e879-0e8b-4633-aa7b-d3c5a0e10614" TYPE="ext4"
2)编写/etc/fstab文件:添加最后一行信息,保存退出即可。
[[email protected] ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Sat Jun 21 09:11:21 2014
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk‘
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=261e0e16-2332-4716-9af4-0d0449a53c92 / ext4 defaults 1 1
LABEL=YUNIFYSWAP swap swap defaults 0 0
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
UUID=0c43e879-0e8b-4633-aa7b-d3c5a0e10614 /data ext4 defaults 0 2