msdos hard disk partition

Hard disk partition and format

This example requires familiarity with hard disk partition structure, use fdisk partitioning tool to create a partition on the disk according to the following requirements / dev / vdb:
Using default msdos partition mode
1, the first partition / dev size / vdb1 is 200MiB
2, the size of the second partition / dev / vdb2 is 2000MiB
. 3, the size of the third partition / dev / vdb3 is 1000MiB, complete after the partition
4, the boot can be configured to automatically mount / dev / vdb2 partition: EXT4 file system type, mount it to / mnt / part2 directory

fdisk utility msdos partition scheme to establish which primary interaction mode command follows:

instruction use
m Listed in Instruction Help
p View the current partition table information
n New Partition
d Delete partition
t Change the partition identifier
q Abandon changes and exit partition
w Save the changes to the partition table

step

This case needs to be achieved in the following steps.
Step a: new partition table

  1. Open fdisk tools, operating disk / dev / vdb
[root@server0 ~]# fdisk   /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x9ac1bc10.
Command (m for help):                         //交互操作提示信息
  1. New first partition / dev / vdb1
Command (m for help): n                                  //新建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p                                    //类型为p(主分区)
Partition number (1-4, default 1): 1                     //分区编号1
First sector (2048-20971519, default 2048):              //起始位置默认
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +200M  
Partition 1 of type Linux and of size 200 MiB is set      //结束位置+200MiB大小
Command (m for help): p                                   //确认当前分区表
.. ..
  Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   83  Linux
  1. New second partition / dev / vdb2
Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p                                   //类型为p(主分区)
Partition number (2-4, default 2): 2                    //分区编号2
First sector (411648-20971519, default 411648):         //起始位置默认
Using default value 411648
Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +2000M
Partition 2 of type Linux and of size 2 GiB is set       //结束位置+2000MiB大小
Command (m for help): p                                  //确认当前分区表
.. ..
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   83  Linux
/dev/vdb2          411648     4507647     2048000   83  Linux
  1. New third partition / dev / vdb3
Command (m for help): n     
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 3
First sector (4507648-20971519, default 4507648): 
Using default value 4507648
Last sector, +sectors or +size{K,M,G} (4507648-20971519, default 20971519): +1000M
Partition 3 of type Linux and of size 1000 MiB is set
Command (m for help): p                                  //确认当前分区表
.. ..
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   83  Linux
/dev/vdb2          411648     4507647     2048000   83  Linux
/dev/vdb3         4507648     6555647     1024000   83  Linux
  1. Adjust the partition type identifier (optional)
    the type of the / dev / vdb1 (default is 83, showing EXT2 / 3/4 partitions) modified to 8e (LVM device):
Command (m for help): t                                  //修改分区类型标识
Partition number (1-3, default 3): 1                     //指定第1个分区
Hex code (type L to list all codes): 8e                  //类型改为8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p                                  //确认当前分区表
.. ..
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   8e  Linux LVM
/dev/vdb2          411648     4507647     2048000   83  Linux
/dev/vdb3         4507648     6555647     1024000   83  Linux
  1. Save zoning changes and exit fdisk partition tool
Command (m for help): w                                            //保存并退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
  1. Refresh partition table
[root@server0 ~]# partprobe  /dev/vdb         //重新检测磁盘分区
//或者
[root@server0 ~]# reboot                      //对已使用中磁盘的分区调整,应该重启一次
.. ..

Step Two: Mount the partition formatting and

  1. The partition / dev / vdb2 formatted with EXT4 file system
[root@server0 ~]# mkfs.ext4  /dev/vdb2
.. .. 
Allocating group tables: done  
Writing inode tables: done 
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
  1. Configure boot automatically mount
[root@server0 ~]# vim  /etc/fstab
.. ..
/dev/vdb2       /mnt/part2      ext4    defaults        0 0
  1. Create a mount point, mount and verify the configuration
