SUSE Conversations


Disk Management



By: DamianMyerscough

April 21, 2008 6:00 am

Reads:549

Comments:0

Rating:0

In this article we are going to look at disk management, this includes partitioning the hard disk drive using three different partition management utilities. We will also look at resizing the ext3 and ReiserFS file systems. The partitioning utilities that we will look at are listed in Table 1.

Partition Utility Description
cfdisk The cfdisk is a curses based partitioning tool similar to fdisk only with a curses based interface.
fdisk The fdisk partition utility is the standard partitioning utility for manipulating partition tables. The fdisk utility that is ported with Linux is similar, if not identical to Microsoft Windows fdisk.
GNU parted The parted utility is a much more powerful partitioning utility as it provides a batch and a non-batch mode. When using parted for manipulating partition tables the effects are written on the fly.

Table 1: Partition utilities.

Introduction

In the first section of this article we are going to look at partitioning the hard disk drive using three different tools, we will start with the easiest utility first and work our way up to the more advance utility. We will also look at partitioning in a batched mode using the parted utility. Table 2 lists the current partition table that we will be working with.

Partition Description
/dev/sda1 This partition is a Linux swap partition which is about 2155MB.
/dev/sda2 This partition were SUSE Linux Enterprise Server 10 SP1 is installed. The size of this partition is 43GB.
/dev/sda3 This is an empty partition that we will be using through out this article.

Table 2: Current partition layout.

cfdisk

The first partition utility that we are going to use is cfdisk, this utility is very similar to the fdisk utility with the only difference being the curses based interface as shown in Figure 1. The command used to start the cfdisk utility is cfdisk followed by the disk partition you would like to work with, in this article we will be using “/dev/sda”.

Click to view.

Figure 1: cfdisk user interface.

As you can see from Figure 1, a nice, clean and simple interface appears showing the current state of the partition table. Figure 1 also shows the functions that are available, using the left and right arrow keys you can navigate to each function.

Once you have had a look around with the cfdisk utility we can begin to create our first partition, as you can see in Figure 1 the sda3 partition has a file system already installed on it so we will first need to navigate to the delete function and delete the partition. Once the partition has been deleted the “FS Type” column should change to “Free Space” and you should now see a new function called: “New”.

The next step is to select the “New” function to begin creating the new partition, you will be asked what type of partition you want i.e. “Primary” or “Logical”. When dealing with partitions you are only allowed to create the maximum of four primary partitions, if you want more partitions you need to create the forth partition as an extended partition which will house logical partitions. Figure 1.1 shows what happens when you create four primary partitions.

Click to view.

Figure 1.1: Maximum of four primary partitions.

As you can see from Figure 1.1 the rest of the disk space becomes unusable when you have four primary partitions. So back to creating a partition, we are going to create two partitions, the first partition we will create will be one gigabyte and will be a primary partition and the second partition will be also one gigabyte but will be a logical partition. Once you are happy with the layout you can click the “New” button and then select primary by pressing the return key, you will then be asked how big you want the partition in megabytes so in our example we will be using 1024 megabytes. The next question you will be asked is “Add partition at beginning of free space” you just have to select “Beginning”.

Once the partition has been create and that it is the third partition in our scenario we will now need to create a logical partition. This progress is similar to creating a primary partition, the only difference is you need to select logical instead of primary. Once you have create the new logical partition you should have something similar to Figure 1.2.

Click to view.

Figure 1.2: New partition table.

Once you have finished with your partitioning you can simply select the “Write” button to have the effects written to the disk. However, if you don’t want to keep the changes you can navigate to the “Quit” button or just press the “q” key. Once you have written the effects to the disk you can use a utility called partprobe to make the kernel re-read the partition table as shown in Figure 1.3. If the partition table is not reloaded you will need to reboot the machine because the devices will not exist in the /dev directory.

linux-2ovj:~ # partprobe

Figure 1.3: Making the kernel re-read the partition table.

If you are happy with the results from using the cfdisk utility you can jump straight to the “Installing a File System” section in this article otherwise you can see what the other partitioning utilities are like, it is always good to know how to do things more than one way.

