Linux磁盘分区 挂载 格式化 扩容

目录

一.扩容

二.挂载磁盘

1.使用命令检查磁盘挂载和分布情况

2.新建一个磁盘

3.磁盘分区

4.磁盘格式化

5.磁盘挂载


一.扩容

#第一步在虚拟机中扩容根目录磁盘
#每个磁盘只能最多有四个分区
[root@19c ~]# df -h#首先看一下磁盘分区情况
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.4G     0  1.4G   0% /dev
tmpfs                    1.4G     0  1.4G   0% /dev/shm
tmpfs                    1.4G  9.9M  1.4G   1% /run
tmpfs                    1.4G     0  1.4G   0% /sys/fs/cgroup
/dev/mapper/centos-root   46G   22G   25G  48% /
/dev/sda1               1014M  184M  831M  19% /boot
tmpfs                    283M  8.0K  283M   1% /run/user/42
tmpfs                    283M     0  283M   0% /run/user/0
[root@19c ~]# fdisk -l#查看磁盘分区

Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c22e1

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM

Disk /dev/mapper/centos-root: 49.4 GB, 49383735296 bytes, 96452608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 3221 MB, 3221225472 bytes, 6291456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@19c ~]# fdisk /dev/sda#开始分区
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.


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
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   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 partitions 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        
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p#这里我们选择p
Partition number (3,4, default 3): 
First sector (104857600-125829119, default 104857600): 
Using default value 104857600
Last sector, +sectors or +size{K,M,G} (104857600-125829119, default 125829119): 
Using default value 125829119
Partition 3 of type Linux and of size 10 GiB is set

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.
[root@19c ~]# fdisk -l

Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c22e1

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM
/dev/sda3       104857600   125829119    10485760   83  Linux#这就是我们新增的分区

Disk /dev/mapper/centos-root: 49.4 GB, 49383735296 bytes, 96452608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 3221 MB, 3221225472 bytes, 6291456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes







#接下来我们需要reboot虚拟机
[root@19c ~]# fdisk -l#再看一下磁盘分区情况

Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000c22e1

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM
/dev/sda3       104857600   125829119    10485760   83  Linux

Disk /dev/mapper/centos-root: 49.4 GB, 49383735296 bytes, 96452608 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 3221 MB, 3221225472 bytes, 6291456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@19c ~]# vgextend centos /dev/sda3#将分区加到vg组
  Physical volume "/dev/sda3" successfully created.
  Volume group "centos" successfully extended
[root@19c ~]# lvextend -L +9.99G /dev/mapper/centos-root#扩展vg组容量
  Rounding size to boundary between physical extents: 9.99 GiB.
  Size of logical volume centos/root changed from 45.99 GiB (11774 extents) to 55.98 GiB (14332 extents).
  Logical volume centos/root successfully resized.
[root@19c ~]# df -T#查看一下文件系统的格式
Filesystem              Type     1K-blocks     Used Available Use% Mounted on
devtmpfs                devtmpfs   1430612        0   1430612   0% /dev
tmpfs                   tmpfs      1447632        0   1447632   0% /dev/shm
tmpfs                   tmpfs      1447632    10172   1437460   1% /run
tmpfs                   tmpfs      1447632        0   1447632   0% /sys/fs/cgroup
/dev/mapper/centos-root xfs       48202756 22913288  25289468  48% /
/dev/sda1               xfs        1038336   187596    850740  19% /boot
tmpfs                   tmpfs       289528       12    289516   1% /run/user/42
tmpfs                   tmpfs       289528        0    289528   0% /run/user/0
[root@19c ~]# xfs_growfs /dev/mapper/centos-root#扩容到根目录
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=3014144 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=12056576, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=5887, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 12056576 to 14675968

[root@19c ~]# df -h#查看已经扩容到56G了
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.4G     0  1.4G   0% /dev
tmpfs                    1.4G     0  1.4G   0% /dev/shm
tmpfs                    1.4G   10M  1.4G   1% /run
tmpfs                    1.4G     0  1.4G   0% /sys/fs/cgroup
/dev/mapper/centos-root   56G   22G   35G  40% /
/dev/sda1               1014M  184M  831M  19% /boot
tmpfs                    283M   12K  283M   1% /run/user/42
tmpfs                    283M     0  283M   0% /run/user/0

二.挂载磁盘

1.使用命令检查磁盘挂载和分布情况

