Wednesday, June 13, 2012

Chpt 6 - Linux Filesystem Administration


Storage Mgt and Partitions

[root@server01 etc]# fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x0002d481

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        7833    62401536   8e  Linux LVM

Disk /dev/mapper/vg_server01-lv_root: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00000000

Disk /dev/mapper/vg_server01-lv_root doesn't contain a valid partition table
Disk /dev/mapper/vg_server01-lv_swap: 4227 MB, 4227858432 bytes
255 heads, 63 sectors/track, 514 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: 0x00000000

Disk /dev/mapper/vg_server01-lv_swap doesn't contain a valid partition table
Disk /dev/mapper/vg_server01-lv_home: 5981 MB, 5981077504 bytes
255 heads, 63 sectors/track, 727 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: 0x00000000

Disk /dev/mapper/vg_server01-lv_home doesn't contain a valid partition table
[root@server01 etc]#

[root@server01 etc]# mount
/dev/mapper/vg_server01-lv_root 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,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg_server01-lv_home on /home 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)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
/dev/sr0 on /media/RHEL_6.1 x86_64 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500)


[root@server01 etc]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_server01-lv_root
                      51606140   6114864  42869836  13% /
tmpfs                  1027936       260   1027676   1% /dev/shm
/dev/sda1               495844     31945    438299   7% /boot
/dev/mapper/vg_server01-lv_home
                       5749032    142524   5314464   3% /home
/dev/sr0               3516418   3516418         0 100% /media/RHEL_6.1 x86_64 Disc 1
[root@server01 etc]#
[root@server01 etc]# df -haFilesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_server01-lv_root
                       50G  5.9G   41G  13% /
proc                     0     0     0   -  /proc
sysfs                    0     0     0   -  /sys
devpts                   0     0     0   -  /dev/pts
tmpfs                1004M  260K 1004M   1% /dev/shm
/dev/sda1             485M   32M  429M   7% /boot
/dev/mapper/vg_server01-lv_home
                      5.5G  140M  5.1G   3% /home
none                     0     0     0   -  /proc/sys/fs/binfmt_misc
sunrpc                   0     0     0   -  /var/lib/nfs/rpc_pipefs
gvfs-fuse-daemon         0     0     0   -  /root/.gvfs
/dev/sr0              3.4G  3.4G     0 100% /media/RHEL_6.1 x86_64 Disc 1


Using fdisk :
  • p examine partition table
  • n create new partition table
  • p or l (primary or logical)
  • e extended partition
  • w write partition table changes
  • m help menu
[root@server01 etc]# fdisk /dev/sda1
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xf614dc33.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
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): p
Disk /dev/sda1: 524 MB, 524288000 bytes
255 heads, 63 sectors/track, 63 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: 0xf614dc33

     Device Boot      Start         End      Blocks   Id  System
Command (m for help):
[root@server01 etc]# parted
GNU Parted 2.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)


(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 64.4GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  525MB   524MB   primary  ext4         boot
 2      525MB   64.4GB  63.9GB  primary               lvm

(parted)

(parted) help mkpart
  mkpart PART-TYPE [FS-TYPE] START END     make a partition

        PART-TYPE is one of: primary, logical, extended
        FS-TYPE is one of: ext4, ext3, ext2, fat32, fat16, hfsx, hfs+, hfs, jfs, swsusp, linux-swap(v1), linux-swap(v0), ntfs, reiserfs, hp-ufs, sun-ufs, xfs,
        apfs2, apfs1, asfs, amufs5, amufs4, amufs3, amufs2, amufs1, amufs0, amufs, affs7, affs6, affs5, affs4, affs3, affs2, affs1, affs0, linux-swap,
        linux-swap(new), linux-swap(old)
        START and END are disk locations, such as 4GB or 10%.  Negative values count from the end of the disk.  For example, -1s specifies exactly the last
        sector.

        'mkpart' makes a partition without creating a new file system on the partition.  FS-TYPE may be specified to set an appropriate partition ID.
(parted)

(parted) mklabel
New disk label type?


Filesystem Formats

Creating a swap partition with parted :

Added a 10 GB new virtual disk :

[root@server01 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table
[root@server01 ~]#
[root@server01 ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
121920 inodes, 487424 blocks
24371 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
60 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Create an ext4 partition first (practice) :

[root@server01 ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
New disk label type? msdos
(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? ext4
Start? 1MB
End? 500MB
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start   End    Size   Type     File system  Flags
 1      1049kB  500MB  499MB  primary
(parted)

(parted) mkpart
Partition type?  primary/extended? primary
File system type?  [ext2]? linux-swap
Start? 501MB
End? 1000MB
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start   End     Size   Type     File system  Flags
 1      1049kB  500MB   499MB  primary
 2      500MB   1000MB  500MB  primary
(parted)

[root@server01 ~]# mkswap /dev/sdb2
Setting up swapspace version 1, size = 488444 KiB
no label, UUID=9f4834c5-5901-45d8-9b0c-1c265c057721
[root@server01 ~]# swapon /dev/sdb2
[root@server01 ~]#

[root@server01 ~]# cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/dm-1                               partition       4128760 0       -1
/dev/sdb2                               partition       488440  0       -2
[root@server01 ~]#

Basic Linux Filesystems and Directories

Mount these directories as part of the root filesystem : /bin, /dev, /etc, /lib, /root, /sbin, /selinux

These dierctories may be on their own partitions :
/, /boot, /opt, /srv, /tmp, /var

LVM and LUKS Setup


NOTE : Show examples for parted using LVM

[root@server01 ~]# yum install gnome-disk-utility -y



Creating an ext4 filesystem on our new partition /dev/sdb1 :

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

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@server01 ~]#


 
Quick LVM Example :

[root@server01 ~]# fdisk /dev/sdb
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): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x00099af9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          61      487424   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2              61         122      488448   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (122-1305, default 122):
Using default value 122
Last cylinder, +cylinders or +size{K,M,G} (122-1305, default 1305): +2GB

Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x00099af9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          61      487424   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2              61         122      488448   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sdb3             122         365     1954966+  83  Linux

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


[root@server01 ~]# fdisk /dev/sdb
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): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x00099af9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          61      487424   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2              61         122      488448   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sdb3             122         365     1954966+  83  Linux

Command (m for help): 3
3: unknown command
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): t
Partition number (1-4): 3
Hex code (type L to list codes): L

 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
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

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 or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@server01 ~]#