fdisk

In this section of the article we are going to look at deleting the previous partitions we created and creating some new partitions. The fdisk utility is almost identical to the cfdisk with the only difference being the curses based interface.

The first step you need to do to begin the partitioning process is type fdisk followed by the disk partition you would like to partition as shown in Figure 2.

linux-2ovj:~ # 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: Starting the fdisk utility.

As you can see from Figure 2 the command prompt changes to the fdisk command prompt and waits for the user to enter some fdisk commands. The first command you should issue is “m”, this will display the fdisk help menu and display all the supported commands as shown in Figure 2.1.

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help):

Figure 2.1: fdisk supported commands.

Once you get an idea for the commands that fdisk supports you can print the partition table out by issuing the “p” command as shown in Figure 2.2.

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         262     2104483+  82  Linux swap / Solaris
/dev/sda2   *         263        5484    41945715   83  Linux
/dev/sda3            5485        5608      996030   83  Linux
/dev/sda4            5609        5732      996030    5  Extended
/dev/sda5            5609        5732      995998+  83  Linux

Figure 2.2: Print the current partition table.

As you can see from Figure 2.2, the partition table is the one we created earlier with the cfdisk utility, you maybe wondering why there is a /dev/sda4 partition, as mentioned earlier the forth partition houses logical partitions thus allowing more than four partitions to be created. We are now going to delete the two partitions that we created earlier with the cfdisk utility, the command to delete these partitions is “d” as shown in Figure 2.3.

Command (m for help): d
Partition number (1-5): 5

Command (m for help): d
Partition number (1-5): 4

Command (m for help): d
Partition number (1-4): 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         262     2104483+  82  Linux swap / Solaris
/dev/sda2   *         263        5484    41945715   83  Linux

Command (m for help):

Figure 2.3: Deleting previous partitions.

To create a new partition with the fdisk utility you need to issue the “n” command and then you will be asked multiple questions regarding your new partition as shown in Figure 2.4.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (5485-9729, default 5485): 
Using default value 5485
Last cylinder or +size or +sizeM or +sizeK (5485-9729, default 9729): +1024M

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         262     2104483+  82  Linux swap / Solaris
/dev/sda2   *         263        5484    41945715   83  Linux
/dev/sda3            5485        5609     1004062+  83  Linux

Command (m for help):

Figure 2.4: Creating a new partition.

As you can see in Figure 2.4 the questions are straight forward. However, you might be wondering where I got the value three for the partition number, this is because sda1 and sda2 already exist and when selecting partition three sda3 is created.

Once you have created a primary partition you will need to create an extended partition because the next partition is the forth one. Once again you will have to issue the “n” command as shown in Figure 2.5.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First cylinder (5610-9729, default 5610): 
Using default value 5610
Last cylinder or +size or +sizeM or +sizeK (5610-9729, default 9729): 
Using default value 9729

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         262     2104483+  82  Linux swap / Solaris
/dev/sda2   *         263        5484    41945715   83  Linux
/dev/sda3            5485        5609     1004062+  83  Linux
/dev/sda4            5610        9729    33093900    5  Extended

Command (m for help):

Figure 2.5: Creating an extended partition.

As you can see in Figure 2.5 I left the default for the first cylinder and the last cylinder, the reason for this is because I wanted to use all the available space left for the logical partitions. Once your extended partition has been created you may notice when creating a new partition that you are not asked for a partition number as shown in Figure 2.6.

Command (m for help): n 
First cylinder (5610-9729, default 5610): 
Using default value 5610 
Last cylinder or +size or +sizeM or +sizeK (5610-9729, default 9729): +1024M 

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         262     2104483+  82  Linux swap / Solaris 
/dev/sda2   *         263        5484    41945715   83  Linux 
/dev/sda3            5485        5609     1004062+  83  Linux 
/dev/sda4            5610        9729    33093900    5  Extended 
/dev/sda5            5610        5734     1004031   83  Linux