[root@zhuke ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_oracle1-lv_root
                       27G   15G   11G  59% /
tmpfs                 1.5G   88K  1.5G   1% /dev/shm
/dev/sda1             485M   55M  405M  12% /boot
[root@zhuke ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_oracle1-lv_root
                       27G   15G   11G  59% /
tmpfs                 1.5G   88K  1.5G   1% /dev/shm
/dev/sda1             485M   55M  405M  12% /boot
[root@zhuke ~]# cd /dev/sda
sda   sda1  sda2  
[root@zhuke ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x000df97d

   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        3917    30944256   8e  Linux LVM

Disk /dev/mapper/vg_oracle1-lv_root: 28.5 GB, 28512878592 bytes
255 heads, 63 sectors/track, 3466 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


Disk /dev/mapper/vg_oracle1-lv_swap: 3170 MB, 3170893824 bytes
255 heads, 63 sectors/track, 385 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

2.新建一个磁盘

[root@zhuke ~]# fdisk -l#添加磁盘后使用命令检查新建的磁盘

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x000df97d

   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        3917    30944256   8e  Linux LVM

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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


Disk /dev/mapper/vg_oracle1-lv_root: 28.5 GB, 28512878592 bytes
255 heads, 63 sectors/track, 3466 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


Disk /dev/mapper/vg_oracle1-lv_swap: 3170 MB, 3170893824 bytes
255 heads, 63 sectors/track, 385 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

3.磁盘分区

[root@zhuke ~]# 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 0x7644cc73.
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 partitions 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)

Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 
Value out of range.
Partition number (1-4): 
Value out of range.
Partition number (1-4): 
Value out of range.
Partition number (1-4): 1
First cylinder (1-130, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130): 
Using default value 130

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@zhuke ~]# fdisk -l

Disk /dev/sda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 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: 0x000df97d

   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        3917    30944256   8e  Linux LVM

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 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: 0x7644cc73

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         130     1044193+  83  Linux

Disk /dev/mapper/vg_oracle1-lv_root: 28.5 GB, 28512878592 bytes
255 heads, 63 sectors/track, 3466 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


Disk /dev/mapper/vg_oracle1-lv_swap: 3170 MB, 3170893824 bytes
255 heads, 63 sectors/track, 385 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.磁盘格式化

[root@zhuke ~]# 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
65280 inodes, 261048 blocks
13052 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8160 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376

Writing inode tables: done                            
Creating journal (4096 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.

5.磁盘挂载

[root@zhuke /]# mkdir test
[root@zhuke /]# ll -ls
total 114
 4 dr-xr-xr-x.   2 root   root      4096 Feb 19  2023 bin
 2 dr-xr-xr-x.   5 root   root      1024 Feb 19  2023 boot
 0 drwxr-xr-x   17 root   root      3680 Oct 19 21:53 dev
12 drwxr-xr-x. 113 root   root     12288 Oct 19 21:48 etc
 4 drwxr-xr-x.   3 root   root      4096 Jun  4 15:50 home
 4 dr-xr-xr-x.  11 root   root      4096 Feb 19  2023 lib
12 dr-xr-xr-x.   9 root   root     12288 Feb 19  2023 lib64
16 drwx------.   2 root   root     16384 Feb 19  2023 lost+found
 4 drwxr-xr-x.   3 root   root      4096 Jun  5 22:59 media
 0 drwxr-xr-x    2 root   root         0 Oct 19 21:48 misc
 4 drwxr-xr-x.   3 root   root      4096 Feb 19  2023 mnt
 0 drwxr-xr-x    2 root   root         0 Oct 19 21:48 net
 4 drwxr-xr-x.   4 root   root      4096 Feb 19  2023 opt
 4 drwxr-xr-x.   3 root   root      4096 Feb 19  2023 oracle
 0 dr-xr-xr-x  112 root   root         0 Oct 19 21:47 proc
 4 dr-xr-x---.  26 root   root      4096 Oct 19 21:48 root
12 dr-xr-xr-x.   2 root   root     12288 Feb 19  2023 sbin
 4 drwxr-xr-x.   2 root   root      4096 Feb 19  2023 selinux
 4 drwxr-xr-x.   2 root   root      4096 Nov  1  2011 srv
 0 drwxr-xr-x   13 root   root         0 Oct 19 21:47 sys
 4 drwxr-xr-x    2 root   root      4096 Oct 19 21:58 test
 4 drwxrwxrwt.  20 root   root      4096 Oct 19 21:48 tmp
 4 drwxrwxr-x    3 oracle oinstall  4096 Jun  4 15:51 u01
 4 drwxr-xr-x.  13 root   root      4096 Feb 19  2023 usr
 4 drwxr-xr-x.  22 root   root      4096 Feb 19  2023 var
[root@zhuke /]# mount /dev/sdb1 /test
[root@zhuke /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_oracle1-lv_root
                       27G   15G   11G  59% /
tmpfs                 1.5G   88K  1.5G   1% /dev/shm
/dev/sda1             485M   55M  405M  12% /boot
/dev/sdb1            1004M   18M  936M   2% /test

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值