Skip navigation

How to Resize LVM Root in Oracle Linux 7

 

Author: Dude!

 

 

 

1. About

This document explains how to resize the LVM root and home volumes in order to reclaim space to create additional files systems. The tasks includes a backup and restore in rescue mode to USB media using the xfsdump and xfsrestore utilities, and adding additional LVM volumes. The instructions are written for Red Hat Enterprise Linux 7 and apply to all derivatives. The system used in the example is a minimal Oracle Linux 7.3 installation on a 64 GB hard drive.

 

The information is provided under the terms and conditions of http://www.oracle.com/us/legal/terms/index.html.

Please do not plagiarize. Use on your own risk.

 

Copyright 2017, Dude@OTN

 

 

2. Analysis

 

Below example shows the space utilization of a minimal Oracle Linux 7.3 installation on a 64 GB hard drive. The installation was done using automatic partitioning and the installer created a 40 GB LVM root and a 20 GB home volume.

 

For the current project, the size of the root and home volumes are not necessary, and instead, 47 GB of disk space is needed to create additional LVM volumes named u01, u02 and u03. Volumes u02 and u03 should to be using an older EXT3 file system for reasons of application compatibility.

 

Analyze the disk space usage of the root and home file systems.

[root@ol1 ~]# df -PhT

Filesystem          Type      Size  Used Avail Use% Mounted on

devtmpfs            devtmpfs  2.0G     0  2.0G   0% /dev

tmpfs               tmpfs     2.0G     0  2.0G   0% /dev/shm@

tmpfs               tmpfs     2.0G  8.4M  2.0G   1% /run

tmpfs               tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup

/dev/mapper/ol-root xfs       40G  1.2G   39G   3% /

/dev/sda1           xfs      1014M  155M  859M  16% /boot

/dev/mapper/ol-home xfs        20G   33M   20G   1% /home

tmpfs               tmpfs     396M     0  396M   0% /run/user/0

 

Analyze current LVM volumes.

[root@ol1 ~]# lvs --segments -o +devices

  LV   VG Attr       #Str Type   SSize  Devices       

  home ol -wi-ao----    1 linear 19.39g /dev/sda2(992)

  root ol -wi-ao----    1 linear 39.72g /dev/sda2(5957)

  swap ol -wi-ao----    1 linear  3.88g /dev/sda2(0)  

 

 

The LVM volumes required are as following:

 

LVM VolumeCurrentUsedNewFS#
/dev/ol/root40 GB1.2 GB9 GBXFS- 31 GB
/dev/ol/home20 GB33 MB3 GBXFS- 17 GB
/dev/ol/u012 GBXFS+  2 GB
/dev/ol/u0215 GBEXT3+ 15 GB
/dev/ol/u0330 GBEXT3+ 30 GB

 

 

By reducing the LVM root volume to 9 GB and home to 3 GB, 48 GB of volume space can be reclaimed, which is enough to create volumes u01, u02 and u03. To avoid free space fragmentation however, both, root and home volumes will need to be relocated. A complete backup and restore of the root and home volume to external USB should be an appropriate safeguard and assist in the process.

 

 

Note:

Starting with RHEL 7 and consequently Oracle Linux 7,  XFS has become the default file system. According to XFS FAQ, it is not possible to reduce a XFS volume and the only way to shrink it is to do a complete dump, mkfs and restore.

 

 

3. Requirements

 

The following will be required:

 

  • Oracle Linux 7 standard installation DVD.
  • Direct or remote access to the physical server console.
  • External hard drive - 8 GB USB flash drive will be sufficient.

 

4. Rescue Mode

 

The LVM root volume cannot be removed while in use. It is therefore necessary to start the computer from external media and to access the system in rescue mode, also formerly known as single user mode. This will also quiescence the volumes and ensure no applications are running and no regular users are accessing the system when performing the backup and restore operations.

 

In order to start the computer from DVD or USB you may have to enter the PC boot menu, or change the boot order in the PC BIOS configuration. Please see the instruction manual of your computer for the details.

 

To start the computer into rescue mode, insert the standard Oracle Linux installation media and restart the computer.

If you are using VirtualBox, you can mount the ISO disk image and restart the guest OS.

 

Use the up and down arrow key to select Troubleshooting.

Screen Shot 2017-01-06 at 2.55.35 AM.jpg

 

Select Rescue a Oracle Linux system.

Select option 3 - Skip to shell.

