Linux格式化磁盘

 具体操作步骤如下:

[root@host-172-16-29-154 code]# lsblk
NAME                         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda                          252:0    0  100G  0 disk 
├─vda1                       252:1    0  500M  0 part /boot
├─vda2                       252:2    0   20G  0 part [SWAP]
└─vda3                       252:3    0 79.5G  0 part 
  └─VolGroup-LogVol00 (dm-0) 253:0    0 79.5G  0 lvm  /
vdb                          252:16   0  300G  0 disk 
[root@host-172-16-29-154 code]# fdisk /dev/vdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x76ee3922.
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): p

Disk /dev/vdb: 322.1 GB, 322122547200 bytes
16 heads, 63 sectors/track, 624152 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x76ee3922

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-624152, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-624152, default 624152): 1

Command (m for help): p

Disk /dev/vdb: 322.1 GB, 322122547200 bytes
16 heads, 63 sectors/track, 624152 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x76ee3922

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1           1         472+  83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/vdb: 322.1 GB, 322122547200 bytes
16 heads, 63 sectors/track, 624152 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x76ee3922

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-624152, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-624152, default 624152): 624152

Command (m for help): p

Disk /dev/vdb: 322.1 GB, 322122547200 bytes
16 heads, 63 sectors/track, 624152 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x76ee3922

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1      624152   314572576+  83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/vdb: 322.1 GB, 322122547200 bytes
16 heads, 63 sectors/track, 624152 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x76ee3922

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1      624152   314572576+  8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@host-172-16-29-154 code]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created
[root@host-172-16-29-154 code]# pvs
  PV         VG       Fmt  Attr PSize   PFree  
  /dev/vda3  VolGroup lvm2 a--u  79.51g      0 
  /dev/vdb1           lvm2 ---- 300.00g 300.00g

[root@host-172-16-29-154 code]# vgcreate vg_data /dev/vdb1
  Volume group "vg_data" successfully created

[root@host-172-16-29-154 code]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree  
  VolGroup   1   1   0 wz--n-  79.51g      0 
  vg_data    1   0   0 wz--n- 300.00g 300.00g

[root@host-172-16-29-154 code]# lvcreate -L 300G -n lv_data vg_data
  Volume group "vg_data" has insufficient free space (76799 extents): 76800 required.

[root@host-172-16-29-154 code]# lvcreate -l 76799 -n lv_data vg_data
  Logical volume "lv_data" created.

[root@host-172-16-29-154 code]# lvs
  LV       VG       Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  LogVol00 VolGroup -wi-ao----  79.51g                                                    
  lv_data  vg_data  -wi-a----- 300.00g                                                    

[root@host-172-16-29-154 code]# mkfs -t ext3 
Usage: mkfs [-V] [-t fstype] [fs-options] device [size]
[root@host-172-16-29-154 code]# mkfs -t ext3 /dev/vg_data/lv_data 
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
19660800 inodes, 78642176 blocks
3932108 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2400 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, 20480000, 23887872, 71663616

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@host-172-16-29-154 code]# mkdir /data
[root@host-172-16-29-154 code]# mount /dev/vg_data/lv_data /data/
[root@host-172-16-29-154 code]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol00
                       79G   65G  9.6G  88% /
tmpfs                 7.8G  800K  7.8G   1% /dev/shm
/dev/vda1             477M   64M  388M  15% /boot
/dev/mapper/vg_data-lv_data
                      296G  191M  281G   1% /data

 

你可能感兴趣的:(Linux学习博客专栏)