Figure 2.6: Creating a logical partition.

Once you are happy with your partition table, you can issue the “w” command to write the changes to the hard disk drive, if you are not happy with the results you can issue the “q” command to quit the fdisk utility and the changes will not be committed.

Once the partition table has been written you will notice that the partitions do not exist in the /dev directory, for the effect to occur you can either reboot your machine or issue the partprobe command as shown in Figure 1.3.

If you are happy with the results from using the fdisk utility you can jump straight to the “Installing a File System” section in this article otherwise you can see what the other utilities are like, it is always good to know how to do things more than one way.

GNU parted

In this section of the article we are going to look at the GNU parted utility to manipulate the current partition table, we will be deleting the partitions that we previously created and creating new ones. Please note that when using the GNU parted utility that the effects are committed on the fly so if you accidentally delete a partition then its gone and with whatever was on that partition, so be very careful.

The GNU parted utility can be run in two modes, interactive mode (The user manipulates the partition table through an interface) or in a batch mode (The user manipulates the partition table via the command line). In this article we will look at both interactive and batch mode.

The first mode that we will look at is interactive mode, the GNU parted utility can be run simply by issuing the parted command followed by the disk partition you would like to manipulate as shown in Figure 3.

linux-2ovj:~ # parted /dev/sda 
GNU Parted 1.6.25.1 
Copyright (C) 1998 - 2005 Free Software Foundation, Inc. 
This program is free software, covered by the GNU General Public License. 

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See 
the GNU General Public License for more details. 

Using /dev/sda 
(parted)

Figure 3: Starting the GNU parted utility.

As you can see from Figure 3 that the GNU parted interface is similar to the fdisk utility, the only difference is you are not presented with a message telling you how to get help, to receive help you can issue the command “h” or type the word “help” as shown in Figure 3.1.

(parted) h                                                                
  check NUMBER                  do a simple check on the file system 
  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition 
  help [COMMAND]                prints general help, or help on COMMAND 
  mklabel LABEL-TYPE            create a new disklabel (partition table) 
  mkfs NUMBER FS-TYPE           make a FS-TYPE file system on partititon NUMBER 
  mkpart PART-TYPE [FS-TYPE] START END     make a partition 
  mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system 
  move NUMBER START END         move partition NUMBER 
  name NUMBER NAME              name partition NUMBER as NAME 
  print [NUMBER]                display the partition table, or a partition 
  quit                          exit program 
  rescue START END              rescue a lost partition near START and END 
  resize NUMBER START END       resize partition NUMBER and its file system 
  rm NUMBER                     delete partition NUMBER 
  select DEVICE                 choose the device to edit 
  set NUMBER FLAG STATE         change a flag on partition NUMBER 
  unit UNIT                     set the default unit to UNIT

Figure 3.1: Parted help screen.

Once you know how to retrieve help from the parted utility you can begin to remove the partitions that we created earlier using the “rm” command. Figure 3.2 shows the previous partitions being removed.

(parted) rm 5                                                                                                  
(parted) rm 4 
(parted) rm 3 
(parted) p                                                                
Disk geometry for /dev/sda: 0kB - 80GB 
Disk label type: msdos 
Number  Start   End     Size    Type      File system  Flags 
1       32kB    2155MB  2155MB  primary   linux-swap   type=82 
2       2155MB  45GB    43GB    primary   reiserfs     boot, type=83 
(parted)

Figure 3.2: Removing the previously created partitions.

Once you have deleted the partitions with the “rm” command you don’t have to issue anything else because the effects are committed on the fly. Once you have deleted the partitions you can exit the parted utility and check to see if the devices are still present on your machine as shown in Figure 3.3.

linux-2ovj:~ # ls /dev/sda* 
/dev/sda  /dev/sda1  /dev/sda2

Figure 3.3: Checking the available partitions.

As you can see from Figure 3.3 that no sda3, sda4 or sda5 exist, this is because, as I stated earlier the effects are committed on the fly. Once you have checked the devices no longer exist you can start the parted utility again and begin creating a partition.