Screen Shot 2017-01-06 at 3.00.41 AM.jpg

 

 

Tip:

If you are not fancy using the console, the following will let you connect using your ssh client from your desktop, assuming DHCP is available.

 

 

[anaconda root@localhost ~]# ip link show

[anaconda root@localhost ~]# ip link set enp0s3 down

[anaconda root@localhost ~]# dhclient enp0s3

[anaconda root@localhost ~]# ip address | grep global

[anaconda root@localhost ~]# ssh-keygen -t rsa -N "" -f /etc/ssh/ssh_host_rsa_key

[anaconda root@localhost ~]# /sbin/sshd -f /etc/ssh/sshd_config.anaconda

 

Screen Shot 2017-01-08 at 3.49.56 AM.jpg


After that, you should be able to connect with a ssh client. No prompt for password !!!

Screen Shot 2017-01-08 at 3.27.23 PM.jpg

 

 

 

5. Backup to USB

 

You will need a USB flash disk or hard drive in order to backup the LVM root and home volume.

Make it has enough capacity. As mentioned earlier, 8 GB should be sufficient.

 

Tip:To use USB in Oracle VirtualBox, attach the USB drive to your host system and select Settings from the VirtualBox Machine menu. Select Ports, then USB and add the USB device using the flash drive + symbol, where you can choose the device from the list of detected items. Press OK and unplug and re-insert the USB media so that VirtualBox can capture the device.

 

Plug in the USB device.

 

Determine the USB media device name (/dev/sdb).
[anaconda root@localhost ~]# dmesg | tac | grep -m 1 "removable"

[  658.877169] sd 3:0:0:0: [sdb] Attached SCSI removable disk ]

Partition and initialize the USB disk.

Warning: All existing data on the USB media will be erased!

[anaconda root@localhost ~]# parted -s /dev/sdb mklabel msdos mkpart primary 1 -- -1

[anaconda root@localhost ~]# parted -s /dev/sdb print

Model: SanDisk U3 Contour (scsi)

Disk /dev/sdb: 8213MB

Sector size (logical/physical): 512B/512B

Partition Table: mdse.

Disk Flags:
Number  Start   End     Size    Type     File system  Flags

1      1049kB  8212MB  8211MB  primary

Initialize partition no. 1, e.g.: /dev/sdb1

[anaconda root@localhost ~]# mkdosfs -n Linuxback -v -F 32 -I /dev/sdb1

mkfs.fat 3.0.20 (12 Jun 2013)

/dev/sdb1 has 253 heads and 62 sectors per track,

logical sector size is 512,

using 0xf8 media descriptor, with 16037888 sectors;

filesystem has 2 32-bit FATs and 8 sectors per cluster.

FAT size is 15632 sectors, and provides 2000824 clusters.

There are 32 reserved sectors.

Volume ID is 89cea7e0, volume label LINUXBACK  .

 

 

Mount the USB file system.

[anaconda root@localhost ~]# mkdir /mnt/usb

[anaconda root@localhost ~]# mount /dev/sdb1 /mnt/usb

 

[anaconda root@localhost ~]# df -hT /mnt/usb

Filesystem     Type  Size  Used Avail Use% Mounted on

/dev/sdb1      vfat  7.7G  4.0K  7.7G   1% /mnt/usb

Activate the LVM volumes.

[anaconda root@localhost ~]# vgchange -a y

3 logical volume(s) in volume group "ol" now active

[anaconda root@localhost ~]# lvscan

  ACTIVE            '/dev/ol/swap' [3.88 GiB] inherit

  ACTIVE            '/dev/ol/home' [19.39 GiB] inherit

  ACTIVE            '/dev/ol/root' [39.72 GiB] inherit

Mount LVM home and root and verify the correct file systems are mounted.

[anaconda root@localhost ~]# mkdir /mnt/root

[anaconda root@localhost ~]# mkdir /mnt/home

[anaconda root@localhost ~]# mount /dev/ol/root /mnt/root

[anaconda root@localhost ~]# mount /dev/ol/home /mnt/home

 

[anaconda root@localhost ~]# df -hT /mnt/home /mnt/root

Filesystem          Type  Size  Used Avail Use% Mounted on

/dev/mapper/ol-home xfs    20G   33M   20G   1% /mnt/home

/dev/mapper/ol-root xfs    40G  1.2G   39G   3% /mnt/root

 

 

