The Sky is not the limit

Entries tagged as ‘parted’

How to use parted for creating patition larger that 2 TB ?

August 23, 2008 · 1 Comment

To create partitions larger than 2TB we need to use GPT labels. Standard fdisk doesn’t understand GPT labels so we need to use parted.

Here we are going to partition the disk /dev/sdb

root@localhost ~> parted /dev/sdb

This will bring up parted.  Type help to view the commands in parted prompt.

(parted) help
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,mktable 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 [free|NUMBER|all]                  display the partition table, a partition, or all devices
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 the FLAG on partition NUMBER
toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
unit UNIT                                set the default unit to UNIT
version                                  displays the current version of GNU Parted and copyright information

root@localhost ~> parted /dev/sdb
GNU Parted 1.8.1
Using /dev/sdb
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted)

To change the label to gpt we run the following command:

(parted) mklabel gpt

Next run the print command: This will list the disk geometry. Please note the size listed:

(parted) print

Model: Adaptec raid5-1 (scsi)
Disk /dev/sdb: 10.7TB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End     Size    File system  Name     Flags

This will tell us where to start and end the partitions. To create one huge partition ( 8 Tb = 8388608 bytes) run the following commands:

(parted) mkpart primary 0 8388607.000

The command reads as make a primary partition, start at 0 and end at 8388607.000

Also, if you are making a partition for a device smaller than the limit from the notes below, you can use the following if the geometry doesn’t show like it does above. Just exit out of parted, and run this from a shell:

root@localhost ~> parted -s — /dev/sdb  mkpart primary ext3 0 -1

This will take the whole disk for creating the partition.

The parition has been created and now you can quit parted:
(parted) quit

Now all that has to be done is to format the partition:(the -m swith tells mkfs to only reserve 1% of the blocks for the super block)

root@localhost ~> mkfs.ext3 -m1 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1024000000 inodes, 2047999751 blocks
20479997 blocks (1.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
62500 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000, 550731776, 644972544, 1934917632

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

This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Mount the disk

root@localhost ~> mount /dev/sdb1 /disk1

root@localhost ~> df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             240G  2.3G  225G   2% /
/dev/sda1             996M   45M  900M   5% /boot
tmpfs                 2.0G     0  2.0G   0% /dev/shm
/dev/sdb1             7.6T  177M  7.5T   1% /disk1

Now edit /etc/fstab to mount the partiton automatically on boot.

root@localhost ~>vi /etc/fstab

Add the following  line  in /etc/fstab

/dev/sdb1     /disk1   ext3    defaults        0 0

Reference :-  http://www.gnu.org/software/parted/manual/html_mono/parted.html

Categories: Linux tutorials
Tagged: , , , , ,

Adding swap space

May 5, 2008 · Leave a Comment

Swap Memory is a space in the Hard Disk of your computer that Operating Systems (Linux in our case) will use to put the info that is actually on the RAM to free it for another application. Sometimes in the course of a system’s existence you find that the swap partition you set up at install-time just isn’t enough anymore. So we need to increase the swap space for better performance of the system. You have two options: add a swap partition or add a swap file. It is recommended that you add a swap partition, but sometimes that is not easy if you do not have any free space available in the disk to create partition.

A) To add a swap partition (assuming /dev/sdb2 is the swap partition you want to add):

1. The hard drive can not be in use (partitions can not be mounted, and swap space can not be enabled). The easiest way to achieve this it to boot your system in rescue mode. Refer to Chapter 8 for instructions on booting into rescue mode. When prompted to mount the filesystem, select Skip.

Alternately, if the drive does not contain any partitions in use, you can unmount them and turn off all the swap space on the hard drive with the swapoff command.

2. Create the swap partition using parted or fdisk. Using parted is easier than fdisk; thus, only parted will be explained. To create a swap partition with parted:

* At a shell prompt as root, type the command parted /dev/sdb, where /dev/sdb is the device name for the hard drive with free space.

* At the (parted) prompt, type print to view the existing partitions and the amount of free space. The start and end values are in megabytes. Determine how much free space is on the hard drive and how much you want to allocate for a new swap partition.

* At the (parted) prompt, type mkpartfs part-type linux-swap start end, where part-type is one of primary, extended, or logical, start is the starting point of the partition, and end is the end point of the partition.

Changes take place immediately; be careful when you type.

* Exit parted by typing quit.

3. Now that you have the swap partition, use the command mkswap to setup the swap partition. At a shell prompt as root, type the following:

mkswap /dev/sdb2

4. To enable the swap partition immediately, type the following command:

swapon /dev/sdb2

5. To enable it at boot time, edit /etc/fstab to include:

/dev/sdb2 swap swap defaults 0 0

The next time the system boots, it will enable the new swap partition.

6. After adding the new swap partition and enabling it, make sure it is enabled by viewing the output of the command cat /proc/swaps or free.

B) To add a swap file:

1. Determine the size of the new swap file and multiple by 1024 to determine the block size. For example, the block size of a 128 MB swap file is 131072.

2. At a shell prompt as root, type the following command with count being equal to the desired block size:

root@localhost ~> dd if=/dev/zero of=swapfile bs=1024 count=131072
131072+0 records in
131072+0 records out

where

dd: – is used to copy a specified number of bytes from an Input file (if) to an Output file (of). Here the dd command copy null characters from the special file “/dev/zero” and copy it to the output file “aSwapFile” in the “/” directory. The “bs” specifies that the characters are read as BYTES. The “count” specifies the size of the bytes block that is to be created in the output file.

3. Change the permission

root@localhost ~> chmod 600 swapfile

4. Setup the swap file with the command

root@localhost ~> mkswap swapfile
Setting up swapspace version 1, size = 135372800 bytes

5. To enable the swap file immediately but not automatically at boot time:

root@localhost ~> swapon swapfile

6. To enable it at boot time, edit /etc/fstab to include:

/swapfile swap swap defaults 0 0

The next time the system boots, it will enable the new swap file.

7. After adding the new swap file and enabling it, make sure it is enabled by viewing the output of the command cat /proc/swaps or free.

Adding a Swap File on FreeBSD

1. Be certain that your kernel configuration includes the memory disk driver (md(4)). It is default in GENERIC kernel.

device md # Memory “disks”

2. Create a swapfile (/usr/swap0):

# dd if=/dev/zero of=/usr/swap0 bs=1024k count=64

3. Set proper permissions on (/usr/swap0):

# chmod 0600 /usr/swap0

4. Enable the swap file in /etc/rc.conf:

swapfile=”/usr/swap0″ # Set to name of swapfile if aux swapfile desired.

5. Reboot the machine or to enable the swap file immediately, type:

# mdconfig -a -t vnode -f /usr/swap0 -u 0 && swapon /dev/md0

Adding a Swap File on Solaris

If you have a Solaris system that badly needs more swap but you don’t have a free swap device available, you can create a file in the file system and add it as additional swap.

  1. Use mkfile to create a file suitable for a local swap area. For example, to create a 1GB swap file:
        /usr/sbin/mkfile 1024m /swap

    where /swap is the name of the file to be used as swap space. Units for the size can be kilobytes (k), blocks (b), or megabytes (m).

  2. Tell the system to start using the file as swap:
        /usr/sbin/swap -a /swap

    Use swap -l to verify that the swap file has been activated.

Categories: Linux tutorials
Tagged: , , , , , , , , , ,