[root@server0 ~]# mkdir  /mnt/part2                 //创建挂载点
[root@server0 ~]# mount  -a                         //挂载fstab中的可用设备
[root@server0 ~]# df  -hT  /mnt/part2/              //检查文档所在的文件系统及设备
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/vdb2      ext4  1.9G  5.9M  1.8G   1% /mnt/part2
Create a logical volume
LVM management tools collection
Features Physical Volume Management Volume Group Management Logical Volume Management
Scan Scan pvscan vgscan lvscan
Create create pvcreate vgcreate lvcreate
Display display pvdisplay vgdisplay lvdisplay
Remove deleted pvremove vgremove lvremove
Extend extension / vgextend lvextend
This embodiment follows the one day before the required case using partition / dev / vdb1 build LVM storage requirements as follows:
Create a volume group is named systemvg
created in this volume group is a logical volume called vo, size 180MiB
logical volume vo EXT4 formatted file system
will be mounted to the logical volume vo / vo directory, and the directory under establish a test file votest.txt, content is "I AM KING."
  • Program
    LVM tools to create basic usage:
    the vgcreate volume group physical devices ... ...
    lvcreate -L size -n logical volume group name

  • Steps
    to achieve this case need to follow the steps below.

Step one: create a volume group

  1. The new volume group named systemvg
[root@server0 ~]# vgcreate  systemvg  /dev/vdb1
  Physical volume "/dev/vdb1" successfully created
  Volume group "systemvg" successfully created
  1. verify results
[root@server0 ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "systemvg" using metadata type lvm2

Step two: create a logical volume

  1. New logical volume called the vo
[root@server0 ~]# lvcreate  -L  180MiB  -n  vo  systemvg 
  Logical volume "vo" created
  1. verify results
[root@server0 ~]# lvscan
  ACTIVE            '/dev/systemvg/vo' [180.00 MiB] inherit

Step Three: To Mount formatting and

  1. Formatting the logical volume / dev / systemvg / vo
[root@server0 ~]# mkfs.ext4  /dev/systemvg/vo
.. ..
Allocating group tables: done 
Writing inode tables: done 
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
  1. Mount the logical volume / dev / systemvg / vo
[root@server0 ~]# mkdir  /vo                              //创建挂载点
[root@server0 ~]# mount  /dev/systemvg/vo  /vo             //挂载
[root@server0 ~]# df  -hT  /vo/                         //检查结果
Filesystem              Type  Size  Used Avail Use% Mounted on
/dev/mapper/systemvg-vo ext4  171M  1.6M  157M   1% /vo
  1. Access the logical volume / dev / systemvg / vo
[root@server0 ~]# cat  /vo/votest.txt
I AM KING.
Adjust the existing disk partition
  • This embodiment follows the one day before the required case, the disk / dev / vdb partition table is adjusted, the following:
    Do not change the original partition, the remaining space using a new three partitions, size order of: 500MiB, 2000MiB, 512MiB
    then based newly established building new partition 2000MiB LVM memory:
    the new logical volume designated Database, physical size of the expansion unit 50 (physical Extent), belonging to the volume group datastore
    all logical volumes in the volume group datastore, the physical extension unit ( Physical Extent) size of 16MiB
    using logical database EXT3 file system format, this logical volume should be automatically mounted to / mnt / database after a boot

  • Program
    when you create a volume group, you can specify the size of the PE option by -s.
    When a new logical volume allocated space, space can be a multiple of the size of the PE.

  • Steps
    to achieve this case need to follow the steps below.
    Step one: Adjust the existing disk partition

  1. New extended partition (using the remaining free space)
[root@server0 ~]# fdisk  /dev/vdb
Command (m for help): p                                  //确认原有分区表
.. ..
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   8e  Linux LVM
/dev/vdb2          411648     4507647     2048000   83  Linux
/dev/vdb3         4507648     6555647     1024000   83  Linux
Command (m for help): n                                 //新建分区
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e                                 //类型指定为e(扩展分区)
Selected partition 4                                     //只一个可用编号,自动选取
First sector (6555648-20971519, default 6555648):          //起始位置默认
Using default value 6555648
Last sector, +sectors or +size{K,M,G} (6555648-20971519, default 20971519): 
Using default value 20971519                             //结束位置默认
Partition 4 of type Extended and of size 6.9 GiB is set
Command (m for help): p     
.. ..
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   8e  Linux LVM
/dev/vdb2          411648     4507647     2048000   83  Linux
/dev/vdb3         4507648     6555647     1024000   83  Linux
/dev/vdb4         6555648    20971519     7207936    5  Extended
  1. 3 new logical partition in the extended partition
    to create the first logical volume (due to the primary partition number runs out, automatically select partition type l logical partitions):
Command (m for help): n 
All primary partitions are in use
Adding logical partition 5                                 //分区编号5
First sector (6557696-20971519, default 6557696):          //起始位置默认
Using default value 6557696
Last sector, +sectors or +size{K,M,G} (6557696-20971519, default 20971519): +500M
                                                          //结束位置默认
Partition 5 of type Linux and of size 500 MiB is set
创建第2个逻辑卷:
Command (m for help): n
All primary partitions are in use
Adding logical partition 6                                 //分区编号6
First sector (7583744-20971519, default 7583744):          //起始位置默认
Using default value 7583744
Last sector, +sectors or +size{K,M,G} (7583744-20971519, default 20971519): +2000M
                                                          //结束位置默认
Partition 6 of type Linux and of size 2 GiB is set
创建第3个逻辑卷:
Command (m for help): n
All primary partitions are in use 
Adding logical partition 7                                //分区编号7
First sector (11681792-20971519, default 11681792):      //起始位置默认
Using default value 11681792
Last sector, +sectors or +size{K,M,G} (11681792-20971519, default 20971519): +512M
                                                         //结束位置默认
Partition 7 of type Linux and of size 512 MiB is set
根据预计的用途调整分区类型(可选):
Command (m for help): t                                 //修改
Partition number (1-7, default 7): 5                     //第5个分区
Hex code (type L to list all codes): 8e                 //类型为8e(LVM)
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): t                                 //修改
Partition number (1-7, default 7): 6                     //第6个分区
Hex code (type L to list all codes): 8e                 //类型为8e(LVM)
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): t                                 //修改
Partition number (1-7, default 7): 7                     //第7个分区
Hex code (type L to list all codes): 82                 //类型为82(交换分区)
Changed type of partition 'Linux' to 'Linux swap / Solaris'
确认分区结果并保存:
Command (m for help): p
.. ..
   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1            2048      411647      204800   8e  Linux LVM
