Linux磁盘管理、分区、扩展SWAP

简介:

[root@RHEL7 ~]# fdisk /dev/sdb

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): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x2fa2fc5f

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    10485759     5241856   83  Linux

Command (m for help): d

Selected partition 1

Partition 1 is deleted

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x2fa2fc5f

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-10485759, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): +500MB

Partition 1 of type Linux and of size 477 MiB is set

Command (m for help): p

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x2fa2fc5f

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048      978943      488448   83  Linux

Command (m for help): n

Partition type:

   p   primary (1 primary, 0 extended, 3 free)

   e   extended

Select (default p): p

Partition number (2-4, default 2):

First sector (978944-10485759, default 978944):

Using default value 978944

Last sector, +sectors or +size{K,M,G} (978944-10485759, default 10485759): +100MB

Partition 2 of type Linux and of size 95 MiB is set

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@RHEL7 ~]# mkfs.xfs -f /dev/sdb1

meta-data=/dev/sdb1              isize=256    agcount=4, agsize=30528 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0

data     =                       bsize=4096   blocks=122112, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal log           bsize=4096   blocks=853, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@RHEL7 ~]# mkfs.ext4 /dev/sdb2

[root@RHEL7 ~]# mkdir /sdb1

[root@RHEL7 ~]# mkdir /sdb2

[root@RHEL7 ~]# mount /dev/sdb1 /sdb1

[root@RHEL7 ~]# mount /dev/sdb2 /sdb2

[root@RHEL7 ~]# mount

/dev/sdb1 on /sdb1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)

/dev/sdb2 on /sdb2 type ext4 (rw,relatime,seclabel,data=ordered)

[root@RHEL7 ~]# df | tail -2

/dev/sdb1                485036   24580    460456   6% /sdb1

/dev/sdb2                 90099    1550     81740   2% /sdb2

设备开机自动挂载

[root@RHEL7 ~]# vim /etc/fstab

/dev/sdb1       /sdb1   xfs     defaults 0 0

/dev/sdb2       /sdb2   ext4    defaults 0 0

重新挂载所有分区

[root@RHEL7 ~]# mount -a

 

使用UUID实现 自动挂载

查看分区的UUID

[root@RHEL7 ~]# blkid /dev/sdb1

/dev/sdb1: UUID="58972903-1d37-4acf-a108-d7221f08e1af" TYPE="xfs"

[root@RHEL7 ~]# blkid /dev/sdb2

/dev/sdb2: UUID="46adcd74-5806-45de-8006-a893c548c9d4" TYPE="ext4"

将/dev/sdb1,/dev/sdb2设备名称使用uuid号替代

[root@RHEL7 ~]# vim /etc/fstab

UUID=58972903-1d37-4acf-a108-d7221f08e1af       /sdb1   xfs     defaults 0 0

UUID=46adcd74-5806-45de-8006-a893c548c9d4       /sdb2   ext4    defaults 0 0

再重新挂载 

[root@RHEL7 ~]# mount -a

卸载挂载点

[root@RHEL7 ~]# umount /sdb1

[root@RHEL7 ~]# umount /sdb2

大于2TB以上的分区 使用parted分区

GPT:全局唯一标识分区表,Gpt对分区数量没有限制

查看是否安装了parted 

[root@RHEL7 ~]# rpm -qf `which parted`

parted-3.1-17.el7.x86_64

[root@RHEL7 ~]# rpm -qa | grep parted

pyparted-3.9-7.el7.x86_64

parted-3.1-17.el7.x86_64

查看分区状态

[root@RHEL7 ~]# parted -l

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sda: 21.5GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Disk Flags:

Number  Start   End     Size    Type     File system  Flags

 1      1049kB  211MB   210MB   primary  xfs          boot

 2      211MB   11.8GB  11.5GB  primary               lvm

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdb: 5369MB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Disk Flags:

Number  Start   End    Size    Type     File system  Flags

 1      1049kB  501MB  500MB   primary  xfs

 2      501MB   601MB  99.6MB  primary  ext4

Model: Linux device-mapper (linear) (dm)

Disk /dev/mapper/rhel-swap: 1049MB

Sector size (logical/physical): 512B/512B

Partition Table: loop

Disk Flags:

Number  Start  End     Size    File system     Flags

 1      0.00B  1049MB  1049MB  linux-swap(v1)

Model: Linux device-mapper (linear) (dm)

Disk /dev/mapper/rhel-root: 10.5GB

Sector size (logical/physical): 512B/512B

Partition Table: loop

Disk Flags:

Number  Start  End     Size    File system  Flags

 1      0.00B  10.5GB  10.5GB  xfs

Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0

has been opened read-only.

                                                                       Model: NECVMWar VMware SATA CD01 (scsi)

Disk /dev/sr0: 3743MB

Sector size (logical/physical): 2048B/2048B

Partition Table: msdos

Disk Flags:

Number  Start   End     Size    Type     File system  Flags

 2      1123MB  1149MB  25.7MB  primary

[root@RHEL7 ~]# parted /dev/sdb

GNU Parted 3.1

Using /dev/sdb

Welcome to GNU Parted! Type 'help' to view a list of commands.

                                                                       (parted) print

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdb: 5369MB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Disk Flags:

Number  Start   End    Size    Type     File system  Flags

 1      1049kB  501MB  500MB   primary  xfs

 2      501MB   601MB  99.6MB  primary  ext4

                                                                       (parted) rm 2