Create a backup of the LVM root and home volume using the xfsdump utility.

 

When prompted for session and media label, simply enter "root" and "home".

(Below shows only partial output.)

[anaconda root@localhost ~]# xfsdump -f /mnt/usb/root.dmp /mnt/root

please enter label for this dump session (timeout in 300 sec)

-> root

please enter label for media in drive 0 (timeout in 300 sec)

-> root

xfsdump: media file size 1113760064 bytes

xfsdump: dump complete: 74 seconds elapsed

xfsdump: Dump Summary:

xfsdump:   stream 0 /mnt/usb/root.dmp OK (success)

xfsdump: Dump Status: SUCCESS

 

[anaconda root@localhost ~]# xfsdump -f /mnt/usb/home.dmp /mnt/home

please enter label for this dump session (timeout in 300 sec)

-> home

please enter label for media in drive 0 (timeout in 300 sec)

-> home

xfsdump: media file size 25600 bytes

 

xfsdump: dump complete: 2 seconds elapsed

xfsdump: Dump Summary:

xfsdump:   stream 0 /mnt/usb/home.dmp OK (success)

xfsdump: Dump Status: SUCCESS

 

Verify the results.

[anaconda root@localhost ~]# ls -l /mnt/usb

total 1088456

-rwxr-xr-x. 1 root root      25600 Jan  8 14:38 home.dmp

-rwxr-xr-x. 1 root root 1113760064 Jan  8 14:35 root.dmp

 

Unmount the USB backup, LVM root and home volumes.

[anaconda root@localhost ~]# umount /mnt/usb /mnt/root /mnt/home

 

 

 

6. Resizing LVM Root and Home

 

As mentioned earlier, XFS file systems cannot be resized and will essentially have to be erased and re-initialized.

 

Note:

Be sure to have completed the instructions so far. Do not continue if you do not have a backup of the LVM root and home volume, since the data is going to be deleted.

 

 

Deactivate and remove the LVM root and home volumes.

Warning: All data on these volumes will be lost!

[anaconda root@localhost ~]# vgchange -a n

  0 logical volume(s) in volume group "ol" now active

[anaconda root@localhost ~]# lvremove /dev/ol/root /dev/ol/home

  Logical volume "home" successfully removed

  Logical volume "root" successfully removed

 

Verify the physical LVM free volume space has increased.

[anaconda root@localhost ~]# pvs

  PV         VG Fmt  Attr PSize  PFree

  /dev/sda2  ol lvm2 a--  63.00g 59.12g

 

Recreate the LVM root and home volume.

Respond with "y" when prompted to wipe the previous XFS signature.

[anaconda root@localhost ~]# lvcreate -L 9G -n root ol

WARNING: xfs signature detected on /dev/ol/root at offset 0. Wipe it? [y/n]: y

  Wiping xfs signature on /dev/ol/root.

  Logical volume "root" created.

[anaconda root@localhost ~]# lvcreate -L 3G -n home ol

  Logical volume "home" created.


[anaconda root@localhost ~]# pvs

  PV         VG Fmt  Attr PSize  PFree

  /dev/sda2  ol lvm2 a--  63.00g 47.12g

 

 

Active LVM and show available LVM volumes.

[anaconda root@localhost ~]# vgchange -a y

  3 logical volume(s) in volume group "ol" now active

[anaconda root@localhost ~]# lvscan

  ACTIVE            '/dev/ol/swap' [3.88 GiB] inherit

  ACTIVE            '/dev/ol/root' [9.00 GiB] inherit

  ACTIVE            '/dev/ol/home' [3.00 GiB] inherit

 

Initialize and mount the LVM root and home volumes.
(Below shows only partial output.)

[anaconda root@localhost ~]# mkfs.xfs -L root /dev/ol/root

[anaconda root@localhost ~]# mkfs.xfs -L home /dev/ol/home

 

 

 

7. Restoring LVM Root and Home

 

Mount the LVM root and home volumes.

[anaconda root@localhost ~]# mount /dev/ol/root /mnt/root

[anaconda root@localhost ~]# mount /dev/ol/home /mnt/home

 

Verify that the correct volumes are mounted.

[anaconda root@localhost ~]# df -PhT /mnt/root /mnt/home

Filesystem          Type  Size  Used Avail Use% Mounted on

/dev/mapper/ol-root xfs   9.0G   33M  9.0G   1% /mnt/root