/dev/vdb2          411648     4507647     2048000   83  Linux
/dev/vdb3         4507648     6555647     1024000   83  Linux
/dev/vdb4         6555648    20971519     7207936    5  Extended
/dev/vdb5         6557696     7581695      512000   8e  Linux LVM
/dev/vdb6         7583744    11679743     2048000   8e  Linux LVM
/dev/vdb7        11681792    12730367      524288   82  Linux swap / Solaris
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.                                         //提示重启
  1. Refresh partition table
[root@server0 ~]# partprobe  /dev/vdb
[root@server0 ~]# reboot
  • New volume group, logical volume
  1. New volume group datastore, designated PE size 16MiB
[root@server0 ~]# vgcreate  -s 16MiB  datastore  /dev/vdb6
  Volume group "datastore" successfully created
[root@server0 ~]# vgscan                                  //确认新建的卷组
  Reading all physical volumes.  This may take a while...
  Found volume group "systemvg" using metadata type lvm2
  Found volume group "datastore" using metadata type lvm2
  1. New logical database, the size is set to 50 PE
[root@server0 ~]# lvcreate  -l 50  -n  database  datastore
  Logical volume "database" created
[root@server0 ~]# lvscan                                  //确认新建的逻辑卷
  ACTIVE            '/dev/systemvg/vo' [180.00 MiB] inherit
  ACTIVE            '/dev/datastore/database' [800.00 MiB] inherit
  • Formatting and use logical volumes
  1. Formatting the logical volume / dev / datastore / database
[root@server0 ~]# mkfs.ext3  /dev/datastore/database
.. ..
Allocating group tables: done 
Writing inode tables: done 
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
  1. Mount boot configuration
