linux fdisk command disk to divide and mount new partitions

Today, Ubuntu in VirtualBox cannot enter the system. After logging in with the guest user, I know that the storage is insufficient. I found a solution on the Internet and copied it down and made a backup. To

enter the safe mode of linux, you need to press and hold shift

linux fdisk after booting up the command

fdisk - Partition table manipulator For Linux
1. Check the number of hard disks and partitions on the machine through fdisk -l;
fdsik can divide the disk into several areas, and can also specify the file system of the partition for each partition, such as linux, fat32, linux swap, fat16 And in fact, the file system of the Unix-like operating system, etc. Of course, after using fdisk to operate the partition on the disk, the file system required for formatting the partition must be formatted, so that a partition can be used.
The primary partition [Primary] (including the extended partition [ The total number of Extended]) cannot exceed 4; that is to say, the total number of primary partition [Primary] + extended partition [Extended] is at most 4, and there can only be one extended partition [Extended].
Therefore , if you want to divide into 4 fast disk partitions, then At most:
P+P+P+P or
P+P+P+E
Among them, 3P+E has only 3 available disks, the extended partition cannot be used directly, and it must be partitioned into a logical partition [Logical].

fdisk - l View hard disk and partition information
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux main partition
/dev/sda2 14 6387 51199155 83 Linux main partition  
/dev/sda3 6388 7407 8193150 82 Linux swap / Solaris primary partition
/dev/sda4 7408 60801 428887305 5 Extended extended partition
/dev/sda5 7408 20155 102398278+ 83 Linux logical partition
/dev/sda6 20156 26529 51199123+ 83 Linux logical partition From


the above information we know that this machine is mounted 1 hard disk sda, size 500G,
with 255 magnetic surfaces, 63 sectors, and 60801 magnetic columns;
The capacity of each magnetic column is 8225280 bytes, which is about 8.225280M
sda has 4 primary partitions sda1, sda2, sda3, sda4 (extended partition), and the logical partition is sd5, sd6 The total capacity of
the hard disk = the total capacity of the primary partition (including the extended partition)
Extended partition capacity = total capacity of logical partitions + total undivided capacity

Start: indicates that a partition starts from X cylinder (magnetic column);
End: indicates that a partition ends at Y cylinder (magnetic column);
id and System indicate that One meaning, id does not seem intuitive, we need to confirm the partition type by specifying the id when fdisk a partition; for example, 7 means NTFS partition; this must be specified by the t function in fdisk.
Blocks: Indicates how many os blocks the disk has, the unit is k. Usually, the size of an os block can be viewed through the command /sbin/tune2fs -l /dev/sda1 There is a block size parameter
Blocks = (the corresponding partition End value - the corresponding partition Start Value) x the capacity of the unit cylinder (magnetic cylinder), which is the amount of space the disk has.

From the above, it can be seen that the extended partition is from 7408 to 60801 magnetic cylinders and the logical partition is only from 7408 to 26529 magnetic cylinders, indicating that the extended partition has not been divided.

2. Let's see how to add a partition

#fdisk /dev/sda
Command (m for help):m [Press m here, it will output help]
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition Note: This is an action to delete a partition;
l list known partition types Note: l is to list the partition types for us to set the type of the corresponding partition;
m print this menu Note: m is to list the help information;
n add a new partition Note: add a partition;
o create a new empty DOS partition table
p print the partition table Note: p lists the partition table;
q quit without saving changes Note: exit without saving;
s create a new empty Sun disklabel
t change a partition's system id Note: t change the partition type;
u change display/entry units
v verify the partition table
w write table to disk and exit Note: write the partition table to the hard disk and exit;
x extra functionality (experts only) Note: extended application, expert function;

warning: be careful when deleting partitions, please look at the serial number of the partition, if you delete the extended partition, the logical partitions under the extended partition will be deleted; Be careful; if you know you are doing it wrong, don't panic, use q to exit without saving; remember! ! ! ! When the partition operation is wrong, do not enter w to save and exit! ! !