There are two ways to create a partition the first way is to just issue the “mkpart” command and answer some questions as shown in Figure 3.4.

(parted) mkpart                                                       
Partition type?  primary/extended? primary 
File system type?  [ext2]? reiserfs                                     
Start? 45GB                                                              
End? 46GB 
(parted) p                                                                
Disk geometry for /dev/sda: 0kB - 80GB 
Disk label type: msdos 
Number  Start   End     Size    Type      File system  Flags 
1       32kB    2155MB  2155MB  primary   linux-swap   type=82 
2       2155MB  45GB    43GB    primary   reiserfs     boot, type=83 
3       45GB    46GB    897MB   primary                type=83 
(parted)

Figure 3.4: Creating a simple partition.

Once the partition has been created, we will now need to create an extended partition which will house all future logical partitions. The reason for this is because we already have three primary partitions, you maybe wonder in Figure 3.4 why we started at 45GB, the reason for this is because partition two ended at 45GB thus only allowing us to start from there without destroying any data.

The first task we need to do before creating a logical partitions is create an extended partition as shown in Figure 3.5 which fills the rest of the hard disk space.

(parted) mkpart extended 46GB 80GB                                        
(parted) p                                                                
Disk geometry for /dev/sda: 0kB - 80GB 
Disk label type: msdos 
Number  Start   End     Size    Type      File system  Flags 
1       32kB    2155MB  2155MB  primary   linux-swap   type=82 
2       2155MB  45GB    43GB    primary   reiserfs     boot, type=83 
3       45GB    46GB    897MB   primary                type=83 
4       46GB    80GB    34GB    extended               type=05

Figure 3.5: Creating an extended partition to house all logical partitions.

Once you have created your extended partition you can now create a logical partition using the “mkpart” command as shown in Figure 3.6.

(parted) mkpart logical 46GB 47GB                                         
(parted) p                                                                
Disk geometry for /dev/sda: 0kB - 80GB 
Disk label type: msdos 
Number  Start   End     Size    Type      File system  Flags 
1       32kB    2155MB  2155MB  primary   linux-swap   type=82 
2       2155MB  45GB    43GB    primary   reiserfs     boot, type=83 
3       45GB    46GB    897MB   primary                type=83 
4       46GB    80GB    34GB    extended               type=05 
5       46GB    46GB    8193kB  logical                type=83

Figure 3.6: Creating a simple logical partition.

Once you have created your logical partition and you are happy with your layout you can exit the parted utility by issuing the “q” command or by writing the word “quit”.

Now that we have created our partitions we are going to remove them and create them again, this time in batch mode. The first task we need to do is print the current partition table and then delete the partitions we made earlier as shown in Figure 3.7.

linux-2ovj:~ # parted /dev/sda print 
Disk geometry for /dev/sda: 0kB - 80GB 
Disk label type: msdos 
Number  Start   End     Size    Type      File system  Flags 
1       32kB    2155MB  2155MB  primary   linux-swap   type=82 
2       2155MB  45GB    43GB    primary   reiserfs     boot, type=83 
3       45GB    46GB    897MB   primary                type=83 
4       46GB    80GB    34GB    extended               type=05 
5       46GB    46GB    8193kB  logical                type=83 
Information: Don't forget to update /etc/fstab, if necessary.             

linux-2ovj:~ # parted /dev/sda rm 5 
Information: Don't forget to update /etc/fstab, if necessary.             

linux-2ovj:~ # parted /dev/sda rm 4 
Information: Don't forget to update /etc/fstab, if necessary.             

linux-2ovj:~ # parted /dev/sda rm 3 
Information: Don't forget to update /etc/fstab, if necessary.             

linux-2ovj:~ # parted /dev/sda print 
Disk geometry for /dev/sda: 0kB - 80GB 
Disk label type: msdos 
Number  Start   End     Size    Type      File system  Flags 
1       32kB    2155MB  2155MB  primary   linux-swap   type=82 
2       2155MB  45GB    43GB    primary   reiserfs     boot, type=83 
Information: Don't forget to update /etc/fstab, if necessary.             