/dev/mapper/ol-home xfs   3.0G   33M  3.0G   2% /mnt/home

 

Mount the USB backup media.

[anaconda root@localhost ~]# mount /dev/sdb1 /mnt/usb

 

[anaconda root@localhost ~]# ls -l /mnt/usb

total 1088456

-rwxr-xr-x. 1 root root      25600 Jan  8 14:38 home.dmp

-rwxr-xr-x. 1 root root 1113760064 Jan  8 14:35 root.dmp

 

Restore the LVM root and home volumes.

(Below shows only partial output.)

[anaconda root@localhost ~]# xfsrestore -f /mnt/usb/root.dmp /mnt/root

xfsrestore: restore complete: 206 seconds elapsed

xfsrestore: Restore Summary:

xfsrestore:   stream 0 /mnt/usb/root.dmp OK (success)

xfsrestore: Restore Status: SUCCESS

 

[anaconda root@localhost ~]# xfsrestore -f /mnt/usb/home.dmp /mnt/home

xfsrestore: restore complete: 0 seconds elapsed

xfsrestore: Restore Summary:

xfsrestore:   stream 0 /mnt/usb/home.dmp OK (success)

xfsrestore: Restore Status: SUCCESS

 

Verify the result.

[anaconda root@localhost ~]# df -PhT

Filesystem          Type      Size  Used Avail Use% Mounted on

/dev/mapper/live-rw ext4      2.0G  1.1G  941M  53% /

devtmpfs            devtmpfs  2.0G     0  2.0G   0% /dev

tmpfs               tmpfs     2.0G  4.0K  2.0G   1% /dev/shm

tmpfs               tmpfs     2.0G  8.4M  2.0G   1% /run

tmpfs               tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup

/dev/sr0            iso9660   415M  415M     0 100% /run/install/repo

tmpfs               tmpfs     2.0G  380K  2.0G   1% /tmp

/dev/mapper/ol-root xfs       9.0G  1.2G  7.9G  13% /mnt/root

/dev/mapper/ol-home xfs       3.0G   33M  3.0G   2% /mnt/home

/dev/sdb1           vfat      7.7G  1.1G  6.6G  14% /mnt/usb

 

 

Make sure that there is no mismatch between the UUID of the actual device and the UUID used in the file system table (fstab) of the restored LVM root volume. If necessary, edit the file system table accordingly. Normally this is should not be necessary, because LVM root and home volumes are usually not mounted using their UUID value.

[anaconda root@localhost ~]# lsblk -o name,size,mountpoint,uuid /dev/sda

NAME        SIZE MOUNTPOINT UUID

sda          64G           

|-sda1        1G            433b636e-9b4a-4ea1-8960-6c2288433ac5

`-sda2       63G            hCDgtc-lOph-wvHY-Za5Q-VtY5-r0fo-JcKMsa

  |-ol-root   9G /mnt/root  16e712b1-c194-4591-83d1-41dc2a36d6b8

  `-ol-home   3G /mnt/home  45a6818a-b13e-4a21-806b-454394eba056

 

[anaconda root@localhost ~]# cat /mnt/root/etc/fstab

#

# /etc/fstab

# Created by anaconda on Sun Jan  5 17:30:10 2017

#

# 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

#

/dev/mapper/ol-root                       /      xfs     defaults        0 0

UUID=433b636e-9b4a-4ea1-8960-6c2288433ac5 /boot  xfs     defaults        0 0

/dev/mapper/ol-home                       /home  xfs     defaults        0 0

/dev/mapper/ol-swap                       swap   swap    defaults        0 0

 

 

Remove the Oracle Linux installation media and USB storage device.

 

Dismount all mounted volumes and restart the system.

[anaconda root@localhost ~]# umount /mnt/*

umount: /mnt/install: not mounted

umount: /mnt/sysimage: not mounted

 

[anaconda root@localhost ~]# reboot

 

 

Verify the result.

[root@ol1 /]# df -PhT

Filesystem          Type      Size  Used Avail Use% Mounted on

devtmpfs            devtmpfs  2.0G     0  2.0G   0% /dev

tmpfs               tmpfs     2.0G     0  2.0G   0% /dev/shm

tmpfs               tmpfs     2.0G  8.4M  2.0G   1% /run

tmpfs               tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup

/dev/mapper/ol-root xfs       9.0G  1.2G  7.9G  13% /

