• openSUSE Leap 15格式化挂载新分区


    前言

    安装系统的时候,因为有两块盘,一块机械盘sda,一块固态盘sdb。所以为了速度快,把系统安装在了固态盘中。安装的时候选择挂载了机械盘

    系统安装完成后,发现,sdb正常使用,sda只使用了boot和swap两个分区,剩下的空间都没有使用。现在想的是在home目录下创建一个code目录,用来保存代码,把sda剩下的空间挂载到code下。

    修改之前的状态

    $ sudo fdisk -l
    [sudo] password for root: 
    Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
    Disk model: TOSHIBA DT01ACA0
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disklabel type: gpt
    Disk identifier: EBE70B6B-5802-43FD-BD47-30042084360C
    
    Device       Start       End   Sectors   Size Type
    /dev/sda1     2048     18431     16384     8M BIOS boot
    /dev/sda2    18432   4212735   4194304     2G Linux swap
    
    
    Disk /dev/sdb: 223.6 GiB, 240057409536 bytes, 468862128 sectors
    Disk model: KINGSTON SA400S3
    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: gpt
    Disk identifier: 8B141E9A-1AA5-46AB-916C-BA6EB2A67712
    
    Device     Start       End   Sectors   Size Type
    /dev/sdb1   2048 468862094 468860047 223.6G Linux filesystem
    $ df -lh
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        3.9G     0  3.9G   0% /dev
    tmpfs           3.9G     0  3.9G   0% /dev/shm
    tmpfs           3.9G   18M  3.9G   1% /run
    tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
    /dev/sdb1       224G   14G  210G   7% /
    /dev/sdb1       224G   14G  210G   7% /boot/grub2/i386-pc
    /dev/sdb1       224G   14G  210G   7% /srv
    /dev/sdb1       224G   14G  210G   7% /opt
    /dev/sdb1       224G   14G  210G   7% /var
    /dev/sdb1       224G   14G  210G   7% /home
    /dev/sdb1       224G   14G  210G   7% /.snapshots
    /dev/sdb1       224G   14G  210G   7% /boot/grub2/x86_64-efi
    /dev/sdb1       224G   14G  210G   7% /tmp
    /dev/sdb1       224G   14G  210G   7% /usr/local
    /dev/sdb1       224G   14G  210G   7% /root
    tmpfs           791M     0  791M   0% /run/user/465
    tmpfs           791M   12K  791M   1% /run/user/1000

    我们可以看到sda只使用了2G多一点的空间,其余的并没有使用,df并不会显示swap和boot挂载的信息。整个系统,根目录,都挂在了sdb下。

    现在我们想把sda剩下的空间挂载到/home/xxx/code下

    创建分区

    fdisk /dev/sda

    运行fdisk,输入m,可以看到命令提示,输入n(add a new partition),然后看着提示默认就可以了,把sda剩下的空间分区到sda3,操作完成后,按照提示,输入w写入退出结束

    格式化分区

    分区创建完成后,需要格式化一下,如果不格式化,直接mount,会提示

    mount: wrong fs type, bad option, bad superblock on /dev/sda3

    通过mkfs格式化分区

    mkfs -t btrfs /dev/sda3

    因为opensuse默认的文件系统是btrfs,其他的分区都是btrfs,所以这里就按照默认操作

    这样分区就好了,可以通过mount挂载到其他的目录,但是如果想系统启动的时候自动挂载需要修改/dev/fstab

    fstab

    fstab是一个描述文件系统挂载信息的文件。格式如下

    $ cat /etc/fstab 
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /                       btrfs  defaults                      0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /var                    btrfs  subvol=/@/var                 0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /usr/local              btrfs  subvol=/@/usr/local           0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /tmp                    btrfs  subvol=/@/tmp                 0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /srv                    btrfs  subvol=/@/srv                 0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /root                   btrfs  subvol=/@/root                0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /opt                    btrfs  subvol=/@/opt                 0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /home                   btrfs  subvol=/@/home                0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /boot/grub2/x86_64-efi  btrfs  subvol=/@/boot/grub2/x86_64-efi  0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /boot/grub2/i386-pc     btrfs  subvol=/@/boot/grub2/i386-pc  0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /.snapshots             btrfs  subvol=/@/.snapshots          0  0
    UUID=22b6f5df-043f-4ecf-b9dc-cff2519112a3  swap                    swap   defaults                      0  0

    第一列是表示哪块分区,第二列表示挂载到哪里,第三列是文件系统,第四列是额外的配置,第五烈表示是否需要dump,第六列表示是否需要开机检查。

    第一列可以写成/dev/sda3,也可以写成上面的格式。用/dev/sda3有个问题就是如果磁盘中间动过,导致/dev下的设备描述符变了,那么挂载就会出错,所以可以使用分区的UUID来标识,这样就不会担心设备描述符变化的问题。UUID从哪里可以获得呢?

    $ ls -l /dev/disk/by-uuid
    total 0
    lrwxrwxrwx 1 root root 10 May 25 16:01 22b6f5df-043f-4ecf-b9dc-cff2519112a3 -> ../../sda2
    lrwxrwxrwx 1 root root 10 May 25 15:26 b682ce97-78fe-4879-a2da-f21fbb4c116f -> ../../sdb1

    在/dev/disk/by-uuid目录下,记载了对应的UUID。

    最后配置

    上面格式化完成分区后,通过查询对应的uuid,找到sda3的uuid,然后按照fstab的格式添加一条记录,重启,我们发现sda3分区已经挂载到code目录下了

    $ ls -l /dev/disk/by-uuid
    total 0
    lrwxrwxrwx 1 root root 10 May 25 16:01 22b6f5df-043f-4ecf-b9dc-cff2519112a3 -> ../../sda2
    lrwxrwxrwx 1 root root 10 May 25 15:26 b682ce97-78fe-4879-a2da-f21fbb4c116f -> ../../sdb1
    lrwxrwxrwx 1 root root 10 May 25 16:01 e5f117b8-7464-48d3-8122-102b3e15e27a -> ../../sda3
    $ cat /etc/fstab 
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /                       btrfs  defaults                      0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /var                    btrfs  subvol=/@/var                 0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /usr/local              btrfs  subvol=/@/usr/local           0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /tmp                    btrfs  subvol=/@/tmp                 0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /srv                    btrfs  subvol=/@/srv                 0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /root                   btrfs  subvol=/@/root                0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /opt                    btrfs  subvol=/@/opt                 0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /home                   btrfs  subvol=/@/home                0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /boot/grub2/x86_64-efi  btrfs  subvol=/@/boot/grub2/x86_64-efi  0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /boot/grub2/i386-pc     btrfs  subvol=/@/boot/grub2/i386-pc  0  0
    UUID=b682ce97-78fe-4879-a2da-f21fbb4c116f  /.snapshots             btrfs  subvol=/@/.snapshots          0  0
    UUID=22b6f5df-043f-4ecf-b9dc-cff2519112a3  swap                    swap   defaults                      0  0
    UUID=e5f117b8-7464-48d3-8122-102b3e15e27a  /home/arthas/code       btrfs  defaults                      0  0
    $ df -lh
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        3.9G     0  3.9G   0% /dev
    tmpfs           3.9G     0  3.9G   0% /dev/shm
    tmpfs           3.9G   18M  3.9G   1% /run
    tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
    /dev/sdb1       224G   14G  210G   7% /
    /dev/sdb1       224G   14G  210G   7% /boot/grub2/i386-pc
    /dev/sdb1       224G   14G  210G   7% /srv
    /dev/sdb1       224G   14G  210G   7% /opt
    /dev/sdb1       224G   14G  210G   7% /var
    /dev/sdb1       224G   14G  210G   7% /home
    /dev/sdb1       224G   14G  210G   7% /.snapshots
    /dev/sdb1       224G   14G  210G   7% /boot/grub2/x86_64-efi
    /dev/sdb1       224G   14G  210G   7% /tmp
    /dev/sdb1       224G   14G  210G   7% /usr/local
    /dev/sdb1       224G   14G  210G   7% /root
    /dev/sda3       464G  3.8M  462G   1% /home/xxx/code
    tmpfs           791M     0  791M   0% /run/user/465
    tmpfs           791M   12K  791M   1% /run/user/1000
    $ sudo fdisk -l
    [sudo] password for root: 
    Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
    Disk model: TOSHIBA DT01ACA0
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disklabel type: gpt
    Disk identifier: EBE70B6B-5802-43FD-BD47-30042084360C
    
    Device       Start       End   Sectors   Size Type
    /dev/sda1     2048     18431     16384     8M BIOS boot
    /dev/sda2    18432   4212735   4194304     2G Linux swap
    /dev/sda3  4212736 976773134 972560399 463.8G Linux filesystem
    
    
    Disk /dev/sdb: 223.6 GiB, 240057409536 bytes, 468862128 sectors
    Disk model: KINGSTON SA400S3
    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: gpt
    Disk identifier: 8B141E9A-1AA5-46AB-916C-BA6EB2A67712
    
    Device     Start       End   Sectors   Size Type
    /dev/sdb1   2048 468862094 468860047 223.6G Linux filesystem
  • 相关阅读:
    腾讯2014年实习生招聘笔试面试经历
    GitHub具体教程
    Hadoop Hive与Hbase关系 整合
    阿里中间件——消息中间件Notify和MetaQ
    Android分享介绍
    Python的包管理工具Pip
    [ACM] POJ 1094 Sorting It All Out (拓扑排序)
    机器学习实践指南:案例应用解析
    android之照相、相冊裁剪功能的实现过程
    组织:OASIS(结构化信息标准促进组织)
  • 原文地址:https://www.cnblogs.com/studywithallofyou/p/12957540.html
Copyright © 2020-2023  润新知