linux-2ovj:~ #

Figure 3.7: Manipulating partitions from the command line.

Once you have deleted all the previous partitions you can begin creating a primary partition as shown in Figure 3.8.

linux-2ovj:~ # parted /dev/sda mkpart primary 45GB 47GB 
Information: Don't forget to update /etc/fstab, if necessary.             

linux-2ovj:~ # parted /dev/sda print 
Disk geometry for /dev/sda: 0kB - 80GB 
Disk label type: msdos 
Number  Start   End     Size    Type      File system  Flags 
1       32kB    2155MB  2155MB  primary   linux-swap   type=82 
2       2155MB  45GB    43GB    primary   reiserfs     boot, type=83 
3       45GB    47GB    1892MB  primary                type=83 
Information: Don't forget to update /etc/fstab, if necessary.             

linux-2ovj:~ #

Figure 3.8: Creating a primary partition via command line.

Once you have created a primary partition you will need to created an extended partition which will house all logical partition. Figure 3.9 show the creation of an extended partition along with a logical partition using a logical and (&&).

linux-2ovj:~ # parted /dev/sda mkpart extended 47GB 80GB && parted /dev/sda mkpart logical 47GB 48GB 
Information: Don't forget to update /etc/fstab, if necessary.             

Information: Don't forget to update /etc/fstab, if necessary.             

linux-2ovj:~ #

Figure 3.9: Creating a extended partition and a logical partition.

Installing a File System

Once you have created your partitions, you’ll need to decide what type of file system you would like to install on the partition. In this article, on the first primary partition we created we will install the ReiserFS file system and on the logical partition we created we will install the ext3 file system.

The partition that we will first install a file system on to is the /dev/sda3 partition, this partition will contain the ReiserFS file system and can be installed by simply issuing the “mkfs.reiserfs” command as shown in Figure 4.

linux-2ovj:~ # mkfs.reiserfs /dev/sda3 
mkfs.reiserfs 3.6.19 (2003 www.namesys.com) 

A pair of credits: 
Hans Reiser was the project initiator,  source of all funding for the first 5.5 
years. He is the architect and official maintainer. 

Continuing core development of ReiserFS is  mostly paid for by Hans Reiser from 
money made selling licenses  in addition to the GPL to companies who don't want 
it known that they use ReiserFS  as a foundation for their proprietary product. 
And my lawyer asked 'People pay you money for this?'. Yup. Life is good. If you 
buy ReiserFS, you can focus on your value add rather than reinventing an entire 
FS. 

Guessing about desired format.. Kernel 2.6.16.46-0.12-bigsmp is running. 
Format 3.6 with standard journal 
Count of blocks on the device: 461856 
Number of blocks consumed by mkreiserfs formatting process: 8226 
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: 032d5245-26fa-458b-bcbe-69b7273f6969 
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.

Figure 4: Installing the ReiserFS file system.

Once you have installed the ReiserFS file system you can now install the ext3 file system on the /dev/sda5 partition simply by issuing the”mkfs.ext3” command as shown in Figure 4.1.

linux-2ovj:~ # mkfs.ext3 /dev/sda5 
mke2fs 1.38 (30-Jun-2005) 
Filesystem label= 
OS type: Linux 
Block size=4096 (log=2) 
Fragment size=4096 (log=2) 
122624 inodes, 244983 blocks 
12249 blocks (5.00%) reserved for the super user 
First data block=0 
8 block groups 
32768 blocks per group, 32768 fragments per group 
15328 inodes per group 
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376 

Writing inode tables: done                            
Creating journal (4096 blocks): done 
Writing superblocks and filesystem accounting information: done 

This filesystem will be automatically checked every 37 mounts or 
180 days, whichever comes first.  Use tune2fs -c or -i to override. 
linux-2ovj:~ #

Figure 4.1: Installing the ext3 file system.

Now that you have installed the file system on both partitions you will need to do two things, the first action that needs to be done is creating two mount point for the partitions and then mounting the file system to see if it works.

