Root Partition

Warning

If not used carefully this process can be dangerous

Altering partitions as described in this article with incorrect arguments can cause loss of data and potentially damage the computer.

Parted, the partition editing tool discussed in this article, alters partition structures in a way that cannot be undone. To ensure that the computer is not compromised, follow the instructions in this article with care and ensure that each step performed is not in doubt.

It is recommended to make backups of valuable data on the computer before performing operations that cannot be undone.

Introduction

The root volume used in the initrd: initial ramdisk article is a RAM disk located in primary storage. Initially locating the root volume in initrd ensures that it can be used on any PC regardless of what hardware is or is not connected. However, a RAM disk is very limited in storage capacity and any changes (e.g. files saved) are not persistent - they are lost when the computer is turned off.

To be useful, the root volume should be located in more permanent storage; it usually resides in a partition on a hard disk. If Unix has been deployed to flash memory in previous articles there will be unused space on the flash drive which can be partitioned to contain the root volume, and it is suggested that this volume be used as a trial the first time this article is followed. The partitioning example in this article demonstrates creation of a partition in flash memory.

This article explains how to use GNU Parted to examine and edit partitions and to provide a partition that can be used as the root volume.

Concepts

partition 

Partitioning is the creation of separate divisions of a hard disk, flash memory or similar recording medium. Each partition is normally a volume.

This article explains how to use GNU Parted to partition a storage device and make a partition available for use as the root volume.

volume 

A volume is a single accessible region of data that contains a single filesystem and can therefore hold directories and files. It is either a partition in the partitioned recording medium or the unpartitioned recording medium in a data storage device.

The volume made available in this article is used to hold the root directory.

filesystem 

A filesystem is a defined structure for storing and organising data to facilitate location and access.

Data within a filesystem is stored in files. The filesystem provides access to data in a volume by maintaining the physical location of the files.

The volume made available in this article contains an ext2 filesystem holding the root directory. Creation of subdirectories is not discussed in this article.

Prerequisites

The following article must have been completed:

  • initrd: initial ramdisk

The following programs must have been installed:

To install any of the programs, clicking on the item in the list will display installation instructions.

Partitioning

The Parted static binary installation creates a file named parted-1.8.1-static. Note the device and directory this file is located in. The directory will be referred to as the Parted directory.

Before editing partitions, the Parted manual should be downloaded and read. At the time of writing this article the manual could be found at http://www.gnu.org/software/parted/manual.

Parted provides the following commands:

check 

Check whether the filesystem on a partition has errors.

cp 

Copy the filesystem from one partition to another, deleting the original contents of the destination partition.

help 

Display help.

mklabel 

Create a disk label.

mkfs 

Make a filesystem on a partition, destroying all data that resides on that partition.

mkpart 

Create a new partition without creating a new filesystem on it.

mkpartfs 

Create a new partition with a new filesystem on it.

move 

Move a partition on the device.

The old and new partition positions must not overlap. A partition can only be moved into free space.

name 

Set the name of a partition.

print 

Display the partition table on the selected device or detailed information about a particular partition.

quit 

Leave Parted.

rescue 

Rescue a lost partition.

resize 

Resize a partition.

rm 

Remove a partition.

select 

Select the device for Parted to edit.

set 

Change a flag on a partition.

unit 

Select the default unit that Parted will use.

The commands make it possible to rearrange partitions on secondary storage devices in numerous ways, providing facilities to make a partition available for use as a root volume.

The following instructions demonstrate how to create a new partition on the flash drive used while following the instructions in the initrd: initial ramdisk article. If there is no other preferred location, this is recommended as a trial the first time this procedure is followed. If another location is preferred, the instructions in this article should be read and then modified as required making use of the above commands and their descriptions in the Parted user manual.

1. 

Start Unix.

The last activity performed on startup is a check for USB devices. Note the device representing the flash drive. In the above example this is sdb.

2. 

Mount the Parted volume: the volume containing the Parted directory.


# mount /dev/[Parted volume] /mnt -n

If the computer has one hard disk with one partition which contains the Parted directory, [Parted volume] will be sda1. If there is more than one hard disk or partition, a different device may need to be specified. For example if the Parted directory resides in the ninth partition of the first disk the following command is issued to mount the volume:


# mount /dev/sda9 /mnt -n

It may be necessary to experiment with various sd?? options until the correct one is found. The ls command can be used to confirm that the correct device has been selected by typing


# ls /mnt/[Parted directory]

For example, if the Parted directory is product/parted, typing the following command will list the parted-1.8.1-static file:


# ls /mnt/product/parted

3. 

Run Parted.


# /mnt/[Parted directory]/parted-1.8.1-static /dev/[flash drive device]

For example if the Parted directory is product/parted and the device representing the flash drive is sdb, type the following:


# /mnt/product/parted/parted-1.8.1-static /dev/sdb

4. 

Display the partition table


(parted) print free

Parted displays information relating to each partition on the current device and free space.

If the selected device is the flash drive used while following the instructions in the initrd: initial ramdisk article, the partition information will be similar to the above.

The information above relates to a flash drive represented by device sdb with capacity of 1007MB and free space of 967MB after the partition created following the initrd: initial ramdisk article. Any flash drive populated using that article would have one partition with the details displayed above.

5. 

Create a partition utilising the free space.


(parted) mkpartfs primary ext2 [start] [end]

In the example above [start] is 39.4MB and [end] is 1007MB, so the command is


(parted) mkpartfs primary ext2 39.4MB 1007MB

6. 

Display the partition table again.

This time partition information is similar to the following:

7. 

Leave Parted.


(parted) quit

8. 

Unmount the Parted volume.


# umount /mnt

Term

root directory 

The root directory is the top-most directory in a hierarchy, and can be likened to the root of a tree as the starting point where all branches originate. Unix abstracts this hierarchy, and in Unix-like systems, the root directory is denoted by /, where the directory entry itself has no name (its name is the empty part before the initial directory delimiter (/)). All filesystem entries, including mounted volumes, are “branches” of this root.

Further Comments

This article demonstrates creation of a partition in flash memory for use as a root volume. A root volume can exist on a variety of secondary storage recording media, including:

Parted provides commands for creating, destroying, moving, resizing, checking and copying partitions and the filesystems on them. The commands make it possible to create space for new operating systems, to reorganise usage of secondary storage devices, to copy data between devices and to create images for replicating an installation on another computer.

Any partition can be used as a root volume and the commands provided by Parted make it possible to create a root volume in a partition located in the most convenient region of data storage. Factors affecting the choice of where to locate the root volume include:

  • the durability of the storage, e.g. whether data is lost when the computer is turned off, how long data stored remains available and how many times data can be written or read.

  • the ease with which stored data can be accessed when the computer is booted, e.g. whether special drivers are required to read the data.

  • the stability of the device identifier. For example, a storage device connected via USB may be identified by sdb on one occasion and the next time it may be identified by sdc if another device has been connected.

  • the availability of the device. For example, it may be preferable to locate the root volume on a device that cannot be disconnected from the computer.

  • portability between machines. For example, it may be intended that the same root volume is used on more than one physical computer for data transferability or operation in multiple geographical locations.


home Home Page