Manually Partitioning Your Hard Drive with fdisk
Creating partitions via the command line interface is simple and quick, also having the kernel acknowledge the partition table has been modified and having the partition scheme take effect without having to reboot your workstation/server and without having to use the parted utility.
The first step to this guide is to see what hard drives are available and what hard drive you would like to partition. If you have multiple hard drives in your machine, fdisk will report them to you as shown in Figure 1. There are two hard drives shown in Figure 1 “sda” and “sdb”.
The fdisk command with the -l qualifier (“fdisk -l“) will display the current partition tables along with the hard drives that are attached to your workstation/server as shown in Figure 1.
linux-1reo:~ # fdisk -l Disk /dev/sda: 80.0 GB, 80026361856 bytes 255 heads, 63 sectors/track, 9729 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 1402 11261533+ 7 HPFS/NTFS /dev/sda2 1403 1415 104422+ 83 Linux /dev/sda3 1416 1546 1052257+ 82 Linux swap / Solaris /dev/sda4 1547 9729 65729947+ 5 Extended /dev/sda5 1547 7920 51199123+ 8e Linux LVM Disk /dev/sdb: 80.0 GB, 80026361856 bytes 255 heads, 63 sectors/track, 9729 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sdb1 * 1 9729 78148161 8e Linux LVM Disk /dev/sdc: 500.1 GB, 500107862016 bytes 255 heads, 63 sectors/track, 60801 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Figure 1: fdisk -l output.
Once you have determined which hard drive you want to partition you can issue the fdisk command followed by the hard drive (“fdisk /dev/sda“), in this article we will use the first hard drive (sda).
linux-1reo:~ # fdisk /dev/sda The number of cylinders for this disk is set to 9729. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help):
Figure 2: Partitioning the first hard drive (sda).
Once fdisk has been executed your command prompt will change to “Command (m for help):” and you are ready to examine and partition your hard drive. The commands that are supported by fdisk can be displayed by pressing the “m” character followed by the return key. The commands that we will be using are “p” for printing the partition table, “n” for creating a new partition and “w” for saving the changes and exiting.
Displaying the current partition table
The first step before we start to partition our hard drive is to get a sense of what disk space we have available and what the current partition table looks like. The command we will use from fdisk is the “p” character which will print the current partition table as show in Figure 3.
Command (m for help): p Disk /dev/sda: 80.0 GB, 80026361856 bytes 255 heads, 63 sectors/track, 9729 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 1402 11261533+ 7 HPFS/NTFS /dev/sda2 1403 1415 104422+ 83 Linux /dev/sda3 1416 1546 1052257+ 82 Linux swap / Solaris /dev/sda4 1547 9729 65729947+ 5 Extended /dev/sda5 1547 7920 51199123+ 8e Linux LVM
Figure 3: Current partition table.
The output shown in Figure 3 shows that we have 1809 cylinders available (9729 ? 7920 = 1809) and with this we can use the calculation (1809 * 16065 * 512 = 14879531520 Bytes) which is roughly about 14 gigabytes. (The 16065 and 512 were taken from the “Units =” statement and may differ on your system, so you may be require to substitute them if necessary).
Creating a new partition
The next step is to create our new partition. For our example, we will create a partition of type “Linux” with the partition size of one gigabyte. The command that we will use to create our new partition is the “n” character, we will then be asked to select what cylinder to start from (I recommend sticking with the default) and the size of the partition as shown in Figure 4.
Command (m for help): n First cylinder (7921-9729, default 7921): Using default value 7921 Last cylinder or +size or +sizeM or +sizeK (7921-9729, default 9729): +1024M
Figure 4: Creating a new partition with the size of one gigabyte.
Once the partition has been created, using the “p” character we can display our new partition table which will show the newly created partition, as shown in Figure 5.
Command (m for help): p Disk /dev/sda: 80.0 GB, 80026361856 bytes 255 heads, 63 sectors/track, 9729 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 1402 11261533+ 7 HPFS/NTFS /dev/sda2 1403 1415 104422+ 83 Linux /dev/sda3 1416 1546 1052257+ 82 Linux swap / Solaris /dev/sda4 1547 9729 65729947+ 5 Extended /dev/sda5 1547 7920 51199123+ 8e Linux LVM /dev/sda6 7921 8045 1004031 83 Linux
Figure 5: Newly created partition (sda6).
Writing the new partitions to disk
Now that the partition has been successfully created you can save the changes by issuing the “w” character which will write the new partition table to the hard disk as shown in Figure 6.
Command (m for help): w The partition table has 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 will be used at the next reboot. Syncing disks. Figure 6: Writing the new partition table to disk.
Activating the newly created partition
Once the new partition table has been written to the hard disk it is possible to have the kernel read the new partition table without the need of rebooting. The first step is to create a mount point for the new partition, in our example we will use “/media/newpart” and also use the command “partprobe” to have the kernel re-read the partition table, as shown in Figure 7.
linux-1reo:~ # mkdir /media/newpart linux-1reo:~ # partprobe
Figure 7: Creation of a new mount point and a re-read of the partition table.
Now that a new mount point has been created and the partition table has been re-read by the kernel you can now format the partition and place a file system of your choice on it. (ext2, ext3, ResierFS etc) In our example we have chosen the ResierFS file system as shown in Figure 8.
linux-1reo:~ # mkfs.reiserfs /dev/sda6 mkfs.reiserfs 3.6.19 (2003 www.namesys.com) A pair of credits: The Defense Advanced Research Projects Agency (DARPA, www.darpa.mil) is the primary sponsor of Reiser4. DARPA does not endorse this project; it merely sponsors it. Alexander Lyamin keeps our hardware running, and was very generous to our project in many little ways. Guessing about desired format.. Kernel 22.214.171.124-0.8-default is running. Format 3.6 with standard journal Count of blocks on the device: 126496 Number of blocks consumed by mkreiserfs formatting process: 8215 Blocksize: 4096 Hash function used to sort names: "r5" Journal Size 8193 blocks (first block 18) Journal Max transaction length 1024 inode generation number: 0 UUID: e20e2dc1-7277-4ab1-930c-038e54548540 ATTENTION: YOU SHOULD REBOOT AFTER FDISK! ALL DATA WILL BE LOST ON '/dev/sda3'! Continue (y/n):y Initializing journal - 0%....20%....40%....60%....80%....100% Syncing..ok ReiserFS is successfully created on /dev/sda3. linux-1reo:~ #
Figure 8: Formatting the newly created partition.
Once the partition has been formatted with the file system of your choice you can mount and use your newly created partition, Figure 9 shows the newly created partition being mounted.
linux-1reo:~ # mount /dev/sda6 /media/partnew
Figure 9: Mounting the newly created partition.
Once you have mounted your newly created and formatted partition you can store your files on the partition without having any problems, you may also add your new partition to the “/etc/fstab” file so that the partition will be mounted after every reboot.
SUSE Linux Enterprise Desktop 10
SUSE Linux Enterprise Server 10