Linux 磁盘分区、格式化、挂载

1、添加磁盘,查看磁盘状态
[root@zhongxin172 lib]# fdisk -l
 
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
 
Disk /dev/sdb: 6001.1 GB, 6001095958528 bytes
255 heads, 63 sectors/track, 729591 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
 
Device Boot Start End Blocks Id System
/dev/sdb1 1 267350 2147483647+ ee GPT
 
Disk /dev/sda: 146.8 GB, 146778685440 bytes
255 heads, 63 sectors/track, 17844 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: 0x0008f797
 
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 1109 8388608 82 Linux swap / Solaris
/dev/sda3 1109 17845 134436864 83 Linux
 
 
2、用fdisk 对磁盘进行分区/查看
[root@localhost ~]# fdisk /dev/sda //这里不带数字
 
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
(e.g., DOS FDISK, OS/2 FDISK)
 
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibilityflag
d delete a partition //删除磁盘分区
l list known partition types
m print this menu //查看磁盘分区功能
n add a new partition //增加一个磁盘分区
o create a new empty DOSpartition table
p print the partition table //查看磁盘分区
q quit without saving changes
s create a new empty Sundisklabel
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 (expertsonly)
 
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652):
Using default value 652
 
Command (m for help): w
The partition table has been altered!
 
Calling ioctl() to re-read partition table.
Syncing disks.
 
3、cat /proc/partitions查看分区情况
(如果创建完之后,/proc/partitions 查看不到对应的分区,使用parprobe  /dev/sdb刷新下
[root@zhongxin172 lib]# cat /proc/partitions
major minor #blocks name
 
8 16 5860445272 sdb
8 17 5860445238 sdb1
8 0 143338560 sda
8 1 512000 sda1
8 2 8388608 sda2
8 3 134436864 sda3
 
4、格式化 /dev/sdb1分区
[root@db1 /]# mkfs -t ext3 /dev/sdb1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
655360 inodes, 1309289 blocks
65464 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
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
 
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
 
This filesystem will be automatically checked every 30 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
 
5、创建目录,并将目录挂载在/dev/sdb1下
[root@db1 /]# mkdir /u01
[root@db1 /]# ls
backup dev initrd media opt sbin sys u01
bin etc lib misc proc selinux tftpboot usr
boot home lost+found mnt root srv tmp var
[root@db1 /]# mount /dev/sdb1 /u01
 
6、验证挂载是否成功
[root@db1 /]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 9131772 7066884 1601012 82% /
none 454256 0 454256 0% /dev/shm
/dev/sdb1 5154852 43040 4849956 1% /backup
 
7.查看磁盘 的文件系统类型
[root@zhongxin172 mysql]# parted /dev/sdb1 print
Model: Unknown (unknown)
Disk /dev/sdb1: 6001GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
 
Number Start End Size File system Flags
1 0.00B 6001GB 6001GB ext4
 
8、设置开启自动挂载 (如果没有设置,重启后就丢失挂载信息)
[root@db1 /]# vi /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/ / ext3 defaults 1 1
none /dev/pts devpts gid=5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
LABEL=SWAP-sda2 swap swap defaults 0 0
/dev/sdb1 /u01 ext3 defaults 0 0
/dev/hdc /media/cdrom auto pamconsole,exec,noauto,m
anaged 0 0
/dev/fd0 /media/floppy auto pamconsole,exec,noauto,m
anaged 0 0
 
posted @ 2017-04-09 22:06  漫舞沧海  阅读(194)  评论(0编辑  收藏  举报