The first step we need to do is create a mount point using the mkdir command as shown in Figure 4.2. The mount point can be placed anywhere on the Linux system. However, I recommend either putting your new mount points in the root of the file system (/) or in the /media directory.

linux-2ovj:~ # mkdir /new_mount_point1 
linux-2ovj:~ # mkdir /new_mount_point2

Figure 4.2: Creating the new mount points.

Once you have created the mount points you can begin to mount the partitions using the mount command as shown in Figure 4.3.

linux-2ovj:~ # mount /dev/sda3 /new_mount_point1 
linux-2ovj:~ # mount /dev/sda5 /new_mount_point2

Figure 4.3: Mounting the newly created partitions.

Once you have mounted the new partitions you can view them using two commands, mount or df as shown in Figure 4.4.

linux-2ovj:~ # df -h 
Filesystem            Size  Used Avail Use% Mounted on 
/dev/sda2              41G  2.4G   38G   6% / 
udev                  4.0G  156K  4.0G   1% /dev 
/dev/sda3             1.8G   33M  1.8G   2% /new_mount_point1 
/dev/sda5             942M   17M  879M   2% /new_mount_point2

Figure 4.4: Checking to see what partitions are mounted.

Once your partitions have been mounted you can use them as normal. However, to make these partitions mount automatically when your system reboots you will need to add them to the /etc/fstab file as shown in Figure 4.5.

/dev/sda3            /new_mount_point1    reiserfs      acl,user_xattr 1 1 
/dev/sda5            /new_mount_point2    ext3          acl,user_xattr 1 1

Figure 4.5: /etc/fstab file entries.

As you can see in Figure 4.5 the layout may seem a little strange. However, Table 3 explains what each column is for.

Column Description
/dev/sda3 The first field defines the block device.
/new_mount_point1 The second field defines the actual mount point on the file system.
reiserfs The third filed defines what type of file system is on that partition e.g. ReiserFS, ext2/3, XFS etc.
acl,user_xattr The forth field defines the mount options that are to be applied to the mount point.
1 The fifth field defines if the file system needs to be dumped using the dump command.
1 The sixth field defines if the file system needs to be checked using the fsck utility.

Table 3: Figure 4.5 explained.

Once you have appended your partitions to the /etc/fstab file you can unmount the partitions using the umount command as shown in Figure 4.6.

linux-2ovj:~ # umount /new_mount_point1 
linux-2ovj:~ # umount /new_mount_point2

Figure 4.6: Unmounting the partitions.

Once you have unmounted the previously mounted partitions you can issue the mount command followed by the “-a” qualifier to have the mount program read the /etc/fstab file and mount the partitions as shown in Figure 4.7.

linux-2ovj:~ # mount -a 
linux-2ovj:~ # df -h 
Filesystem            Size  Used Avail Use% Mounted on 
/dev/sda2              41G  2.4G   38G   6% / 
udev                  4.0G  156K  4.0G   1% /dev 
/dev/sda3             1.8G   33M  1.8G   2% /new_mount_point1 
/dev/sda5             942M   17M  879M   2% /new_mount_point2

Figure 4.7: Mounting all the partitions in the /etc/fstab file.

Resizing File System

In this section of the article we are going to resize the ext3 and ReiserFS file systems that we created earlier. The commands that we will be using are resize_reiserfs and resize2fs. The first command if you haven’t already guessed resizes ReiserFS file systems and the second command resizes ext2 and ext3 file systems.

Resizing ext2/3

The partition that we will be working with is the /dev/sda5 partition, as this was the partition that we installed the ext3 file system on, we will shrink this file system to 500 megabytes. The first command you need to execute is the umount command followed by /dev/sda5, the reason for this is because it could damage your data if the partition has not been unmounted. The second command that you need to execute is the e2fsck as this will perform check on the file system as shown in Figure 5.

