Disk Managment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Disk Management.

Disk Partitioning:-
1. Primary Partition In any hard disk you can create only 4 primary
partition
2. Extended Partition

Logical Partition

1. To Identify the device.


[root@server1 ~]#cd /dev ……...<PRESS ENTER>
[root@server1 ~]#ll ……...<PRESS ENTER>

2. To view the free space of the partition.


[root@server1 ~]#df -h /dev/sda5 ……...<PRESS ENTER>
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 1008M 190M 767M 20% /
Or
[root@server1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 1008M 190M 767M 20% /
tmpfs 250M 260K 250M 1%
/dev/shm
/dev/sda1 1008M 52M 906M 6%
/boot
/dev/sda7 1008M 34M 924M 4% /home
/dev/sda8 194M 5.7M 179M 4%
/tmp
/dev/sda2 9.9G 2.1G 7.4G 22%
/usr
/dev/sda3 9.9G 3.0G 6.4G 32% /var
/dev/sr0 2.8G 2.8G 0 100%
/media/RHEL_6.0 i386 Disc 1
/dev/mapper/VG1-LV2 97M 5.6M 87M 7%
/data/LV2
3. To list known partition types.
[root@server1 ~]#fdisk -l ……...<PRESS ENTER>

Disk /dev/sda: 42.9 GB, 42949672960 bytes


255 heads, 63 sectors/track, 5221 cylinders
Units = cylinder of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier : 0x000d5093

Device Boot Start End Blocks Id System


/dev/sda1 * 1 131 1048576 83 Linux
Partition 1 does not end on the cylinder boundary
/dev/sda2 131 1437 10485760 83 Linux
/dev/sda3 1437 2742 10485760 83 Linux
/dev/sda4 2742 5222 19921920 5 Extended
/dev/sda5 2742 2873 1048576 83 Linux
/dev/sda6 2873 3003 1048576 82 Linux swap / Solaris
/dev/sda7 3004 3134 1048576 83 Linux
/dev/sda8 3134 3160 204800 83 Linux
/dev/sda9 3160 3200 327200+ 83 Linux

4. To create a new partition.


[root@server1 ~]#fdisk /dev/sda ……...<PRESS ENTER>

WARNING: DOS-compatible mode is deprecated. It's strongly recommended


to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): m …….<PRESS ENTER>


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): p …….<PRESS ENTER>

Disk /dev/sda: 42.9 GB, 42949672960 bytes


255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d5093

Device Boot Start End Blocks Id System


/dev/sda1 * 1 131 1048576 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 131 1437 10485760 83 Linux
/dev/sda3 1437 2742 10485760 83 Linux
/dev/sda4 2742 5222 19921920 5 Extended
/dev/sda5 2742 2873 1048576 83 Linux
/dev/sda6 2873 3003 1048576 82 Linux swap / Solaris
/dev/sda7 3004 3134 1048576 83 Linux
/dev/sda8 3134 3160 204800 83 Linux
/dev/sda9 3160 3200 327200+ 83 Linux

Command (m for help): n …….<PRESS ENTER>


First cylinder (3003-5222, default 3003): 3201 …….<PRESS
ENTER>
Last cylinder, +cylinders or +size{K,M,G} (3201-5222, default 5222): 3250
…….<PRESS
ENTER>

Command (m for help): p …….<PRESS ENTER>

Disk /dev/sda: 42.9 GB, 42949672960 bytes


255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d5093
Device Boot Start End Blocks Id System
/dev/sda1 * 1 131 1048576 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 131 1437 10485760 83 Linux
/dev/sda3 1437 2742 10485760 83 Linux
/dev/sda4 2742 5222 19921920 5 Extended
/dev/sda5 2742 2873 1048576 83 Linux
/dev/sda6 2873 3003 1048576 82 Linux swap / Solaris
/dev/sda7 3004 3134 1048576 83 Linux
/dev/sda8 3134 3160 204800 83 Linux
/dev/sda9 3160 3200 327200 83 Linux
/dev/sda10 3201 3250 401593+ 83 Linux

Command (m for help): w …….<PRESS ENTER>

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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@server1 ~]# partx /dev/sda …….<PRESS ENTER>
OR
sudo partprobe /dev/sdb

Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda
(Device or resource busy). As a result, it may not reflect all of your changes
until after reboot.
Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0
has been opened read-only.
or
[root@server1 ~]# init 6 …….<PRESS ENTER>

5. To format the partition.


