Linux Add hard drive device

Source: Internet
Author: User

The FDISK command is used to manage disk partitions in the format: "fdisk [disk name]".

Managing hard disk devices in Linux systems the most common method is to use the FDISK command, which provides a "one-stop partition service" for adding, deleting, converting partitions, and so on, but the parameters of this command are interactive instead of the same parameters we used to write directly behind the command. Therefore, in the management of hard disk equipment is particularly convenient, can be adjusted according to the needs of the dynamic.

Parameters Role
M View all the available parameters
N Add a new partition
D Delete a partition information
L List all available partition types
T Change the type of a partition
P View Partition Table information
W Save and exit
Q Do not save direct exit

One, add a disk partition

To view current disk and partition conditions:

[[email protected] ~]# df-hfilesystem Size used Avail use% mounted on/dev/mapper/rhel-root 8.5G 3.1G                 5.5G 36%/devtmpfs 986M 0 986M 0%/devtmpfs 1001M 84K 1001M 1%/DEV/SHMTMPFS              1001M 8.7M 992M 1%/runtmpfs 1001M 0 1001M 0%/sys/fs/cgroup/dev/sda1 497M 140M 358M 29%/boottmpfs 201M 16K 201M 1%/run/user/42tmpfs 201M 0 20 1M 0%/run/user/0[[email protected] ~]# fdisk-ldisk/dev/sda:10.7 GB, 10737418240 bytes, 20971520 sectorsUnits =  Sectors of 1 * = bytessector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): Bytes/ Bytesdisk label Type:dosdisk identifier:0x0006c4ff Device Boot Start End Blocks Id system/de V/SDA1 * 2048 1026047 512000, linux/dev/sda2 1026048 20971519 9972736 8e Linux LV Mdisk/dev/mapper/rhel-root:9093 MB, 9093251072 bytes, 17760256 sectorsunits = sectors of 1 * = bytessector size (logical/physical): 512 bytes/512 bytesi/o Size (minimum/optimal): bytes/512 bytesdisk/dev/mapper/rhel-swap:1073 MB, 1073741824 bytes, 2 097152 sectorsunits = sectors of 1 * = bytessector size (logical/physical): bytes/512 bytesi/o Size (minimum  /optimal): bytes/512 bytesdisk/dev/sdb:5368 MB, 5368709120 bytes, 10485760 sectorsunits = sectors of 1 * 512 = 512 Bytessector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): + bytes/512 Bytes[[email p  Rotected] ~]#

As can be seen from the above, the second disk/dev/sdb a total of 5368MB, not used. Now we use the Fdisk command to divide the/dev/sdb into 500MB, mount it to the/lxjtest directory, and then divide the 200MB as a swap partition.

The 1th step: First Use the Fdisk command to try to manage the/DEV/SDB hard disk device, see the prompt information after the input parameter p to see the hard disk device has the partition information, which includes the size of the hard disk, the number of sectors and so on information:

[Email protected] ~]# fdisk/dev/sdbwelcome to fdisk (Util-linux 2.23.2). Changes'll remain in memory only, until the decide to write them. Be careful before using the Write command. Device does not contain a recognized partition table  ---Disk does not include any available partitions building a new DOS Disklabel with disk identifier 0x148e18c9. Command (M for help): pdisk/dev/sdb:5368 MB, 5368709120 bytes, 10485760 sectorsunits = sectors of 1 * = bytessec Tor size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk label Type:dosdis K identifier:0x148e18c9   Device Boot      Start         End      Blocks   Id  System

2nd step: Enter the parameter N to try to create a new partition information, the system will be asked to choose to continue to enter the parameter p to make a primary partition, or enter the parameter E to create an extended partition, so enter the parameter p to create a primary partition:

Command (M for help): npartition type:   P   Primary (0 primary, 0 extended, 4 free)   e   extendedselect (default p): P

3rd step: After confirming the creation of a primary partition, the system requires you to enter the number of the partition, since you already know that the primary partition number range is 1-4, so the default input 1 , then the system will be prompted to define the next start of the sector, the default does not need to change, The system will automatically calculate the most front free sector position, we can hit the carriage return, and finally the system will be asked to define the end sector location of the partition, which is actually want to define the size of the entire partition, but actually do not have to calculate the number of sectors, only need to input +500m You can create a hard disk partition with a capacity of 500MB.

Partition number (1-4, default 1): First sector (2048-10485759, default 2048): Using default value 2048Last sector, +secto RS or +size{k,m,g} (2048-10485759, default 10485759): +500mpartition 1 of type Linux and of size MiB is set

4th step: Use the parameter p again to see the partition information on the hard disk device, and sure enough to see a name called/DEV/SDB1, the starting sector is 2048, the end sector is 1026047 of the partition, this time do not directly close the window, but should hit the parameter w after the return, So the partition information is the true write success.

Command (M for help): pdisk/dev/sdb:5368 MB, 5368709120 bytes, 10485760 sectorsunits = sectors of 1 * = bytessec Tor size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk label Type:dosdis K identifier:0x148e18c9   Device Boot      Start         End      Blocks   Id  system/dev/sdb1            2048     1026047      512000   83  

5th step: After all the above mentioned steps, the Linux system will automatically abstract the hard disk partition into/DEV/SDB1 This device file, you can use the file command to see the properties of this document. Sometimes the system does not automatically synchronize the partition information to the Linux kernel, you can also enter the Partprobe command to manually synchronize information to the kernel, and generally recommended to hit two times will be better, but once encountered even this command can not be resolved, then restart the computer.

[Email protected] ~]# File/dev/sdb1/dev/sdb1:block Special

Use MKFS to format the/DEV/SDB1 partition.