linux-2ovj:~ # e2fsck -f /dev/sda5 
e2fsck 1.38 (30-Jun-2005) 
Pass 1: Checking inodes, blocks, and sizes 
Pass 2: Checking directory structure 
Pass 3: Checking directory connectivity 
Pass 4: Checking reference counts 
Pass 5: Checking group summary information 
/dev/sda5: 11/122624 files (0.0% non-contiguous), 7965/244983 blocks

Figure 5: Performing file system checks.

Once you have checked the file system you can issue the resize2fs command as shown in Figure 5.1 to resize the ext3 file system.

linux-2ovj:~ # resize2fs /dev/sda5 500M 
resize2fs 1.38 (30-Jun-2005) 
Resizing the filesystem on /dev/sda5 to 128000 (4k) blocks. 
The filesystem on /dev/sda5 is now 128000 blocks long.

Figure 5.1: Resize the ext3 file system.

Once you have resized the file system you can issue the mount command followed by the “-a” qualifier, this will remount all the partitions on the system. Once the partition has been remounted you can issue the df command to check the size of the file system that has just been resized as shown in Figure 5.2.

linux-2ovj:~ # mount -a 
linux-2ovj:~ # df -h 
Filesystem            Size  Used Avail Use% Mounted on 
/dev/sda2              41G  2.4G   38G   6% / 
udev                  4.0G  156K  4.0G   1% /dev 
/dev/sda3             1.8G   33M  1.8G   2% /new_mount_point1 
/dev/sda5             493M   17M  457M   4% /new_mount_point2 
linux-2ovj:~ #

Figure 5.2: Mounting and display the size of the new file system.

As you can see the file system was resized successfully, if you want to increase the file system size you need to resize the partition and then resize the file system to the size of the partition.

Resizing ReiserFS

In this section of the article we are going to be working with the /dev/sda3 partition which has the file system type of ReiserFS, we will be using the resize_reiser utility. The first step that needs to be done is the /dev/sda3 partition needs to be unmounted using the umount command as shown in Figure 6.

linux-2ovj:~ # umount /dev/sda3

Figure 6: Unmounting the sda3 partition.

Once the partition has been unmounted you can begin resizing the partition, in this article we are going to shrink the partition by 500 megabytes as shown in Figure 6.1.

linux-2ovj:~ # resize_reiserfs -s 500M /dev/sda3 
resize_reiserfs 3.6.19 (2003 www.namesys.com) 

You are running BETA version of reiserfs shrinker. 
This version is only for testing or VERY CAREFUL use. 
Backup of you data is recommended. 

Do you want to continue? [y/N]:y 
Processing the tree: 0%....20%....40%....60%....80%....100%                           left 0, 0 /sec 

nodes processed (moved): 
int        0 (0), 
leaves     1 (0), 
unfm       0 (0), 
total      1 (0). 

check for used blocks in truncated region 

ReiserFS report: 
blocksize             4096 
block count           128000 (461856) 
free blocks           119785 (453630) 
bitmap block count    4 (15) 

Syncing..done 

resize_reiserfs: Resizing finished successfully.

Figure 6.1: Resizing the ReiserFS file system.

Once you have resized the file system you can issue the mount command followed by the “-a” qualifier as shown in Figure 5.2. Once you have remounted the file system you can issue the df command and you will notice that the file system is 500 megabytes smaller.

Final Thoughts

In this article we looked at using three different partitioning utilities to repartition the hard disk drive using two different methods interactive and non-interactive, if you look back at what we did with the parted utility you will notice that we only covered the very basics. The parted utility has much more advanced features such as being able to move partitions around and resize them on the fly, I would strongly recommend reading the GNU parted manual. If by request, I could also write an article on using the GNU parted utility if anyone would be interested.

I would also recommend looking at the ext2online utility which has the power to resize live file systems which means you do not have to unmount the file system.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Tags:
Categories: Enterprise Linux, Technical Solutions

Disclaimer: As with everything else at SUSE Conversations, this content is definitely not supported by SUSE (so don't even think of calling Support if you try something and it blows up).  It was contributed by a community member and is published "as is." It seems to have worked for at least one person, and might work for you. But please be sure to test, test, test before you do anything drastic with it.

Comment

RSS