[root@server0 ~]# mkdir  /mnt/database                     //创建挂载点
[root@server0 ~]# vim  /etc/fstab
.. ..
/dev/datastore/database         /mnt/database   ext3    defaults    0 0
3)验证挂载配置
[root@server0 ~]# mount  -a
[root@server0 ~]# df  -hT  /mnt/database/                 //确认挂载点设备
Filesystem                     Type  Size  Used Avail Use% Mounted on
/dev/mapper/datastore-database ext3  772M  828K  715M   1% /mnt/database
Expand the size of the logical volume
  • Requirements follow a practice, a logical volume vo resized to 300MiB, requirements are as follows:
    the contents of the original file system must remain intact
    prepared, if necessary, can be used before the partition / dev / vdb5 to supplement space
    Note: Partition size rarely completely meet the requirements of size, so size is between 270MiB and 300MiB is acceptable

  • Program
    for the logical volume has been formatted in size after expansion, must inform the new kernel size.
    If the file system on the logical volume is EXT3 / EXT4 type, require the use of tools resize2fs;
    file systems on logical volumes XFS If this type requires that xfs_growfs.

  • Steps
    to achieve this case requires the following steps

Step a: vo logical profile of

  1. Find out where the logical volume group
[root@server0 ~]# lvscan
  ACTIVE            '/dev/systemvg/vo' [180.00 MiB] inherit
  ACTIVE            '/dev/datastore/database' [800.00 MiB] inherit
  1. Check whether the remaining space in the volume group needs to be expanded to meet the
[root@server0 ~]# vgdisplay  systemvg
  --- Volume group ---
  VG Name               systemvg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               196.00 MiB                          //卷组总大小
  PE Size               4.00 MiB
  Total PE              49
  Alloc PE / Size       45 / 180.00 MiB
  Free  PE / Size       4 / 16.00 MiB                      //剩余空间大小
  VG UUID               czp8IJ-jihS-Ddoh-ny38-j521-5X8J-gqQfUN
  • In this embodiment the total size of the volume group systemvg enough 300MiB, the remaining space was 16MiB, it is necessary to expand the volume group. Only the remaining space is enough, we can expand the size of the logical volume directly.

Step two: Extended volume group

  1. Will be prepared in advance of the partition / dev / vdb5 added to the volume group systemvg
[root@server0 ~]# vgextend  systemvg  /dev/vdb5
  Physical volume "/dev/vdb5" successfully created
  Volume group "systemvg" successfully extended
  1. The new size of the volume group confirmation
[root@server0 ~]# vgdisplay  systemvg
  --- Volume group ---
  VG Name               systemvg
  .. ..
  VG Size               692.00 MiB                          //总大小已变大
  PE Size               4.00 MiB
  Total PE              173
  Alloc PE / Size       45 / 180.00 MiB
  Free  PE / Size       128 / 512.00 MiB                  //剩余空间已达512MiB
  VG UUID               czp8IJ-jihS-Ddoh-ny38-j521-5X8J-gqQfUN

Step Three: Extend the logical volume size

  1. The logical volume / dev / systemvg / vo resized to 300MiB
[root@server0 ~]# lvextend  -L 300MiB  /dev/systemvg/vo 
  Extending logical volume vo to 300.00 MiB
  Logical volume vo successfully resized
  1. The results confirm the adjustment
[root@server0 ~]# lvscan
  ACTIVE            '/dev/systemvg/vo' [300.00 MiB] inherit
  ACTIVE            '/dev/datastore/database' [800.00 MiB] inherit
  1. Flush the file system size of
    the file system on the logical volume vo type:
[root@server0 ~]# blkid  /dev/systemvg/vo
/dev/systemvg/vo: UUID="d4038749-74c3-4963-a267-94675082a48a" TYPE="ext4"

Select the right tools to refresh Size:

[root@server0 ~]# resize2fs  /dev/systemvg/vo 
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/systemvg/vo to 307200 (1k) blocks.
The filesystem on /dev/systemvg/vo is now 307200 blocks long.

Confirm the new size (approximately equal 300MiB):

[root@server0 ~]# mount  /dev/systemvg/vo  /vo/
[root@server0 ~]# df  -hT  /vo
Filesystem              Type  Size  Used Avail Use% Mounted on
/dev/mapper/systemvg-vo ext4  287M  2.1M  266M   1% /vo

Guess you like

Origin blog.csdn.net/weixin_44965389/article/details/90446871