/dev/mapper/ol-home xfs       3.0G   33M  3.0G   2% /home

/dev/sda1           xfs      1014M  156M  859M  16% /boot

tmpfs               tmpfs     396M     0  396M   0% /run/user/0

 

 

8. Creating Additional LVM Volumes

 

It should now be possible to create the additional LVM volumes.

 

Analyze the LVM space.

[root@ol1 /]# lvs --segments -o +devices

  LV   VG Attr       #Str Type   SSize Devices       

  home ol -wi-ao----    1 linear 3.00g /dev/sda2(3296)

  root ol -wi-ao----    1 linear 9.00g /dev/sda2(992)

  swap ol -wi-ao----    1 linear 3.88g /dev/sda2(0)  

 

[root@ol1 /]# pvs

  PV         VG Fmt  Attr PSize  PFree

  /dev/sda2  ol lvm2 a--  63.00g 47.12g

 

Create new LVM volumes u01, u02 and u03.

[root@ol1 /]# lvcreate -L 2G -n u01 ol

  Logical volume "u01" created.

[root@ol1 /]# lvcreate -L 15G -n u02 ol

  Logical volume "u02" created.

[root@ol1 /]# lvcreate -L 30G -n u03 ol

  Logical volume "u03" created.

 

The LVM volume space should now be used, with only a small amount remaining.

[root@ol1 /]# pvs

  PV         VG Fmt  Attr PSize  PFree

  /dev/sda2  ol lvm2 a--  63.00g 124.00m

 

Initialize the new LVM volumes.

(Below shows only partial output.)

[root@ol1 /]# mkfs.xfs -L u01 /dev/ol/u01

 

[root@ol1 /]# mkfs.ext3 -L u02 /dev/ol/u02

 

[root@ol1 /]# mkfs.ext3 -L u03 /dev/ol/u03

 

Create mount points (/u01 /u02 /u03) and add the appropriate LVM volumes to the /etc/fstab file system table to mount during startup.

[root@ol1 /]# mkdir /u01 /u02 /u03

 

[root@ol1 /]# lvscan

  ACTIVE            '/dev/ol/swap' [3.88 GiB] inherit

  ACTIVE            '/dev/ol/root' [9.00 GiB] inherit

  ACTIVE            '/dev/ol/home' [3.00 GiB] inherit

  ACTIVE            '/dev/ol/u01' [2.00 GiB] inherit

  ACTIVE            '/dev/ol/u02' [15.00 GiB] inherit

  ACTIVE            '/dev/ol/u03' [30.00 GiB] inherit

 

Modify /etc/fstab accordingly.

[root@ol1 /]# cat /etc/fstab

#

# /etc/fstab

# Created by anaconda on Sun Jan  8 17:30:10 2017

#

# 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

#

/dev/mapper/ol-root                        /       xfs   defaults        0 0

UUID=433b636e-9b4a-4ea1-8960-6c2288433ac5  /boot   xfs   defaults        0 0

/dev/mapper/ol-home                        /home   xfs   defaults        0 0

/dev/mapper/ol-swap                        swap    swap  defaults        0 0

/dev/mapper/ol-u01                         /u01    xfs   defaults        0 0

/dev/mapper/ol-u02                         /u02    ext3  defaults        0 2

/dev/mapper/ol-u03                         /u03    ext3  defaults        0 2

 

Either restart the system or manually mount all devices listed in /etc/fstab.

[root@ol1 /]# mount -a

 

Verify the result.

[root@ol1 /]# df -PhT

Filesystem          Type      Size  Used Avail Use% Mounted on

devtmpfs            devtmpfs  2.0G     0  2.0G   0% /dev

tmpfs               tmpfs     2.0G     0  2.0G   0% /dev/shm

tmpfs               tmpfs     2.0G  8.4M  2.0G   1% /run

tmpfs               tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup

/dev/mapper/ol-root xfs       9.0G  1.2G  7.9G  13% /

/dev/mapper/ol-home xfs       3.0G   33M  3.0G   2% /home

/dev/sda1           xfs      1014M  156M  859M  16% /boot

tmpfs               tmpfs     396M     0  396M   0% /run/user/0

/dev/mapper/ol-u01  xfs       2.0G   33M  2.0G   2% /u01

/dev/mapper/ol-u02  ext3       15G   38M   14G   1% /u02

/dev/mapper/ol-u03  ext3       30G   44M   28G   1% /u03

 

 