[root@RHEL7 ~]# parted /dev/sdb

GNU Parted 3.1

Using /dev/sdb

Welcome to GNU Parted! Type 'help' to view a list of commands.

                                                                       (parted) print

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdb: 5369MB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Disk Flags:

Number  Start   End    Size   Type     File system  Flags

 1      1049kB  501MB  500MB  primary  xfs

                                                                       (parted) rm 1

                                                                       (parted) print

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdb: 5369MB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Disk Flags:

Number  Start  End  Size  Type  File system  Flags

                                                                       (parted) mklabel gpt

Warning: The existing disk label on /dev/sdb will be destroyed and all

data on this disk will be lost. Do you want to continue?

                                                                                                                                              Yes/No? yes

                                                                       (parted) print

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdb: 5369MB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:

Number  Start  End  Size  File system  Name  Flags

                                                                       (parted) mkpart primary 0 1000

Warning: The resulting partition is not properly aligned for best

performance.

                                                                                                                                              Ignore/Cancel? ignore

                                                                       (parted) print

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdb: 5369MB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:

Number  Start   End     Size    File system  Name     Flags

 1      17.4kB  1000MB  1000MB               primary

                                                                       (parted) mkpart primary 1000 2000

                                                                       (parted) print

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdb: 5369MB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:

Number  Start   End     Size    File system  Name     Flags

 1      17.4kB  1000MB  1000MB               primary

 2      1000MB  2000MB  999MB                primary

                                                                       (parted) q

Information: You may need to update /etc/fstab.

扩展SWAP分区

[root@RHEL7 ~]# ls /dev/sdb*

/dev/sdb  /dev/sdb1

[root@RHEL7 ~]# mkswap /dev/sdb1

mkswap: /dev/sdb1: warning: wiping old xfs signature.

Setting up swapspace version 1, size = 195580 KiB

no label, UUID=8b9719da-bd1c-487c-8346-4b9d2b7eb082

[root@RHEL7 ~]# swapon /dev/sdb1

[root@RHEL7 ~]# free -m

             total       used       free     shared    buffers     cached

Mem:          1826       1132        694         10          1        434

-/+ buffers/cache:        696       1129

Swap:         1190          0       1190

[root@RHEL7 ~]# swapoff /dev/sdb1


本文转自    OpenStack2015 博客,原文链接:      http://blog.51cto.com/andyliu/1839031  如需转载请自行联系原作者


相关文章
|
2月前
|
Linux Shell C语言
【Shell 命令集合 磁盘维护 】Linux 分区管理的工具 sfdisk命令使用教程
【Shell 命令集合 磁盘维护 】Linux 分区管理的工具 sfdisk命令使用教程
33 1
|
2月前
|
存储 Shell Linux
【Shell 命令集合 磁盘维护 】Linux 管理硬盘分区 mpartition命令使用教程
【Shell 命令集合 磁盘维护 】Linux 管理硬盘分区 mpartition命令使用教程
43 1
|
2月前
|
安全 Shell Linux
【Shell 命令集合 磁盘管理 】Linux 磁盘分区工具 fdisk命令使用教程
【Shell 命令集合 磁盘管理 】Linux 磁盘分区工具 fdisk命令使用教程
68 0
|
2月前
|
存储 Shell Linux
【Shell 命令集合 磁盘管理 】Linux读取、转换并输出数据 dd命令使用教程
【Shell 命令集合 磁盘管理 】Linux读取、转换并输出数据 dd命令使用教程
45 0
|
2月前
|
Shell Linux C语言
【Shell 命令集合 磁盘管理 】Linux losetup命令使用教程 将一个文件或设备与一个回环设备(loop device)进行关联
【Shell 命令集合 磁盘管理 】Linux losetup命令使用教程 将一个文件或设备与一个回环设备(loop device)进行关联
52 0
|
2月前
|
存储 Shell Linux
【Shell 命令集合 磁盘管理 】⭐⭐ Linux 显示当前shell会话中的目录栈 dirs命令使用教程
【Shell 命令集合 磁盘管理 】⭐⭐ Linux 显示当前shell会话中的目录栈 dirs命令使用教程
28 0
|
2月前
|
监控 Linux Shell
【Shell 命令集合 磁盘维护 】Linux 交换分区的特殊文件或设备 swapon命令使用指南
【Shell 命令集合 磁盘维护 】Linux 交换分区的特殊文件或设备 swapon命令使用指南
41 1
|
2月前
|
存储 Shell Linux
【Shell 命令集合 磁盘维护 】Linux 创建一个用作交换空间(swap space)的特殊文件或设备 mkswap命令使用教程
【Shell 命令集合 磁盘维护 】Linux 创建一个用作交换空间(swap space)的特殊文件或设备 mkswap命令使用教程
38 0
|
2月前
|
存储 安全 Linux
【Shell 命令集合 磁盘维护 】Linux 在特定的分区上建立 linux 文件系统 mkfs命令使用教程
【Shell 命令集合 磁盘维护 】Linux 在特定的分区上建立 linux 文件系统 mkfs命令使用教程
35 0
|
2月前
|
Shell Linux C语言
【Shell 命令集合 磁盘管理 】Linux 以树状图列出目录的内容 tree命令使用指南
【Shell 命令集合 磁盘管理 】Linux 以树状图列出目录的内容 tree命令使用指南
48 0