Anda di halaman 1dari 13

Partition Management

● Creating partitions
● Formatting partitions
● Mounting partitions
● Auto mounting partitions
● Repairing partitions using fsck
● Monitoring partitions using fuser
● Reading NTFS partitions

Version 1.0 linuxslides.blogspot.com


Creating Partitions
Before a hard disk can be used, you should:

1. Create partitions
2. Format partitions
3. Mount partitions

Version 1.0 linuxslides.blogspot.com


Displaying partitions using fdisk
Displaying partition table using command line fdisk:
$ sudo fdisk -l

Disk /dev/sda: 20.0 GB, 20020396032 bytes


255 heads, 63 sectors/track, 2434 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x97c997c9

Device Boot Start End Blocks Id System


/dev/sda1 * 1 1020 8193118+ 83 Linux
/dev/sda2 1021 1147 1020127+ 82 Linux swap/ Solaris
/dev/sda3 1148 2434 10337827+ 83 Linux

Disk /dev/sdb: 8086 MB, 8086618112 bytes


255 heads, 63 sectors/track, 983 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x04dd5721

Device Boot Start End Blocks Id System


/dev/sdb1 * 1 984 7897056+ b W95 FAT32
Partition 1 has different physical/logical endings:
phys=(982, 254, 63) logical=(983, 36, 13)

Version 1.0 linuxslides.blogspot.com


Displaying partitions using fdisk
Displaying partition table interactively using fdisk:
$ sudo fdisk /dev/sda

The number of cylinders for this disk is set to 2434.


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): p

Disk /dev/sda: 20.0 GB, 20020396032 bytes


255 heads, 63 sectors/track, 2434 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x97c997c9

Device Boot Start End Blocks Id System


/dev/sda1 * 1 1020 8193118+ 83 Linux
/dev/sda2 1021 1147 1020127+ 82 Linux swap / Solaris
/dev/sda3 1148 2434 10337827+ 83 Linux

Version 1.0 linuxslides.blogspot.com


fdisk menus
To see all menus type “m” inside fdisk:
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)

If we want to create a new partition, which menu should we


choose?
Version 1.0 linuxslides.blogspot.com
Creating partitions using fdisk
To create a new partition, choose “n” (add a new partition):
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (854-2482, default 854): [ENTER]
Using default value 854
Last cylinder, +cylinders or +size{K,M,G} (854-2482, default 2482): +1G

Then choose “w” to write all change to hard disk. IMPORTANT:


after write we can not undo the changes.
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. Version 1.0 linuxslides.blogspot.com
Formatting partitions
To format a partition use mke2fs:
$ sudo mke2fs -t ext4 /dev/sda3
The type option “-t” could accept these formats ext2, ext3, ext4, etc.
Or you can use mkfs.ext2, mkfs.ext3, mkfs.ext4,
mkfs.raiserfs, mkfs.vfat, and etc. For example:
$ sudo mkfs.ext4 /dev/sda3

Version 1.0 linuxslides.blogspot.com


Mounting partition
To mount a partition use mount command (first make the
mount point if not exist):
$ mkdir /mnt/data
$ mount /dev/sda3 /mnt/data
To show mounted partition use command below:
$ mount
or
$ df -h

Release a mounted partition using umount command:


$ umount /mnt/data
check if partition already released:
$ df -h
IMPORTANT: umount can not be done if the partition is accessed
by any users or applications
Version 1.0 linuxslides.blogspot.com
Monitoring partitions using fuser
To monitor who is accessing certain partitions, use fuser:
$ sudo fuser -u /mnt/data
/mnt/data: 9544c(linux)


/mnt/data is the mount point

9544 is the PID of the process that runs in the partition

linux is the user

If we want to kill the process use options “-uki”


(u = user, k = kill, i = interactive):

$ sudo fuser -uki /mnt/data


/mnt/data: 9544c(linux)
Kill process 9544 ? (y/N) y

Version 1.0 linuxslides.blogspot.com


Auto mounting partitions
Mounted partitions will automatically released after the
computer restarted. To automatically mount a partition every
restart use /etc/fstab.
The format of /etc/fstab:
<partition> <mount point> <type> <options> <dump> <pass>

For example, if we want partition /dev/sda3 always


mounted on /mnt/data, so the /etc/fstab configuration is:
$ sudo vim /etc/fstab
/dev/sda3 /mnt/data ext4 defaults 0 0

Version 1.0 linuxslides.blogspot.com


Repairing partitions using fsck
To check and repair partitions form damages use fsck:

$ sudo fsck /dev/sda3


fsck 1.40.8 (13-Mar-2008)
e2fsck 1.40.8 (13-Mar-2008)
/dev/sda3 is mounted.

WARNING!!! Running e2fsck on a mounted filesystem may cause


SEVERE filesystem damage.

Do you really want to continue (y/n)? n

You should umount the partition before running fsck:

$ umount /mnt/data
$ sudo fsck /dev/sda3

Version 1.0 linuxslides.blogspot.com


Reading NTFS partitions
To enable NTFS support, install ntfs-config package for GUI,
or ntfs-3g for command line:
$ sudo apt-get install ntfs-config

To activate, run ntfs-config from menu “System Tools” or


invoke ntfs-config from terminal.

NTFS setting in /etc/fstab:


$ sudo vim /etc/fstab
/dev/sda4 /mnt/windows ntfs-3g defaults 0 0

Version 1.0 linuxslides.blogspot.com


Using gparted
$ sudo gparted

Version 1.0 linuxslides.blogspot.com

Anda mungkin juga menyukai