zoukankan      html  css  js  c++  java
  • Linux 硬盘相关操作

    常用查询命令

    • 查看当前磁盘及分区情况
    df  -h
    fdisk -l

    • fdisk 命令说明
    参数 作用
    m 查看全部可用的参数
    n 添加新的分区
    d 删除某个分区信息
    l 列出所有可用的分区类型
    t 改变某个分区的类型
    p 查看分区表信息
    w 保存并退出
    q 不保存直接退出

     新增分区

    • 开始挂载空闲硬盘
    fdisk  /dev/vdb
    • 输入p查看当前硬盘
    root@chongzhuang-ghj-redhat6-01-20210:~# fdisk  /dev/vdb
    
    Welcome to fdisk (util-linux 2.27.1).
    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.
    Created a new DOS disklabel with disk identifier 0xdc60fc48.
    
    Command (m for help): p
    Disk /dev/vdb: 1000 GiB, 1073741824000 bytes, 2097152000 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
    Disklabel type: dos
    Disk identifier: 0xdc60fc48
    • 输入n创建新分区

    这里依次输入了四个参数

    参数一:主分区(p)还是扩展分区(e)    我这里选择了主分区

    参数二:主分区的编号默认是1 我这里也输入1

    参数三:扇区起始位置 直接回车不输入选默认

    参数四: 定义下整个分区的大小 我这里输入900000

    Command (m for help): n
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1): 1
    First sector (2048-2097151999, default 2048): 
    Last sector, +sectors or +size{K,M,G,T,P} (2048-2097151999, default 2097151999): 900000
    
    Created a new partition 1 of type 'Linux' and of size 438.5 MiB.
    • 保存退出

    输入w  命令

    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.
    • 查看分区
     file  /dev/vdb1
    • 格式化分区
    root@chongzhuang-ghj-redhat6-01-20210:~#  mkfs.xfs  /dev/vdb1
    meta-data=/dev/vdb1              isize=512    agcount=4, agsize=28061 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=1, sparse=0
    data     =                       bsize=4096   blocks=112244, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =internal log           bsize=4096   blocks=855, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =none                   extsz=4096   blocks=0, rtextents=0
    • 挂载到文件夹
    root@chongzhuang-ghj-redhat6-01-20210:~# cd /
    root@chongzhuang-ghj-redhat6-01-20210:/# mkdir  /data
    root@chongzhuang-ghj-redhat6-01-20210:/# ^C
    root@chongzhuang-ghj-redhat6-01-20210:/# mount  /dev/vdb1   /data
    root@chongzhuang-ghj-redhat6-01-20210:/# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    udev            7.9G     0  7.9G   0% /dev
    tmpfs           1.6G   73M  1.5G   5% /run
    /dev/vda1        78G   73G  1.7G  98% /
    tmpfs           7.9G  1.1M  7.9G   1% /dev/shm
    tmpfs           5.0M     0  5.0M   0% /run/lock
    tmpfs           7.9G     0  7.9G   0% /sys/fs/cgroup
    tmpfs           1.6G     0  1.6G   0% /run/user/0
    none             78G   73G  1.7G  98% /var/lib/docker/aufs/mnt/c66a3d8b2e9fcb96c8a842f985baf8cd45a9971042c882daab583a0892e7afdf
    shm              64M     0   64M   0% /var/lib/docker/containers/ff4ecd20fdaf7667aa4f3583726f1e670b8c2c7068b7620e802bdba0f05fff1d/shm
    /dev/vdb1       436M   23M  414M   6% /data
    root@chongzhuang-ghj-redhat6-01-20210:/# 

     删除分区

     卸载正在使用的硬盘分区

     删除对应分区

    root@chongzhuang-ghj-redhat6-01-20210:~# umount /data
    root@chongzhuang-ghj-redhat6-01-20210:~# fdisk /dev/vdb
    
    Welcome to fdisk (util-linux 2.27.1).
    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/vdb: 1000 GiB, 1073741824000 bytes, 2097152000 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
    Disklabel type: dos
    Disk identifier: 0xdc60fc48
    
    Device Boot Start End Sectors Size Id Type
    /dev/vdb1 2048 2097151800 2097149753 1000G 83 Linux
    
    Command (m for help): d
    Selected partition 1
    Partition 1 has been deleted. 

    如果要重新挂载该分区 注意生成后格式化

    mkfs -t  ext4 /dev/vdb1
  • 相关阅读:
    python selenium启动配置
    pyqt5安装 + pycharm配置
    Python redis 存取使用
    pycharm 打不开 解决办法
    Python 将图片上传至阿里云OSS对象存储
    mysql表中已有数据,为表新增一个自增id。
    Python 使用BrowserMob Proxy + Selenium 获取Ajax加密数据
    Pycharm 2020.01亲测激活到2089年
    Python3 执行JS出现JSON未定义问题
    pycharm激活,此方法为永久激活。
  • 原文地址:https://www.cnblogs.com/cyh1282656849/p/14677511.html
Copyright © 2011-2022 走看看