[root@server1 ~]# mkfs.ext4 /dev/sda10 …….<PRESS ENTER>
mke2fs 1.41.12 (17-May-2010)
warning: 183 blocks unused.

Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
100744 inodes, 401409 blocks
20079 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
49 block groups
8192 blocks per group, 8192 fragments per group
2056 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185

Writing inode tables: done


Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or


180 days, whichever comes first. Use tune2fs -c or -i to override.

6. To set label formatted partition.


[root@server1 ~]# e2label /dev/sda10 /new …….<PRESS ENTER>
[root@server1 ~]# e2label /dev/sda10 …….<PRESS ENTER>

7. To view the drive label.


[root@server1 ~]# cd /dev/disk/by-label/ …….<PRESS ENTER>
[root@server1 by-label]# ll …….<PRESS ENTER>
total 0
lrwxrwxrwx 1 root root 9 Jan 1 10:52 RHEL_6.0\x20i386\x20Disc\x201 -
> ../../sr0
lrwxrwxrwx 1 root root 11 Jan 1 10:59 \x2fnew -> ../../sda10

8. To mount a partition Temporarily.


[root@server1 ~]# mkdir /new …….<PRESS ENTER>
[root@server1 ~]# mount /dev/sda10 /new …….<PRESS ENTER>
[root@server1 ~]# mount …….<PRESS ENTER>
/dev/sda5 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda7 on /home type ext4 (rw)
/dev/sda8 on /tmp type ext4 (rw)
/dev/sda2 on /usr type ext4 (rw)
/dev/sda3 on /var type ext4 (rw)
/dev/sda9 on /acl type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/RHEL_6.0 i386 Disc 1 type iso9660
(ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmod
e=0500)
/dev/sda10 on /new type ext4 (rw)

9. To mount a partition permanently.


Note: to get the blocked or uuid of any partition use the below command
blkid
[root@server1 ~]# vi /etc/fstab …….<PRESS ENTER>
<PRESS> i

#
# /etc/fstab
# Created by anaconda on Tue Jan 1 09:37:27 2013
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=aea71178-a303-4725-8854-0b065575865e / ext4 defaults 11
UUID=4c51ce83-4c2e-4f23-8fd1-cc0e7c384990 /boot ext4 defaults
12
UUID=2fe9c195-d708-447c-b18c-f43c14ff021e /home ext4 defaults
12
UUID=7617828f-bd14-4773-9bc9-2e8f2d68cd40 /tmp ext4 defaults 12
UUID=d239eeb0-3190-4423-b2c1-c88d7599e20e /usr ext4 defaults 12
UUID=6cd376da-5dab-4f57-8d6a-0293d494e009 /var ext4 defaults 12
UUID=0350a0d9-35e1-4741-b1b8-8c046499d992 swap swap defaults
00
UUID=33d2e7ba-f014-42bd-938b-0b05f6887033 /acl ext4 defaults 00
tmpfs /dev/shm tmpfs defaults 00
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 00
proc /proc proc defaults 00
/dev/sda10 /new ext4 defaults
00
<ESC>
:wq!
Right click on it
Or and select copy
Paste it into fstab

[root@server1 ~]# cd /dev/disk/by-uuid/ …….<PRESS ENTER>


[root@server1 by-uuid~]# ll …….<PRESS ENTER>
lrwxrwxrwx 1 root root 10 Jan 1 11:19 0350a0d9-35e1-4741-b1b8-
8c046499d992 -> ../../sda6
lrwxrwxrwx 1 root root 11 Jan 1 11:19 12d19b6a-eb43-4e35-88a3-
ebf3e11f686d -> ../../sda10
lrwxrwxrwx 1 root root 10 Jan 1 11:19 2fe9c195-d708-447c-b18c-
f43c14ff021e -> ../../sda7
lrwxrwxrwx 1 root root 10 Jan 1 11:19 33d2e7ba-f014-42bd-938b-
0b05f6887033 -> ../../sda9
lrwxrwxrwx 1 root root 10 Jan 1 11:19 4c51ce83-4c2e-4f23-8fd1-
cc0e7c384990 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jan 1 11:19 6cd376da-5dab-4f57-8d6a-
0293d494e009 -> ../../sda3
lrwxrwxrwx 1 root root 10 Jan 1 11:19 7617828f-bd14-4773-9bc9-
2e8f2d68cd40 -> ../../sda8
lrwxrwxrwx 1 root root 10 Jan 1 11:19 aea71178-a303-4725-8854-
0b065575865e -> ../../sda5
lrwxrwxrwx 1 root root 10 Jan 1 11:19 d239eeb0-3190-4423-b2c1-
c88d7599e20e -> ../../sda2