That's it. Best of luck!

How To Convert a Linux System Disk to VirtualBox in Mac OS X

 

Author: Dude!

 

 

Disclaimer

 

This document is provided under the terms of http://www.oracle.com/us/legal/terms/index.html.

Please do not plagiarize. Use at your on risk. Thanks!

 

Abstract

 

Operating systems other than Linux do not support Linux LVM volumes and file systems. Accessing or analyzing the data on a Linux hard disk is therefore usually not feasible without running the original system. Computer virtualization can provide an easy solution for such scenarios in order to consolidate hardware, or access systems when hardware is not available.

 

The following instructions outline how to copy and convert a Oracle Linux 6 system hard disk to a virtual disk image and how to use it as a guest OS in VirtualBox. The task was performed on an Apple Mac Pro running OS X 10.9.5 and Oracle VirtualBox 5.0.16. Other software combinations or systems should work as well.

 

 

 

 

1. Connecting a hard drive

 

Attaching a hard drive to a computer obviously requires an appropriate hardware interface or suitable adapter. Most computers use IDE or SATA and offer USB to connect external devices. If the Linux hard drive is IDE or SATA, you may simply be able to replace the hard drive of an USB enclosure, or use a generic SATA/IDE to USB adapter. Such adapters are inexpensive and can be purchased from many online computer retail stores.

 

Your options to connect SCSI or SAS drives, which are common in enterprise servers systems and some workstations, are rather limited. Unless your computer is equipped with an extra SCSI or RAID host bus adapter, you will not be able to connect such drives directly, and probably not at all.

 

SCSI to Firewire or USB converters exist, but they are relatively expensive and primarily designed to connect older SCSI peripherals, such as a scanner. An external SCSI enclosure or appropriate adapter is still necessary to connect to the interface of a SCSI hard drive.

 

SAS is an evolution of SCSI and such controllers usually support also SATA drives, but SAS drives do not operate with SATA controllers and are keyed to prevent any chance of plugging them in incorrectly. There are simple SAS to SATA adapters, however, SAS drives will not work with SATA controllers.

 

The standard storage controller inside any Intel based Apple desktop or portable computer does not support SCSI or SAS drives. Searching on eBay or Amazon might be your best option to find converters and adapters, and depending on your Mac Pro model, find an appropriate host bus adapter card, such as the Apple RAID card, which supports SAS and SATA hard drives.

 

 

Note:As always, do not move any conventional or mechanical hard drive HDD while it is powered on, otherwise you may risk permanent damage of the disk and data.

 

 

 

2. Converting a hard disk to a virtual disk image

 

 

Note:

Copying and converting a complete hard disk can be time and disk space consuming. Make sure you have enough capacity in order not to use all your remaining free disk space and cause your computer system to malfunction. As a rule of thumb, you should always have at least 15 % of free disk space.

 

For example, to convert a 120 GB hard disk will require 120 GB plus the disk space that is actually being used on that hard drive, e.g. 30 GB. You would need more than 152 GB of free disk space on your computer for the task to complete successfully.  If you connect the hard drive via USB-2, you are not likely going to get more than 40 MB/s of data throughout, and converting a 120 GB hard disk will take at least 50 minutes.

 

 

After you have connected the hard drive to your Mac, it won't show up on the desktop, because Mac OS X does not recognize Linux LVM volumes or Linux file systems. It will display an initialization dialog instead. When prompted, choose Ignore.

 

Do not Initialize the disk, since this would erase it's contents.

 

Screen Shot 2016-12-30 at 10.55.35 AM.jpg

 

 

Open the Mac OS X Terminal application (Applications:Utilities).

 

Use the diskutil list  command to list all available disk devices. Your output may look similar to the following example:

 

Saturn:~ dude$ diskutil list

/dev/disk0

   #:                       TYPE NAME                    SIZE       IDENTIFIER

   0:      GUID_partition_scheme                        *1.0 TB     disk0

   1:                        EFI EFI                     209.7 MB   disk0s1

   2:          Apple_CoreStorage                         999.3 GB   disk0s2

   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

/dev/disk1

   #:                       TYPE NAME                    SIZE       IDENTIFIER

   0:                  Apple_HFS Saturn                 *999.0 GB   disk1

/dev/disk2

   #:                       TYPE NAME                    SIZE       IDENTIFIER

   0:     FDisk_partition_scheme                        *120.0 GB   disk2

   1:                      Linux                         524.3 MB   disk2s1

   2:                  Linux_LVM                         119.5 GB   disk2s2

 

 

