设为首页 收藏本站
查看: 389|回复: 0

[经验分享] Linux磁盘管理、分区、扩展SWAP

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-17 09:50:00 | 显示全部楼层 |阅读模式
[iyunv@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.
[iyunv@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
[iyunv@RHEL7 ~]# mkfs.ext4 /dev/sdb2
[iyunv@RHEL7 ~]# mkdir /sdb1
[iyunv@RHEL7 ~]# mkdir /sdb2
[iyunv@RHEL7 ~]# mount /dev/sdb1 /sdb1
[iyunv@RHEL7 ~]# mount /dev/sdb2 /sdb2
[iyunv@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)
[iyunv@RHEL7 ~]# df | tail -2
/dev/sdb1                485036   24580    460456   6% /sdb1
/dev/sdb2                 90099    1550     81740   2% /sdb2
设备开机自动挂载
[iyunv@RHEL7 ~]# vim /etc/fstab
/dev/sdb1       /sdb1   xfs     defaults 0 0
/dev/sdb2       /sdb2   ext4    defaults 0 0
重新挂载所有分区
[iyunv@RHEL7 ~]# mount -a

使用UUID实现 自动挂载
查看分区的UUID
[iyunv@RHEL7 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="58972903-1d37-4acf-a108-d7221f08e1af" TYPE="xfs"
[iyunv@RHEL7 ~]# blkid /dev/sdb2
/dev/sdb2: UUID="46adcd74-5806-45de-8006-a893c548c9d4" TYPE="ext4"
将/dev/sdb1,/dev/sdb2设备名称使用uuid号替代
[iyunv@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
再重新挂载
[iyunv@RHEL7 ~]# mount -a
卸载挂载点
[iyunv@RHEL7 ~]# umount /sdb1
[iyunv@RHEL7 ~]# umount /sdb2
大于2TB以上的分区 使用parted分区
GPT:全局唯一标识分区表,Gpt对分区数量没有限制
查看是否安装了parted
[iyunv@RHEL7 ~]# rpm -qf `which parted`
parted-3.1-17.el7.x86_64
[iyunv@RHEL7 ~]# rpm -qa | grep parted
pyparted-3.9-7.el7.x86_64
parted-3.1-17.el7.x86_64
查看分区状态
[iyunv@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
[iyunv@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
[iyunv@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分区
[iyunv@RHEL7 ~]# ls /dev/sdb*
/dev/sdb  /dev/sdb1
[iyunv@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
[iyunv@RHEL7 ~]# swapon /dev/sdb1
[iyunv@RHEL7 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1826       1132        694         10          1        434
-/+ buffers/cache:        696       1129
Swap:         1190          0       1190
[iyunv@RHEL7 ~]# swapoff /dev/sdb1


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-259090-1-1.html 上篇帖子: cheungssh自动化运维工具 下篇帖子: [root@RHEL7 ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Change... Linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表