[root@server01 ~]# pvcreate /dev/sdb3
  Device /dev/sdb3 not found (or ignored by filtering).


???

[root@server01 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 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: 0x00099af9

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1          61      487424   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sdb2              61         122      488448   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sdb3             122         365     1954966+  8e  Linux LVM

[root@server01 ~]# parted /dev/sdb
GNU Parted 2.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) set
Partition number? 3
Flag to Invert? lvm
New state?  on/[off]? on
Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb
(Device or resource busy).  As a result, it may not reflect all of your changes
until after reboot.
(parted)


 LUKS Example :

[root@server01 ~]# lsmod | grep dm_crypt
[root@server01 ~]# modprobe dm_crypt
[root@server01 ~]# lsmod | grep dm_crypt
dm_crypt               12988  0
dm_mod                 75539  12 dm_crypt,dm_mirror,dm_log
[root@server01 ~]#


[root@server01 ~]# yum install cryptsetup-luks -y
[root@server01 ~]# dd if=/dev/urandom of=/dev/sdb3
dd: writing to `/dev/sdb3': No space left on device
6303619+0 records in
6303618+0 records out
3227452416 bytes (3.2 GB) copied, 964.044 s, 3.3 MB/s
[root@server01 ~]#


[root@server01 ~]# cryptsetup luksFormat /dev/sdb3
WARNING!
========
This will overwrite data on /dev/sdb3 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter LUKS passphrase:
Verify passphrase:
Cannot format device /dev/sdb3 which is still in use.


Stop here with LUKS example, mayhaps needs an un-formatted partition ???
  

Hmmm ...come back to this little later , in a nutshell :

# pvcreate /dev/sdb3
# vgcreate vgDiskB3 /dev/sdb3
# vgextend vgDiskB3 /dev/sdb3
# lvcreate -L 200M vgDiskB3 -n flex

Command set for LVM manipulation is like : pv* , vg* , lv* , resize2fs,

GUI LVM Tool :

[root@server01 ~]# yum install system-config-lvm -y


NOTE : More later on LVM's frpom the book lab !!

[root@server01 ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system     Flags
 1      1049kB  500MB   499MB   primary  ext4
 2      500MB   1000MB  500MB   primary  linux-swap(v1)
 3      1000MB  3002MB  2002MB  primary                  lvm

[root@server01 ~]#

 OK finally fixed the LVM thing, had to reboot (go figure) :

[root@server01 ~]# pvcreate /dev/sdb3
  Physical volume "/dev/sdb3" successfully created

[root@server01 ~]# vgcreate vgDiskB3 /dev/sdb3
  Volume group "vgDiskB3" successfully created


[root@server01 ~]# vgextend vgDiskB3 /dev/sdb3
  Physical volume '/dev/sdb3' is already in volume group 'vgDiskB3'
  Unable to add physical volume '/dev/sdb3' to volume group 'vgDiskB3'.

oops, guess that is for adding extra PV's to my VG.

[root@server01 ~]# lvcreate -l 1 vgDiskB3 -n logvol3B
  Logical volume "logvol3B" created



Autofs files for autofs service :

/etc/auto.master
/etc/auto.misc
/etc/auto.net
/etc/auto.smb

[root@server01 ~]# service autofs status
automount (pid  1644) is running...


NOTE : Show a better example of Autofs with NFS later !!


No comments:

Post a Comment