The Linux hard disk in the above example is obviously disk2.

 

Enter the following commands to copy and convert the Linux hard disk to a VirtualBox disk image.

 

Tip:

Be sure to use /dev/rdisk and not /dev/disk as shown in the disk utility when using the dd command to copy the device. /dev/rdisk provides direct access to the physical hard disk and is not buffered or cached by the operating system, which in this particular case would slow down the copy processes drastically.

 

You can press control-t to display the current performance and status of the dd command:

 

For example:

 

$ sudo dd if=/dev/rdisk1 of=Linux120GB.raw bs=2m

load: 0.62  cmd: dd 2651 uninterruptible 0.00u 0.57s

370+0 records in

370+0 records out

775946240 bytes transferred in 19.262300 secs (40283156 bytes/sec)

 

You will need to supply your administrator password, or current password if you use an admin account already.

 

Saturn:~ dude$ cd

Saturn:~ dude$ cd Desktop

Saturn:Desktop dude$ mkdir hdconvert

Saturn:Desktop dude$ cd hdconvert

 

Saturn:Desktop dude$ diskutil unmountdisk disk2

Unmount of all volumes on disk1 was successful

Saturn:Desktop dude$ sudo dd if=/dev/rdisk2 of=Linux120GB.raw bs=2m

Password:

Saturn:Desktop dude$ sudo chown $USER Linux120GB.raw

Password:

 

Saturn:Desktop dude$ VBoxManage convertfromraw Linux120GB.raw Linux120GB.vdi

Converting from raw image file="Linux120GB.raw" to file="Linux120GB.vdi"...

Creating dynamic image with size 120034123776 bytes (114474MB)...

 

Saturn:Desktop dude$ open ./

 

 

To save disk space, delete the Linux120GB.raw file and empty the Trash. The file is no longer going to be used.

Screen Shot 2016-12-30 at 5.45.18 PM.jpg

 

 

The file with the .vdi extension is a special VirtualBox disk image. The VirtualBox utility will create a dynamic disk image, that will automatically expand as more disk space is required, until the disk image reaches the maximum capacity that was chosen when it was created, e.g.120 GB. The size of the Linux120GB.vdi disk image is the amount of data that was actually used, e.g. 26 GB.

 

 

3. Creating a virtual machine

 

 

Note:

Keep in mind that VirtualBox is a type 2 Hypervisor and running a 64-bit virtual machine or guest OS is mandatory in order to take advantage of hardware assisted virtualization (VT-x). The host OS as such is irrelevant. Using a 32-bit virtual machine template or running a x86 guest OS would operate in software emulation mode, which is less efficient.

 

All Intel based Apple Computers ship with a 64-bit CPU with virtualization enabled. Be sure to create a virtual machine template that matches the actual operating system contained in the virtual disk image created earlier.

 

 

Open VirtualBox.

Click the New button from the toolbar,

or select New from the Machine menu.

 

Depending on your previous settings, the next series of dialogs are going to be in Guided or Expert mode.

You can choose by pressing the Guided or Expert button. For simplicity, the following shows Expert mode.

 

Feel free to give the virtual machine any useful name, but be sure to create the correct VM template.

For example, Linux, Oracle 64-bit.

 

For general purpose, 2 GB of RAM should be sufficient.

Choose "Do not add a virtual hard disk".

Click the Create button.

 

Screen Shot 2017-01-01 at 3.35.18 PM.jpg

 

Open the VirtualBox application Preferences to locate the machine folder where to place the virtual disk image.

Screen Shot 2017-01-01 at 2.09.42 PM.jpg

 

By default, the virtual machine folder is inside your home folder.

 

Screen Shot 2017-01-01 at 2.15.23 PM.jpg

 

Move the virtual disk image, converted earlier, into the appropriate virtual machine folder.

 

Screen Shot 2017-01-01 at 3.28.22 PM.jpg

 

 

Open VirtualBox.

Select the virtual machine (single click) in the left window

Choose Settings from the toolbar.

Select Storage.

Click on the SATA controller.

Click on the rightmost square icon with a plus sign to add a virtual disk image.

Select the button Choose existing disk.

 

Screen Shot 2017-01-01 at 3.42.33 PM.jpg

 

Navigate to the machine folder of the virtual machine.

