Class: Getch::Disk

Inherits:
Object
  • Object
show all
Defined in:
lib/getch/disk.rb

Instance Method Summary collapse

Constructor Details

#initialize(disk, fs) ⇒ Disk

Returns a new instance of Disk.



3
4
5
6
7
# File 'lib/getch/disk.rb', line 3

def initialize(disk, fs)
  @hdd = disk
  @fs = fs
  @state = Getch::States.new()
end

Instance Method Details

#cleaningObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/getch/disk.rb', line 10

def cleaning
  return if STATES[:partition ]
  puts
  print "Cleaning data on #{@hdd}, can be long, avoid this on Flash Memory (SSD,USB,...) ? (n,y) "
  case gets.chomp
  when /^y|^Y/
    system("dd if=/dev/urandom of=/dev/#{@hdd} bs=4M status=progress")
  else
    return
  end
end

#formatObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/getch/disk.rb', line 36

def format
  return if STATES[:format]
  puts "Format #{@hdd} with #{@fs}"
  if Helpers::efi? then
    system("mkfs.fat -F32 /dev/#{@hdd}1")
    system("mkswap /dev/#{@hdd}2")
    system("mkfs.ext4 /dev/#{@hdd}3")
    system("mkfs.ext4 /dev/#{@hdd}4")
  else
    system("mkswap /dev/#{@hdd}2")
    system("mkfs.ext4 /dev/#{@hdd}3")
    system("mkfs.ext4 /dev/#{@hdd}4")
  end
  @state.format
end

#partitionObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/getch/disk.rb', line 22

def partition
  return if STATES[:partition]
  system("sgdisk --zap-all /dev/#{@hdd}")
  system("wipefs -a /dev/#{@hdd}")
  if Helpers::efi? then
    puts "Partition disk #{@hdd} for an EFI system"
    partition_efi
  else
    puts "Partition disk #{@hdd} for a Bios system"
    partition_bios
  end
  @state.partition
end