百度智能云

All Product Document

          Cloud Disk Service

          Format Partition in Linux System

          Overview

          If the Baidu Cloud Compute (BCC) purchased by you is Linux system, you should partition the disk after purchasing a new disk.

          Operation Steps

          You can use the two partition modes, namely, MBR mode and GPT mode. For the differences of the two modes and the precautions in the disk partition, you can view Overview of Disk Partition.

          Use the MBR Mode for Partition

          This operation step is to create one single partition for a new data disk of 5 GB (device name/dev/vdb) in CentOS/7.6 x86_64 (64bit) system.

          1.Log in to the BCC instance remotely

          Please first log in to the BCC instance. For the specific log-in mode, please view "Log in to Instance".

          2.View the information of the current disk

          Execute the command fdisk -l to view the information of the current disk.

          [root@instance-xxx ~]# fdisk -l 
          Disk/dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors 
          Units=sector of 1 * 512 = 512 bytes 
          Sector size (logic/physical): 512 bytes/512 bytes 
          I/O size (minimum/optimal): 512 bytes/512 bytes 
          Disk label type: dos 
          Disk identifier: 0x000b8163 
          Device        Boot       Start        End       Blocks     Id    System 
          /dev/vda1   *        2048    83886046    41941999+  83  Linux 
          Disk/dev/vdb: 5368 MB, 5368709120 bytes, 10485760 sectors 
          Units=sector of 1 * 512 = 512 bytes 
          Sector size (logic/physical): 512 bytes/512 bytes 
          I/O size (minimum/optimal): 512 bytes/512 bytes 

          Tips:

          • Please confirm the data disk has been mounted before viewing the information. If not, please mount the disk to the instance and then view the information.

          3.Partition the CDS cloud disk

          Partition the data disk using fdisk by running the following commands in sequence:

          • Execute fdisk/dev/vdb to partition the data disk;
          • Enter p and then press Enter key: Print the partition list to view the data disk partition; in this instance, the disk hasn't been partitioned;
          • Enter n and then press Enter key: Create a new partition;
          • Enter p and then press Enter key: Select the partition type as the main partition;

            Tips:

            • This operation step is to create a separate partition for the disk, namely, only the main partition is required. If you want to create multiple partitions for the disk, please select e.
          • Enter the partition number, and then press Enter key: In this example, create only one partition and enter 1;
          • Enter the first available sector number, and then press Enter key: Use the default value 2048;
          • Enter the last sector number, and then press Enter key: If you create one partition, press Enter key to use the default value; if you want to create multiple partitions, please enter the sector number according to the actual situation;
          • Enter p and then press Enter key: Print the partition list to view the partition of the current data disk;
          • Enter w and then press Enter key: Start the partition operation;
          [root@instance-xxx ~]# fdisk /dev/vdb 
          Welcome to use fdisk (util-linux 2.23.2). 
          The change will stay in the memory until you decide to write the change to the disk. 
          Please twice before using the write command. 
          Device does not contain a recognized partition table 
          Use the disk identifier 0x88504a48 to create a DOS disk label. 
          
          Command (enter m for help): p 
          Disk/dev/vdb: 5368 MB, 5368709120 bytes, 10485760 sectors 
          Units=sector of 1 * 512 = 512 bytes 
          Sector size (logic/physical): 512 bytes/512 bytes 
          I/O size (minimum/optimal): 512 bytes/512 bytes 
          Disk label type: dos 
          Disk identifier: 0xbc3ca63f 
          Device Boot       Start          End       Blocks    Id   System 
          
          Command (enter 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 
          
          Starting sector (2048-10485759, 2048 by default): 2048 
          
          Last sector, + sector or + size or +size{K, M, G} (2048-10485759, 10485759 by default): 
          
          The default value 10485759 will be used. 
          The partition 1 has been set as Linux type, with the size set as 5 GiB. 
          
          Command (enter m for help): p 
          Disk/dev/vdb: 5368 MB, 5368709120 bytes, 10485760 sectors 
          Units=sector of 1 * 512 = 512 bytes 
          Sector size (logic/physical): 512 bytes/512 bytes 
          I/O size (minimum/optimal): 512 bytes/512 bytes 
          Disk label type: dos 
          Disk identifier: 0xbc3ca63f 
          
           Device Boot       Start     End           Blocks    Id   System 
          /dev/vdb1            2048    10485759      5241856   83  Linux 
          
          Command (enter m for help): w 
          The partition table has been altered! 
          Calling ioctl() to re-read partition table. 
          The disk is being synchronized. 

          Tips:

          • The fdisk partition command parameters are as follows:
            b : Edit bsd disklabel;
            c : Switch the dos compatibility flag;
            d : Delete one partition;
            g : Create an empty GPT partition table;
            G : Create one IRIX (SGI) partition table;
            l : List the known partition type; m print the help menu;
            n : Add a new partition;
            o : Create a new empty DOS partition table;
            p : Print the partition table information;
            q : Exit and not save the changes;
            s : Create an empty Sun disk label;
            t : Change the system ID of partition;
            u : Change the display/entry unit;
            v : Verify the partition table;
            w : Write the partition table in the disk and exit;
            x : Additional function

          4.View a new partition

          Execute the command fdisk -l to view the establishment of a new partition.

          [root@instance-xxx ~]# fdisk -l 
          
          Disk/dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors 
          Units=sector of 1 * 512 = 512 bytes 
          Sector size (logic/physical): 512 bytes/512 bytes 
          I/O size (minimum/optimal): 512 bytes/512 bytes 
          Disk label type: dos 
          Disk identifier: 0x000b8163 
           Device Boot         Start          End       Blocks      Id   System 
          /dev/vda1   *         2048        83886046    41941999+   83   Linux 
          
          Disk/dev/vdb: 5368 MB, 5368709120 bytes, 10485760 sectors 
          Units=sector of 1 * 512 = 512 bytes 
          Sector size (logic/physical): 512 bytes/512 bytes 
          I/O size (minimum/optimal): 512 bytes/512 bytes 
          Disk label type: dos 
          Disk identifier: 0xbc3ca63f 
          Device Boot       Start          End       Blocks    Id   System 
          /dev/vdb1          2048       10485759     5241856   83    Linux 

          5.Create one file system

          Execute the command mkfs.ext4/dev/vdb1 to create one file system in the new partition. The creation time changes with the Cloud Disk Storage (CDS) capacity.

          [root@instance-xxx ~]# mkfs.ext4 /dev/vdb1 
          mke2fs 1.42.9 (28-Dec-2013) 
          File system label= 
          OS type: Linux 
          Block size=4096 (log=2) 
          Blocking size=4096 (log=2) 
          Stride=0 blocks, Stripe width=0 blocks 
          327680 inodes, 1310464 blocks 
          65523 blocks (5.00%) reserved for the super user 
          First data block=0 
          Maximum filesystem blocks=1342177280 
          40 block groups 
          32768 blocks per group, 32768 fragments per group 
          8192 inodes per group 
          Superblock backups stored on blocks: 
          32768, 98304, 163840, 229376, 294912, 819200, 884736
          Allocating group tables: done                            
          Writing inode table: done                            
          Creating journal (32768 blocks): done 
          Writing superblocks and filesystem accounting information: done 

          Tips:

          • You can also create other file systems according to your own requirements.

          6.Back up a new partition file

          Execute the command echo/dev/vdb1/mnt ext4 defaults 0 0>>/etc/fstab, and write in the new partition information.

          [root@instance-xxx ~]# echo /dev/vdb1 /mnt ext4 defaults 0 0 >> /etc/fstab 

          Tips:

          • If you need to mount the Cloud Disk Storage (CDS) to other directories, you can modify/mnt in the command above to other mount nodes.

          7.View the new partition information

          Execute the command cat/etc/fstab to view the information, and it means the new partition information is written in when the information below displays.

          [root@instance-xxx ~]# cat /etc/fstab 
          # /etc/fstab 
          # Created by anaconda on Thu Mar 21 07:01:01 2019 
          # 
          # Accessible filesystems, by reference, are maintained under '/dev/disk' 
          # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info 
          # 
          UUID=84953f78-xxxx-4dbd-ac60-aaabc2e4cb9c /          ext4    defaults        1 
          1 
          /dev/vdb1 /mnt ext4 defaults 0 0 

          8.Mount the file system

          Execute the command mount/dev/vdb1/mnt to mount the file system to/mnt node.

          [root@instance-xxx ~]# mount /dev/vdb1 /mnt 

          9. View the current disk space

          Execute the command df -h to view the mounting condition, and if the partition information appears, it means the new partition is mounted.

          [root@instance-xxx ~]# df -h 
          File system  Capacity Used Available Used % mount target 
          /dev/vda1        40G  1.7G   36G    5% / 
          devtmpfs        2.0G     0  2.0G    0% /dev 
          tmpfs           2.0G     0  2.0G    0% /dev/shm 
          tmpfs           2.0G   17M  2.0G    1% /run 
          tmpfs           2.0G     0  2.0G    0% /sys/fs/cgroup 
          tmpfs           396M     0  396M    0% /run/user/0 
          /dev/vdb1       4.8G   20M  4.6G    1% /mnt 

          Use the GPT Mode for Partition

          This operation step is to create one single partition for a new data disk of 2300 GB (device name/dev/vdc) in CentOS/7.6 x86_64 (64bit) system.

          1.Log in to the BCC instance remotely

          Please first log in to the BCC instance. For the specific log-in mode, please view "Log in to Instance"

          2.View the information of the current disk

          Execute the command fdisk -l to view the information of the current disk. You can see that the current/dev/vdc disk is in the status of "Partition".

          [root@instance-xxxx ~]# fdisk -l 
          
          Disk/dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors 
          Units=sector of 1 * 512 = 512 bytes 
          Sector size (logic/physical): 512 bytes/512 bytes 
          I/O size (minimum/optimal): 512 bytes/512 bytes 
          Disk label type: dos 
          Disk identifier: 0x000b8163 
          
          Device Boot       Start    End          Blocks      Id   System 
          /dev/vda1  *       2048    83886046     41941999+   83   Linux 
          
          Disk/dev/vdc: 2469.6 GB, 2469606195200 bytes, 4823449600 sectors 
          Units=sector of 1 * 512 = 512 bytes 
          Sector size (logic/physical): 512 bytes/512 bytes 
          I/O size (minimum/optimal): 512 bytes/512 bytes 

          Tips:

          • Please confirm the data disk has been mounted before viewing the information. If not, please mount the disk to the instance and then view the information.

          3.Partition the CDS cloud disk

          • Use parted to partition the data disk, execute the command parted/dev/vdc, and then press Enter key. According to the prompts, operate respectively as follows.
          • Enter mklabel gpt, and then press Enter key to change into GPT partition format.
          • Enter mkpart primary 1 100% and then press Enter key to divide one main partition, and set its start and end positions.
          • Enter align-check optimal 1 and then press Enter key to check whether the partition is aligned. If 1 is returned, the partition is aligned.
          • Enter print and then press Enter key to view the partition table of the current disk.
          • Enter quit and then press Enter key to exit.
          [root@instance-xxxx ~]# parted /dev/vdc 
          GNU Parted 3.1 
          Use/dev/vdc 
          Welcome to GNU Parted!Type 'help' to view a list of commands. 
          (parted) mklabel gpt                                                      
          (parted) mkpart primary 1 100%                                            
          (parted) align-check optimal 1                                            
          1 aligned 
          (parted) print                                                            
          Model: Virtio Block Device (virtblk) 
          Disk /dev/vdc: 2470GB 
          Sector size (logical/physical): 512B/512B 
          Partition Table: gpt 
          Disk Flags: 
          
          Number   Start    End      Size     File system   Name      Mark 
           1       1049kB   2470GB   2470GB                 primary 
          
          (parted) quit                                                             
          Information: You may need to update/etc/fstab. 

          4.The system rereads the partition table

          Run the command partprobe to enable the system to reread the partition table.

          [root@instance-xxxx ~]# partprobe 

          5.Create a file system

          Run the command mkfs -t<file system format>/dev/vdc1 to create a file system. This example takes ext4 as an example.

          [root@instance-xxxx ~]# mkfs -t ext4 /dev/vdc1 
          mke2fs 1.42.9 (28-Dec-2013) 
          File system label= 
          OS type: Linux 
          Block size=4096 (log=2) 
          Blocking size=4096 (log=2) 
          Stride=0 blocks, Stripe width=0 blocks 
          150732800 inodes, 602931200 blocks 
          30146560 blocks (5.00%) reserved for the super user 
          First data block=0 
          Maximum filesystem blocks=2751463424 
          18400 block groups 
          32768 blocks per group, 32768 fragments per group 
          8192 inodes per group 
          Superblock backups stored on blocks: 
          	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
          	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
          	102400000, 214990848, 512000000, 550731776
          
          Allocating group tables: done                            
          Writing inode table: done                            
          Creating journal (32768 blocks): done 
          Writing superblocks and filesystem accounting information: done 

          6.Create a mount target and mount the file system

          Execute mkdir<mount target> to create a mount target. This instance is mounted to/set mount target. Execute mount/dev/vdc1/set to mount the partition/dev/vdc to/set. Execute df -h to view the space and usage of the current disk.

          [root@instance-xxxx ~]# mkdir /set 
          [root@instance-xxxx ~]# mount /dev/vdc1 /set 
          [root@instance-xxxx ~]# df -h 
          File system  Capacity Used Available Used % mount target 
          /dev/vda1        40G  1.7G   36G    5% / 
          devtmpfs        2.0G     0  2.0G    0% /dev 
          tmpfs           2.0G     0  2.0G    0% /dev/shm 
          tmpfs           2.0G   17M  2.0G    1% /run 
          tmpfs           2.0G     0  2.0G    0% /sys/fs/cgroup 
          /dev/vdb1       4.8G   20M  4.6G    1% /mnt 
          tmpfs           396M     0  396M    0% /run/user/0 
          /dev/vdc1        2.3T   85M  2.1T    1% /set 
          Previous
          Format Partition in Windows System
          Next
          Uninstall Cloud Disk