Select the virtual disk image, e.g. Linux120GB

Click Open.

 

Screen Shot 2017-01-01 at 3.48.10 PM.jpg

 

 

 

4. Configuring the virtual machine network

 

You can configure up to 4 virtual network adapters and combine their function, but keep in mind that you will need to understand how TCP/IP network routing works in combination with VirtualBox. You cannot arbitrarily assign a TCP/IP addresses or network and expect it to function.

 

To understand the purpose of the various network adapters, please review the VirtualBox documentation:

https://www.virtualbox.org/manual/ch06.html

 

Below is brief overview that may help you to choose the right adapter:

Screen Shot 2017-01-01 at 4.03.04 PM.jpg

 

 

Tip:

VirtualBox uses the NAT adapter by default and it should work out of the box. When using the NAT interface, connections from the guest OS will appear as connection from the host OS. Incoming connection to the guest OS under NAT are however rejected and shielded by design.

 

Keep in mind that the NAT adapter requires a dynamic TCP/IP address assigned by the VirtualBox internal router (DHCP) in order to function. If you do not need to connect to the guest OS by SSH, or provide any other service, but allow the guest OS to access the Internet, the NAT adapter should be fine.

 

If you do not wish to limit your connectivity options and maintain your own simple network, the bridged network adapter is usually the easiest to configure, and you can assign any TCP/IP address to your guest OS that is available within your host system network.

 

 

For simplicity, the following configures the VirtualBox bridged network adapter.

 

Open VirtualBox.

Select the virtual machine (single click)

Choose Settings from the toolbar.

Select the Network icon.

Change Attached to from NAT to Bridged Adapter.

Flip the Advanced switch to show further details.

Write down the MAC address - Note that O's are Zero's!

 

Screen Shot 2017-01-02 at 11.04.48 AM.jpg

 

Click the OK button.

 

 

Note:

Regardless of the type of network adapter you choose, the guest OS will have to use a different network adapter than the computer where the hard drive was initially installed. The hardware address of the network adapter (MAC address) will be different and require some adjustment.

 

It should work to obtain the MAC address of the network device that was configured in the previous computer and update the MAC address of the virtual network adapter accordingly, however, it is better to update the guest OS to avoid potential conflicts.

 

Start the virtual machine

Login as user root.

 

If you do not see the console, open a terminal command prompt.

 

[root@ol1 ~]# cd /etc/udev/rules.d

 

The file 70-persistent-net.rules belongs to the UDEV subsystem and assures persistent network adapter names across system restarts. It assigns network adapter names to physical MAC addresses and gets automatically populated when new network devices are detected during a system start up.

 

All entries in the current file belong to the previous computer system and are irrelevant. If there was already an entry for device eth0 from the previous system, the new network interface of the virtual machine will be assigned another name, e.g. eth1. For this reason, any existing TCP/IP configuration for eth0 will not function.

 

Simply delete or rename the file and let the system recreate it during the next system restart.

 

[root@ol1 rules.d]# mv 70-persistent-net.rules 70-persistent-net.rules.backup

[root@ol1 rules.d]# shutdown -h now

 

Note:

The virtual machine must shut down to recreate the udev network device entry for eth0. You should verify that the virtual machine network adapter was indeed assigned eth0 after the next system restart. If necessary, edit 70-persistent-net.rules accordingly.

 

After the next start up, device eth0 should reflect the MAC address of the virtual machine network adapter.

 

Screen Shot 2017-01-02 at 1.19.25 PM.jpg

 

If you had a previous TCP/IP setup, analyze the content of the eth0 configuration file and make appropriate adjustments.

 

[root@ol1 ~]# cd /etc/sysconfig/network-scripts

[root@ol1 network-scripts]# cat ifcfg-eth0

 

Edit the file ifcfg-eth0 to change the TCP/IP configuration according to your requirements.

 

Tip:

You can either remove or update HWADDR. If you update HWADDR, the value must match the MAC address of the virtual network adapter, using the correct 00:00:00:00:00:00 format.

 

You may need to change or remove the Gateway address, or change the default Gateway in /etc/sysconfig/network. If you do not specify any particular interface gateway, the default gateway will be used instead.

 

Your output may look similar to the following:

Screen Shot 2017-01-04 at 5.52.51 AM.jpg

 

Restart the guest OS:

 

[root@ol1 ~]# shutdown -r now

 

 

 

 

That's all. Best of luck!