[root@server1 ~]# vi /etc/fstab …….<PRESS ENTER>


<PRESS> i

#
# /etc/fstab
# Created by anaconda on Tue Jan 1 09:37:27 2013
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=aea71178-a303-4725-8854-0b065575865e / ext4 defaults 11
UUID=4c51ce83-4c2e-4f23-8fd1-cc0e7c384990 /boot ext4 defaults
12
UUID=2fe9c195-d708-447c-b18c-f43c14ff021e /home ext4 defaults
12
UUID=7617828f-bd14-4773-9bc9-2e8f2d68cd40 /tmp ext4 defaults 12
UUID=d239eeb0-3190-4423-b2c1-c88d7599e20e /usr ext4 defaults 12
UUID=6cd376da-5dab-4f57-8d6a-0293d494e009 /var ext4 defaults 12
UUID=0350a0d9-35e1-4741-b1b8-8c046499d992 swap swap defaults
00
UUID=33d2e7ba-f014-42bd-938b-0b05f6887033 /acl ext4 defaults 00
UUID=12d19b6a-eb43-4e35-88a3-ebf3e11f686d /new ext4 defaults
00
tmpfs /dev/shm tmpfs defaults 00
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 00
proc /proc proc defaults 00

<ESC>
:wq!
[root@server1 ~]#mkdir /new …….<PRESS ENTER>
[root@server1 ~]#mount –t ext4 /dev/sda10/new …….<PRESS
ENTER>
[root@server1 ~]#mount …….<PRESS ENTER>
/dev/sda5 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda7 on /home type ext4 (rw)
/dev/sda8 on /tmp type ext4 (rw)
/dev/sda2 on /usr type ext4 (rw)
/dev/sda3 on /var type ext4 (rw)
/dev/sda9 on /acl type ext4 (rw)
/dev/sda10 on /new type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/RHEL_6.0 i386 Disc 1 type iso9660
(ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmod
e=0500)

10. To umount a partition.


[root@server1 ~]# umount /dev/sda10 …….<PRESS ENTER>
[root@server1 ~]# mount …….<PRESS ENTER>
/dev/sda5 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sda7 on /home type ext4 (rw)
/dev/sda8 on /tmp type ext4 (rw)
/dev/sda2 on /usr type ext4 (rw)
/dev/sda3 on /var type ext4 (rw)
/dev/sda9 on /acl type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/RHEL_6.0 i386 Disc 1 type iso9660
(ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmod
e=0500)

11. To delete a partition.


[root@server1 ~]# fdisk /dev/sda …….<PRESS ENTER>

WARNING: DOS-compatible mode is deprecated. It's strongly recommended


to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): m …….<PRESS ENTER>


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): d …….<PRESS ENTER>


Partition number (1-10): 10 …….<PRESS ENTER>

Command (m for help): p …….<PRESS ENTER>

Disk /dev/sda: 42.9 GB, 42949672960 bytes


255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000d5093

Device Boot Start End Blocks Id System


/dev/sda1 * 1 131 1048576 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 131 1437 10485760 83 Linux
/dev/sda3 1437 2742 10485760 83 Linux
/dev/sda4 2742 5222 19921920 5 Extended
/dev/sda5 2742 2873 1048576 83 Linux
/dev/sda6 2873 3003 1048576 82 Linux swap / Solaris
/dev/sda7 3004 3134 1048576 83 Linux
/dev/sda8 3134 3160 204800 83 Linux
/dev/sda9 3160 3200 327200 83 Linux

Command (m for help): w …….<PRESS ENTER>


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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@server1 ~]# partx -a /dev/sda …….<PRESS ENTER>
or
[root@server1 ~]# init 6 …….<PRESS ENTER>

12. To view partition type.


[root@server1 ~]# fdisk /dev/sda …….<PRESS ENTER>

WARNING: DOS-compatible mode is deprecated. It's strongly recommended


to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): m …….<PRESS ENTER>
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): l …….<PRESS ENTER>

0 Empty 24 NEC DOS 81 Minix / old Lin bf


Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1
DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec
(FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6
DRDOS/sec (FAT-
4 FAT16<32M 41 PPC PReP Boot 85 Linux extended
c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-
FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M /
CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext
de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df
BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS
access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT
e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi
eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee
GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI
(FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0
Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1
SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4
SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot
f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb
VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc
VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap
fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe
LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1

Command (m for help): w …….<PRESS ENTER>


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 or after you run partprobe(8) or kpartx(8)
Syncing disks.

You might also like