After the above menu appears, press p to see the partition situation
Command (m for help): p


Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 6387 51199155 83 Linux
/dev/sda3 6388 7407 8193150 Extended 82 Linux swap / Solaris
/dev/sda4 7408 60801 42888730
/dev/sda5 7408 20155 102398278+ 83 Linux
/dev/sda6 20156 26529 51199123+ 83 Linux

then press n (add a partition)
Command (m for help): n
First cylinder (26530-60801, default 26530): 27000
here Prompt which magnetic column this partition starts from. The default is followed by the previous partition. Enter here is the default value. It is best to press Enter directly. If you enter a non-default number, it will cause a waste of space;
then the
Last cylinder or +size or +sizeM or +sizeK (26530-60801, default 60801):
Note: This is to define the size of the partition, +200M means the size is 200M; of course, you can also calculate it according to the size of the unit cylinder indicated by p, and then come to Specify the value of End; if you want to add a partition with a size of about 10G, please input +10000M; after

inputting, you can exit from fdisk, use q or w
, where q is to exit without saving, and w is to save and exit
Command (m for help) : w
or
Command (m for help): q

Since my machine already has 4 primary partitions,
if the primary partition does not reach 4, it will not appear when it reaches 4. It will appear when
pressing n to add a partition
Command (m for help): n (Note: add a partition;)
Command action
e extended
p primary partition (1-4)
At this time, choose the primary partition or the extended partition according to your own needs.


3. After the partition is completed, the partition format must be changed

Use mkfs.bfs mkfs.ext2 mkfs.jfs mkfs.msdos mkfs.vfatmkfs.cramfs mkfs.ext3 mkfs.minix mkfs.reiserfs mkfs.xfs and other commands to format the partition, for example, I want to format sda7 as ext3 file system , then enter;

# mkfs.ext3 /dev/sda7
and then load sda7 to the current system to access files, there should be a mount command, but first you have to create a mount directory; for example /mnt/sda7

# mount /dev/sda7 / mnt/sda7
and then df -lh view,
you can enter the /mnt/sda7 directory, and then access the file

4. Let the hard disk start to mount automatically Edit the /etc/fstab file
with vi and add the following content
/dev/sda7 /mnt/sda7 ext3 defaults 1 2

/etc/fstab This file has other parameters that will be written later.

Excerpted from http://blog.itpub.net/29392174/viewspace-1064061/

First partition the two hard disks, format them, and then mount them into the system. For example, the hard disk that saves usr is mounted to /mnt/usr, and the hard disk that saves home is mounted to /mnt/home (/mnt/usr , /mnt/home needs to be established by yourself), then first copy the original system /usr and /home to /mnt/usr and /mnt/home respectively, the copy is completed, unmount the mounts of the two new disks, and then put These two disks are mounted to /home and /usr respectively. Modify /etc/fstab. After the modification is completed, mount -a should be fine. You can check the mount command.

1) Create a new partition with enough space for what you want Moved directory, such as /home
2) Create a new directory, $mkdir /mnt/newhome
3) Mount the new partition to the new directory, $sudo mount -t ext3 /dev/hda5 /mnt/newhome
(assuming here Now, the newly created partition is of ext3 type and is in /dev/hda5)
4) Copy the entire /home,
$cd /home/
$find . -depth -print0 | cpio --null --sparse -pvd /mnt/newhome/ (untested)

tar cpf - .|(cd /mnt/opttemp; tar xvpf -) (in the opt directory, there is a . in the command) (tested)
5) Unmount $sudo umount /mnt/ newhome
6) Rename the original /home, $sudo mv /home /old_home
7) Create a new /home, sudo mkdir /home
Mount the partition, $sudo mount /dev/hda5 /home
9) Add /dev/hda5 /home ext3 nodev,nosuid 0 2 to the "/etc/fstab" file, so that it will be automatically mounted when the system starts.
10) Delete the existing home, $sudo rm -r /old_home

tar cpf - .|(cd /mnt/opttemp; tar xvpf -)
has been tested, it has been done on the production machine, and it is available from elsewhere

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326682947&siteId=291194637