[Email protected] ~]# mkfs.xfs/dev/sdb1meta-data=/dev/sdb1              isize=256    agcount=4, agsize=32000 blks         =                       sectsz=512   attr=2, projid32bit=1         =                       crc=0        finobt=0data     =                       bsize=4096   blocks= 128000, imaxpct=25         =                       sunit=0      swidth=0 blksnaming =version   2              bsize=4096   ascii-ci=0 Ftype=0log      =internal log           bsize=4096   blocks=853, version=2         =                       sectsz=512   sunit=0 blks , Lazy-count=1realtime =none                   extsz=4096   

Next, you can mount the use.

[[email protected] ~]# mkdir/lxjtest[[email protected] ~]# mount/dev/sdb1/lxjtest/[[email protected] ~]# df-hfilesyste M             Size  used Avail use% mounted on/dev/mapper/rhel-root  8.5G  3.1G  5.5G  36%/devtmpfs               986M     0  986M   0%/devtmpfs                 1001M   84K 1001M   1%/dev/shmtmpfs                 1001M  8.7M  992M   1%/runtmpfs                 1001M     0 1001M   0%/sys/fs/cgroup/dev/sda1              497M  140M  358M  29%/boottmpfs                  201M   16K  201M   1%/run/user/42tmpfs                  201M     0  201M   0%/ RUN/USER/0/DEV/SDB1              497M   26M  472M   6%/lxjtest

The device files mounted with the Mount command will expire on the next reboot, so if you want to keep the device file mounted permanently, you will need to write the mounted information item to the configuration file:

[Email protected] ~]# Vi/etc/fstab #/etc/fstab# Created by Anaconda on Wed Jul  5 03:56:47 2017## Accessible Filesy Stems, by reference, is maintained under '/dev/disk ' # See mans Pages Fstab (5), Findfs (8), mount (8) and/or Blkid (8) for Mor E info#/dev/mapper/rhel-root   /                       xfs     defaults        0 0uuid=4f396f9a-467e-4472-a654-836f2dc7d6ca/boot                   xfs     defaults        0 0/dev/mapper/rhel-swap   swap                    swap    defaults        0 0/dev/sdb1       / Lxjtest        xfs     defaults        0 0    
second, add the swap partition

Swap partition is a function similar to the virtual memory of Windows system, which can be used to solve the insufficient memory capacity by virtual memory of some hard disk space. However, since the swap is virtual with hard disk resources, the speed is much slower than the real physical memory, so generally only when the real physical memory is exhausted to call swap partition, the memory of temporarily infrequently used data storage temporarily to the hard disk, freeing up memory space for more active program services to use.

1th: Swap partition creation process is very similar to the one described in the previous section of the partition device Mount method, the first step is to do the/DEV/SDB storage device partition operation, take out a 200MB size of the primary storage partition and then save the exit:

[[email protected] ~]# fdisk/dev/sdbwelcome to fdisk (Util-linux 2.23.2). Changes'll remain in memory only, until the decide to write them. Be careful before using the Write command. Command (M for help): Npartition Type:p Primary (1 primary, 0 extended, 3 free) e extendedselect (default p): PPa  Rtition number (2-4, default 2): First sector (1026048-10485759, default 1026048): Using default value 1026048Last sector, +sectors or +size{k,m,g} (1026048-10485759, default 10485759): +200m Partition 2 of type Linux and of size M  IB is SetCommand (M-help): pdisk/dev/sdb:5368 MB, 5368709120 bytes, 10485760 sectorsunits = sectors of 1 * 512 = 512 Bytessector size (logical/physical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk label Typ     E:dosdisk identifier:0x148e18c9 Device Boot Start End Blocks Id system/dev/sdb1 2048 1026047 512000 linux/dev/sdb2 1026048 1435647 204Linuxcommand (M for help): Wthe partition table have been altered! Calling IOCTL () to re-read partition table. Warning:re-reading the partition table failed with error 16:device or resource busy. The kernel still uses the old table. The new table is being used atthe next reboot or after you run Partprobe (8) or KPARTX (8) Syncing disks. [[email protected] ~]# Partprobe executes the command to synchronize the partition information to the kernel

2nd step: Format the newly created storage partition using the format MKSWAP command dedicated to swap partition:

[[email protected] ~]# mkswap/dev/sdb2setting up swapspace version 1, size = 204796 kibno label, uuid=4746286f-4680-4a05- 878d-118fff5904ac

3rd Step: Next use the Swapon command to formally mount the prepared swap partition device to the system, and you can use the FREE-M command to see the change in the size of the swap partition (from 1023M to 1223M):

[[email protected] ~]# free-m        Total used        free      shared  buff/cache   availablemem:           2000         259        1398           8         342        1578Swap:          1023           0        1023[[email protected] ~]# swapon/dev/sdb2[ [Email protected] ~]# free-m        Total used        free      shared  buff/cache   Availablemem:         259        1398           8         342        1578Swap:          1223           0        1223

4th step: In order to allow the new swap partition device to be active after the reboot, you need to write to the configuration file in the following format.

[Email protected] ~]# Vi/etc/fstab #/etc/fstab# Created by Anaconda on Wed Jul  5 03:56:47 2017## Accessible Filesy Stems, by reference, is maintained under '/dev/disk ' # See mans Pages Fstab (5), Findfs (8), mount (8) and/or Blkid (8) for Mor E info#/dev/mapper/rhel-root   /                       xfs     defaults        0 0uuid=4f396f9a-467e-4472-a654-836f2dc7d6ca/boot                   xfs     defaults        0 0/dev/mapper/rhel-swap   swap                    swap    defaults        0 0/dev/sdb1       / Lxjtest        xfs     defaults        0 0/dev/sdb2       swap    swap    defaults        0 0

Linux Add hard drive device

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.