Login
Password

Forgot your password?

Managing Partitions with Bash

By Edited Oct 19, 2016 0 0

If you've ever installed older versions of Linux or any version of Windows Server, you might remember having to manually create partitions on the hard disk. Partitions are basically segments or “logical drives” stored on the physical drive and each partition contains exactly one filesystem. You can manage your partitions using Terminal, Bash and the commands fdisk and parted.

Fdisk

FDisk

Fdisk has two modes, interactive and non-interactive. The non-interactive mode might look like the command pictured above, which displays information about the partitions on the hard drive. Using this command might require typing su or sudo in front of it and entering your administrator password. This is a way to prevent non-administrators from making unwanted changes to your partitions.

FDisk Interactive

To make changes to a particular partition, use the interactive mode of fdisk. The command will look like, fdisk /dev/partitionname, replacing partitionname with the partition you want to modify. Then, type in m to see a full list of available options. You should only type in “x” if you have plenty of experience with partitions! It contains options such as changing the number of cylinders or heads, fixing partition order, and changing the disk identifier. Each option in the “expert command” list holds the potential of making unintended changes to your partition and possibly making your data inaccessible.

Parted

Parted Interactive

Like fdisk, the parted command also has an interactive and a non-interactive mode. Users can modify partitions in either mode using parted. Simply typing in sudo parted gives me the interactive mode, and then I can type in help to see a list of available commands. Print will produce a chart with information about partitions, including size in gigabytes and type of partition. Unlike fdisk, print doesn't give an actual partition name. Instead, it assigns each partition a number.

Be careful when modifying partition tables using parted because it will overwrite existing partition tables without prompting you first. If you're used to Terminal, you're probably used to hitting the up arrow when you've made a typo, but you shouldn't rely on that when using parted. One typo could leave you in the dark or reaching for your favorite recovery tool.

Mkpart is parted's equivalent of the more familiar mkdir that tells Bash to make a directory. The usual syntax is mkpart PART-TYPE [FS-TYPE] START END. PART-TYPE tells Bash what type of partition to make. Options for this include primary, logical or extended. FS-TYPE tells which type of filesystem you want to use for the partition, such as FAT32 or NTFS. START and END tells which location on the disk you want the partition to start and end, such as 4GB or 10%. If you want the command to count from the end of the disk, type in a negative number such as -1s to end the partition at the last sector on the disk. For the mkpart command, the FS-TYPE is optional; to require the FS-TYPE option and the creation of a filesystem type, use the command mkpartfs. If you used mkpart and now want to specify a filesystem type for it, mkfs NUMBER FS-TYPE will set a filesystem type for the partition number you select.

The rmNUMBER command will remove the partition that you specify by its number. Be very careful about using this so you don't accidentally delete an important partition.

There are many useful options with both fdisk and parted, but it is always a good idea to test new options in a safe environment like a virtual box or an old computer that nobody uses anymore so you can easily rebuild if you run into trouble. As always, it makes sense to learn as much as you can, so resources like the book below should be helpful if you are new to Bash.

Advertisement
Advertisement

Comments

Add a new comment - No HTML
You must be logged in and verified to post a comment. Please log in or sign up to comment.

Explore InfoBarrel

Auto Business & Money Entertainment Environment Health History Home & Garden InfoBarrel University Lifestyle Sports Technology Travel & Places
© Copyright 2008 - 2016 by Hinzie Media Inc. Terms of Service Privacy Policy XML Sitemap

Follow IB Technology